tags:

views:

61

answers:

2

I have to generate roughly 18,000 PDFs that contain sensitive information. The PDFs will be served up through a web application to the end users. Obviously, some users need to see more reports than others. The two ways I'm thinking of serving up the PDFs are physically saving each PDF to a directory under the web application or storing the PDF in the database. The PDFs need to be viewable only by those authorized and I don't want users to guess URLs to see other users information. But I'm a little hesitant to put this information in a database.

Is one way preferred over the other?

+6  A: 

A PDF in the database is no more secure than a PDF on the disk when both are served through the same website. Unless you're allowing your web server to service the requests for the PDF just like any resource on disk. Which, in your case, would be a bad idea.

I've worked on a project with similar requirements. Our documents are stored on disk (not accessible directly via URL in the website), and their locations and security information is stored in a database.

When a request comes in for a document, I determine if the user has rights to the document (queries to the database) and if so, I get the file location out and deliver the file directly over the response stream.

Will
Also ensure to enable the 'no save' and 'no print' options when generating the PDF's.
Corey Downie
You are aware that those options are only suggestions?
Stephan Eggermont
Yeah, anybody can right-click the link that delivers the pdf (or construct a URL) and save it to the disk directly. And you can print anything you can see (see:snipping tool)
Will
+2  A: 

Don't store the PDFs in the document tree. Put them somewhere else on the drive where there is no way a user can type in the URL because there is no URL. Then retrieve the data programmatically only AFTER verifying that the user is authorized to see it, and feed the bytes back from the program.

Alternatively, you could create a separate directory in the document tree for each user and put passwords on those directories using the web server security, like Apache basic authentication or whatever the equivalent is on your server. This might be simpler, but if user can share documents in inconsistent combinations, i.e. Al and Bob can see #1, Al and Cathy can see #2, Cathy and Dave can see #3, etc, this won't work.

Jay
Definitely, don't put the files under the document root - it just means that you _have to_ restrict access to portions of the tree. And depending on your HTTP server, it could make backup/restore more straightforward.
NVRAM