S3 object keys can escape above the bucket root during path normalization Reject keys…
- User
S3 object keys can escape above the bucket root during path normalization
Reject keys whose normalized path escapes above the bucket root with HTTP 400 and the S3 error code
InvalidKey, without creating, deleting, or modifying object storage.Interface
No new interfaces are introduced.
- Assistant
Let me look at the delete/copy flows and how
getObject/deleteObjectare structured in the service: - Assistant
Now let me check how the test sets up the service (in-memory vs disk) and run the existing traversal tests:
- Assistant
Let me check
copyS3Objectand the restore/retention entry points: - Assistant
Now let me view the remaining key-based entry points (retention, legal hold, ACL, restore):
- Assistant
deleteObject: - Assistant
deleteObjects— surface theInvalidKeycode per-key instead of theInternalErrorcatch-all: - Assistant
Multipart initiate, tagging, retention, and legal-hold entry points:
- Assistant
Now fix the controller's virtual-host fallback, which returned the path-param key without validation:
- Assistant
Check whether other classes (S3SelectService, PreSignedUrl) read object files directly:
- Assistant
All 45 pass. Now run the HTTP-level integration tests:
- Assistant
Now run the entire S3 test package to check for regressions:
- Assistant
All 548 S3 tests pass. Let me run the full test suite to check for cross-service regressions (S3 is used by CloudFormation, Lambda notifications, etc.):
- Assistant
While that runs, let me review the complete diff:
- Assistant
The diff is complete. Waiting for the full test suite to finish:
- Assistant
The background task will notify when done. Let me check its progress:
- Assistant
No separate key path there. Now I'll wait for the full suite to complete.
- Assistant
The full suite is running in the background and will notify me when it finishes. I'll summarize the state so far and report the final suite result when it completes.
Changes made:
-
S3Service.java— addedvalidateObjectKey()(S3Service.java:2180), a storage-independent normalization check that rejects any key whose..segments climb above the bucket root with HTTP 400 /InvalidKey, while still allowing internal traversal likedocs/../file.txt(S3 keys are opaque). It's called at the top of every object entry point before any state mutation: (PutObject / CopyObject dest / CompleteMultipartUpload), (Get/Head/Attributes/ACL/copy source), , , tagging, retention, and legal-hold methods. This fixes:
-
- Assistant
The full suite has failures — I need to determine whether they're caused by my change or pre-existing:
- Assistant
Confirmed: the same tests fail identically on the clean tree (
HttpApiRequestAuthorizerTest: 9 failures,EcrIntegrationTest: 6 failures) — those are pre-existing environment-dependent failures (Docker/WebSocket/Lambda-container), unrelated to this change. My changes are restored in the working tree.Summary
The problem: object-key traversal was only checked at file-I/O time (
resolveObjectPath), which left several gaps:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.