CVE-2026-31938: Jspdf JsPDF Has HTML Injection Vulnerability

CRITICAL
Advisory Identifier: GHSA-wfv2-pwc8-crg5
CVSS 9.6
CWE-79
Published
Advisory Summary

CVE-2026-31938 is a CRITICAL (CVSS 9.6) jspdf has html injection vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Jspdf libraries in the npm ecosystem. The issue involves jspdf has html injection in new window paths. Remediation is available by upgrading affected packages to version 4.2.1.

CVE-2026-31938 at a Glance

CVE Identifier CVE-2026-31938
GHSA Identifier GHSA-wfv2-pwc8-crg5
Severity CRITICAL
CVSS v3.1 Base Score 9.6
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Jspdf
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.6

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:L).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability Low (A:L)

How to Fix CVE-2026-31938

To remediate this vulnerability, upgrade all affected Jspdf dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

jspdf fixed: 4.2.1
npm install jspdf@4.2.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls jspdf

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-31938, inspect your project dependencies using npm:

npm ls jspdf

Analyze the terminal output to locate any version of Jspdf in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.2.1), your application is affected.

Note: The npm ls jspdf command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Jspdf, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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.

CVE-2026-31938 Affected Jspdf Versions

1 component(s)
Fixed Versions:
4.2.1
Product / Package Ecosystem Affected Versions Fixed Version
jspdf
npm
< 4.2.1
4.2.1

References

Frequently Asked Questions

What is CVE-2026-31938?
CVE-2026-31938 is a security vulnerability in Jspdf involving jsPDF has HTML Injection in New Window paths under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Jspdf versions are affected?
Affected versions include releases prior to 4.2.1 across affected packages: jspdf.
What version fixes CVE-2026-31938?
Upgrading to 4.2.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is jspdf affected?
Yes, jspdf is affected in releases prior to 4.2.1. Upgrade your dependency to 4.2.1 or later.
What is the CVSS score of CVE-2026-31938?
CVE-2026-31938 has a CVSS v3.1 base score of 9.6 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:L.
What CWE is associated with CVE-2026-31938?
CVE-2026-31938 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2026-31938?
Run the dependency tree command: 'npm ls jspdf'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wfv2-pwc8-crg5",
  "modified" : "2026-03-19T21:00:33Z",
  "published" : "2026-03-17T17:07:59Z",
  "aliases" : [ "CVE-2026-31938" ],
  "summary" : "jsPDF has HTML Injection in New Window paths",
  "details" : "### Impact\n\nUser 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:\n\n* `\"pdfobjectnewwindow\"`: the `pdfObjectUrl` option and the entire options object, which is JSON-serialized and included verbatim in the generated HTML-string.\n* `\"pdfjsnewwindow\"`: the `pdfJsUrl` and `filename` options\n* `\"dataurlnewwindow\"`: the `filename` option\n\nThe 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.\n\nExample attack vector:\n\n```js\nimport { jsPDF } from 'jspdf';\nconst doc = new jsPDF();\n\nconst payload =  'x\\\"></iframe><script>window.__n=1</script><iframe src=\"';\n\ndoc.output('pdfjsnewwindow', {\n  filename: payload,\n  pdfJsUrl: 'viewer.html'\n});\n```\n\n### Patches\nThe vulnerability has been fixed in jspdf@4.2.1.\n\n### Workarounds\nSanitize user input before passing it to the output method.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "jspdf"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.2.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.2.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/parallax/jsPDF/security/advisories/GHSA-wfv2-pwc8-crg5"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-31938"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/parallax/jsPDF/commit/87a40bbd07e6b30575196370670b41f264aa78d7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/parallax/jsPDF"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/parallax/jsPDF/releases/tag/v4.2.1"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-17T17:07:59Z",
    "nvd_published_at" : "2026-03-18T04:17:23Z"
  }
}