/

CVE-2026-25755

Severity:

HIGH RISK

(8.1)

Code Injection in jsPDF PDF Generation

CVE-2026-25755

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-116

Impact:

Arbitrary Code Execution within PDF Context / Document Manipulation

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

jsPDF versions prior to 4.2.0 contain a code injection vulnerability where user-controlled input passed to the addJS method is embedded into the PDF without proper escaping.

An attacker who can influence the JavaScript argument to addJS may inject arbitrary PDF objects or script, leading to malicious actions or document manipulation when the PDF is opened.

Affected context

This vulnerability affects applications that:

  • Use jsPDF (prior to 4.2.0) to generate PDFs in the browser or server-side, and
  • Call addJS with data that is directly or indirectly influenced by user input, and
  • Distribute or render the resulting PDFs to other users or systems.

The risk materializes when untrusted or insufficiently sanitized JavaScript code is embedded into a PDF and executed by a PDF viewer that supports JavaScript actions and object references.

Exploit preconditions

  • Attack surface: PDF generation functionality that relies on jsPDF and exposes addJS to user-controlled or externally sourced data.
  • Required access: Ability to supply or influence the string passed to addJS (e.g., form fields, query parameters, API payloads, templating systems).
  • Trigger point: Opening the generated PDF in a viewer that executes embedded JavaScript or interprets the injected PDF objects.
  • Why exploitation is possible: The addJS method embeds its argument directly into the PDF structure without robust escaping (notably for parentheses and delimiters), allowing crafted input to break out of the intended JavaScript string and introduce arbitrary PDF objects or script.

Why this happens

The core issue is improper neutralization of special characters in user-supplied content before embedding it into a structured context (the PDF object and JavaScript string).

This maps to:

  • CWE-94: Improper Control of Generation of Code, because user-controlled data is incorporated into executable JavaScript within the PDF without adequate constraints.
  • CWE-116: Improper Encoding or Escaping of Output, as characters such as parentheses and delimiters are not safely escaped, enabling attackers to escape the intended string literal or object boundaries.

Conceptually, the bug arises from treating untrusted input as trusted code/structure within a document format that supports embedded scripting and complex object graphs.

Potential impact

  • Execution of attacker-controlled JavaScript within the PDF viewer context (where supported).
  • Manipulation of the PDF's internal structure, including injecting or altering objects, annotations, or actions.
  • Content spoofing, such as modifying visible text, forms, or links to mislead users.
  • Data exfiltration from PDF form fields or embedded data available to the script.
  • Delivery of socially engineered documents that perform unexpected or unwanted actions when opened.

General mitigation guidance

Effective mitigation focuses on treating the addJS argument as untrusted and minimizing or eliminating dynamic code generation:

  • Prefer avoiding the use of addJS with user-supplied data; embed only static, audited scripts where possible.
  • When dynamic behavior is unavoidable, constrain input to a safe subset (e.g., whitelisted tokens) rather than interpolating arbitrary JavaScript strings.
  • Apply robust escaping and encoding for characters that have structural meaning in JavaScript strings and PDF syntax, such as parentheses, backslashes, quotes, and control characters.
  • Introduce a sanitization layer that validates user input against expected patterns before including it in any executable or structural context.
  • Architect PDF generation so that user input populates data fields, not code paths, reducing the need for runtime evaluation inside the PDF.
  • Combine these patterns with the principle of least functionality, disabling or avoiding PDF JavaScript features when they are not strictly required by the application's use case.

How teams detect issues like this

Detection efforts can focus on both code-level and artifact-level analysis:

  • Static analysis and code scanning rules that flag:
  • Calls to addJS where the argument is derived from request parameters, form data, or other untrusted sources.
  • String concatenation or template literals that mix user input with JavaScript code used in PDF generation.
  • Code review checklists that include:
  • Verifying that addJS usage is limited, documented, and does not depend on arbitrary user data.
  • Ensuring any dynamic content inserted into PDF scripts passes through a dedicated encoding/sanitization routine.
  • Security testing and fuzzing of PDF generation endpoints using crafted payloads that attempt to break out of string delimiters or introduce PDF object syntax.
  • Applying policy-based controls (e.g., linters or CI rules) to prevent introduction of new code paths where user data is embedded into executable contexts.
  • Organizations may leverage automated SAST/IAST tools to highlight unsafe output encoding patterns in JavaScript and TypeScript codebases that interact with jsPDF.

Sources

SourceLink
github.comgithub.com/ZeroXJacks/CVEs/blob/main/2026/CVE-2026-25755.md
github.comgithub.com/parallax/jsPDF/commit/56b46d45b052346f5995b005a34af5dcdddd5437
github.comgithub.com/parallax/jsPDF/releases/tag/v4.2.0
github.comgithub.com/parallax/jsPDF/security/advisories/GHSA-9vjf-qc39-jprp
access.redhat.comaccess.redhat.com/errata/RHSA-2026:7110
access.redhat.comaccess.redhat.com/errata/RHSA-2026:7128
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-25755
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2440993
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-25755.json

Frequently asked

questions

Exploitability depends on whether your application passes user-controlled or externally sourced data into addJS and then distributes the resulting PDFs. If addJS is only used with static, hardcoded scripts and no user input, the practical risk is significantly reduced.

No. An attacker generally only needs a way to influence the value passed to addJS—for example, by submitting crafted form data or API requests that your application then embeds into the PDF. They do not need system-level access to the server running jsPDF.

The safest approach is to avoid embedding user-supplied content in addJS entirely. If dynamic behavior is absolutely necessary, enforce strict validation and escaping of input (such as reliably escaping parentheses and other control characters) and restrict scripts to a predefined, minimal set of safe operations.

Design document generation so that user input is treated as data, not code. Use strong output encoding when embedding data into any executable or structural context, perform threat modeling for document scripting features, and adopt code review and automated scanning practices that flag dynamic code construction or unescaped insertion of user data into scriptable document formats.

Find out what's already
exploitable in your codebase.