jsPDF's PDF Injection in AcroForm module allows Arbitrary JavaScript Execution (RadioButton.createOption and "AS" property)
Description
jsPDF is a library to generate PDFs in JavaScript. Prior to 4.2.0, user control of properties and methods of the Acroform module allows users to inject arbitrary PDF objects, such as JavaScript actions. If given the possibility to pass unsanitized input to one of the following property, a user can inject arbitrary PDF objects, such as JavaScript actions, which are executed when the victim hovers over the radio option. The vulnerability has been fixed in jsPDF@4.2.0. As a workaround, sanitize user input before passing it to the vulnerable API members.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
jspdfnpm | < 4.2.0 | 4.2.0 |
Affected products
1Patches
12 files changed · +42 −3
src/modules/acroform.js+15 −3 modified@@ -2143,7 +2143,11 @@ var AcroFormButton = function() { return _AS; }, set: function(value) { - _AS = value; + var name = value === undefined || value === null ? "" : value.toString(); + if (name.substr(0, 1) === "/") { + name = name.substr(1); + } + _AS = "/" + pdfEscapeName(name); } }); @@ -2296,7 +2300,11 @@ var AcroFormChildClass = function() { return _AS; }, set: function(value) { - _AS = value; + var name = value === undefined || value === null ? "" : value.toString(); + if (name.substr(0, 1) === "/") { + name = name.substr(1); + } + _AS = "/" + pdfEscapeName(name); } }); @@ -2313,7 +2321,11 @@ var AcroFormChildClass = function() { return _AS.substr(1, _AS.length - 1); }, set: function(value) { - _AS = "/" + value; + var name = value === undefined || value === null ? "" : value.toString(); + if (name.substr(0, 1) === "/") { + name = name.substr(1); + } + _AS = "/" + pdfEscapeName(name); } }); this.caption = "l";
test/specs/acroform.spec.js+27 −0 modified@@ -1162,5 +1162,32 @@ describe("Module: Acroform Integration Test", function() { expect(output).not.toContain("/AA <<"); expect(output).toContain("#2FAA"); }); + it("escapes malicious input in CheckBox AS", function() { + var doc = new jsPDF(); + var field = new doc.AcroFormCheckBox(); + field.x = 10; field.y = 10; field.width = 20; field.height = 10; + doc.addField(field); + + field.AS = "/Off /AA << /E << /S /JavaScript /JS (app.alert(1)) >> >>"; + + var output = doc.output(); + expect(output).not.toContain("/AA << /E << /S /JavaScript"); + expect(field.AS).toContain("#2FAA"); + }); + + it("escapes malicious input in RadioButton child appearanceState", function() { + var doc = new jsPDF(); + var group = new doc.AcroFormRadioButton(); + group.x = 10; group.y = 10; group.width = 20; group.height = 10; + doc.addField(group); + + var child = group.createOption("opt1"); + child.x = 10; child.y = 10; child.width = 20; child.height = 10; + child.appearanceState = "Off /AA << /E << /S /JavaScript /JS (app.alert(1)) >> >>"; + + var output = doc.output(); + expect(output).not.toContain("/AA << /E << /S /JavaScript"); + expect(child.AS).toContain("#2FAA"); + }); }); });
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
5- github.com/advisories/GHSA-p5xg-68wr-hm3mghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2026-25940ghsaADVISORY
- github.com/parallax/jsPDF/commit/71ad2dbfa6c7c189ab42b855b782620fa8a38375ghsax_refsource_MISCWEB
- github.com/parallax/jsPDF/releases/tag/v4.2.0ghsax_refsource_MISCWEB
- github.com/parallax/jsPDF/security/advisories/GHSA-p5xg-68wr-hm3mghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.