Skip to content

fix: trim whitespace from bucket location - #2274

Open
vigneshakaviki wants to merge 1 commit into
minio:masterfrom
vigneshakaviki:fix/bucket-location-whitespace
Open

fix: trim whitespace from bucket location#2274
vigneshakaviki wants to merge 1 commit into
minio:masterfrom
vigneshakaviki:fix/bucket-location-whitespace

Conversation

@vigneshakaviki

@vigneshakaviki vigneshakaviki commented Aug 1, 2026

Copy link
Copy Markdown

Description

Trim whitespace from decoded LocationConstraint values before applying existing empty-region and EU normalization. This prevents whitespace-only responses from being cached and inserted into SigV4 Authorization headers.

Testing

  • go test -run '^TestProcessBucketLocationResponse$' -count=1 .
  • go test -short -race ./...
  • go test -race -v ./... against TLS-enabled AIStor edge
  • Full functional suite against TLS-enabled AIStor edge
  • make lint
  • make examples
  • go build ./...
  • govulncheck ./... with Go 1.26.5

Fixes #2271

Summary by CodeRabbit

  • Bug Fixes

    • Improved bucket location handling by removing surrounding whitespace from responses.
    • Ensured blank or whitespace-only locations correctly use the default region.
  • Tests

    • Added coverage for blank locations and regional values containing extra whitespace.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 38ef3788-17b2-4bc4-82ba-243fbbd4fbbd

📥 Commits

Reviewing files that changed from the base of the PR and between 802bd60 and 248c6cd.

📒 Files selected for processing (2)
  • bucket-cache.go
  • bucket-cache_test.go

📝 Walkthrough

Walkthrough

The bucket location response processor now trims whitespace before normalizing empty and legacy-region values. Tests cover whitespace-only input and whitespace-padded regional input.

Changes

Bucket location normalization

Layer / File(s) Summary
Normalize and test bucket locations
bucket-cache.go, bucket-cache_test.go
processBucketLocationResponse trims location responses before applying default and EU conversions. Tests verify whitespace-only input becomes us-east-1 and padded eu-central-1 is trimmed.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • minio/minio-go#2268: Both changes modify bucket-location response processing and its tests, but this change addresses whitespace normalization.

Suggested reviewers: projectmutilation

Poem

A rabbit trims the region clean,
No stray whitespace can be seen.
Empty paths find us-east-1,
Padded regions now align.
Tests hop softly, green and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: trimming whitespace from bucket locations.
Linked Issues check ✅ Passed The implementation trims LocationConstraint values before normalization, treats whitespace-only values as us-east-1, and adds matching tests for issue #2271.
Out of Scope Changes check ✅ Passed The changes are limited to bucket-location trimming and related unit tests, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vigneshakaviki
vigneshakaviki marked this pull request as ready for review August 1, 2026 05:57
Comment thread bucket-cache_test.go
{"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},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says the trim happens before the EU normalization, but neither new row exercises that ordering. The padded eu-central-1 row trims to a value that never reaches the EU branch, and the plain "EU" row passes with or without trimming, so nothing here would notice if the two steps were ever reordered.

This row covers the interaction directly: it resolves to eu-west-1 with the trim in place, and comes back as " EU " unchanged without it.

Suggested change
{"my-bucket", " \neu-central-1\t", false, APIError{}, "eu-central-1", nil, true},
{"my-bucket", " \neu-central-1\t", false, APIError{}, "eu-central-1", nil, true},
{"my-bucket", " EU ", false, APIError{}, "eu-west-1", nil, true},

Comment thread bucket-cache.go
}

location := locationConstraint
location := strings.TrimSpace(locationConstraint)

Copy link
Copy Markdown
Contributor

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.Region without the same treatment, and the errResp.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 by getBucketLocation, 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 where errResp.Region is populated covers all three callers, and has the nicer property that a whitespace-only region normalizes to "" and falls through to the x-amz-bucket-region header instead of defaulting to us-east-1. strings is already imported in that file.

In api-error-response.go, immediately before the existing header fallback:

	errResp.Region = strings.TrimSpace(errResp.Region)
	if errResp.Region == "" {
		errResp.Region = resp.Header.Get("x-amz-bucket-region")
	}

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.

@allanrogerr allanrogerr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetBucketLocation() should trim whitespace from LocationConstraint before caching bucket location

2 participants