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
I'll locate S3 key normalization and where object operations are handled so we can reject paths that escape the bucket root.
- Assistant
Validation exists only on disk paths and in the controller, so in-memory mode and metadata updates can still accept traversal keys. I'll add centralized early validation in
S3Servicebefore any storage mutations. - Assistant
Implemented centralized S3 key validation so traversal keys are rejected before any storage is touched.
Changes
S3Service.java— AddedvalidateObjectKey()that normalizes the key against a sandbox root and throwsAwsException("InvalidKey", ..., 400)when the path escapes above the bucket root (or contains invalid path characters).Called early in all object-mutating and object-access paths:
storeObject,getStoredObject,deleteObject- Tagging, retention, legal hold
initiateMultipartUpload,copyS3ObjectresolveObjectPath/resolveVersionedPath(disk I/O)
S3Controller.java—validateKeyNoTraversal()now delegates toS3Service.validateObjectKey()instead of duplicating logic.S3ServiceTest.java— Added tests for:- In-memory mode rejection (previously bypassed validation)
- No storage mutation on rejected
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.