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:
- Floci version / image tag: local Docker image built from main commit
Assistant
Let me understand the issue:
- When an S3 object key contains ".." (dot-dot) path segments (like
../bad.txt), AWS S3 returns HTTP 400 Bad Request with an empty response body. - Floci (the S3 implementation) currently returns an
InvalidKeyerror body instead.
So the fix should make Floci return HTTP 400 Bad Request with an empty body when keys contain ".." path segments.
Let me explore the repository structure first.
- When an S3 object key contains ".." (dot-dot) path segments (like
Assistant
This looks like a Java/Maven project. Let me explore the source structure and find S3-related code.
Assistant
Let me search for S3-related files:
Assistant
Let me look at the S3 controller and request parser to find where key validation happens:
Assistant
The open command seems to need different arguments. Let me just use cat or the standard open command.
Assistant
I can see the key validation methods. Let me look at how errors are handled - the
xmlErrorResponsemethod andAwsException:Assistant
Let me look at the
xmlErrorResponsemethod andAwsExceptionclass to understand how errors are formatted.Assistant
Now let me look at the
S3RequestParserand understand the flow better:Assistant
Let me look at more of the S3Controller to understand the flow around key validation:
Assistant
Let me find the PutObject and DeleteObject handlers:
Assistant
Let me look at the putObject and deleteObject methods:
Assistant
Now let me look at deleteObject:
Assistant
Let me check the global exception mapper and how errors are handled:
Assistant
Let me search for any other exception mappers or error handling that might affect the response:
Assistant
Let me check where
validateRawUriis called and if there's any pre-filtering:Assistant
Let me see context around line 2496 and the methods:
Assistant
Let me look at line 297 to see the third
validateRawUri()call:Assistant
Now I have a clear understanding of the issue. Let me create a script to reproduce the error first:
Assistant
Now I understand the issue fully. Let me implement the fix. The key insight is:
- AWS S3 returns HTTP 400 with an empty body for dot-dot path traversal in keys
- Floci currently returns an XML error body with
InvalidKeyerror code - The fix: change the validation methods to throw
jakarta.ws.rs.WebApplicationException(which yields empty body 400) instead ofAwsExceptionfor dot-dot traversal
Let me implement:
Assistant
Let me first see the imports:
Assistant
Good,
jakarta.ws.rs.*is already imported which includesWebApplicationException. Now let me make the changes. First, let me changevalidateKeyNoTraversal:Assistant
Now let me make the changes. First, change
validateKeyNoTraversal:Assistant
Let me use the proper syntax for the replace command:
Assistant
Let me use sed instead for the edits:
Assistant
Let me verify which lines were changed:
Assistant
Let me check line 2527 context - I want to keep the URL decode failure as AwsException:
Assistant
Good, the changes look correct. Now let me verify there's no global exception mapper that might interfere with
WebApplicationException:Assistant
Let me check the listObjects method to make sure the
validateRawUri()call there will work with the new exception:Assistant
Let me check all methods that call
extractObjectKey:Assistant
Let me check each call site to ensure they handle the exception properly:
Assistant
So line 569 is in a try block. Let me check the other:
Assistant
And line 933:
Assistant
All call sites are inside try-catch blocks for
AwsException, soWebApplicationExceptionwill propagate correctly. Let me verify the current state of the changes:Assistant
Now let me see if there are any existing tests for this behavior that I should check:
Assistant
Let me check the tests that reference
InvalidKeyto understand what they test:Assistant
Let me also check the other test cases:
Assistant
Let me check the S3ServiceTest:
Assistant
This test calls
s3Service.putObjectdirectly. Let me check if S3Service has its own key validation:Assistant
Let me look at the
resolveObjectPathmethod in S3Service:Assistant
Let me look at
resolveObjectPath:Assistant
The changes look correct. Let me now try to compile the project to make sure the changes are valid:
Assistant
The mvnw script requires HOME to be set. Let me set it.
Assistant
Let me verify the build was successful:
Assistant
Let me force recompilation of the changed file:
Assistant
The build succeeds. Now let me also check that we need to also update the
S3Service.javato be consistent. Let me look at the service layer methods again. Currently, theresolveObjectPathandresolveVersionedPathin S3Service also throwAwsException("InvalidKey", ...).But the controller validates first (via
validateKeyNoTraversalandvalidateRawUri), so the service layer wouldn't be reached for HTTP requests with dot-dot keys.However, for consistency, should I also update the service layer? The issue says "Floci returns an InvalidKey error body" - this is the HTTP API response. My controller changes fix that. The service layer changes would be a secondary concern.
Let me now run the relevant tests to see what passes and what fails:Let me run the specific S3 tests related to this change:
Assistant
The S3ServiceTest passes. Now let me check if there are any other places that might need changes, like the PreSignedUrlFilter:
Assistant
Let me verify there are no other key-handling methods that might need changes:
Assistant
All methods that handle keys go through
extractObjectKey→validateKeyNoTraversal. The fix covers all object operations. Let me verify the final state of my
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.