CVE-2026-31898:
CVE-2026-31898
jsPDF is a library to generate PDFs in JavaScript. Prior to version 4.2.1, user control of arguments of the `createAnnotation` method allows users to inject arbitrary PDF objects, such as JavaScript a...
Overview
A significant security flaw, identified as CVE-2026-31898, has been discovered in the popular jsPDF library, which is used to generate PDF documents in web browsers and Node.js applications. This vulnerability is rated HIGH with a CVSS score of 8.1. It allows an attacker to inject malicious content into a generated PDF, potentially compromising anyone who opens the file.
What is the Vulnerability?
In simple terms, this is an input validation flaw. Versions of jsPDF prior to 4.2.1 do not properly sanitize user-supplied input passed to the createAnnotation method, specifically through the color parameter. An attacker who can control this input-for example, by submitting a specially crafted form or URL parameter-can inject arbitrary PDF objects.
The most dangerous type of object that can be injected is a JavaScript action. This means the attacker can embed scripts that execute automatically when the PDF is opened or when a user interacts with an annotation (like a link or a note) in the PDF viewer.
Potential Impact
The primary risk is to end-users who open a malicious PDF generated by a vulnerable application. If successful, the injected JavaScript could:
- Redirect the user to phishing or malware-hosting websites.
- Perform actions on behalf of the user within the PDF viewer’s context.
- Potentially exploit other vulnerabilities in the PDF reader software itself.
This vulnerability is particularly concerning for web applications that dynamically generate PDFs from user-contributed data, such as report generators, invoicing systems, or document portals. A single compromised PDF could be used in targeted attacks. For context on how such exploits can lead to data compromise, you can review historical incidents in our breach reports.
Remediation and Mitigation
Immediate action is required to secure applications using jsPDF.
Primary Fix: Update the Library The issue has been patched in jsPDF version 4.2.1. The most effective remediation is to upgrade your project’s jsPDF dependency to this version or later.
npm update jspdf
Workaround: Sanitize Input
If an immediate update is not possible, you must implement strict input sanitization. All user-controlled data that is passed to the createAnnotation method-or any method that ultimately calls it-must be validated and sanitized. Treat this input as untrusted and restrict it to expected values (e.g., allow only specific, safe color formats).
Next Steps
- Inventory all applications and services that use the jsPDF library.
- Prioritize updating public-facing web applications that generate PDFs from user input.
- Test the updated library in your development environment before deploying to production.
Staying informed about such vulnerabilities is crucial for maintaining security. For the latest updates on threats and patches, follow our security news.
Never miss a critical vulnerability
Get real-time security alerts delivered to your preferred platform.
Am I Affected by CVE-2026-31898?
Pick an ecosystem, paste your installed version, and we'll compare it against the fixed version published on OSV.dev. Browser-only — nothing is sent to a server.
Heuristic comparison only. Always cross-check against the vendor advisory before making patching decisions.
Related Advisories
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) i...
Postiz is an AI social media scheduling tool. Prior to version 2.21.6, a file upload validation bypass allows any authenticated user to upload arbitrary HTML, SVG, or other executable file types to th...
Note Mark is an open-source note-taking application. In versions 0.19.1 and prior, the asset delivery handler serves uploaded files inline and relies on magic-byte detection for content type, which do...
FastGPT is an AI Agent building platform. In versions prior to 4.14.9.5, the password change endpoint is vulnerable to NoSQL injection. An authenticated attacker can bypass the "old password" verifica...