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

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (0.48%). Schedule for your next planned update.

Does your project use an affected jspdf version?

Paste your package-lock.json to check it for CVE-2026-31938 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my package-lock.json

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:

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 (254 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, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: npm (1).

PackageFixed In
jspdf npm · Affected: 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. It has a 0.5% probability of exploitation within 30 days (EPSS score). 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

Maximum impact if exploited, often with little effort or access required.

EPSS Score (30-day exploit probability)
0.48%
EPSS percentile: 34

This is a below-median EPSS score — only 34% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.

Also Known As

GHSA-wfv2-pwc8-crg5

Related CVEs

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my package-lock.json