-
Notifications
You must be signed in to change notification settings - Fork 755
fix: trim whitespace from bucket location #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -309,6 +309,8 @@ func TestProcessBucketLocationResponse(t *testing.T) { | |||||||
| }{ | ||||||||
| {"my-bucket", "", true, APIErrors[0], "us-east-1", nil, true}, | ||||||||
| {"my-bucket", "", false, APIError{}, "us-east-1", nil, true}, | ||||||||
| {"my-bucket", "\n \n", false, APIError{}, "us-east-1", nil, true}, | ||||||||
| {"my-bucket", " \neu-central-1\t", false, APIError{}, "eu-central-1", nil, true}, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description says the trim happens before the This row covers the interaction directly: it resolves to
Suggested change
|
||||||||
| {"my-bucket", "EU", false, APIError{}, "eu-west-1", nil, true}, | ||||||||
| {"my-bucket", "eu-central-1", false, APIError{}, "eu-central-1", nil, true}, | ||||||||
| {"my-bucket", "us-east-1", false, APIError{}, "us-east-1", nil, true}, | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One branch up, the error-response path returns
errResp.Regionwithout the same treatment, and theerrResp.Region == ""check guarding it has the identical gap this line just closed below: a whitespace-only region is not"", so it is returned as-is, cached bygetBucketLocation, and ends up as the SigV4 region — the same newline-in-the-Authorization-header failure described in #2271.The same value also reaches that cache and the signer from
executeMethod's retry path (api.go:805,814,822) without passing through this function at all, so trimming only here would not cover it. Trimming once whereerrResp.Regionis populated covers all three callers, and has the nicer property that a whitespace-only region normalizes to""and falls through to thex-amz-bucket-regionheader instead of defaulting tous-east-1.stringsis already imported in that file.In
api-error-response.go, immediately before the existing header fallback:I have not seen a server actually emit a padded
<Region>in an error body, so treat this as hardening rather than something you are hitting today — likely its own PR, and entirely your call.