/

CVE-2026-31938

Severity:

CRITICAL RISK

(9.6)

Cross-Site Scripting (XSS) in jsPDF PDF Generation

CVE-2026-31938

Modified

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Arbitrary Script Execution in Victim's Browser Context

Severity:

CRITICAL RISK

(9.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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() as options
  • 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 options argument of jsPDF.output() (forms, query parameters, API data, or UI-driven configuration).
  • Trigger point: The victim generates a PDF using one of the affected output API 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 options argument 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 output options 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 the options object) 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 output options, 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.

Sources

SourceLink
github.comgithub.com/parallax/jsPDF/commit/87a40bbd07e6b30575196370670b41f264aa78d7
github.comgithub.com/parallax/jsPDF/releases/tag/v4.2.1
github.comgithub.com/parallax/jsPDF/security/advisories/GHSA-wfv2-pwc8-crg5
access.redhat.comaccess.redhat.com/errata/RHSA-2026:7110
access.redhat.comaccess.redhat.com/errata/RHSA-2026:7128
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-31938
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2448550
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-31938.json

Frequently asked

questions

Yes. If an application exposes PDF generation over the web and maps attacker-controlled data into jsPDF's output options, an attacker can craft inputs that cause script execution when a victim generates and opens the PDF in their browser.

The attacker needs the ability to influence or supply values that the application passes into jsPDF.output() options.

This might be as simple as filling out a form, sending data through an API, or leveraging any feature that stores and later reuses user input in PDF generation.

Avoid passing raw user input into jsPDF's output options and similar configuration surfaces.

Where dynamic values are truly needed, strictly validate them against allowlists, apply appropriate sanitization, and decouple them from any HTML or script-capable context used to render or open the PDF.

Establish a consistent XSS prevention strategy for the front-end:

  • Treat all client-supplied data as untrusted by default.
  • Use context-aware encoding or sanitization before inserting data into HTML, attributes, URLs, or JavaScript contexts.
  • Limit dynamic configuration of rendering libraries, preferring fixed, safe defaults.
  • Integrate security-focused code review and automated scanning into the development workflow to catch unsafe data flows early.
Find out what's already
exploitable in your codebase.