Prompt
I'm building a compliance tool that has to process PDFs securely
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
Here’s a practical security checklist for processing PDFs in a compliance tool:
1) Treat PDFs as untrusted input
- Assume PDFs can be malformed or malicious.
- Parse with a hardened, maintained library.
- Never trust embedded metadata, filenames, or extracted text.
2) Isolate PDF processing
- Run parsing/conversion in a sandboxed worker, container, or VM.
- Use least privilege: no network, read-only filesystem, minimal OS capabilities.
- Set CPU, memory, and wall-clock time limits to prevent DoS via zip-bomb-like PDFs or huge objects.
3) Disable active content and risky features
- Block JavaScript, launch actions, external links, embedded files, forms if not needed.
- Prevent auto-loading remote resources.
- Strip attachments and annotations unless explicitly required.
4) Protect against common PDF attacks
- Validate structure and file size before deep parsing.
- Defend against:
- Recursive object graphs
- Oversized streams
- Image bombs
- Font parsing bugs
- Incremental update trickery
- Encryption/password edge cases
- Keep libraries patched; PDF parsers often have CVEs.
5) Secure rendering and OCR pipelines
- If converting PDFs to images or text:
- Use a separate isolated service.
- Limit DPI and page dimensions.
- Sanitize image inputs after rendering too.
- For OCR, assume the OCR engine is also untrusted if it processes user-controlled files.
6) Handle sensitive data carefully
- Encrypt documents at rest and in transit.
- Control access with strong authn/authz and audit logging.
- Avoid logging raw PDF contents or extracted PII.
- Redact sensitive fields in outputs and debug logs.
7) Validate outputs
- Extracted text and metadata should be normalized and escaped before use in HTML, SQL, JSON, or shell commands.
- Treat filenames and metadata as hostile to prevent injection/XSS/path traversal.
8) Build operational safeguards
- Rate limit uploads and processing.
- Virus/malware scan files if appropriate, but don’t rely on scanning alone.
- Monitor for crashes, hangs, memory spikes, and repeated parse failures.
- Keep a quarantine path for suspicious documents.
9) Prefer safer architectures
- If possible, use:
- A stateless document processing microservice
- Queued asynchronous processing
- Ephemeral workers that are destroyed after use
- Never process PDFs in the main web app process.
10) Test offensively
- Add a corpus of malicious PDFs and fuzz your parser.
- Include regression tests for known CVEs and edge cases.
- Verify sandbox escape resistance and timeout behavior.
If you want, I can turn this into:
- a secure reference architecture,
- a threat model for PDF ingestion, or
- a concrete implementation checklist for your stack (e.g., Python/Java/.NET/Node).