Advisory Database
  • Advisories
  • Dependency Scanning
  1. npm
  2. ›
  3. jspdf
  4. ›
  5. CVE-2026-31938

CVE-2026-31938: jsPDF has HTML Injection in New Window paths

March 17, 2026 (updated March 19, 2026)

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'
});

References

  • github.com/advisories/GHSA-wfv2-pwc8-crg5
  • github.com/parallax/jsPDF
  • github.com/parallax/jsPDF/commit/87a40bbd07e6b30575196370670b41f264aa78d7
  • github.com/parallax/jsPDF/releases/tag/v4.2.1
  • github.com/parallax/jsPDF/security/advisories/GHSA-wfv2-pwc8-crg5
  • nvd.nist.gov/vuln/detail/CVE-2026-31938

Code Behaviors & Features

Detect and mitigate CVE-2026-31938 with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →

Affected versions

All versions before 4.2.1

Fixed versions

  • 4.2.1

Solution

Upgrade to version 4.2.1 or above.

Impact 9.6 CRITICAL

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

Learn more about CVSS

Weakness

  • CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Source file

npm/jspdf/CVE-2026-31938.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Tue, 24 Mar 2026 12:17:07 +0000.