fix(decryptpdf): prevent path traversal in multer filename callback#2181
Open
sebastiondev wants to merge 1 commit into
Open
fix(decryptpdf): prevent path traversal in multer filename callback#2181sebastiondev wants to merge 1 commit into
sebastiondev wants to merge 1 commit into
Conversation
…th traversal (CWE-22)
|
@sebastiondev is attempting to deploy a commit to the prafull 's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability Summary
The
/decryptpdfendpoint inapps/OpenSignServer/cloud/customRoute/decryptpdf.jsis vulnerable to path traversal (CWE-22) through thefile.originalnamefield in the multerdiskStorageconfiguration.When a file is uploaded via
POST /decryptpdf, multer'sdiskStoragecallback usesfile.originalnamedirectly as the filename:The
originalnameproperty is taken directly from theContent-Dispositionheader in the multipart upload and is fully attacker-controlled. An attacker can set it to a value like../../malicious.jsto write files outside the intendedexportsdirectory, potentially overwriting application code, configuration files, or other sensitive data on the server.The
/decryptpdfroute is mounted incustomApp.jswithout any authentication middleware — the Express app uses onlycors()and body parsers, with no auth gates on this route. This means the vulnerability is exploitable by any unauthenticated client with network access to the server.Severity: High — unauthenticated arbitrary file write.
Proof of Concept
An attacker can upload a file with a traversal payload in the filename to write outside the
exportsdirectory:This causes multer to write the uploaded content to
exports/../../overwrite-target.txt, which resolves tooverwrite-target.txttwo directories above theexportsfolder. Depending on the deployment layout, this can overwrite application source files,.envconfiguration,package.json, or other files the Node.js process user has write access to.The route is defined at
apps/OpenSignServer/cloud/customRoute/customApp.js:19:Fix Description
The fix wraps
file.originalnameinpath.basename()to strip any directory components:path.basename()extracts only the final filename segment, so../../malicious.jsbecomesmalicious.js, and the file is written into the intendedexportsdirectory. This is the standard Node.js mitigation for this class of vulnerability and has no impact on legitimate uploads, since valid filenames contain no directory separators.Testing
path.basename('../../etc/passwd')returns'passwd'(directory components stripped).path.basename('normal-file.pdf')returns'normal-file.pdf'(no change for clean filenames).pathfromnode:path) and one wrapped call.Adversarial Review
Before submitting, we considered whether existing protections would prevent exploitation. The Express app in
customApp.jsapplies no authentication middleware — onlycors()and body parsers — so the endpoint is reachable by any network client. Multer does not sanitizeoriginalnameby design (it documents this as the caller's responsibility). Theexportsdestination directory is a relative path, making traversal straightforward. No other server-side validation or sandboxing prevents the file write. The vulnerability is exploitable as described.Submitted by Sebastion — autonomous open-source security research from Foundation Machines. Free for public repos via the Sebastion AI GitHub App.