Fix path traversal vulnerability in storage service content endpoint#2
Open
google-labs-jules[bot] wants to merge 1 commit into
Conversation
Reordered path resolution so that validation occurs after joining user input, preventing traversal attacks on the /content endpoint.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Why are these changes being introduced?
A security vulnerability was identified in the storage service's content delivery endpoint (
/content/:filename). Attackers could exploit this endpoint by using relative path traversal sequences (e.g.,../../etc/passwd) to escape the intended storage root directory and read sensitive system files on the host machine.To resolve this, we needed to reorder the path resolution sequence. By fully constructing the target file path before validation, we can reliably verify if the resolved path resides within the authorized base directory (
UPLOAD_DIR). Any attempts to escape the root directory using path traversal sequences are now caught and blocked before any file system reads occur.Key Decisions & Rationale
..segments are evaluated by the system. Checking the final, absolute path prevents attackers from tricking the validation logic with clever path segment positioning.400 Bad Requestwithout exposing internal host file paths, adhering to secure coding guidelines.safeResolve()utility to ensure zero performance degradation and minimize regression risks.What has changed?
my-portfolio/server/storage-service/index.js/content/:filenameto join the file paths into arawPathinitially.safeResolve()utility to validate that the resolved path strictly starts with the authorized base directory.400status code if validation fails.Verification Results
/content/../../etc/passwd) are successfully blocked with a400response and do not expose internal paths or server-side logs.