fix(storage-simulator): prevent path traversal in mock S3 server#14915
Open
adrianjoshua-strutt wants to merge 1 commit into
Open
fix(storage-simulator): prevent path traversal in mock S3 server#14915adrianjoshua-strutt wants to merge 1 commit into
adrianjoshua-strutt wants to merge 1 commit into
Conversation
The mock storage simulator (localhost:20005) was vulnerable to path traversal via crafted object keys combined with the prefix query parameter. An attacker with network access to the simulator could read, write, or delete arbitrary files on the developer workstation. Root cause: parseUrl() applied path.normalize() to the full request URL including the query string, causing ../ sequences in query parameter values to be resolved as path traversal. Additionally, the single-character leading dot/slash strip was insufficient to prevent traversal when the prefix query parameter injected multiple ../ sequences. Fix: 1. Strip query string before calling path.normalize() on the URL 2. Add post-normalization check rejecting paths containing .. or absolute paths (falls back to basename only) 3. Add defense-in-depth assertPathWithinRoot() validation in every filesystem-accessing handler (GET, PUT, POST, DELETE, LIST) Tested: normal S3 operations (put, get, delete, list, multipart) continue to work. Path traversal attempts are blocked.
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.
Summary
Fixes a path traversal vulnerability in the mock storage simulator (
amplify-storage-simulator) that allows arbitrary file read/write/delete outside the configured storage directory on a developer's workstation.Root Cause
parseUrl()inutils.tscalledpath.normalize(decodeURIComponent(request.url))on the full URL including the query string. This caused../sequences in query parameter values (e.g.?prefix=../../) to be resolved as filesystem path traversal bypath.normalize(). Combined with the insufficient single-character strip of a leading.or/, an attacker with network access to the simulator (localhost:20005) could escape the storage root.Attack vector:
PUT /test-bucket/ESCAPE/pwned.txt/?prefix=../..writes a file one level above the configured storage directory.Fix
request.url.split('?')[0]before passing topath.normalize()params.paththat starts with..or is absolute after all normalization (falls back topath.basename())assertPathWithinRoot()checks - added to every handler (GET, PUT, POST, DELETE, LIST) that performs filesystem operations, validating that the resolved path stays within the storage rootTesting
Impact
Limited to developers running
amplify mock storagewho also have port 20005 reachable from untrusted networks or processes. No AWS production infrastructure affected.