jsPDF has HTML Injection in New Window paths
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": thepdfObjectUrloption and the entire options object, which is JSON-serialized and included verbatim in the generated HTML-string."pdfjsnewwindow": thepdfJsUrlandfilenameoptions"dataurlnewwindow": thefilenameoption
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.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| npm package | jspdf | < 4.2.1 | 4.2.1 |
References
- CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:L- Weakness (CWE)
CWE-79- Platform
- npm
- Package
jspdf- Disclosed
- 17.03.2026
- Updated
- 11.10.2026 10:22
Sources and licenses
OSV / GitHub Advisory Database - GHSA-wfv2-pwc8-crg5 - CC BY 4.0
Vulnerability history: jspdf
All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 15
- First → latest
- 03.2021 03.2026
- Without a fix
- 0
- Exploited in attacks
- 0
Severity breakdown
- Critical 2
- High 9
- Medium 4
Disclosures per year
- 2021: 3
- 2022: 0
- 2023: 0
- 2024: 0
- 2025: 2
- 2026: 10
-
jsPDF has HTML Injection in New Window paths this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.