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:textAn error occurred (InvalidKey) when calling the PutObject operation: The specified key is invalid.Reproduction
bashprintf '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
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 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 call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Floci version / image tag: local Docker image built from main commit
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now let me understand the issue. When you do
aws s3api put-object --key ../bad.txt, the request URI looks like/raw-path-bucket/../bad.txtwhich contains a dot-dot path segment. AWS rejects this with HTTP 400 with an empty response body.Let me look at how this is currently handled. The existing
validateRawUri()method does some validation, but it might not be triggered for all cases. Let me look at how it's used.Assistant
Now let me look at how the existing
extractObjectKeyis implemented. The issue is with thevalidateKeyNoTraversalandvalidateRawUrimethods. ThevalidateRawUrimethod properly detects dot-dot in the raw URI, butextractObjectKeyonly callsvalidateKeyNoTraversal, notvalidateRawUri. Let me trace through what happens when the request comes in.Assistant
Let me look at the test cases that exist for S3 dot-dot validation.
Assistant
Let me reproduce the issue first to understand the actual behavior. Let me also look at the test for the same to understand expected behavior.
Assistant
Let me look at the S3RequestParser to see if it has any path validation.
Assistant
Let me check if there's a Dockerfile or how to test this in dev mode:
Assistant
Let me first try to run the existing tests to see if they pass:
Assistant
Let me look at the entire
extractObjectKeyandvalidateKeyNoTraversalandvalidateRawUriagain with full context:Assistant
Now let me start Floci and try to reproduce the issue. First, let me build the project:
Assistant
Good, Java 25 and Maven are available. Let me first try to understand the current behavior by directly making HTTP requests with curl. First, let me start Floci in the background:
Assistant
Now Floci is running. Let me test the current behavior:
Assistant
Now let me reproduce the issue with curl:
Assistant
The issue is reproduced. The
../is being normalized by curl or by HTTP server, and the request ends up at/bad.txt(which is treated as a bucket). Let me try with--path-as-isto send the raw path:Assistant
Now I can confirm the bug exists. Let me also check what happens with the URL-encoded form (which is what the AWS CLI typically sends):
Assistant
Let me also check what AWS actually returns. I need to test against the real AWS, but since I don't have credentials, let me search for AWS documentation/issue:
Assistant
Let me look at the relevant tests and any documentation:
Assistant
Now let me look at the existing tests in the repository:
Assistant
Let me look at the filter files:
Assistant
Let me look at all the routes/endpoints to understand where to add the validation. Let me also look at the existing tests to see what changes might happen:
Assistant
Let me see all endpoints in the S3Controller:
Assistant
Now I have a clear picture. Let me look at the
S3Controller.javato understand the structure better. Let me first look at where the bucket operations are.Assistant
Let me check the other filters:
Assistant
Let me look at the other filters:
Assistant
Let me check which endpoints don't have validation:
Assistant
Now I have a clear understanding. Let me first stop the dev server to make my changes, then make the fix.
Assistant
Good. Now let me make the fix. The approach is to add a helper method that detects dot-dot in the raw URI and returns a 400 with empty body, then call it at the start of all S3 endpoints that handle bucket/object operations.
Assistant
Now let me make the changes. First, I'll add a new method to detect dot-dot traversal and return a 400 with empty body:
Assistant
Now let me add the new method to detect dot-dot in raw URI and return 400 with empty body. I'll add it right before
extractObjectKey:Assistant
Now let me add the new method. I'll insert it right before the
extractObjectKeymethod's Javadoc:Assistant
Let me add the new method to the controller. I'll use the edit command.
Assistant
Now let me use the
edittool to insert the new method. First, I need to open the file:Assistant
Now let me insert this new method just before the
extractObjectKeyJavadoc. I'll use a Python script to do this safely:Assistant
The new method has been added. Now I need to call it at the start of every endpoint that involves a bucket or key in the URI. Let me identify all the endpoints:
Assistant
Now let me add the call to
rejectIfTraversalInRawUri()at the start of each endpoint. I'll use a Perl script:Assistant
Let me use single-quoted strings to avoid Perl interpolation issues:
Assistant
Let me use a different approach with a more careful Perl script:
Assistant
Perl regex syntax requires parens to be escaped. Let me try again with escaped parens.
Assistant
The issue is Perl interpolation. Let me use single-quoted strings:
Assistant
Let me use a simpler approach with
sed:Assistant
Let me write a different Perl script that uses
evalto avoid the interpolation issues:Assistant
Let me verify the changes:
Assistant
Now let me update the other endpoints. Let me continue with the listObjects endpoint:
Assistant
Now let me update the rest of the endpoints. I'll add the check at the start of each method body, before any existing validation:
Assistant
Let me check the
AwsExceptionhandling:Assistant
Let me check the
getObjectand other endpoints:Assistant
Now let me add the call to all the remaining endpoints. I'll do this with a more comprehensive script:
Assistant
Let me check the actual signatures of these methods:
Assistant
Let me update the script to match the correct end of each method:
Assistant
Now let me also add the call to the OPTIONS endpoints and the handleBucketPost:
Assistant
Now let me verify all the changes look good:
Assistant
I see 12 call sites. Let me verify by looking at each one:
Assistant
All 12 endpoints have been updated. Now let me also make sure the
validateRawUriandvalidateKeyNoTraversalmethods are not called for the dot-dot case (since we handle it before them). Let me also think about whether thevalidateRawUriinlistObjectsis a problem.Let me check the
listObjectsmethod again:Assistant
Now let me build the project to make sure everything compiles:
Assistant
Compilation succeeded. Now let me start Floci and test:
Assistant
Now let me test the fix:
Assistant
The fix is working. All three dot-dot variations now return HTTP 400 with empty body. Let me also test that valid requests still work:
Assistant
All valid requests work. Now let me test more edge cases:
Assistant
Let me test these one at a time:
Assistant
GET and DELETE work. HEAD request hangs (that's normal for curl). Let me test more:
Assistant
Now let me run the existing tests to see if my fix breaks any:
Assistant
The existing test
pathTraversalAttemptsReturn400is failing because it expects "InvalidKey" body, but my fix returns empty body. This is the expected behavior change as per the issue. The task says to ignore such test failures.Let me also run the test for internal dot-dot to make sure it still works:
Assistant
Let me look at the test setup:
Assistant
Let me run the full S3IntegrationTest to see which tests pass and which fail:
Assistant
There's a new failure
copyObjectWithNonAsciiKeySucceedsthat I need to investigate. Let me look at it:Assistant
Let me run just the failing test to see the actual error:
Assistant
Let me look at the full test log:
Assistant
Let me check if this test was passing before my changes:
Assistant
The test was already failing before my changes. So this is a pre-existing issue, not caused by my fix. Let me restore my changes:
Assistant
Good. Now let me look at all the test results to make sure my changes only break the tests that need to be updated (i.e., the ones that expect "InvalidKey" body). Let me run the full test suite again to see the current state:
Assistant
Let me also check the S3ControlController:
Assistant
Let me check the PreSignedUrlGenerator:
Assistant
Let me also search for any other tests that might be affected:
Assistant
Let me also check for any other tests with dot-dot:
Assistant
Let me run the S3ServiceTest to make sure my changes don't break it:
Assistant
The S3ServiceTest error is also a pre-existing issue with non-ASCII characters and
java.nio.file.Path. This is not caused by my changes.Let me verify the changes look good by reviewing the final code:
Assistant
Now let me verify the new method looks correct:
Assistant
Let me check the diff:
Assistant
The diff looks good. All 12 endpoints have been updated, and the new method
rejectIfTraversalInRawUrihas been added. Now let me also run a broader test to make sure I haven't broken anything else:Assistant
S3PreservationTest passes. Let me also run a few more S3-related tests:
Assistant
Let me also run a broader test suite:
Assistant
All other S3 tests pass. Let me also run a broader set of S3 tests:
Assistant
All other S3 tests pass. Now let me also verify the issue's exact reproduction works correctly:
Assistant
All tests pass:
- ✅ Create bucket works
- ✅ Raw dot-dot (
../bad.txt) - 400 with empty body - ✅ URL-encoded dot-dot (
..%2Fbad.txt) - 400 with empty body - ✅ Fully URL-encoded (
%2E%2E%2Fbad.txt) - 400 with empty body - ✅ Delete with dot-dot - 400 with empty body
- ✅ Valid request - 200
- ✅ Internal dot-dot - 200 (still allowed)
The fix correctly matches the AWS behavior described in the issue. Let me clean up the dev server:
Assistant
Now let me also do a final review of the changes:
Assistant
Let me also verify the new method's content is correct one more time:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.