Loading...
Skip to main content

CVE-2026-31938 — jsPDF has HTML Injection in jspdf — CVE Details

CRITICAL

jsPDF has HTML Injection in New Window paths

Published March 17, 2026Updated September 10, 2026Source: osv

Summary

### Impact User control of the `options` argument of the `output` function allows attackers to inject arbitrary HTML (such as scripts) into the browser context the created PDF is opened in. The affected overloads and options are: * `"pdfobjectnewwindow"`: the `pdfObjectUrl` option and the entire options object, which is JSON-serialized and included verbatim in the generated HTML-string. * `"pdfjsnewwindow"`: the `pdfJsUrl` and `filename` options * `"dataurlnewwindow"`: the `filename` option The vulnerability can be exploited in the following scenario: the attacker provides values for the output options, for example via a web interface. These values are then passed unsanitized (automatically or semi-automatically) to the attack victim. The victim creates and opens a PDF with the attack vector using one of the vulnerable method overloads inside their browser. The attacker can thus inject scripts that run in the victims browser context and can extract or modify secrets from this context. Example attack vector: ```js import { jsPDF } from 'jspdf'; const doc = new jsPDF(); const payload = 'x\"></iframe><script>window.__n=1</script><iframe src="'; doc.output('pdfjsnewwindow', { filename: payload, pdfJsUrl: 'viewer.html' }); ``` ### Patches The vulnerability has been fixed in jspdf@4.2.1. ### Workarounds Sanitize user input before passing it to the output method.

Advisory Timeline

  • First published March 17, 2026 (209 days ago).
  • Last revised September 10, 2026 — 176 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

npm
Update jspdf to 4.2.1 or later
npm install jspdf@4.2.1

After upgrading, run your dependency scanner again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: npm (1).

PackageEcosystemAffectedFixed In
jspdf
npm
All versions4.2.1

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

  • CWE-79
    Cross-site Scripting (XSS)MITRE

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 9.6 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
Required
Scope
Changed
Confidentiality
High
Integrity
High
Availability
Low

CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:L

Frequently Asked Questions

What is CVE-2026-31938?
jsPDF has HTML Injection in New Window paths This vulnerability has been assigned a severity rating of CRITICAL (CVSS score: 9.6/10).
How do I check if my project is affected by CVE-2026-31938?
CVE-2026-31938 affects jspdf. Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-31938 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
9.6

Exploitation is straightforward and causes maximum impact. Patch immediately.

Also Known As

GHSA-wfv2-pwc8-crg5

Related CVEs

  • CVE-2026-107722
    CRITICAL

    fast-jwt: Incomplete patch of CVE-2026-34950: Non-whitespace key-prefix re-enables RSA→HS256 algorithm confusion

  • CVE-2026-108261
    CRITICAL

    TinaCMS admin preview iframe loads an attacker-controlled origin from the URL fragment

Check if you're affected

Scan your dependencies to see if this vulnerability affects your projects.

Scan Your Dependencies