Skip to content

fix(storage-simulator): prevent path traversal in mock S3 server#14915

Open
adrianjoshua-strutt wants to merge 1 commit into
devfrom
fix/storage-simulator-path-traversal
Open

fix(storage-simulator): prevent path traversal in mock S3 server#14915
adrianjoshua-strutt wants to merge 1 commit into
devfrom
fix/storage-simulator-path-traversal

Conversation

@adrianjoshua-strutt

Copy link
Copy Markdown
Member

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() in utils.ts called path.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 by path.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

  1. Strip query string before normalize - request.url.split('?')[0] before passing to path.normalize()
  2. Post-normalization traversal check - reject any params.path that starts with .. or is absolute after all normalization (falls back to path.basename())
  3. Defense-in-depth assertPathWithinRoot() checks - added to every handler (GET, PUT, POST, DELETE, LIST) that performs filesystem operations, validating that the resolved path stays within the storage root

Testing

  • Verified with a live PoC that the exploit is blocked after the fix
  • Regression tested: normal PUT, GET, DELETE, POST, multipart upload, nested paths all work correctly
  • 17/17 passed in regression suite

Impact

Limited to developers running amplify mock storage who also have port 20005 reachable from untrusted networks or processes. No AWS production infrastructure affected.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant