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
I’ll first inspect the repository structure and search for S3 key validation, URI path handling, and existing
InvalidKeybehavior. Then I’ll reproduce the relevant code path with the project’s tests or a focused temporary harness, implement the smallest compatible fix, and run affected tests. - Assistant
The broad search shows this is a Maven/Quarkus Java service, but not yet the implementation because the initial output was dominated by compatibility tests. I’ll narrow the search to
src, inspect repository-specific agent guidance, and locate controller/exception-mapper tests that define raw-path behavior and response serialization. - Assistant
There is already explicit traversal detection in
S3Controller, and it currently throwsAwsException("InvalidKey", ...), exactly explaining the reported XML body. I’ll inspect that helper in context, all callers (to ensure both PUT and DELETE are covered), nearby malformed-key rules that must retainInvalidKey, and available mechanisms for returning a bare HTTP 400 without global side effects. - Assistant
The existing integration tests actually encode the old, now-incorrect expectation (
InvalidKey) for traversal, while null-byte and other invalid-character cases correctly need to keep that body. Per the instruction not to modify tests, I’ll change only production code and validate with focused requests. First I need precise helper/caller flow: whether controller methods catchAwsExceptionand serialize locally means a distinct exception may be safest, or the validator can return/throw a JAX-RS response exception that bypasses those catches. - Assistant
Two validators can reject above-root traversal:
validateRawUri()is invoked before routes that may have been normalized away, whilevalidateKeyNoTraversal()handles encoded object keys. Both currently produceInvalidKey. A JAX-RSWebApplicationExceptioncarrying an explicitly built empty 400 response will bypass each method’scatch (AwsException)and preserve malformed encoding/null-byte asInvalidKey. I’ll confirm all endpoint placements and test runtime behavior before editing both traversal branches. - Assistant
The flow confirms PUT and DELETE both call
extractObjectKey, and normalized raw traversal can land on bucket routes wherevalidateRawUricatches it. The same protocol condition applies regardless of HTTP method, so the response-shape fix should be centralized in both traversal checks rather than hardcoded to PUT/DELETE. I’ll run the existing traversal-focused tests now to establish the reported pre-fix behavior (400 withInvalidKey) before making the change. - Assistant
The Maven wrapper cannot start because this minimal environment has no
HOME; this is environmental, not a repository failure. I’ll rerun with a temporary standard home directory set, preserving the same focused test selection. - Assistant
The baseline reproduces the bug: all four requests pass assertions requiring
InvalidKeyin the body. I’ll now replace only the two “traversal escapes object-key root” exceptions with an empty-responseWebApplicationException. Invalid percent encoding and invalid path characters remainAwsException/InvalidKey, and internal balanced traversal remains accepted. - Assistant
Python is unavailable in this container, so no file was changed. I’ll apply the same narrow edits using the repository-provided
editcommand at the known line ranges, working bottom-up so line numbers remain stable. - Assistant
The diff is correct and compiles via the existing wildcard JAX-RS import. I’ll rerun the same focused tests. Their traversal assertions should now fail specifically because the actual response body is empty; the null-byte subcase in the combined test should still satisfy
InvalidKey. This gives direct HTTP-level confirmation of response mapping without changing tests. - Assistant
Post-fix HTTP tests show status remains 400 and the actual body is empty for raw, encoded, and encoded-slash traversal—the intended behavior. The combined legacy GET test stops at its first now-obsolete assertion, so it does not independently prove null-byte preservation. I’ll launch the service temporarily and use
curl --path-as-isto verify PUT and DELETE (raw and encoded), null-byteInvalidKey, and balanced internal traversal. No repository tests will be added or modified. - Assistant
Manual wire-level verification confirms all required cases: raw and encoded PUT/DELETE return
400with exactly 0 response bytes; null-byte remains a 400 XMLInvalidKey; and balanceddocs/../file.txtpasses traversal validation (then returnsNoSuchBucket, as expected in the standalone temporary server). I’ll improve the helper name/comment to make the intentional empty AWS response and catch bypass clear, then run service tests and compile/package checks. - Assistant
The final diff is seven added lines/two replacements and documents why a
WebApplicationExceptionis intentional. I’ll run the S3 service unit suite (ensuring storage-level traversal defenses remain unchanged), the balanced internal traversal integration test, and a package build without rerunning the known obsolete traversal-body assertions. - Assistant
The test command exposed two pre-existing test-environment/order issues unrelated to this diff: the ordered integration method assumes an earlier test created
test-bucket, and the service suite’s non-ASCII filename test fails under this container’s ASCII filesystem encoding. All other 40 service tests passed. I’ll run the directly relevant service traversal method by name, then package separately (the previous&&correctly prevented packaging after test failure). I’ll also verify no dev process remains. - Assistant
Packaging succeeds. My first focused method selector used the wrong name and therefore ran zero tests; the source shows the correct names. I’ll run exactly the two storage traversal tests with UTF-8 forced to avoid the container locale issue, then perform final status/diff review.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.