PDF JavaScript detector — what's running inside the PDF and why most documents shouldn't have any
Most PDFs are static documents — text, images, vectors, sometimes form fields. A subset can also carry JavaScript: actual executable code that runs when the document is opened, when a form is submitted, when a link is clicked, when a button is pressed. Legitimate uses exist — form validation, dynamic field calculations, copy-protection schemes — but JavaScript inside a PDF is also a major vector for phishing, exfiltration, and tracker-pixel-style telemetry. Here is how PDFs can run code, the four trigger points the detector surfaces, and the patterns that distinguish benign automation from malicious payloads.
How JavaScript ends up inside a PDF
The PDF spec includes a JavaScript runtime — a subset of JavaScript intended for in-document interactivity. Code can be attached at four levels of granularity: at the document level (runs on open), at the page level (runs when a specific page is shown), at the field level (runs on field events like input or validation), and at the annotation level (runs when a link is clicked, a button is pressed, or a checkbox is toggled). The /Names tree, /OpenAction entry, every form field's /A (action) and /AA (additional action) dictionaries, and every annotation's /A and /AA dictionaries all carry potential script bindings.
The detector walks every one of these locations and surfaces every script binding it finds, along with the trigger (when the script fires) and the source code. Readers that don't run JavaScript (Chrome built-in PDF viewer, Firefox built-in, Edge built-in) ignore the scripts entirely — those readers are the safest for unknown PDFs. Acrobat, Foxit, Nitro each have their own JS engines that DO execute scripts.
Four trigger points the detector surfaces
Each trigger has different risk implications:
- Document open (/OpenAction). Runs as soon as the PDF is opened. Highest-risk trigger — a malicious page-load script can phone home, log open events, or fire credential-phishing prompts. Modern Acrobat prompts on JavaScript at open; users frequently click through without reading the prompt.
- Page load. Runs when a specific page is shown. Lower-frequency than open-action but still automatic. Used legitimately for context-specific form validation; used maliciously for paging-based tracking.
- Form submit and field events. Runs on form interaction. Most common legitimate use: client-side validation ("this field requires a 5-digit zip code") or calculated fields ("total = quantity × price"). Most common malicious use: data exfiltration via submitForm to an attacker-controlled URL.
- Annotation actions (link click, button press, checkbox toggle). Runs on explicit user action. The user clicked something; the script fires. Acrobat usually does NOT prompt for these even though they're scripts. Pre-flight inspection is essential because the script is hidden behind a normal-looking UI element.
Distinguishing benign from malicious
Reading scripts requires judgment. Three patterns that signal real risk:
- External URLs in any non-link-click trigger. Page-load or document-open scripts containing http:// or https:// strings are red flags. Legitimate validation scripts don't need to hit a server. Tracking pixels embedded as JavaScript do.
- submitForm to a domain different from the document's source. If you received the PDF from contoso.com and the submitForm sends to evil.example.org, that's exfiltration. Acrobat doesn't prompt for this.
- Eval, unescape, or string-concatenation that builds the actual script at runtime. Obfuscation. Legitimate scripts have no reason to construct themselves at runtime; this pattern is almost exclusively malicious.
When to strip vs when to keep
Three decision categories:
- Strip immediately. PDFs from unknown senders, PDFs flagged by security scanning, any of the three malicious-pattern signals above. Run Strip JavaScript (paid) or open in Acrobat Pro and use Sanitize Document.
- Keep and document. Legitimate forms with client-side validation. Internal documents from trusted creators where the JavaScript performs known automation. In these cases, the detector output goes into the compliance file alongside the document for future audit.
- Strip but archive the original. Documents being put into long-term archival storage. PDF/A forbids JavaScript; you have to strip. But if the original needs to be preserved for some reason, archive both versions.
What readers do with JavaScript
Reader-specific behavior matters for risk assessment:
- Adobe Acrobat (since v11). Prompts before executing JavaScript at document-open. Does NOT prompt for field / annotation triggers. Settings can disable JS entirely.
- Foxit, Nitro. Each has its own JS engine with similar prompt-on-open behavior but different defaults. Worth checking your organization's reader policy.
- Chrome / Edge / Firefox built-in PDF viewers. Do not execute PDF JavaScript at all. Safest for unknown PDFs — open in browser first, run through the detector to inventory the JS, then decide whether to open in Acrobat.
- macOS Preview. Limited JS support; many scripts simply don't fire. Reasonable middle-ground for casual PDF viewing.
Limits and compatibility
On the free web tool, the JavaScript detector handles PDFs up to 100 MB. Parsing runs in your browser via byte-level parsing; nothing is uploaded — important for forensic and threat-hunting workflows where the file itself IS the suspicious artifact. Output lists every script with trigger, source code, and host element. Exportable for inclusion in security reviews.
Common pairings: JS Detector → Strip JavaScript to remove findings. JS Detector → PDF Inspector for full structural audit of suspicious PDFs. JS Detector findings → flag the PDF for organizational quarantine before sharing further.