Summary
A path traversal and local file inclusion issue in jsPDF's Node.js builds allows user-controlled paths to be passed into file-loading methods such as loadFile, addImage, html, and addFont.
When untrusted input is used as the first argument to these APIs, an attacker can cause jsPDF to read arbitrary files from the local filesystem and embed their contents directly into generated PDFs.
Affected context
This vulnerability affects applications that:
- Use jsPDF in a Node.js environment (specifically
dist/jspdf.node.jsordist/jspdf.node.min.js) - Allow user input to influence the file path argument of
loadFile,addImage,html, oraddFont - Run jsPDF with filesystem access in the same privilege context as the Node.js process
The risk is elevated in multi-user or internet-facing services where end users can indirectly or directly control file paths used by jsPDF.
Exploit preconditions
- Attack surface: Server-side jsPDF usage in Node.js where PDFs are generated dynamically based on user input
- Required access: Ability to supply or influence path-like data passed into jsPDF methods (
loadFile,addImage,html,addFont) - Trigger point: Invocation of these methods with unsanitized, attacker-controlled path values
- Why exploitation is possible: The Node.js build of jsPDF accesses the local filesystem using caller-supplied paths without enforcing strict path normalization, directory whitelisting, or permission boundaries, enabling traversal outside intended directories.
Why this happens
The underlying issue is the direct use of untrusted input as filesystem paths in the Node.js build of jsPDF, without robust validation or restriction.
This behavior maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), because user-supplied paths can escape the intended directory.
It also relates to CWE-35/CWE-73, where external inputs control resource names and configuration, allowing access to arbitrary local files.
Conceptually, the bug stems from treating user data as trusted file identifiers in a context where the runtime has broad filesystem privileges, and then embedding whatever is read directly into the generated PDF.
Potential impact
- Disclosure of sensitive local files (e.g., application logs, configuration files, access tokens) via generated PDFs
- Exposure of secrets or credentials stored alongside the application (API keys, database passwords)
- Leakage of source code or proprietary business logic present on the server
- Indirect assistance to further attacks (privilege escalation, lateral movement) by revealing environment details
General mitigation guidance
Effective mitigation focuses on constraining file access and reducing trust in user-controlled paths:
- Introduce a strict allowlist of directories or file identifiers that can be used with jsPDF, rejecting any input outside these sets
- Normalize and validate paths before use, ensuring they remain within an approved base directory and disallowing patterns that indicate traversal
- Avoid passing raw user input as filesystem paths; instead, map user-selectable options to internal identifiers that resolve to safe, predefined files
- Run the Node.js process with the minimum required filesystem permissions and limit access to sensitive directories where possible
- Use runtime controls (such as Node.js permission flags where available) to restrict file system access by default
How teams detect issues like this
Detection typically involves both code-centric and runtime-focused approaches:
- Static analysis: Search for calls to jsPDF's
loadFile,addImage,html, andaddFontwhere arguments derive from request data, query parameters, form fields, or other user-controlled sources without intermediate validation - Code review signals: Flag any code that concatenates or forwards user-provided strings into file paths, especially when used within PDF generation or image/font loading logic
- Automated checks: Configure SAST tools or custom linters to alert on use of unvalidated paths passed to filesystem-related APIs or jsPDF wrapper functions
- Runtime monitoring: Instrument logging around file access calls used during PDF generation, looking for unexpected directories, traversal sequences, or unusual file names being read

