4 ms·
It's definitely brute force, in that it's the equivalent of printing a document onto paper and then scanning it back in. This "flattening" is highly effective a
by userbinator 7y ago
It's definitely brute force, in that it's the equivalent of printing a document onto paper and then scanning it back in. This "flattening" is highly effective at sanitising, but also removes all the semantic content in the process; the output should be several times larger than the input (and if it isn't, then it's an indication that something very suspicious was in the input....)
- necovek 7y agoIndeed, I was hoping for something smarter, that would remove only the "risky" bits of PDF, but keep the overall structure (and size).
- heartbeats 7y agoWhat about converting PDF to PostScript and back? It should keep most of the semantic information while removing the exploits.
- necovek 7y agoYeah, perhaps. The "gruntwork" would be to figure out if that is sufficient. Heck, taking your idea further, perhaps convert to something non-derivative like HP's PCL5 and back. Or SVG or...
- est31 7y agoIIRC this is also how Firefox is doing it for its pdf.js print feature: https://github.com/mozilla/pdf.js/blob/master/web/pdf_print_service.js https://github.com/mozilla/pdf.js/blob/master/web/pdf_print_... Which is why when you print a PDF from Firefox, it doesn't look very nice. But it's safer than sending unsanitized PDFs to printers.