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
Let me start by exploring the repository structure to understand the codebase.
Assistant
This appears to be a LocalStack-like project (Floci). Let me look at the S3 implementation.
Assistant
Let me look at the S3 request parser and the InvalidKey handling.
Assistant
Now let me look at the S3Controller's key validation logic.
Assistant
Let me see where
validateRawUriandvalidateKeyNoTraversalare called.Assistant
Let me look at how AwsException is mapped and the error response handling.
Assistant
Let me find the object PUT and DELETE handlers.
Assistant
Let me look at the AwsExceptionMapper to understand global exception handling.
Assistant
Now I need to understand the desired behavior. The issue says AWS 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.
So the fix should make Floci return HTTP 400 with an empty body when a dot-dot path segment appears.
The key question: should ALL dot-dot path segments be rejected (even ones that don't escape, like
a/../b), or only ones that escape the bucket? Let me re-read the issue:"AWS behavior rejects object requests whose key causes a dot-dot path segment to appear in the request URI"
So any dot-dot path segment in the request URI → 400 empty body. The reproduction uses
--key ../bad.txt.Wait, but let me check the existing
validateRawUri(). It does a depth-based check - it allows..segments as long as depth doesn't go below 0. Soa/../bwould be allowed (depth goes 1, 0, 1). But the issue says AWS rejects ANY dot-dot path segment.Hmm, let me think about this more carefully. Let me look at the test file for leading slash keys and other s3 tests to understand expectations.
Assistant
Let me search for existing tests related to dot-dot / traversal behavior.
Assistant
Let me search the test directory for HTTP-level tests involving dot-dot keys.
Assistant
Let me look at the compatibility tests directory for any hints about the expected dot-dot behavior.
Assistant
Let me check git history for the traversal validation code.
Assistant
So the previous commit (#1235) introduced the traversal rejection. The previous version had a simpler check that rejected ANY
..substring (case-insensitive, including encoded). The new version uses a depth-based check that only rejects escaping...Now the current issue: the response should be 400 with EMPTY body, not InvalidKey XML body.
Let me check the test changes in that commit.
Assistant
Now I understand the existing tests. The issue says AWS returns 400 with empty body, but the current implementation returns InvalidKey XML body. Let me see all the catch blocks in S3Controller.
Assistant
There's already a pattern at line 144 where a catch block returns an empty body. Let me look at lines 127-148.
Assistant
Let me look at where validateRawUri is called relative to try blocks.
Assistant
Let me look at the other object operations (GET, HEAD, DELETE) to see how they extract keys.
Assistant
Let me check the getObject handler body to confirm it calls extractObjectKey.
Assistant
I now have a clear understanding. Let me implement the fix. First, let me add an
emptyBodyflag toAwsException.Assistant
Let me check for any subclasses of AwsException.
Assistant
There's a subclass
TransactionCanceledException. I need to make sure adding the flag doesn't break it. I'll add a new constructor with the flag and keep the existing one. The subclass uses a constructor — let me check.Assistant
Now let me implement the changes. First, add the
emptyBodyflag toAwsException:Assistant
No python3. Let me use the editor commands instead.
Assistant
Now let me update the
AwsExceptionMapperto handle empty-body exceptions:Assistant
Now let me update the
xmlErrorResponsemethod in S3Controller to handle empty-body exceptions:Assistant
Now let me update the
validateRawUriandvalidateKeyNoTraversalmethods to throw the empty-body AwsException.Assistant
Let me check for other tests that assert on the InvalidKey message/body at the service level.
Assistant
Let me look at the tests at lines 1897, 1907, 1920.
Assistant
This test
pathTraversalAttemptsReturn400has three sub-cases:%2e%2e/%2e%2e/secret.txt(dot-dot escape) → expects InvalidKey body%00.txt(NUL byte → InvalidPathException) → expects InvalidKey body%2E%2E/%2E%2E/secret.txt(dot-dot escape) → expects InvalidKey body
The issue is specifically about dot-dot requests. The NUL byte case (sub-case 2) is a different error ("invalid characters") and is not part of this issue. So I'll change only the dot-dot escape throws to empty body, and keep the InvalidPathException (NUL byte) throw returning the InvalidKey body.
Let me now update the controller dot-dot escape throws:
Assistant
Now update the
validateRawUridepth==0 escape throw (line 2550):Assistant
Now let me update the service-level
resolveObjectPathandresolveVersionedPathto also use empty body for consistency:Assistant
Let me open the S3Service file first.
Assistant
Now let me verify the project compiles. Let me check the build setup.
Assistant
Offline mode is missing a plugin. Let me try with network access.
Assistant
Compilation succeeded. Now let me write a temporary reproduction test to verify the behavior. Let me check how the existing tests run (Quarkus tests).
Assistant
Compilation succeeded. Now let me create a temporary reproduction test to verify the behavior matches the issue's expectations.
Assistant
The output was truncated. Let me check the test result.
Assistant
All 10 tests passed, confirming the fix works:
- Dot-dot traversal (raw and encoded) → 400 + empty body ✓
- Internal traversal (
docs/../file.txt) → 200 (unchanged) ✓ - DELETE/GET with dot-dot → 400 + empty body ✓
- NUL byte → 400 + InvalidKey body (unchanged) ✓
- List with traversal in query string → 200 (unchanged) ✓
Now let me run the existing service-level unit tests to ensure they still pass.
Assistant
There's a failure in
copyObjectWithNonASCIIKey— but this looks like a pre-existingInvalidPathExceptionfromPath.resolvewith non-ASCII characters, unrelated to my change. Let me verify by checking if this test fails on the original code too.Assistant
This failure is from
Path.resolvethrowingInvalidPathExceptionfor non-ASCII characters — an environment/locale issue, not related to my change (which only modified the throw inside theifblock, afterPath.resolve). Let me confirm by stashing my changes and running this single test.Assistant
Confirmed:
copyObjectWithNonASCIIKeyfails on the original code too — it's a pre-existing environment/locale issue (filesystem encoding can't handle Japanese characters), not caused by my change. The traversal-related service tests (resolvePathWithTraversalThrows,putObjectWithInternalTraversalStaysWithinBucket) passed.Now let me run the S3IntegrationTest to confirm only the dot-dot-body-assertion tests break (as expected, since they test the old buggy behavior).
Assistant
5 failures, all asserting
containsString("InvalidKey")for dot-dot requests — exactly the buggy behavior the issue says to change. Let me see the full list of failed tests.Assistant
The 5 failures break down as:
- 4 dot-dot tests asserting the old buggy
InvalidKeybody (lines 1972, 1986, 2000, 1897) — these test the behavior the issue says to change, so they need updating (ignored per instructions). - 1 pre-existing
copyObjectWithNonAsciiKeySucceeds— the same non-ASCII/locale environment failure unrelated to my change.
This is exactly the expected outcome. Let me verify there are no other exception mappers or response paths that might serialize the AwsException body and bypass my empty-body check.
- 4 dot-dot tests asserting the old buggy
Assistant
Let me check the other catch blocks in S3Controller that might bypass
xmlErrorResponse.Assistant
Let me verify the POST form upload path (which calls
validateKeyNoTraversalat line 2166) routes throughxmlErrorResponse.Assistant
The POST form upload goes through
handleObjectPost→ which callsvalidateKeyNoTraversal(key)(line 2166, now in the file at a different line after my edits). Let me find the method that contains line 2166'svalidateKeyNoTraversal(key)and check its catch. Earlier I saw the POST handler. Let me find which method callsvalidateKeyNoTraversal(key)at the form-post level.The grep earlier showed:
- 2166: validateKeyNoTraversal(key); (this was before my edits added lines, so now shifted)
Let me re-grep.
Assistant
Line 2247
} catch (AwsException e) { throw e; }is in a policy-validation inner try. ThevalidateKeyNoTraversal(key)at line 2171 is indoHandlePresignedPostwhich is called byhandlePresignedPost(line ~2103 catch returnsxmlErrorResponse(e)). Let me verify. Actually, let me trace:validateKeyNoTraversal(key)at 2171 is insidedoHandlePresignedPost.doHandlePresignedPostis called byhandlePresignedPost(line 2103 area). The catch at 2108 is} catch (AwsException e) { return xmlErrorResponse(e); }? Let me check line 2108 context.Actually earlier output showed line 2108 catch returns xmlErrorResponse? Let me check.
Assistant
handlePresignedPostcatches AwsException and returnsxmlErrorResponse(e)(now handles empty body). Let me check the regular POST object handler at line 914.Assistant
All S3 AwsException handling routes through
xmlErrorResponse(e)(updated) or the globalAwsExceptionMapper(updated). The empty-body flag is respected everywhere.Now let me remove the temporary test file and do a final review of the changes.
Assistant
The diff is clean and focused. Let me do a final compile check to make sure everything builds correctly after removing the temp test.
Assistant
Compilation succeeds. Let me verify no stray temporary files remain and do a final review of the complete diff.
Assistant
Those
*Temp*matches are pre-existing tracked files (e.g., "Template", "VtlTemplateEngine") — not my temporary test, which wasTempDotDotReproTest.javaand is now deleted. Thegit status --shortconfirms only my 4 source files are modified. Let me confirm the temp test is gone.Assistant
All changes are clean and the temporary test is removed. Let me do a final summary review of the complete diff to ensure correctness.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.