|
|
As a site owner, there is only so much you can do about it. The primary responsibility for protecting users from malicious documents lies with the software vendors who make the document viewers (e.g., Adobe, Microsoft, and potentially browser vendors). They are the ones with the opportunity to best help their users; your leverage is more limited.
That said, here are some steps you could/should take, to protect your users as best as possible:
Only allow whitelisted types of documents. Create a whitelist of MIME types, representing document formats that you consider relatively safe and important to support. (This whitelist might include, for example, PDF, Word, Powerpoint, Excel spreadsheets, etc., but not, e.g., native executables, Flash videos, zip or jar archives, HTML or Javascript, etc.) When the user uploads a document, check that it on the whitelist. When you serve this document to others, follow practices I've outlined elsewhere to defend against content-type sniffing attacks. The most important one is to set a correct Content-Type: header on the HTTP responses where you serve the image, using the previously validated MIME type. Also, include a X-Content-Type-Options: nosniff header, to prevent some versions of IE from trying to do content-type sniffing. In addition to defending against content-sniffing attacks, this will also prevent attackers from uploading other files that browser treat specially (e.g., crossdomain.xml, a HTML5 manifest file, and more).
Validate filenames. Perform sanity checks on filenames when they are uploaded. For instance, you might check that they match a regexp like [a-zA-Z-_!(),: ]*(\.[a-zA-Z]+)?. In particular, you want to rule out slashes (to protect against path traversal). Also, check that the extension (if present) seems to match the validated MIME type and is on a whitelist of known-safe extensions. You might want to check that the filename does not contain two extensions (e.g., foo.txt.exe), to prevent social engineering attacks.
Alternatively, you could generate a random filename for each document. This would be the most secure, but it might diminish usability. A third option is to replace the original filename only if the original filename doesn't pass your validity checks.
Optional: Scan file uploads for viruses or malware. When a file is uploaded, you might want to use a virus scanner to check for known viruses or malware. You could use a local virus scanner, but it might be even easier to upload it to VirusTotal. I would do this at upload time, and possibly also subsequently at periodic intervals (e.g., once every 1000 subsequent downloads, or once every week), as sometimes more recent virus definition files will catch more viruses in older documents. It would be fine to do this asynchronously or in batch mode, if that provides better performance; if the virus-check comes back a failure, you can always remove the file at that time.
Optional: Use a separate domain to host file uploads. You could host the documents on a separate domain that is used only to host user-uploaded documents. This will limit the impact of some browser-level attacks, such as content-type sniffing. However, this does not defend against code-injection attacks that exploit a vulnerability (e.g., a buffer overrun, a double-free) in a document viewer and let the attacker execute native code.
Put barriers to denial of service and spam. Put a limit on the maximum file size, to avoid getting overwhelmed with submissions. If you allow unauthenticated users to upload files, require the user to solve a CAPTCHA as part of the upload.
Optional: Detect out-of-date browsers and plugins. Scan the user's browser. If they are running an old browser (like IE6) or old plugins, consider providing a recommendation that they update, to protect themselves as they browse on the net. Here are some resources to help with that:
If you want to recommend IE6 users to update, IE6 Update makes it easy to add a little bit of code to your website that will detect users who are using IE6, and prompt them to update their browser.
If you want more flexibility about which browser versions will trigger a little notification encouraging the user to upgrade, take a look at browser-update.com.
If you must check for out-of-date or known-vulnerable plugins, the Mozilla plugin check may be useful. It supports Firefox, Safari, Chrome, and Opera, and partially supports IE. They also have a programmatic API to their plugin version database. Based on that, you could probably code something up to automatically check the user's plugins and if they have an out-of-date plugin for a document type you support (e.g., an old version of a Adobe PDF viewer plugin), you could trigger a notification to encourage the user to upgrade their plugin.
|
|
|
answered
Feb 22 '12 at 19:05
|
|