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

Published Mar 17, 2026
·
Updated

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.

Other sources

jsPDF is a library to generate PDFs in JavaScript. Prior to version 4.2.1, 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 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. The vulnerability has been fixed in jspdf.1. As a workaround, sanitize user input before passing it to the output method.

Red Hat

jsPDF is a library to generate PDFs in JavaScript. Prior to version 4.2.1, 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 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. The vulnerability has been fixed in jspdf@4.2.1. As a workaround, sanitize user input before passing it to the output method.

MITRE

Affected Software

2 affected componentsFixes available
npm/jspdf<=4.2.0
4.2.1
parall jspdf Node.js<4.2.1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/jspdf to a version that resolves this vulnerability.

    Fixed in 4.2.1
  2. Upgrade

    Upgrade jspdf to a version that resolves this vulnerability.

    Fixed in 1
  3. Upgrade

    Upgrade jspdf to a version that resolves this vulnerability.

    Fixed in 4.2.1
  4. Configuration

    As a workaround, sanitize any user-controlled values before passing them to jsPDF's output() method, specifically the options used by the 'dataurlnewwindow' filename option, the 'pdfjsnewwindow' pdfJsUrl and filename options, and the 'pdfobjectnewwindow' pdfObjectUrl option (and the entire JSON-serialized options object).

    jsPDF output() (PDF new window paths: dataurlnewwindow/pdfjsnewwindow/pdfobjectnewwindow) options.filename / options.pdfJsUrl / options.pdfObjectUrl = sanitized user input only

Event History

Mar 17, 2026
Advisory Published
via GitHub·05:07 PM
Data Sourced
via GitHub·05:07 PM
DescriptionSeverityWeaknessAffected Software
Mar 18, 2026
CVE Published
via MITRE·03:05 AM
Data Sourced
via MITRE·03:05 AM
DescriptionSeverityWeakness
Data Sourced
via Red Hat·04:04 AM
DescriptionSeverityAffected Software
Data Sourced
via NVD·04:17 AM
RemedyDescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-31938?

CVE-2026-31938 is considered a high-severity vulnerability due to the potential for HTML injection leading to arbitrary script execution.

2

How do I fix CVE-2026-31938?

To mitigate CVE-2026-31938, upgrade jsPDF to version 4.2.1 or later.

3

What versions of jsPDF are affected by CVE-2026-31938?

CVE-2026-31938 affects jsPDF versions up to and including 4.2.0.

4

What type of attack is associated with CVE-2026-31938?

CVE-2026-31938 allows attackers to perform HTML injection attacks through user-controlled input.

5

What is the impact of CVE-2026-31938 on users?

The impact of CVE-2026-31938 includes potential unauthorized script execution in the user's browser when a PDF is opened.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203