fix(cli): reject empty normalized bucket path in cors#81
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an edge case in the CLI bucket CORS commands where paths like alias/// normalize to an empty bucket name but were previously accepted, leading to invalid backend calls.
Changes:
- Update
parse_bucket_pathto validate the bucket segment after trimming trailing slashes. - Add a regression test to ensure
local///is rejected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
375
to
+385
| let parts: Vec<&str> = path.splitn(2, '/').collect(); | ||
| if parts.len() < 2 || parts[0].is_empty() || parts[1].is_empty() { | ||
| return Err("Bucket path must be in format alias/bucket".to_string()); | ||
| } | ||
|
|
||
| Ok(( | ||
| parts[0].to_string(), | ||
| parts[1].trim_end_matches('/').to_string(), | ||
| )) | ||
| let bucket = parts[1].trim_end_matches('/'); | ||
| if bucket.is_empty() { | ||
| return Err("Bucket path must be in format alias/bucket".to_string()); | ||
| } | ||
|
|
||
| Ok((parts[0].to_string(), bucket.to_string())) |
There was a problem hiding this comment.
parse_bucket_path still accepts inputs like alias/bucket/prefix or alias//bucket because it splits with splitn(2, '/') and does not validate that the normalized bucket segment contains no additional / characters. Given the CLI help text says the format is alias/bucket, this should be rejected up front to avoid passing an invalid bucket name to bucket_exists/CORS APIs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The new bucket CORS commands accept paths in the
alias/bucketform and normalize trailing slashes before talking to the backend. One untested edge case wasalias///: after normalization, the bucket segment becomes empty, but the parser still returned success. That leaves the command flow treating an invalid path as a real bucket name.Root Cause
parse_bucket_pathonly checked whether the raw suffix after the first slash was non-empty. It did not re-check the bucket segment after trimming trailing slashes, so inputs made entirely of slashes slipped through as an empty bucket.Fix
This change trims trailing slashes first and rejects the path when the normalized bucket name is empty. A focused regression test now covers
local///to lock the behavior down.Validation
I could not run
make pre-commitbecause this repository does not define that target or aMakefile. I ran the equivalent required checks fromAGENTS.md:cargo fmt --all --checkcargo clippy --workspace -- -D warningscargo test --workspace