Summary
jsPDF's AcroForm module previously allowed user-controlled properties and methods to be embedded directly into generated PDFs without proper sanitization.
When untrusted data is passed into vulnerable AcroForm APIs, an attacker can inject arbitrary PDF objects, including JavaScript actions that execute when a victim interacts with form elements such as radio buttons.
Affected context
This vulnerability affects applications that use jsPDF (prior to 4.2.0) to generate interactive PDFs with AcroForm elements and that pass user-controlled data into AcroForm-related properties or methods.
The risk is highest when server-side or client-side code takes untrusted input (e.g., from web forms, query parameters, or imported data) and uses it directly to configure form fields, tooltips, actions, or other AcroForm metadata without validation or encoding.
In such setups, generated PDFs can contain attacker-specified PDF objects, including JavaScript actions that run when users display, hover over, or interact with specific form fields.
Exploit preconditions
- Attack surface: PDF generation workflows using jsPDF's AcroForm module (e.g., web apps that let users customize PDFs).
- Required access: Ability for an attacker to supply data that is passed into vulnerable AcroForm properties or methods without sanitization.
- Trigger point: Opening the crafted PDF in a viewer that supports embedded JavaScript actions; the malicious code can be triggered by user interactions such as hovering over or selecting a radio button.
- Why exploitation is possible: The library treats user-supplied values as trusted content and incorporates them into the PDF structure without proper output neutralization, enabling injection of raw PDF objects and action dictionaries.
Why this happens
The root cause is improper output neutralization of user-controlled data in jsPDF's AcroForm-related APIs.
Instead of treating user input as plain data that must be encoded or constrained to a safe subset, the implementation allows it to influence the structure of the PDF and be inserted directly into object definitions.
This aligns with CWE-116: Improper Encoding or Escaping of Output, where untrusted data is written to a complex output format (here, the PDF object graph) without sanitization.
Because PDF viewers can interpret specially crafted object structures and embedded JavaScript, this pattern gives attackers a path to inject active content into otherwise legitimate PDFs.
Potential impact
- Injection of arbitrary PDF objects and action dictionaries controlled by the attacker
- Execution of embedded JavaScript in compatible PDF viewers when a victim opens or interacts with the PDF
- Phishing and social engineering through malicious dialogs, redirects, or spoofed content inside the PDF
- Potential data exfiltration or keystroke capture within the limits of the PDF viewer's JavaScript sandbox
- Abuse of PDFs for malware delivery or as part of broader document-based attack chains
General mitigation guidance
Mitigation centers on reducing trust in user input and constraining how it is reflected into PDF structures:
- Treat all AcroForm-related inputs as untrusted and sanitize them to a strict, expected format (e.g., whitelisting allowed characters or patterns).
- Avoid allowing user input to define or modify low-level PDF structures, object references, or action fields; map user values only to simple, data-only fields.
- Implement robust output encoding for any content that is inserted into the PDF stream or object dictionaries so that control characters and PDF syntax tokens cannot be injected.
- Separate content configuration from behavior: do not expose PDF action or JavaScript-related options directly to untrusted users.
- Apply least privilege in surrounding workflows: avoid automatically opening generated PDFs in sensitive environments and communicate the risk of active content in PDFs to end users.
How teams detect issues like this
Detection typically involves identifying unsafe flows from untrusted input into PDF generation logic:
- Static analysis: Flag code paths where data from HTTP requests, form fields, or external files is passed directly into jsPDF AcroForm properties or methods without sanitization or encoding.
- Code review: Look for AcroForm-related calls (e.g., adding form fields, tooltips, or actions) that use raw user input, especially where strings are concatenated into object definitions or action-like fields.
- Security testing: Generate PDFs using adversarial or fuzzed input values and inspect the resulting PDF structure for unexpected objects, action dictionaries, or JavaScript sections.
- Policy enforcement: Introduce coding guidelines or automated checks that require explicit sanitization utilities to be used before passing data into PDF-generation routines, and enforce these rules in CI pipelines.

