CVE-2026-31898: jsPDF Arbitrary PDF Object Injection via FreeText Color

jspdf Updated 17 Mar 2026

Summary

17/03/2026
Yes i
High
8.1

CVE-2026-31898: jsPDF has a PDF Object Injection via FreeText color. 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 Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

jsPDF is a popular open-source library used for generating PDF documents in web applications. It allows developers to create complex PDF files programmatically, offering features such as text, images, and annotations. However, a vulnerability exists in the library that permits users to inject arbitrary PDF objects, potentially leading to security risks when the generated PDF is opened or interacted with.

Vulnerability Detail

The vulnerability arises from the user-controlled arguments in the 'createAnnotation' method of jsPDF, specifically the 'color' parameter. This flaw allows an attacker to inject malicious PDF objects, including JavaScript actions, which could execute when the PDF is opened. For instance, an attacker could craft a payload that executes a command on the user's system, posing significant security threats.

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 'createAnnotation' method. For example, you can implement a function to validate and clean the 'color' parameter to prevent injection of malicious content. Here is a simple example of sanitization:

function sanitizeColor(input) {
  // Allow only hexadecimal color codes
  const regex = /^#[0-9A-F]{6}$/i;
  return regex.test(input) ? input : '#000000'; // Default to black if invalid
}

const safeColor = sanitizeColor(userInput);

doc.createAnnotation({
  type: 'freetext',
  bounds: { x: 10, y: 10, w: 120, h: 20 },
  contents: 'hello',

color: safeColor

});

Conclusion

In summary, the jsPDF library has a critical vulnerability that allows for arbitrary PDF object injection through unsanitized user input. It is essential to update to the patched version and implement input sanitization to protect against potential exploits.

See every vulnerability recorded for jspdf →

Share this vulnerability

FAQ

The vulnerability allows for arbitrary PDF object injection through unsanitized user input in the 'createAnnotation' method.

Attackers could inject malicious JavaScript actions that execute when the PDF is opened, potentially compromising user systems.

You can use Vulert's playground at Vulert Scanner to check if your application is affected without needing to sign up.

Update jsPDF to version 4.2.1 or later to mitigate the vulnerability and sanitize user inputs before passing them to vulnerable methods.

The CVSS score for this vulnerability is 8.1, indicating a high severity level.

Related vulnerabilities

Recent vulnerabilities recorded for jspdf.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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