ISSUE DESCRIPTION [BUG] S3 dot-dot object requests return InvalidKey Service Amazon S3…
- User
ISSUE DESCRIPTION
[BUG] S3 dot-dot object requests return InvalidKey
Service
AWS API Action
Expected behavior
AWS behavior rejects object requests whose key causes a dot-dot path segment to appear in the request URI with HTTP 400 Bad Request and an empty response body.
Actual behavior
Floci returns an
InvalidKeyerror body:An error occurred (InvalidKey) when calling the PutObject operation: The specified key is invalid.Reproduction
printf 'safe-data' > body.txt aws --endpoint-url http://localhost:4566 s3api create-bucket \ --bucket raw-path-bucket aws --endpoint-url http://localhost:4566 s3api put-object \ --bucket raw-path-bucket \ --key ../bad.txt \ --body body.txtEnvironment
- Floci version / image tag: local Docker image built from main commit
a7b0826c - Java SDK version (if applicable): N/A; verified with AWS CLI
- How you're running Floci (Docker / native /
mvn quarkus:dev): Docker
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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
- Floci version / image tag: local Docker image built from main commit
Assistant
Let me start by understanding the issue. The problem is about S3 dot-dot object requests. When a key contains
..(like../bad.txt), AWS S3 returns HTTP 400 Bad Request with an empty response body. But Floci (which seems to be a local S3-compatible service, similar to LocalStack) returns anInvalidKeyerror body instead.Let me explore the repository structure first.
Assistant
This looks like a Java/Maven project. Let me explore the src directory to understand the project structure.
Assistant
Let me search for S3-related files and the "InvalidKey" error message.
Assistant
I need to only use one tool call at a time.
Assistant
Let me look at the S3-related files to understand how key validation works
Assistant
Let me look at S3Controller.java and S3Service.java to understand how the key validation works
Assistant
Let me search for "InvalidKey" in the S3Controller and S3Service
Assistant
Let me look at the key validation code around line 2500
Assistant
Now let me understand how
AwsExceptionis handled in the application to see how errors are serialized to responses.Assistant
Let me look at the AwsException and AwsExceptionMapper to understand the error response handling:
Assistant
Now let me look at the AwsExceptionMapper.
Assistant
Let me search for where
validateRawUriandvalidateKeyNoTraversalare called in S3Assistant
Let me look at the S3 test files to understand how the dot-dot path is tested and what response
Assistant
Let me look at the test around that line.
Assistant
Let me look at lines around 156, 243, 297 and 2166 where validateRawUri and validateKeyNoTraversal are called
Assistant
Let me look at the putObject and deleteObject methods
Assistant
Let me look at the putObject method and surrounding
Assistant
Let me find the
xmlErrorResponsemethodAssistant
Let me look at the
xmlErrorResponsemethodAssistant
Let me look at the catch block pattern around line 120-140
Assistant
Let me search for how WebApplicationException or BadRequestException is used in this
Assistant
Let me look more specifically at the main source code for exception handling patterns
Assistant
Let me check what methods call validateRawUri at lines 243 and
Assistant
Now I have a good understanding of the problem. Let me first create a reproduction script to verify the current behavior, then implement
Assistant
Let me first run the specific S3 tests related to path traversal to see the current behavior
Assistant
The HOME environment variable is not set. Let me set it and try again.
Assistant
Now I have a clear understanding of the problem. Let me implement the fix. The issue is that
validateRawUri()andvalidateKeyNoTraversal()throwAwsException("InvalidKey", ...)which results in an XML error body. AWS returns HTTP 400 with an empty body for dot-dot paths.I'll change these methods to throw
jakarta.ws.rs.WebApplicationExceptionwith status 400 and empty entity, which matches AWS behaviorAssistant
Let me check the existing imports in S3Controller.java
Assistant
Good,
jakarta.ws.rs.*is already imported, which includesWebApplicationException. Now let me make the changes. I'll replace eachAwsExceptionthrow invalidateKeyNoTraversalandvalidateRawUriwithWebApplicationException.Assistant
Let me use
--allto replace all occurrences of the first pattern, and then handle the second one separatelyAssistant
Now let me replace the remaining
AwsExceptionat line 2514 (InvalidPathException case)Assistant
Let me verify the changes look correct
Assistant
Let me also check line 2166 where
validateKeyNoTraversalis calledAssistant
Let me check what method
validateKeyNoTraversalat line 2166 is in, and whether it has a try-catchAssistant
Let me find the
handlePostObjectmethodAssistant
Let me look at the method signature around line 2100-2200
Assistant
Let me check the method at line 2242 to see if it's the presigned post handler
Assistant
Now let me run the relevant S3 tests to verify the changes work
Assistant
The tests are failing because they expect "InvalidKey" in the body, but now the body is empty - which is exactly what AWS does. This confirms our fix is working correctly.
Let me also check the test at line 2030 which tests
prefix=../xAssistant
Let me now run a broader set of S3 tests to make sure nothing else is broken
Assistant
Let me see all 5 failing tests
Assistant
Let me look at the
copyObjectWithNonAsciiKeySucceedstest to understand if our change broke itAssistant
Let me look at the full
copyObjectWithNonAsciiKeySucceedstestAssistant
Let me look at the full test from line 348.
Assistant
Let me look at the copy-source handling to understand why the non-ASCII test fails
Assistant
Let me look at
handleCopyObjectmore closelyAssistant
Let me run just the non-ASCII test to see the detailed
Assistant
Let me look at the test more carefully
Assistant
Let me create a quick test to understand if the issue is with how
Path.ofhandlesAssistant
Let me check if this test was already failing before my changes by stashing and testing
Assistant
Good, the
copyObjectWithNonAsciiKeySucceedstest was already failing before my changes - it's a pre-existing issue. Let me restore my changes.Assistant
Let me verify that the 4 dot-dot related tests were passing before
Assistant
Good, the 4 dot-dot tests were passing before, now they fail as expected because the body is empty (matching AWS behavior). Let me restore
Assistant
Let me also check S3ServiceTest for any tests related to key validation
Assistant
Let me look at the tests in S3ServiceTest that test key validation
Assistant
Let me check if S3Service also validates keys
Assistant
Let me look at the key validation in S3Service
Assistant
Let me check if s3Service.putObject calls resolveObjectPath
Assistant
Let me also check other methods that call extractObject
Assistant
Let me fix the typ
Assistant
Let me check the methods at these lines
Assistant
Let me now run the full S3 test suite to see the complete picture of failures
Assistant
Let me check if the S3ServiceTest traversal tests pass
Assistant
Let me review the final diff to make sure everything looks
Assistant
Let me check the try-catch structure around line 2166 in doHandlePresignedPost
Assistant
Let me check handlePresignedPost
Assistant
Let me verify there are no other "InvalidKey" references in the main source that need changing
Assistant
My changes look complete. Let me do a final verification by running the tests that were previously passing to make sure they still pass.
Assistant
Let me run the S3ServiceTest more broadly to ensure no regressions beyond the pre-existing
Assistant
Let me also check the S3MultipartServiceTest for any impact
Assistant
All good. Let me also verify the S3VersioningServiceTest and broader check
Assistant
I'm satisfied with the changes. Let me do a final review of the diff before
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →