Skip to content
TheChatArchiveThe Chat Archive
fable-5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

S3 object keys can escape above the bucket root during path normalization Reject keys…

  1. 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.

  2. Assistant

    The validation code appears to exist. Let me check the write paths and whether in-memory mode bypasses validation, then run the tests.

  3. Assistant

    Let me run the existing traversal tests to see the current state.

  4. 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.

  5. Assistant

    Now let me check the remaining entry points — copy, multipart, tagging — to see where keys enter.

  6. Assistant

    Now wire it into the entry points, before any mutation:

  7. Assistant

    Also close the unvalidated fallback in the controller's extractObjectKey:

  8. Assistant

    Now add regression tests. Let me check the S3Service constructor and public copy API:

  9. Assistant

    Now add the regression tests:

  10. Assistant

    Fix the test API usage to match the actual signatures:

  11. Assistant

    Fix the versioning API usage in the versioned-bucket test:

  12. Assistant

    All 50 service tests pass. Now run the S3 integration tests (HTTP layer):

  13. Assistant

    All 552 S3 tests pass. Let me run the full suite to catch any cross-service regressions:

  14. Assistant

    While that runs, let me review the complete diff:

  15. Assistant

    The diff is complete and coherent. Waiting for the full suite to finish:

  16. Assistant

    The full suite is still running in the background; I'll summarize once it completes.

  17. Assistant

    The full test suite is still running — ./mvnw test output arrives when it finishes (the command pipes to tail -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), after objectStore.put(...) had already created metadata (and demoted versions on versioned buckets) — and in in-memory mode they were never caught at all. Additionally, keys like a/../.. slipped past the file-layer guard because the .s3data suffix 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 throws AwsException("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), and initiateMultipartUpload — mode-independent, so in-memory storage is now covered too.
    • deleteObjects now propagates the real error code (InvalidKey) per entry instead of InternalError.
    • S3Controller.extractObjectKey fallback path now validates the key as well.

    Tests: 9 new regression tests asserting 400/InvalidKey across 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.

  18. Assistant

    The visible failures are WebSocket handshake/timeouts — likely environmental — but I need to verify none are caused by my change:

  19. 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 after objectStore.put(...) — so a PUT with a key like ../escape.txt returned 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 like a/../.. — which normalize above the bucket root — slipped past the file-layer guard because the .s3data suffix was appended to the last segment before normalize(), masking the trailing ...

    Fix:

    • S3Service.validateObjectKey(String) (S3Service.java:2173) — segment-based normalization check: strips leading slashes, ignores ./empty segments, and throws AwsException("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), and initiateMultipartUpload — storage-mode independent, so in-memory mode is now covered.
    • deleteObjects now reports the real per-key error code (InvalidKey) instead of InternalError.
    • S3Controller.extractObjectKey fallback 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 S3ServiceTest covering put/get/head/delete/bulk-delete/multipart-initiate/copy-destination, versioned buckets, the suffix-masked a/../.. case, and in-memory mode — each asserting HTTP 400 + InvalidKey and that no metadata, versions, or on-disk files are left behind.

    Verification: all 552 S3 tests pass (S3ServiceTest 50/50, S3IntegrationTest 108/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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.