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
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 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. - Floci version / image tag: local Docker image built from main commit
Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
So
validateRawUrialready rejects dot-dot segments that would escape, andvalidateKeyNoTraversalalso checks. The issue is that the response body is theInvalidKeyerror, but AWS returns HTTP 400 Bad Request with an empty response body.Let me understand the flow better. Let me look at how these validation methods are called.
Assistant
So the
extractObjectKeycallsvalidateKeyNoTraversalwhich throwsAwsException("InvalidKey", ...). This produces the InvalidKey error body. The issue says AWS returns 400 with empty body.Let me look at how AwsException is mapped to a response.
Assistant
Now let me look at the S3-specific exception handling. The S3Controller has try-catch blocks. Let me look at the putObject and deleteObject handlers to see how exceptions are mapped.
Let me look at how the S3 errors are formatted. The issue says AWS returns 400 with empty body, but Floci returns InvalidKey error body. Let me look at the full putObject method.
Assistant
Now let me look at the putObject method to see how the exception is caught and whether it uses
xmlErrorResponse.Assistant
So when
extractObjectKeythrowsAwsException("InvalidKey", ...), it's caught bycatch (AwsException e) { return xmlErrorResponse(e); }which returns the XML error body.The issue says AWS returns HTTP 400 Bad Request with an empty response body for dot-dot path segment requests. So we need to make the dot-dot traversal case return an empty body instead of the InvalidKey XML.
Let me look at
validateRawUriandvalidateKeyNoTraversalmore carefully. ThevalidateRawUriis called at the start of bucket-level methods and theextractObjectKeycallsvalidateKeyNoTraversal.Wait, let me re-read the issue. The issue says:
- 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.
- Floci returns an InvalidKey error body.
So the fix is: for dot-dot path traversal requests, return 400 with empty body instead of the InvalidKey XML error.
Let me look more closely. There's
validateRawUriwhich is the main one checking for dot-dot. But where isvalidateRawUricalled for object-level operations? Let me check. The bucket-level methods call . Let me check the GET/PUT/DELETE object methods.Assistant
Now I understand the flow. The
validateRawUriis called for bucket-level operations but NOT for object-level operations. The object-level operations callextractObjectKeywhich callsvalidateKeyNoTraversal. ThevalidateKeyNoTraversalthrowsAwsException("InvalidKey", ...)which is caught and produces the XML error body.But the issue says AWS returns 400 with empty body. So the fix should be to make the dot-dot traversal case return 400 with empty body.
Let me reproduce the error first. Let me check the existing tests around this to understand the expected behavior.
Let me look at the S3IntegrationTest or similar tests for dot-dot / traversal.
Assistant
Now I understand. The existing tests expect the body to contain "InvalidKey". But the issue says AWS returns 400 with an empty body.
The issue is specifically about dot-dot path segments in the request URI. Let me look at the S3RequestParser and filters to understand the full request flow.
Assistant
Let me look at the S3Service validation method that's called.
Assistant
Let me look at the existing filters to understand the request pipeline.
Assistant
Now let me look at the object-level DELETE method and the bucket-level methods to see how they catch exceptions.
Assistant
Now let me see all the places where
validateRawUri()is called and the surrounding context.Assistant
Let me check if there are any other exception mappers that might intercept RuntimeExceptions.
Assistant
Now I understand the issue fully. The fix: when a literal
..path segment appears in the raw (undecoded) request URI, AWS returns HTTP 400 with an empty body. Currently Floci decodes the URI and throwsInvalidKey(XML body).My plan:
- Create an
S3PathTraversalException(extendsRuntimeException, notAwsException, so it bypasses thecatch (AwsException)blocks that build XML). - Create a dedicated
ExceptionMapperreturning 400 with empty body. - Detect literal
..segments in the raw undecoded path/key inextractObjectKeyandvalidateRawUri, throwing the new exception. The encoded%2E%2Ecase keeps the existingInvalidKeybehavior.
Let me first create a reproduction test to confirm the current behavior.
- Create an
Assistant
Let me look at the test setup (how the integration test bootstraps, the @BeforeAll etc.) to understand whether I can run a quick test. Actually, let me just look at how the test class is structured to understand port/config.
Assistant
Let me check the build tooling and run the existing traversal tests first to confirm the current behavior.
Assistant
The
putObjectWithInternalTraversalSucceedstest failed only because it depends oncreateBucket(test ordering) which wasn't selected. The traversal tests themselves pass currently. Let me now implement the fix.First, let me create the exception class:
Assistant
Now let me modify
extractObjectKeyto detect literal..segments in the raw (undecoded) key:Assistant
Now let me modify
extractObjectKeyto detect literal..segments in the raw (undecoded) key before decoding:Assistant
No python3. Let me use the
editcommand instead.Assistant
Now let me also handle
validateRawUri(bucket-level) for literal..segments in the raw path key portion:Assistant
Now let me compile to make sure it builds:
Assistant
Compilation succeeded. Now let me create a temporary test to verify the new behavior (literal
..→ 400 empty body; encoded stays InvalidKey; internal encoded stays 200):Assistant
The 5 key tests pass (literal
..PUT/DELETE/GET → 400 empty body; encoded above-bucket → InvalidKey). The only failure isinternalEncodedTraversalSucceedsreturning 404 because the bucket wasn't created yet (test ordering). Let me fix the temp test ordering:Assistant
All 6 temp tests pass. The fix works correctly. Now let me remove the temp test and run the existing S3 integration tests to see what's affected:
Assistant
There's an unintended regression:
copyObjectWithNonAsciiKeySucceedsnow returns 400 instead of 200. Let me investigate:Assistant
Let me check whether
copyObjectWithNonAsciiKeySucceedswas already failing before my change (could be a pre-existing/ordering issue). Let me stash my changes and test:Assistant
The isolated test fails on original code too — but that's an isolation issue. Let me check the full-class baseline on original code to see if
copyObjectWithNonAsciiKeySucceedspasses there normally:Assistant
On the original code, the full
S3IntegrationTestalready has 1 pre-existing failure (copyObjectWithNonAsciiKeySucceeds). With my change, there are 2 failures: the pre-existing one plus the intended behavior change (putObjectWithRawTraversalAboveBucketReturnsBadRequestnow returns empty body — exactly what the issue requires). So my change introduces no unintended regressions.Let me also run the
S3ServiceTest(service-layer traversal tests) to confirm those still pass:Assistant
One error in S3ServiceTest. Let me see what it is — is it pre-existing or caused by my change? My change is only in the controller, not the service. So it's likely pre-existing. Let me check the error detail.
Assistant
This is a pre-existing failure (
copyObjectWithNonASCIIKey) — a filesystem encoding issue inS3Service.resolveObjectPathwhich I didn't touch. Unrelated to my change.Let me run the leading-slash key integration test and the virtual-host test, since those exercise
extractObjectKey/ raw-URI parsing that I modified:Assistant
Hmm, exit code 0 but no output captured by grep. Let me run without grep to see the result.
Assistant
No failures shown — these tests passed. Let me confirm with a clean summary line. Let me run again capturing the "Tests run" line.
Assistant
All pass. Let me verify the final state of my changes and ensure no temp files remain:
Assistant
Let me do a final review of the full diff:
Assistant
The diff is clean and minimal. Let me do a final compile check to be 100% sure:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.