CVE-2026-31938: jsPDF HTML Injection Vulnerability in New Window Paths

jspdf Updated 17 Mar 2026

Summary

17/03/2026
Yes i
Critical
9.6

CVE-2026-31938: jsPDF has HTML Injection in New Window paths. Affects jspdf versions < 4.2.1. Fixed in 4.2.1. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

jsPDF is a popular open-source library used for generating PDF documents in web applications. It allows developers to create PDFs directly in the browser using JavaScript. The library offers various functionalities, including text, images, and shapes rendering, and supports multiple output formats. However, a critical vulnerability has been identified in certain output methods that can lead to HTML injection, posing significant security risks to users.

Vulnerability Detail

The vulnerability arises from user control over the 'options' argument of the 'output' function in jsPDF. Attackers can inject arbitrary HTML, including scripts, into the browser context where the generated PDF is opened. This is particularly concerning for the overloads 'pdfobjectnewwindow', 'pdfjsnewwindow', and 'dataurlnewwindow', where unsanitized user input can be exploited. By providing malicious values through a web interface, attackers can craft a scenario where victims unknowingly execute harmful scripts in their browsers, potentially leading to data theft or unauthorized actions.

How To Fix

Latest published version: 4.2.1 as of 23 Oct 2026

npm install jspdf@4.2.1

The newest release already contains this fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary measure, sanitize all user inputs before passing them to the output method. For example, you can use a function to escape potentially harmful characters in the input:

function sanitizeInput(input) {
  return input.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

const safeFilename = sanitizeInput(userProvidedFilename);

doc.output('pdfjsnewwindow', {
  filename: safeFilename,
  pdfJsUrl: 'viewer.html'
});

Conclusion

The jsPDF library has a critical vulnerability that allows for HTML injection through certain output methods. It is essential to update to the patched version 4.2.1 to mitigate the risks associated with this vulnerability. Additionally, implementing input sanitization can serve as a temporary measure until the update is applied.

See every vulnerability recorded for jspdf →

Share this vulnerability

FAQ

The vulnerability has a CVSS score of 9.6, indicating it is critical and poses a significant risk to users.

You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. Check your application using the Vulert playground at Vulert Scanner without any signup.

If exploited, attackers can inject scripts that run in the victim's browser context, leading to data theft, unauthorized actions, or other malicious activities.

Yes, the vulnerability has been fixed in jsPDF version 4.2.1. It is recommended to update to this version or later.

If immediate updating is not possible, ensure to sanitize all user inputs before passing them to the output method as a temporary workaround.

Related vulnerabilities

Recent vulnerabilities recorded for jspdf.

How To Fix

Latest published version: 4.2.1 as of 23 Oct 2026

npm install jspdf@4.2.1

The newest release already contains this fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback