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 map the repository and locate S3 request-path validation and related tests, then reproduce the current response through the narrowest available test or runtime path. After identifying where
InvalidKeyis generated, I’ll adjust the behavior to return a bare 400 specifically for URI dot-dot traversal cases, cover edge cases through existing test infrastructure where possible, and run the relevant suite. - Assistant
The repository already has explicit S3 key validation in both controller and service layers, with integration coverage around the relevant lines. I’ll inspect those validations, request routing/raw URI access, and global exception mapping to distinguish traversal in the request URI from ordinary invalid object keys without changing unrelated
InvalidKeysemantics. - Assistant
The current implementation already detects raw URI traversal but deliberately throws
AwsException("InvalidKey", ...), exactly causing the reported mismatch. The service-layer checks protect filesystem sandboxing and should retain structured errors; this bug is specifically protocol-level raw URI rejection. I’ll now inspect every call tovalidateRawUri, endpoint ordering, mapper behavior, and the exact integration assertions to choose the narrowest empty-response mechanism (likely returning/throwing a JAX-RS 400 response rather than an AWS domain exception). - Assistant
The affected integration tests currently assert the old body, but the task explicitly requires an empty body; per the environment rules I will not modify tests. Existing status assertions will still validate routing, while body assertions are expected to fail due to the intentional compatibility correction. Before editing, I’ll verify method behavior for PUT, DELETE, GET and whether raw unencoded
..reaches the application unchanged; I’ll also check available JAX-RS exceptions and response conventions so the result is exactly status 400 with no entity/content type. - Assistant
A bare
WebApplicationExceptionbuilt withResponse.status(400).build()bypassesAwsExceptionMapperand has no entity, matching AWS. Importantly, only the traversal branch should use it: malformed percent encoding and null/invalid path characters are separate invalid-key conditions and should remain structured. The existing depth algorithm intentionally follows S3’s relative-segment rule (internaldocs/../fileis valid; traversal above the key root is not), so I’ll preserve it. I’ll inspect object handlers to ensure validation happens before key extraction for PUT and DELETE, then make the minimal branch change. - Assistant
Object-route requests currently skip
validateRawUri()and fall through to filesystem-style key validation, which explains why encoded traversal also producesInvalidKey. I’ll invoke raw URI validation at the start of centralized object-key extraction and change only the “relative traversal escapes key root” outcome to a response-backedWebApplicationExceptionwith an entity-less 400. This covers PUT, DELETE, GET, HEAD, and multipart object requests consistently, while bucket-route calls continue to catch server-normalized raw traversal. Form POST keys still usevalidateKeyNoTraversaland retainInvalidKey, because no dot-dot segment appeared in that request URI. - Assistant
The combined shell command was rejected by the terminal wrapper due to quoting before anything executed. I’ll apply the two edits with the repository’s literal replacement utility, inspect the diff, and then run the focused test separately.
- Assistant
The editor utility found both targets but refused because they were outside its current displayed window. I’ll use line-based edits at the reported stable locations, starting from the later line so insertion does not shift it, then verify the resulting method.
- Assistant
The line-based replacement targeted the
if (depth == 0)line rather than the throw line because the editor’s displayed numbering reflected a different window state, leaving malformed code. I caught this in review. I’ll replace the whole..branch with the intended well-formed block and compile before testing. - Assistant
The code is now syntactically correct; compilation did not run because the environment has
HOMEunset and Maven wrapper requires it. I’ll rerun withHOME=/root. Then I’ll run the focused existing test: its obsoletecontainsString("InvalidKey")assertion should fail while showing an empty body, which directly confirms the required response shape. I’ll subsequently run unaffected S3 tests and use a temporary external check if needed, without changing tests. - Assistant
The focused runtime output confirms the fix precisely: HTTP 400,
content-length: 0, and no body. Its sole failure is the pre-existing assertion that requires the now-incorrectInvalidKeybody, so I will not alter that test. Next I’ll verify edge cases that must remain valid or structured: internal relative traversal (docs/../file) still succeeds, null-byte keys still returnInvalidKey, regular object deletion remains unaffected, and service-layer sandbox tests pass. I’ll locate suitable focused methods and run them. - Assistant
The null-byte assertion is bundled after traversal assertions that intentionally now fail, so it cannot be independently run without modifying tests. Service-layer coverage directly validates that invalid filesystem paths still produce
InvalidKey. I’ll run the two unaffected integration methods and both traversal service methods together, then inspect results. - Assistant
The two service tests passed. The selected integration methods are stateful
@Ordertests and failed only because their prerequisite bucket/object creation methods were excluded (both responses wereNoSuchBucket, not traversal regressions). I’ll avoid misinterpreting that as a code failure. To test HTTP edge cases independently without repository test changes, I can add prerequisite integration methods to the selection if method names are known; I’ll inspect early ordered setup methods and then run a minimal dependency chain plus internal traversal. - Assistant
I’ll rerun with explicit prerequisites:
createBucketbefore internal traversal, andputObject/copyObjectbefore ordinary delete. This validates the new centralized raw-URI check does not reject allowable internal dot-dot segments or normal DELETE requests. - Assistant
The prerequisite-aware run passed all seven selected tests, confirming normal PUT/copy/DELETE, valid internal traversal, and service sandbox behavior remain intact. I’ll add a concise comment documenting why this branch intentionally bypasses S3 XML/JSON error mapping, run the full
S3ServiceTest, compile/check the final diff, and review repository status for accidental files. - Assistant
The full service suite ran 41 tests; 40 passed, with one unrelated environment failure for a non-ASCII filename (
Malformed input ... src/?????.png.s3data) caused by the shell/filesystem character encoding, outside the changed controller path. The relevant service traversal tests passed both in the focused run and this suite.To satisfy the reproduction checklist rigorously, I’ll temporarily save the patch, restore the original controller, run the existing encoded-traversal test (which asserts and therefore confirms the old
InvalidKeybody), then reapply the patch and compile. This does not modify tests and avoids relying only on source inspection.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.