Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION S3 object keys can escape above the bucket root during path…

  1. User

    ISSUE DESCRIPTION

    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.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /floci, current file: none) bash-$

  2. GLM Assistant

    Let me explore the repository structure first.

  3. GLM Assistant

    This is a Java project (pom.xml). Let me explore the structure.

  4. GLM Assistant

    Let me look at the key files - the S3Controller, S3Service, and S3RequestParser, which likely handle key normalization.

  5. GLM Assistant

    Now let me look at the S3Service path normalization logic.

  6. GLM Assistant

    Now let me understand the issue. The issue says S3 object keys can escape above the bucket root during path normalization. Let me look at how keys are used throughout the service. Let me search for all uses of keys in the S3Service.

  7. GLM Assistant

    Let me check what calls validateRawUri and understand the full flow.

  8. GLM Assistant

    Let me look at existing tests related to key validation.

  9. GLM Assistant

    Let me look at the git log to understand recent changes related to this issue.

  10. GLM Assistant

    Let me look at the controller methods more broadly to find all key usages.

  11. GLM Assistant

    Let me look at copy operations which involve parsing a copy-source containing a key.

  12. GLM Assistant

    Let me look at the S3Service to understand the in-memory vs file storage and where keys are validated.

  13. GLM Assistant

    Now I see the key flow. The storeObject method calls writeFile(bucketName, key, data). Let me look at writeFile to see where resolveObjectPath is called and whether the path check happens before the storage write.

    In the in-memory mode, writeFile would put into memoryDataStore keyed by bucketName + "/" + key. In file mode, writeFile calls resolveObjectPath which throws InvalidKey if it escapes. But the order matters: in storeObject, before calling writeFile, the method already does objectStore.put(...) (the in-memory object store). So even if writeFile throws InvalidKey, the object store already has been modified.

    Wait, but the object store is the in-memory metadata store. The issue says "without creating, deleting, or modifying object storage." The object storage modification happens via objectStore.put before writeFile. So if the key escapes, the resolveObjectPath throws InvalidKey AFTER the object store was already modified. That violates the requirement.

    But wait - is the object store modification "object storage"? The "object storage" probably refers to the actual file/memory data store. Hmm.

    Actually, let me re-read the issue more carefully:

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

    So the bug is: keys can escape above the bucket root. The fix: reject such keys with 400 InvalidKey, without creating/deleting/modifying storage.

    Now, the existing resolveObjectPath already has startsWith(bucketDir) check. So why would keys escape? Let me think about cases where this check might pass incorrectly.

    Let me think about the in-memory case. When inMemory is true, writeFile puts into memoryDataStore with key bucketName + "/" + key and does NOT do path validation. So in in-memory mode, a traversal key like ../foo would just be stored. But that doesn't really "escape" in memory.

    Let me look at writeFile.

  14. GLM Assistant

    Let me look at the deleteObjects (DeleteObjects API) and listObjects which take keys from body/query params.

  15. GLM Assistant

    Let me find where deleteObjects is called from the controller.

  16. GLM Assistant

    Let me look at the test infrastructure to understand the testing approach.

  17. GLM Assistant

    Let me write a reproduction test using the S3Service directly.

  18. GLM Assistant

    Interesting. The ..%2fescape.txt key was stored successfully (as a file named ..%2fescape.txt.s3data inside the bucket dir - it's literally treated as a filename, not path traversal). That's actually fine because %2f is a literal string in the decoded key, not a /. So the file is ..%2fescape.txt.s3data which is inside the bucket. That's not a traversal escape.

    So the service-level resolveObjectPath does catch ../escape.txt and a/../../escape.txt and foo/../../../escape.txt. So at the service level, the file-mode path resolution is robust.

    So where is the bug? Let me reconsider. The issue says keys can escape above the bucket root. Let me reconsider the in-memory mode.

    In in-memory mode, writeFile does NOT call resolveObjectPath. It uses memoryDataStore.put(objectKey(bucketName, key), data). So no path validation. But there's no file system escape in memory anyway. But the issue says "without creating, deleting, or modifying object storage" — in in-memory mode, the objectStore.put would create the object even with a traversal key.

    Wait, but the controller's validateKeyNoTraversal should catch these. Let me reconsider the controller flow.

    Actually, wait. Let me reconsider the controller extractObjectKey and validateKeyNoTraversal. The issue may be about the controller validation being inconsistent with the service validation, OR there may be specific key forms that escape the controller's check but not the service's, or vice versa.

    Let me check what happens with a key that has .. but where the controller's validateKeyNoTraversal lets it through but the service catches it (or doesn't).

    Hmm, actually let me reconsider. The issue title is "S3 object keys can escape above the bucket root during path normalization". So there's a key that escapes. Let me think about what keys the controller's validateKeyNoTraversal would let through that escape.

    Wait — what about a key that uses backslashes? On Linux, \ is a valid filename char, not a separator. So \.. is fine.

    Let me reconsider. The key point: the validateKeyNoTraversal in the controller is the front-line defense. But the copy-source keys and delete-objects keys bypass it.

    Let me test the controller-level behavior through the HTTP API. But that requires running the full Quarkus app. Let me instead think about which operations reach the service WITHOUT controller validation.

    Actually, let me reconsider the whole thing. The service has resolveObjectPath/resolveVersionedPath which catch escapes — but only in file mode. In in-memory mode, no path validation. So in-memory mode is vulnerable: a traversal key would be stored/created in the object store.

    But more fundamentally, the issue is that the validation is scattered and the service-level check happens too late (after objectStore.put in storeObject).

    Let me look at the actual production config - is it in-memory or file mode? Let me check.

  19. GLM Assistant

    Let me find where S3Service is instantiated (the bean producer).

  20. GLM Assistant

    The new S3Service only appears in the controller for S3Service.SseCustomerHeaders inner class. So the S3Service is probably a CDI bean with a default constructor or a @Produces. Let me check the S3Service class annotations.

  21. GLM Assistant

    The S3Service is @ApplicationScoped but has a constructor with parameters. Let me find how it's wired.

  22. GLM Assistant

    So in-memory mode is determined by config. Let me check the default storage mode.

  23. GLM Assistant

    Let me look at how objectKey works and how leading-slash keys are stored distinctly.

  24. GLM Assistant

    So objectKey uses the raw key (including leading slash). So /file.txt -> bucket//file.txt and file.txt -> bucket/file.txt. Distinct in the object store.

    But the file storage: resolveObjectPath strips leading slashes from key, so /file.txt -> file.txt -> bucket/file.txt.s3data. And file.txt -> bucket/file.txt.s3data. Same file! So in file mode, /file.txt and file.txt would collide on disk. But the leading-slash test is an integration test... Let me check if that test passes currently. Actually it's a @QuarkusTest which runs the full app. The default storage mode is "hybrid" not "memory", so file mode is used. So the leading-slash test would have a disk collision... unless the test runs in memory mode.

    Hmm, let me check the test config / application.properties for tests.

  25. GLM Assistant

    So tests run in memory mode! That means in tests, inMemory = true, and writeFile uses memoryDataStore (no path validation). Let me search tests for existing behavior around traversal/invalid keys.

  26. GLM Assistant

    There's an existing test for this. Let me look at it carefully.

  27. GLM Assistant

    Let me look at the existing S3IntegrationTest traversal tests at HTTP level.

  28. GLM Assistant

    Let me look at the S3WellKnownKeyIntegrationTest and other key-related tests.

  29. GLM Assistant

    Let me write a focused test to check if storage is modified before the InvalidKey rejection (in file mode).

  30. GLM Assistant

    Confirmed the bug! In file mode (non-versioning bucket), a PUT with traversal key ../outside.txt creates a metadata entry in objectStore BEFORE writeFile throws InvalidKey. So storage IS modified despite the rejection. Let me check getStoredObject and how getObject handles traversal keys.

  31. GLM Assistant

    Confirmed the bug clearly. In file mode, storeObject calls objectStore.put(...) (line 357) BEFORE writeFile (line 358) which throws InvalidKey. So a phantom metadata entry remains despite the 400 response. Also, in memory mode the service does NO path validation at all (only the controller validates URL-path keys; copy-source and DeleteObjects keys bypass it).

    My plan:

    1. Add a centralized validateObjectKey(String key) static method in S3Service that rejects keys whose normalized path escapes the bucket root with InvalidKey 400.
    2. Call it at the start of every public S3Service method that accepts an object key, BEFORE any storage operation.
    3. Have the controller's validateKeyNoTraversal delegate to it for consistency.

    Let me enumerate all public methods that take a key.

  32. GLM Assistant

    Let me check which specific overloads the controller calls.

  33. GLM Assistant

    Let me view the putObject overloads to confirm they all delegate to line 251.

  34. GLM Assistant

    Now let me view the bodies of the remaining key-taking methods (copy, multipart, acl, restore) to find insertion points.

  35. GLM Assistant

    copyObject overloads delegate to either copyObject(..., versionId, CopyObjectOptions) (745) or copyObject(..., CopyObjectOptions) (758). Both call getObject(sourceBucket, sourceKey, ...) (validates sourceKey via getObject) and copyS3Object(... destKey ...) which writes the dest. Let me check copyS3Object — does it call storeObject? If so, destKey validated in storeObject. Let me check.

  36. GLM Assistant

    copyS3Object (line 2286) calls storeObject(destBucket, destKey, ...) at line 2326. So destKey is validated via storeObject. And sourceKey validated via getObject (line 749/761). So copyObject is covered if I validate in storeObject and getObject.

    completeMultipartUpload (line 1246) calls storeObject(bucket, key, ...). So covered via storeObject.

    My strategy: add validateObjectKey(key) at the start of the leaf methods. Let me first add the validateObjectKey method and KEY_SANDBOX constant near resolveObjectPath.

  37. GLM Assistant

    Now let me add the validateObjectKey method and KEY_SANDBOX constant. Let me edit near the DATA_SUFFIX line.

  38. GLM Assistant

    No python3. Let me use the edit command instead.

  39. GLM Assistant

    Now let me insert the validateObjectKey method after the DATA_SUFFIX line.

  40. GLM Assistant

    Now let me add validateObjectKey calls. First, the critical one: storeObject (the leaf for all PUTs). Let me view its start.

  41. GLM Assistant

    I'll add validateObjectKey(key); as the first statement in the leaf storeObject (line 278). The other two storeObject overloads delegate to it.

  42. GLM Assistant

    My edit got mangled — it created a duplicate signature line and dropped the .orElseThrow line. Let me fix lines 278-284.

  43. GLM Assistant

    storeObject now validates the key first. Now let me add validation to the read/mutate methods. Let me re-grep line numbers since they shifted.

  44. GLM Assistant

    Now let me add validateObjectKey calls to getObject (leaf at 401) and getObjectMetadata (leaf at 421, used by headObject/getObjectAttributes).

  45. GLM Assistant

    I'll add validateObjectKey(key); at the start of getObject(bucket, key, versionId) (line 401) and getObjectMetadata (line 421). headObject delegates to getObjectMetadata (covered). getObject(bucket,key) delegates to getObject(401) (covered). getObjectAttributes calls getObjectMetadata (covered).

    Let me add to line 401 (after the signature) and line 421.

  46. GLM Assistant

    Now add validation to getObjectMetadata (the leaf for headObject and getObjectAttributes).

  47. GLM Assistant

    Now deleteObject (leaf at 501).

  48. GLM Assistant

    Now deleteObjects (batch) — validate all keys upfront before deleting any. Let me view it.

  49. GLM Assistant

    For deleteObjects, validate all keys upfront before deleting any, so an invalid key rejects the whole request with InvalidKey 400 without deleting anything.

  50. GLM Assistant

    My edit created a duplicate ensureBucketExists(bucketName); at line 881. Let me remove it.

  51. GLM Assistant

    Now there's a duplicate validateObjectKey(key); at lines 879-880. Let me fix.

  52. GLM Assistant

    There's now a duplicate List<DeleteResult> deleted = new ArrayList<>(); at lines 881-882. Let me remove the duplicate.

  53. GLM Assistant

    The edit keeps shifting. Let me remove the duplicate List<DeleteError> errors line at 883.

  54. GLM Assistant

    The edit tool keeps duplicating. Let me replace the entire deleteObjects method block (874-897) cleanly.

  55. GLM Assistant

    Now deleteObjects is clean. Let me add validation to the tagging methods.

  56. GLM Assistant

    Now the retention/legalhold methods. Let me view them.

  57. GLM Assistant

    Let me add validateObjectKey(key); after ensureBucketExists in the retention/legalhold methods.

  58. GLM Assistant

    Let me use the edit command with line ranges. Let me open at line 1023.

  59. GLM Assistant

    Now putObjectLegalHold (line 1072) and getObjectLegalHold (line 1085).

  60. GLM Assistant

    Now the multipart methods. Let me view uploadPart and uploadPartCopy bodies.

  61. GLM Assistant

    uploadPartCopy calls getObject (validates sourceKey) and uploadPart (need destKey validation). So I'll add validation to uploadPart, initiateMultipartUpload (leaf), completeMultipartUpload, abortMultipartUpload, and listParts.

    Let me add to initiateMultipartUpload leaf (after ensureBucketExists).

  62. GLM Assistant

    Now uploadPart (line 1158), completeMultipartUpload (1221), abortMultipartUpload, listParts. Let me add to uploadPart at the start.

  63. GLM Assistant

    There's a duplicate signature line at 1159-1160. Let me fix.

  64. GLM Assistant

    Now completeMultipartUpload (line 1226).

  65. GLM Assistant

    Now abortMultipartUpload (1293) and listParts. Let me view listParts.

  66. GLM Assistant

    Now getObjectAcl and putObjectAcl.

  67. GLM Assistant

    getObjectAcl/putObjectAcl both call getObject which now validates the key, so they're covered. Now restoreObject.

  68. GLM Assistant

    restoreObject, getObjectAcl, putObjectAcl, copyObject all delegate to getObject/storeObject which now validate. Good. Now let me update the controller's validateKeyNoTraversal to delegate to S3Service.validateObjectKey for consistency.

  69. GLM Assistant

    Now let me compile and run my repro test to confirm the fix.

  70. GLM Assistant

    The fix works: PUT threw InvalidKey 400 and the object count after the failed PUT is 0 (no phantom entry). Let me run the existing S3ServiceTest (which includes the traversal tests).

  71. GLM Assistant

    A test copyObjectWithNonASCIIKey uses a non-ASCII key that Path.resolve rejects with InvalidPathException. Let me look at the test.

  72. GLM Assistant

    The test copyObjectWithNonASCIIKey uses a non-ASCII key. My validateObjectKey threw InvalidPathException. Let me check whether this is a locale issue and whether the test passed before my change.

  73. GLM Assistant

    The locale is POSIX (ASCII). Let me run the non-ASCII test on the original (stashed) code to confirm it passed before.

  74. GLM Assistant

    The locale is POSIX (ASCII), so Path.resolve rejects non-ASCII keys — and copyObjectWithNonASCIIKey was already failing on the original code in this environment (a pre-existing environmental failure, not a regression I introduced). However, my fix should not reject valid non-ASCII keys as InvalidKey. Let me make validateObjectKey locale-independent by doing manual path normalization instead of relying on java.nio.file.Path (which is encoding-sensitive).

    Let me restore my changes and rewrite validateObjectKey.

  75. GLM Assistant

    Now let me rewrite validateObjectKey and its constant to use manual normalization (locale-independent).

  76. GLM Assistant

    Let me verify there's no leftover KEY_SANDBOX reference and check the Path import is still needed.

  77. GLM Assistant

    KEY_SANDBOX is gone, and Path is still used elsewhere. Let me re-run the repro test and S3ServiceTest.

  78. GLM Assistant

    My validateObjectKey now passes for non-ASCII keys; the test fails at resolveObjectPath/writeFile due to the POSIX locale — the same pre-existing failure as on the original code (confirmed earlier). So no regression from my change. ReproTest passed.

    Let me run the rest of S3ServiceTest (excluding the pre-existing POSIX-locale failure) to confirm no regressions.

  79. GLM Assistant

    Both traversal tests pass. Now let me write a comprehensive repro covering memory mode, copy-source, and DeleteObjects (the gaps the issue targets).

  80. GLM Assistant

    All 7 repro tests pass. Now let me run the broader existing non-Quarkus S3 unit tests to check for regressions.

  81. GLM Assistant

    All non-Quarkus tests pass except the pre-existing POSIX-locale copyObjectWithNonASCIIKey failure (identical on original code). Now let me run the QuarkusTest integration tests that my change could most affect: leading-slash keys, well-known keys, and the traversal test.

  82. GLM Assistant

    Both pass. Now let me run the pathTraversalAttemptsReturn400 test from S3IntegrationTest and a couple of copy/multipart tests to be safe.

  83. GLM Assistant

    The traversal test passes. Let me run the full S3IntegrationTest (it runs in memory mode, so the POSIX non-ASCII issue won't affect it) to confirm no regressions.

  84. GLM Assistant

    All 108 pass. Let me run the copy, multipart, presigned-post, and versioning integration tests (the operations I touched).

  85. GLM Assistant

    All pass. Let me run the object-lock, conditional-write, and a few more integration tests covering retention/legalhold paths I touched.

  86. GLM Assistant

    All pass. Now I must remove my temporary ReproTest.java (the instructions forbid adding new tests to the repository).

  87. GLM Assistant

    Only the two source files are modified. Let me review the full diff to ensure correctness and no leftover artifacts.

  88. GLM Assistant

    The S3Service diff looks clean. Let me check the controller diff.

  89. GLM Assistant

    Both diffs are clean. Let me check whether there are HTTP-level non-ASCII key tests that could be affected by the controller behavior change (the controller no longer rejects non-ASCII keys via InvalidPathException).

  90. GLM Assistant

    There's a non-ASCII HTTP test in S3IntegrationTest (line 370). Let me view it and check whether it passed before my change in this POSIX environment.

  91. GLM Assistant

    The HTTP non-ASCII test (copyObjectWithNonAsciiKeySucceeds) runs in memory mode and passes with my change (part of the 108). My change makes the controller accept non-ASCII keys (matching UTF-8 behavior), which is more correct.

    Let me do a final confirmation: run S3ServiceTest excluding the pre-existing POSIX-locale copyObjectWithNonASCIIKey failure, to confirm zero failures from my change.

  92. GLM Assistant

    The only failure is the pre-existing copyObjectWithNonASCIIKey. Let me confirm the stack trace shows it fails at resolveObjectPath/writeFile (the pre-existing POSIX-locale issue), NOT at my validateObjectKey.

  93. GLM Assistant

    Confirmed: the only failure is at resolveObjectPath/writeFile (the pre-existing POSIX-locale issue with Path.resolve on non-ASCII, identical to the original code), NOT at my validateObjectKey — which correctly accepts non-ASCII keys now. No regression.

    Let me verify there are no existing tests expecting DeleteObjects to return per-key errors for traversal keys (which my upfront-rejection change would affect).

  94. GLM Assistant

    No tests expect per-key errors for traversal keys. The fix is complete and verified. Let me do a final full diff review.

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