<p>My boss has come to me and asked how to enure a file uploaded through web page is safe. He wants people to be able to upload pdfs and tiff images (and the like) and his real concern is someone embedding a virus in a pdf that is then viewed/altered (and the virus executed).  I just read something on a procedure that could be used to destroy stenographic information emebedded in images by altering least sifnificant bits.  Could a similar process be used to enusre that a virus isn't implanted?  Does anyone know of any programs that can scrub files?  </p>

<p>Update:
So the team argued about this a little bit, and one developer found a post about letting the file download to the file system and having the antivirus software that protects the network check the files there.  The poster essentially said that it was too difficult to use the API or the command line for a couple of products.  This seems a little kludgy to me, because we are planning on storing the files in the db, but I haven't had to scan files for viruses before.  Does anyone have any thoughts or expierence with this?</p>

<p><a href="http://www.softwarebyrob.com/2008/05/15/virus-scanning-from-code/" rel="nofollow noreferrer">http://www.softwarebyrob.com/2008/05/15/virus-scanning-from-code/</a></p>

[{'answer_id': 33100, 'author': 'pix0r', 'author_id': 72, 'author_profile': 'https://Stackoverflow.com/users/72', 'pm_score': 3, 'selected': True, 'text': '<p>I\'d recommend running your uploaded files through antivirus software such as <a href="http://www.clamav.net/" rel="nofollow noreferrer">ClamAV</a>.  I don\'t know about scrubbing files to remove viruses, but this will at least allow you to detect and delete infected files before you view them.</p>\n'}, {'answer_id': 33108, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 1, 'selected': False, 'text': "<p>You'd probably need to chain an actual virus scanner to the upload process (the same way many virus scanners ensure that a file you download in your browser is safe).</p>\n\n<p>In order to do this yourself, you'd have to keep it up to date, which means keeping libraries of virus definitions around, which is likely beyond the scope of your application (and may not even be feasible depending on the size of your organization).</p>\n"}, {'answer_id': 33125, 'author': 'pix0r', 'author_id': 72, 'author_profile': 'https://Stackoverflow.com/users/72', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, ClamAV should scan the file regardless of the extension.</p>\n'}, {'answer_id': 33194, 'author': 'markus', 'author_id': 3498, 'author_profile': 'https://Stackoverflow.com/users/3498', 'pm_score': 2, 'selected': False, 'text': '<p>It depends on your company\'s budget but there are hardware devices and software applications that can sit between your web server and the outside world to perform these functions.  Some of these are hardware firewalls with anti-virus software built in. Sometimes they are called application gateways or application proxies.</p>\n\n<p>Here are links to an open source gateway that uses Clam-AV:\n<a href="http://en.wikipedia.org/wiki/Gateway_Anti-Virus" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Gateway_Anti-Virus</a>\n<a href="http://gatewayav.sourceforge.net/faq.html" rel="nofollow noreferrer">http://gatewayav.sourceforge.net/faq.html</a></p>\n'}, {'answer_id': 55384, 'author': 'tqbf', 'author_id': 5674, 'author_profile': 'https://Stackoverflow.com/users/5674', 'pm_score': 2, 'selected': False, 'text': '<p>Viruses embedded in image files are unlikely to be a major problem for your application. What will be a problem is JAR files. Image files with JAR trailers can be loaded from any page on the Internet as a Java applet, with same-origin bindings (cookies) pointing into your application and your server.</p>\n\n<p>The best way to handle image uploads is to crop, scale, and transform them into a different image format. Images should have different sizes, hashes, and checksums before and after transformation. For instance, Gravatar, which provides the "buddy icons" for Stack Overflow, forces you to crop your image, and then translates it to a PNG.</p>\n\n<p>Is it possible to construct a malicious PDF or DOC file that will exploit vulnerabilities in Word or Acrobat? Probably. But ClamAV is not going to do a very good job at stopping those attacks; those aren\'t "viruses", but rather vulnerabilities in viewer software. </p>\n'}, {'answer_id': 763265, 'author': 'Alex F', 'author_id': 92471, 'author_profile': 'https://Stackoverflow.com/users/92471', 'pm_score': 0, 'selected': False, 'text': '<p>Use a reverse proxy setup such as</p>\n\n<p>www &lt;-> <strong>HAVP</strong> &lt;-> webserver</p>\n\n<p>HAVP (<a href="http://www.server-side.de/" rel="nofollow noreferrer">http://www.server-side.de/</a>) is <strong>a way to scan http traffic</strong> though ClamAV or any other commercial antivirus software. It will prevent users to download infected files.\nIf you need https or anything else, then you can put another reverse proxy or web server in reverse proxy mode that can handle the SSL before HAVP</p>\n\n<p>Nevertheless, it does not work at upload, so it will not prevent the files to be stored on servers, but <strong>prevent the files from being downloaded and thus propagated</strong>. So use it with a regular file scanning (eg clamscan).</p>\n'}]
['https://Stackoverflow.com/questions/33086', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1942/']