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
Good, only one exception mapper for AwsException. Now let's update the two validation methods to throw a
WebApplicationExceptionwith an empty-body 400 response instead ofAwsException.Assistant
Let's use the
replacespecial command instead.Assistant
Now let's check the S3Service.java places that also throw InvalidKey for similar traversal (lines 2200, 2215) to see if they need similar treatment.
Assistant
Compilation succeeded (no errors reported). Now let's run the relevant integration tests to see behavior, and also update a temporary reproduce script.
Assistant
All good — these catch
AwsExceptiononly, so theWebApplicationExceptionpropagates untouched. Let's write a quick reproduction script using RestAssured-like curl against a running dev instance, or just trust the test run above which already confirms behavior (400, empty body). Let's also run the PUT-based tests (order 200-203) to confirm.Assistant
Good — that failure is pre-existing (order-dependent test unrelated to my change). Let's restore my changes and run the full test class to check overall pass/fail counts.
Assistant
Confirmed pre-existing failure unrelated to my change (likely order-dependent, since running standalone differs from running full sequence). Let's restore my changes.
Assistant
Confirmed: this pre-existing failure (
copyObjectWithNonAsciiKeySucceeds) exists even without my changes (baseline: 1 failure with unpatched code, 5 with my patch — the extra 4 are the intended behavioral changes for dot-dot handling). Let's restore my patch.Assistant
That confirms it's an environment/locale issue unrelated to my change (POSIX locale, not UTF-8), pre-existing regardless of the fix. Let's do a final review of the diff.
Assistant
This looks clean and minimal. Now let's also double check that other callers of
validateKeyNoTraversal/validateRawUriat other route methods (POST, HEAD for multipart, etc.) still function correctly by checking a broader grep for any place that catches genericExceptionthat might intercept theWebApplicationException.Assistant
None of these are in the call path of
extractObjectKey/validateRawUri/validateKeyNoTraversal. The fix is isolated and safe.Let's do a final check of the full diff and re-run the originally failing reproduction-style test one more time to be sure.
Assistant
This confirms the fix behaves as expected (400 with empty body, matching the AWS reference behavior from the issue). This test failure is expected/acceptable since it reflects old (incorrect) behavior; per instructions I won't modify the test file.
Assistant
Now let's go through the checklist explicitly.
Checklist review:
-
Reproduced the error: Yes — I ran the existing
S3IntegrationTesttraversal tests (e.g.,putObjectWithRawTraversalAboveBucketReturnsBadRequest) before my fix and confirmed the response body containedInvalidKey(matching the bug reported), which is the exact behavior described in the issue (anInvalidKeyerror body instead of AWS's empty-body 400). -
Confirmed fix resolves it: Yes — after the fix, the same requests (
PUT /test-bucket/../../secret.txt, encoded%2E%2Evariants, and the GET-basedpathTraversalAttemptsReturn400dot-dot cases) now return HTTP 400 with an empty body (content-length: 0), matching AWS's documented behavior described in the issue.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.