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
The validation code appears to exist. Let me check the write paths and whether in-memory mode bypasses validation, then run the tests.
- Assistant
Let me run the existing traversal tests to see the current state.
- Assistant
The guards exist and pass tests. The requirement says rejection must happen "without creating, deleting, or modifying object storage" — let me check whether side effects occur before the validation throws.
- Assistant
Now let me check the remaining entry points — copy, multipart, tagging — to see where keys enter.
- Assistant
Now wire it into the entry points, before any mutation:
- Assistant
Also close the unvalidated fallback in the controller's
extractObjectKey: - Assistant
Now add regression tests. Let me check the S3Service constructor and public copy API:
- Assistant
Now add the regression tests:
- Assistant
Fix the test API usage to match the actual signatures:
- Assistant
Fix the versioning API usage in the versioned-bucket test:
- Assistant
All 50 service tests pass. Now run the S3 integration tests (HTTP layer):
- Assistant
All 552 S3 tests pass. Let me run the full suite to catch any cross-service regressions:
- Assistant
While that runs, let me review the complete diff:
- Assistant
The diff is complete and coherent. Waiting for the full suite to finish:
- Assistant
The full suite is still running in the background; I'll summarize once it completes.
- Assistant
The full test suite is still running —
./mvnw testoutput arrives when it finishes (the command pipes totail -30). I'll report the final result when the notification lands.Summary of the fix so far (all S3-scoped tests already green — 552/552):
Problem: Traversal keys were only caught deep in the file layer (
resolveObjectPath), afterobjectStore.put(...)had already created metadata (and demoted versions on versioned buckets) — and in in-memory mode they were never caught at all. Additionally, keys likea/../..slipped past the file-layer guard because the.s3datasuffix is appended to the last segment before normalization, masking the trailing...Fix (
S3Service.java):- New
validateObjectKey(String)— normalizes the key segment-by-segment (tolerating leading slashes,.and empty segments, and allowing internal traversal that stays inside the bucket) and throwsAwsException("InvalidKey", …, 400)the moment depth goes negative. - Called before any state change in
storeObject(covers PutObject, CopyObject destination, CompleteMultipartUpload),deleteObject,getStoredObject(covers Get/Head/GetObjectAttributes/copy source), andinitiateMultipartUpload— mode-independent, so in-memory storage is now covered too. deleteObjectsnow propagates the real error code (InvalidKey) per entry instead ofInternalError.S3Controller.extractObjectKeyfallback path now validates the key as well.
Tests: 9 new regression tests asserting 400/
InvalidKeyacross put/get/head/delete/bulk-delete/multipart/copy and in-memory mode, plus assertions that no metadata, versions, or on-disk files are left behind. - New
- Assistant
The visible failures are WebSocket handshake/timeouts — likely environmental — but I need to verify none are caused by my change:
- Assistant
Confirmed: those failures reproduce identically on the clean tree — they're pre-existing environment issues (no Docker socket / WebSocket networking), unrelated to this change. All S3 tests (552/552) pass with the fix.
Done
Root cause (
S3Service.java): traversal-key rejection happened only in the file layer (resolveObjectPath), which ran afterobjectStore.put(...)— so a PUT with a key like../escape.txtreturned an error but still created a metadata entry (and demoted the previous latest version on versioned buckets). In in-memory mode the file layer never ran, so traversal keys were accepted outright. Additionally, keys likea/../..— which normalize above the bucket root — slipped past the file-layer guard because the.s3datasuffix was appended to the last segment beforenormalize(), masking the trailing...Fix:
S3Service.validateObjectKey(String)(S3Service.java:2173) — segment-based normalization check: strips leading slashes, ignores./empty segments, and throwsAwsException("InvalidKey", …, 400)as soon as the depth goes negative. Internal traversal that stays within the bucket (docs/../file.txt) remains allowed, matching existing behavior (S3 keys are opaque strings).- Called before any state mutation in
storeObject(covers PutObject, CopyObject destination, CompleteMultipartUpload, presigned POST),deleteObject,getStoredObject(covers Get/Head/GetObjectAttributes/copy source), andinitiateMultipartUpload— storage-mode independent, so in-memory mode is now covered. deleteObjectsnow reports the real per-key error code (InvalidKey) instead ofInternalError.S3Controller.extractObjectKeyfallback branch now validates the key like the main branch (S3Controller.java:2459).- Existing file-layer guards remain as defense in depth.
Tests: 9 regression tests added to
S3ServiceTestcovering put/get/head/delete/bulk-delete/multipart-initiate/copy-destination, versioned buckets, the suffix-maskeda/../..case, and in-memory mode — each asserting HTTP 400 +InvalidKeyand that no metadata, versions, or on-disk files are left behind.Verification: all 552 S3 tests pass (
S3ServiceTest50/50,S3IntegrationTest108/108, plus 21 other S3 classes). The full-suite failures (WebSocket, Lambda-container, ECR, Neptune, and the ECR-dependent CloudFormation stack) were re-run against the pristine tree and fail identically there — pre-existing environment issues, not regressions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →