Summary
jsPDF's output function previously allowed untrusted values in the options argument to be embedded as HTML in the PDF viewer context, enabling script injection when the PDF is opened in a browser.
When applications pass attacker-controlled output options to jsPDF and users open the resulting PDF in their browser, injected scripts can execute in the victim's browser context and access or modify sensitive data.
Affected context
This vulnerability affects web applications that:
- Use jsPDF to generate PDFs client-side in the browser
- Accept user-controllable input that is passed into
jsPDF.output()asoptions - Provide workflows where victims open generated PDFs in their own browser (e.g., preview, download-and-open, or in-browser PDF viewer)
The issue surfaces when output options can influence HTML or URL-like contexts used to render or open the generated PDF, and those values are not validated or sanitized before use.
Exploit preconditions
- Attack surface: Web applications that expose PDF generation features via jsPDF in the browser.
- Required access: Ability for an attacker to supply or influence values passed into the
optionsargument ofjsPDF.output()(forms, query parameters, API data, or UI-driven configuration). - Trigger point: The victim generates a PDF using one of the affected
outputAPI overloads and then opens the generated PDF in their browser (e.g., popup window, iframe, or built-in viewer). - Why exploitation is possible: jsPDF trusted the
optionsargument and used it in HTML-related contexts without proper sanitization or encoding, allowing attacker-controlled data to become executable script in the PDF viewer environment.
Why this happens
The core issue is untrusted data flowing into HTML or browser execution contexts without appropriate sanitization or context-aware encoding.
In jsPDF, certain overloads of the output method used fields from the options argument to construct or influence how the generated PDF is opened or embedded in the browser.
Because these options could be derived from user-controlled input and were not sanitized, an attacker could craft values that break out of their intended context and introduce script execution.
This aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where application logic fails to neutralize untrusted input before including it in web content that the browser interprets.
Potential impact
- Execution of arbitrary JavaScript in the victim's browser when they open the generated PDF
- Theft or exfiltration of sensitive data accessible in the victim's browser context (session tokens, CSRF tokens, local storage, or page content)
- Unauthorized actions performed on behalf of the victim within the application (e.g., state changes, data manipulation)
- Pivoting to further attacks in the same origin, including tampering with UI, injecting phishing overlays, or modifying application behavior
- Potential compromise of adjacent browser-accessible resources if they share the same origin or trust the compromised context
General mitigation guidance
Mitigation generally focuses on enforcing strict trust boundaries around user input and ensuring that untrusted data never directly controls HTML, URLs, or script-adjacent parameters:
- Treat all data that can reach
jsPDF.output()options as untrusted, regardless of source (forms, APIs, stored values). - Apply robust, context-aware sanitization to any fields that influence how the PDF is rendered or opened (e.g., HTML snippets, window targets, URLs, or names).
- Prefer safe, fixed configuration for
outputoptions where possible, avoiding dynamic values derived from user-controlled sources. - Introduce allowlists for permissible option values (e.g., specific output modes, fixed window names) instead of passing arbitrary strings through.
- Isolate PDF viewing and generation flows, avoiding situations where attacker-controlled HTML or script can execute in privileged or sensitive origins.
- Apply the principle of least privilege in the front-end: minimize exposure of sensitive data in the same browser context that renders attacker-reachable PDFs.
How teams detect issues like this
Detection can focus on code paths where user input flows into jsPDF output options or similar rendering parameters:
- Static analysis and code scanning:
- Flag calls to
jsPDF.output()where any argument (especially theoptionsobject) originates from request parameters, form inputs, or other tainted sources. - Detect patterns where user data is concatenated into HTML strings, window names, or URLs associated with PDF display or download.
- Enforce rules that prohibit passing raw user input into HTML-generating utilities without sanitization or encoding.
- Code review practices:
- During review, trace data that influences jsPDF configuration, especially
outputoptions, and verify it is validated and sanitized. - Look for "glue code" that automatically maps user-facing configuration fields into jsPDF options without explicit checks.
- Pay attention to functions that open PDFs in new windows, iframes, or inline viewers, and ensure no attacker-controlled HTML or script can be introduced.
- Policy and tooling:
- Adopt secure coding guidelines for client-side PDF generation and XSS prevention, and enforce them via linters or CI checks.
- Use automated SAST or security linters configured to recognize common XSS sinks in the front-end, including library APIs like jsPDF.

