Solved

what is the danger in permitting members to upload documents to your database?

Posted on 2016-10-04
6
88 Views
Last Modified: 2016-10-06
We permit members to upload certain file types; pdf, docs, xlms, jpg and some other image file types  from our website into a database table where they are stored as a longblob (MySQL) and the documents/images can be viewed / downloaded by the member as well.

What is the danger of them introducing some malevolent code that would affect our database or our server?  What steps could we take to mitigate this?
0
Comment
Question by:Nemetona
  • 3
  • 3
6 Comments
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41829618
into a database table where they are stored as a longblob (MySQL)
I have never understood why one would want to store documents in a DB Table. The OS file system is a perfectly good store and far simpler than extracting blobs from a database. Best practice is store the document in the file system and the path in the database.

The danger is what you would expect from allowing content from untrusted sources onto your network.
Here are some things to consider
1. Assume all incoming documents are suspect and treat accordingly. Scan all incoming documents for malware
2. Store the documents outside of the webroot to prevent direct access to the documents
3. Store the path to the document in the database.
4. Limit uploads only to the document types you allow
5. Do not trust the extension or the mime type in the header - test the document to ensure it is of the claimed type.
0
 

Author Comment

by:Nemetona
ID: 41831584
Could you provide any pointers on "test the document to ensure it is of the claimed type. "
0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41831747
What is your scripting environment.
In PHP you would use something like finfo_file()
Code might look something like this
$allowedtypes = array(
  'text/html',
  'image/gif',
  'application/vnd.ms-excel'
);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimetype = finfo_file($finfo, $filename);
$valid = false;
foreach($allowedtypes as $t) {
    if ($mimetype == $t) {
      $valid = true;
      break;
     }
}
if (!$valid) {
   echo "File type not allowed ....";
}

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:Nemetona
ID: 41831768
Thank you for that.  We are using javascript.
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41831966
We are using javascript.
That is client side - what are you using to connect to MySQL?
0
 

Author Comment

by:Nemetona
ID: 41831972
java
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Online collaboration can help businesses be more efficient, help employees grow their skills and foster a team environment.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now