We develop a web app that will start accepting pdf uploads, which will be stored and distributed to other users. Pdfs seem remarkably unsafe still. How can I scan and reject any pdf that does anything beyond representing a printable document? No forms, no javascript, no embedded executables, no shell commands. Are there tools?

  • Given that Postscript is a full-on programming language, and that you can't predict what any given PDF generator is going to put into the PDF files, the best you may be able to do is run a virus-scanner and hope. Jul 24, 2018 at 11:10
  • 3
    IMHO, Postscript is not the issue - its been a very long time since there were any vulnerabilities found there and it runs in a well defined sandbox - OTOH, a PDF can contain javascript (usual source of vulnerabilities) jpeg images (several vulns in Microsoft) and EPS (a couple of vulns in Microsoft) and flash (oh dear)
    – symcbean
    Jul 24, 2018 at 11:26
  • 2
    @bbsimonbb: I've not flagged this as a duplicate (since you explicit ask how to validate files rather than how to make them safe) - but this may be relevant: security.stackexchange.com/questions/103323/…
    – symcbean
    Jul 24, 2018 at 11:30
  • @symcbean that's a very useful link thanks. I thought it would be easier to screen and reject, rather than flatten, but I'm not finding the main road from here to there.
    – bbsimonbb
    Jul 24, 2018 at 12:38
  • Didier Sevens PDF tools ( blog.didierstevens.com/programs/pdf-tools )are useful for pulling apart PDF files which should allow you identify javascript and flash nasties - but you would probably consider jpeg images as valid. Unfortunately Microsoft has a history of problems with these files.
    – symcbean
    Jul 24, 2018 at 12:46

1 Answer 1


Validate it's really a pdf (eg it's not an EXE or JS etc). Do this via multiple methods such as file extension but also using magic text.

Antivirus solutions have command line or codeable scan checkers so AV scan the pdf before deciding to permanently store it on your system.

Train the users opening them on how to spot a phishing pdf and how to avoid clicking on security pop ups such as JavaScript execution or loading external resources.

You can use tools like Didier Stevens ones mentioned above to count number of JavaScript sections and if the pdf has any Javascript reject it on the spot and don't save it.

Do all your validation server side as client side such as JavaScript validation can always be bypassed.

Log everything so you know who uploaded a pdf and who viewed it

Have a process in place to quickly remove a Malicious process from the system if one is found

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .