Feb 28, 2026·6 min read·26 visits
jsPDF versions prior to 4.0.0 contain a Local File Inclusion (LFI) vulnerability in their Node.js builds. The library failed to sanitize file paths in methods like `addImage` and `loadFile`, allowing attackers to read files like `/etc/passwd`. The fix in v4.0.0 introduces a strict allowlist mechanism.
A critical Path Traversal vulnerability in the Node.js build of the jsPDF library allows attackers to read arbitrary files from the server filesystem. By manipulating file paths passed to PDF generation methods, unauthorized actors can embed sensitive server data into generated documents.
CVE-2025-68428 represents a critical security flaw in the server-side implementation of jsPDF, a widely used library for generating PDF documents. While jsPDF is primarily known for client-side usage in browsers, it offers specific builds (jspdf.node.js and jspdf.node.min.js) for Node.js environments. These server-side builds require file system access to load resources such as fonts, images, and HTML templates.
The vulnerability is classified as a Path Traversal (CWE-22) and Local File Inclusion (LFI) issue. It arises because the library explicitly trusted user-supplied paths when loading external resources. If a web application exposes PDF generation functionality—for instance, allowing users to specify a logo URL or a font path—an attacker can supply a malicious path containing traversal sequences (e.g., ../../).
Successful exploitation results in the application reading files outside the intended directory. The content of these files is then processed and often embedded directly into the generated PDF, allowing the attacker to retrieve sensitive system configuration files, source code, or credentials simply by downloading the resulting document.
The root cause of this vulnerability lies in the nodeReadFile function located within the libs/fileloading.js module. In versions prior to 4.0.0, this function was responsible for handling file I/O operations when the library detected it was running in a Node.js environment.
The logic used path.resolve(url) to process the input path. While path.resolve resolves relative segments like .., it does not verify that the resulting absolute path resides within a safe or expected directory. It simply normalizes the string and returns an absolute path on the filesystem.
Immediately after resolution, the library passed this absolute path to fs.readFileSync. There were no checks to ensure the path was within a specific sandbox or allowlist. Consequently, an input of ../../../../etc/passwd would be resolved by Node.js to /etc/passwd (assuming the traversal depth was sufficient), and the file system API would obediently read the file. This creates a direct bridge between user input and the server's restricted filesystem.
The following analysis compares the vulnerable file loading logic with the hardened implementation in version 4.0.0.
In the vulnerable version, the code performs no validation on the resolved path. It assumes that path.resolve is sufficient for safety, which is a common misconception.
// libs/fileloading.js (simplified)
function nodeReadFile(url, callback) {
// DANGEROUS: path.resolve processes '..' but enforces no boundaries
var resolvedPath = require('path').resolve(url);
// The file is read immediately without authorization checks
var data = require('fs').readFileSync(resolvedPath);
return data;
}The fix introduces a strict "deny-by-default" model. It requires developers to explicitly allowlist paths via jsPDF.allowFsRead.
// libs/fileloading.js (patched)
function nodeReadFile(url, callback) {
var path = require('path');
var fs = require('fs');
// 1. Resolve the path to handle relative segments
var resolvedPath = path.resolve(url);
// 2. CHECK: Is this path in the allowed list?
// The library now iterates through `jsPDF.allowFsRead` patterns.
// If no match is found, it throws an error preventing the read.
if (!isPathAllowed(resolvedPath)) {
throw new Error("File access denied: " + resolvedPath);
}
// 3. SAFE: Read the file only after validation
return fs.readFileSync(resolvedPath);
}> [!NOTE]
> The patch forces a breaking change. Developers upgrading to v4.0.0 must configure the allowFsRead property, or all local file loading operations will fail by default.
Exploiting this vulnerability requires an application to pass user-controlled input into one of jsPDF's file-loading methods, such as addImage, addFont, or loadFile. A common scenario is an invoice generator that allows a user to specify a custom logo.
POST /api/invoice with {"logo": "default.png"}).{"logo": "../../../../../../../etc/passwd"}./etc/passwd is embedded into the PDF stream.If the application blindly passes the input to doc.addImage, the resulting PDF might be corrupt (as /etc/passwd is not a valid image), but the file data is still present in the PDF source code. If loadFile is used, the text is returned directly.
# Example of retrieving the generated PDF and inspecting raw content
curl -X POST https://vulnerable-app.com/generate -d "image=../../etc/passwd" -o leak.pdf
# Inspecting the PDF binary for known strings
grep "root:x:0:0" leak.pdfThe impact of CVE-2025-68428 is rated Critical (CVSS 9.2) due to the complete loss of confidentiality regarding local files on the server.
This vulnerability is particularly dangerous because it bypasses application-level authentication checks for file access, relying solely on the permissions of the Node.js process, which often runs with excessive read privileges.
The only complete fix is to upgrade the library and configure the new security controls. Network-level mitigations are difficult to implement effectively because the traversal happens within the application logic, not the HTTP URI (unless the input is taken directly from the URL path).
Upgrade to jsPDF v4.0.0 or later immediately. Verify the version in your package.json:
"dependencies": {
"jspdf": "^4.0.0"
}After upgrading, you must explicitly allow access to the directories your application needs. Faiilure to do so will break PDF generation features that load local files.
const { jsPDF } = require('jspdf');
const doc = new jsPDF();
// SECURITY: Whitelist specific directories for file access
doc.allowFsRead = [
path.resolve(__dirname, 'assets/fonts'),
path.resolve(__dirname, 'assets/images')
];For critical environments, consider using the Node.js experimental permission model (available in Node 20+) to restrict the filesystem access of the entire process, providing a safety net even if the library is misconfigured.
node --permission --allow-fs-read="/app/assets/*" app.jsCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
jsPDF parallax | < 4.0.0 | 4.0.0 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-22 |
| Attack Vector | Network |
| CVSS v4.0 | 9.2 (Critical) |
| CVSS v3.1 | 7.5 (High) |
| EPSS Score | 0.02% |
| Exploit Status | Proof of Concept (PoC) |
| KEV Listed | No |
The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.