Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· 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. MiniMax Assistant

    Let me start by exploring the repository structure to understand what we're working with.

  3. MiniMax Assistant

    This is a Java-based AWS emulator called Floci. The issue is about S3 object keys escaping above the bucket root during path normalization. Let me explore the S3 service.

  4. MiniMax Assistant

    Let me look at the relevant section around line 2168 where the bucket directory normalization is happening.

  5. MiniMax Assistant

    Let me look at the S3 controller and search for path resolution patterns:

  6. MiniMax Assistant

    Let me look at the storage configuration:

  7. MiniMax Assistant

    Let me look at existing S3 tests to understand the expected behavior:

  8. MiniMax Assistant

    .Let me look at the existing tests for this feature:

  9. MiniMax Assistant

    Let me look at the integration test for path traversal:

  10. MiniMax Assistant

    Let me look at S3Service.java around the resolveObjectPath:

  11. MiniMax Assistant

    Let me look at the multipart-related code:

  12. MiniMax Assistant

    Let me look at the S3Controller more carefully to see the full path handling:

  13. MiniMax Assistant

    Let me write a quick Java test to verify if there's actually a bug:

  14. MiniMax Assistant

    .The test results show that the current check seems to work for most cases. The key ".." becomes "....s3data" which stays inside the bucket. That's correct because .. as a literal key name isn't a traversal - it's just a file called .. which becomes ....s3data.

    But wait, the issue says "S3 object keys can escape above the bucket root during path normalization". Let me look more carefully at what's happening.

    Let me trace the actual key extraction from the controller. Maybe the issue is that certain keys are NOT being validated by validateKeyNoTraversal?

    Let me look at all the code paths where extractObjectKey is called vs where direct path parameters are used.

  15. MiniMax Assistant

    Let me look at the putObject handler:

  16. MiniMax Assistant

    Let me check all places where the key is used:

  17. MiniMax Assistant

    Let me look at the bucket creation logic:

  18. MiniMax Assistant

    Let me look at the deleteObject method:

  19. MiniMax Assistant

    Let me look at deleteFile:

  20. MiniMax Assistant

    Let me search for places where the path is constructed directly:

  21. MiniMax Assistant

    Let me trace through what happens with a key containing .. carefully. Let me run a real test against the implementation:

  22. MiniMax Assistant

    I can see the issue! When the bucket name contains traversal patterns like ../escape, the bucketDir ends up outside dataRoot. Let me look at where the bucket name is used:

  23. MiniMax Assistant

    I see! The current check resolved.startsWith(bucketDir) is NOT sufficient. It needs to also check that bucketDir is within dataRoot. Let me check if users can create buckets with such names:

  24. MiniMax Assistant

    Let me search for any bucket name validation:

  25. MiniMax Assistant

    Let me look at the headObject handler:

  26. MiniMax Assistant

    Let me look at the getObject handler:

  27. MiniMax Assistant

    Let me look at the S3Service.getObject:

  28. MiniMax Assistant

    Let me try to compile and run the existing tests to see if they pass:

  29. MiniMax Assistant

    There's a test failure! Let me look at the test:

  30. MiniMax Assistant

    Let me run just the tests related to the path traversal issue:

  31. MiniMax Assistant

    Let me write a test to verify the issue:

  32. MiniMax Assistant

    Let me check if there's a bucket name validation:

  33. MiniMax Assistant

    Let me look at the integration tests to understand what's expected:

  34. MiniMax Assistant

    Let me look at the copyObject handler:

  35. MiniMax Assistant

    Let me check the validateKeyNoTraversal method more carefully. I notice the check uses dummyRoot but doesn't have the .s3data suffix:

  36. MiniMax Assistant

    Let me look at what the validateRawUri catches:

  37. MiniMax Assistant

    Let me look at more edge cases:

  38. MiniMax Assistant

    Let me look at the other places that work with keys:

  39. MiniMax Assistant

    Let me look at deleteObjects and completeMultipartUpload:

  40. MiniMax Assistant

    Let me look at handleDeleteObjects and the deleteObjects function:

  41. MiniMax Assistant

    Let me look at the in-memory mode for deleteObject:

  42. MiniMax Assistant

    Let me look at the integration test more carefully to see what specific cases are being tested:

  43. MiniMax Assistant

    Let me look at the leading slash key tests:

  44. MiniMax Assistant

    Let me look more carefully at the issue. Let me check the CHANGELOG to see if there's something about recent changes:

  45. MiniMax Assistant

    Let me look at the previous path traversal hardening commit:

  46. MiniMax Assistant

    Let me look at the existing test to see if there's a specific case being tested:

  47. MiniMax Assistant

    Let me look at the controller diff:

  48. MiniMax Assistant

    Let me check if there's something specific about the S3Service:

  49. MiniMax Assistant

    Let me look at the deleteObjects handler:

  50. MiniMax Assistant

    Let me look at the existing test for the path traversal:

  51. MiniMax Assistant

    Let me write a small test to demonstrate the actual issue:

  52. MiniMax Assistant

    Let me look at the existing tests for path traversal to understand what's expected:

  53. MiniMax Assistant

    Let me look at all the file operations in S3Service:

  54. MiniMax Assistant

    Let me check the multipart path:

  55. MiniMax Assistant

    Let me look at the existing validateKeyNoTraversal more carefully:

  56. MiniMax Assistant

    Let me check where validateRawUri is called:

  57. MiniMax Assistant

    Let me look at all the S3 integration tests to see which ones are about path traversal:

  58. MiniMax Assistant

    Let me look at the S3Controller more carefully to understand the flow:

  59. MiniMax Assistant

    Let me look at storeObject:

  60. MiniMax Assistant

    Let me look for any TODOs or FIXMEs:

  61. MiniMax Assistant

    Let me write a comprehensive test to see all the cases:

  62. MiniMax Assistant

    Let me test with a malicious bucket name:

  63. MiniMax Assistant

    This is a real issue! The test shows that:

    1. The bucket ../escape is created
    2. The bucket test/../escape is created and maps to dataRoot/escape
    3. The bucket /test-bucket is created (but no file is written, possibly because the path is being treated as absolute)

    Let me check what happens with the /test-bucket case. The file foo.s3data was supposed to be created in /test-bucket/foo.s3data. But the listing only shows test-bucket and escape. Let me check if the file was created at the root.

    Actually, looking at the output, the listing starts from tempDir.resolve("s3") which is /tmp/floci-malicious-bucket-test/s3. So:

    • /tmp/floci-malicious-bucket-test/s3/test-bucket/foo.s3data - exists (from the first bucket)
    • /tmp/floci-malicious-bucket-test/s3/escape/foo.s3data - exists (from the third bucket test/../escape)

    But for /test-bucket, the file should be at /test-bucket/foo.s3data which is at the system root. Let me check.

    Wait, but the second bucket ../escape should have created the file at parent(dataRoot)/escape/foo.s3data. Let me check:

    • dataRoot = /tmp/floci-malicious-bucket-test/s3
    • bucketName = "../escape"
    • bucketDir = dataRoot.resolve("../escape").normalize() = /tmp/floci-malicious-bucket-test/escape
    • resolved = bucketDir.resolve("foo.s3data").normalize() = /tmp/floci-malicious-bucket-test/escape/foo.s3data

    But the listing only shows files in /tmp/floci-malicious-bucket-test/s3/.... So the file was NOT created at /tmp/floci-malicious-bucket-test/escape/.... Let me re-check.

    Actually, looking at the output, there's no /tmp/floci-malicious-bucket-test/escape listed. So the file was NOT created there. But there's /tmp/floci-malicious-bucket-test/s3/escape/foo.s3data from the third bucket.

    Wait, let me re-look at the output:

    Files created in tempDir:
      /tmp/floci-malicious-bucket-test/s3
      /tmp/floci-malicious-bucket-test/s3/test-bucket
      /tmp/floci-malicious-bucket-test/s3/test-bucket/foo.s3data
      /tmp/floci-malicious-bucket-test/s3/escape
      /tmp/floci-malicious-bucket-test/s3/escape/foo.s3data
    

    So the files are:

    1. /tmp/floci-malicious-bucket-test/s3/test-bucket/foo.s3data (from bucket "test-bucket")
    2. /tmp/floci-malicious-bucket-test/s3/escape/foo.s3data (from bucket "test/../escape")

    But what about:

    • Bucket "../escape": the file should be at /tmp/floci-malicious-bucket-test/escape/foo.s3data (outside s3)
    • Bucket "/test-bucket": the file should be at /test-bucket/foo.s3data (system root)

    Neither of these is in the listing. So either:

    • The files were not created (maybe an exception was thrown)
    • The files were created at different locations

    Wait, the putObject for both "../escape" and "/test-bucket" returned SUCCEEDED. So the files should have been created somewhere.

    Let me check the file system directly:

  64. MiniMax Assistant

    Now I understand the actual issue. The bucket name itself can be malicious (e.g., ../escape) and the resolved path can escape the data root. Let me look at the current implementation one more time and plan the fix:

  65. MiniMax Assistant

    Now I understand the actual issue clearly. Let me look at the current resolveObjectPath and resolveVersionedPath to understand what changes need to be made:

  66. MiniMax Assistant

    Now I understand the issue. The current implementation has a check that the resolved path starts with bucketDir, but it doesn't check that bucketDir itself is within dataRoot. So if a bucket name contains path traversal (e.g., ../escape), the resolved path can escape the data root.

    Let me also look at how the issue could be in the validateKeyNoTraversal function:

  67. MiniMax Assistant

    Now I have a clear understanding. The issue is in resolveObjectPath and resolveVersionedPath - they don't check that the bucket directory itself is within the data root. Let me make the fix:

  68. MiniMax Assistant

    Now let me implement the fix. The fix is to add a check in resolveObjectPath and resolveVersionedPath to ensure the bucket directory is within the data root:

  69. MiniMax Assistant

    Let me make the fix now. I'll modify resolveObjectPath and resolveVersionedPath to add thecheck that the bucket directory is within the data root.

  70. MiniMax Assistant

    Let me simplify the fix by removing the equals check, since Path.startsWith already handles the equality case:

  71. MiniMax Assistant

    Let me simplify the fix by removing the unnecessary equals checks:

  72. MiniMax Assistant

    Let me look at the putObject flow to ensure the validation happens before storage operations:

  73. MiniMax Assistant

    I notice that storeObject calls writeFile AFTER storing the metadata. Let me look at the flow to ensure the validation happens before any storage operations:

  74. MiniMax Assistant

    I need to ensure the validation happens BEFORE any storage operations. Let me add a validation call at the beginning of storeObject:

  75. MiniMax Assistant

    Now let me add the validateObjectKey method. Let me put it right after resolveObjectPath and resolveVersionedPath:

  76. MiniMax Assistant

    The file is in a bad state. Let me check the current state:

  77. MiniMax Assistant

    The file is messed up. Let me revert and re-apply the fix properly:

  78. MiniMax Assistant

    Now let me apply the fix properly:

  79. MiniMax Assistant

    Now let me also add the validateObjectKey call at the beginning of storeObject:

  80. MiniMax Assistant

    Now let me add the validateObjectKey call at the beginning of storeObject:

  81. MiniMax Assistant

    Now let me also add validation for deleteObject and other operations:

  82. MiniMax Assistant

    Now let me also add validation for getObject and headObject:

  83. MiniMax Assistant

    Now let me also look at the copyObject operation:

  84. MiniMax Assistant

    Let me check the multipart operations:

  85. MiniMax Assistant

    Let me add validation to initiateMultipartUpload and completeMultipartUpload:

  86. MiniMax Assistant

    Let me find the completeMultipartUpload and abortMultipartUpload methods:

  87. MiniMax Assistant

    Let me also check restoreObject:

  88. MiniMax Assistant

    Now let me compile and run the existing tests:

  89. MiniMax Assistant

    Let me run more tests:

  90. MiniMax Assistant

    Let me run more S3 tests to make sure I didn't break anything:

  91. MiniMax Assistant

    All 41 S3ServiceTest tests pass. Let me also run the S3IntegrationTest:

  92. MiniMax Assistant

    There are 75 test failures! Let me investigate:

  93. MiniMax Assistant

    Let me look at one of the failing tests:

  94. MiniMax Assistant

    Let me check what's happening with the request:

  95. MiniMax Assistant

    Let me check the actual error by running a single test:

  96. MiniMax Assistant

    Let me check the storage configuration:

  97. MiniMax Assistant

    Let me write a test to check the path comparison:

  98. MiniMax Assistant

    I found the issue! The dataRoot has a leading ./ that needs to be normalized. Let me fix the comparison:

  99. MiniMax Assistant

    Let me fix the comparison by normalizing the dataRoot:

  100. MiniMax Assistant

    Now let me run the tests again:

  101. MiniMax Assistant

    The error is now NoSuchBucket - the test doesn't create the bucket. Let me check the test order:

  102. MiniMax Assistant

    All 108 S3IntegrationTest tests pass! Let me run all the S3 tests:

  103. MiniMax Assistant

    All 526 S3 tests pass. Now let me write a test to verify the fix works for the malicious bucket name case:

  104. MiniMax Assistant

    The fix works! Let me clean up:

  105. MiniMax Assistant

    Let me re-run all the S3 tests to verify everything still works:

  106. MiniMax Assistant

    Let me also run other tests that interact with S3:

  107. MiniMax Assistant

    Let me run a broader test suite to make sure nothing else is broken:

  108. MiniMax Assistant

    All 1439 tests pass. Let me look at the diff of my changes:

  109. MiniMax Assistant

    Let me also write a final comprehensive test to verify the fix:

  110. MiniMax Assistant

    The fix is working correctly. Let me clean up:

  111. MiniMax Assistant

    Let me also run all the tests one more time to make sure everything is in order:

  112. MiniMax Assistant

    Let me do a final check of my changes:

  113. MiniMax Assistant

    Let me do a final summary of the changes by viewing the final state of the relevant sections:

  114. MiniMax Assistant

    Now let me submit the changes:

  115. MiniMax Assistant

    Let me run the tests one more time to confirm everything is in order:

  116. MiniMax Assistant

    All 526 S3 tests pass. Let me also provide the final summary of my work:

    Summary of Changes

    Issue

    S3 object keys could escape above the bucket root during path normalization. The existing implementation in S3Service.resolveObjectPath only checked if the resolved path was within the bucket directory (resolved.startsWith(bucketDir)), but didn't check that bucketDir itself was within the data root (bucketDir.startsWith(dataRoot)). This allowed malicious bucket names like ../escape or /test-bucket to cause the path to escape the data root, while a normal key like foo would be written to a location outside the S3 data directory.

    Fix

    1. Added a new validateObjectKey method in S3Service.java that:

    • Calls resolveObjectPath to perform path validation without actually using the resolved path
    • Catches InvalidPathException (e.g., for embedded NUL bytes) and converts it to InvalidKey
    • Rejects null keys

    2. Hardened resolveObjectPath and resolveVersionedPath by:

    • Normalizing dataRoot (using toAbsolutePath().normalize()) so it compares consistently with the resolved bucket path (a relative dataRoot like ./data/s3 was failing the check)
    • Adding a check that the bucket directory is within the data root (defense against malicious bucket names)
    • Throwing AwsException("InvalidKey", ..., 400) when the check fails

    3. Added validateObjectKey calls at the beginning of:

    • storeObject (called by putObject)
    • getObject
    • headObject
    • deleteObject
    • initiateMultipartUpload

    This ensures that all object-level operations validate the key BEFORE any storage operations are performed. The rejection happens with HTTP 400 and the S3 error code InvalidKey.

    Tests

    • All 526 S3 tests pass (S3*)
    • All 1439 related tests pass (*S3*Test,S3*Test,*ServiceTest,FilterTest)
    • All 23 CUR tests pass (CUR uses S3)

    Checklist

    • ✅ If an error was reported in the issue description, I have successfully reproduced it. I created a test script that demonstrated bucket names ../escape and /test-bucket could create files outside the data root
    • ✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error. Verified that these malicious bucket names are now rejected with InvalidKey and no files are created outside the data root
    • ✅ I have thought about edge cases and made sure my fix handles them as well. Handles path traversal in keys, malicious bucket names, null keys, embedded NUL bytes, and the case where dataRoot is a relative path
    • ✅ I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. All S3 tests, integration tests, and CUR tests pass

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