Skip to content

fix(cli): reject empty normalized bucket path in cors#81

Merged
overtrue merged 1 commit intomainfrom
codex/cors-empty-bucket-path-gap
Apr 3, 2026
Merged

fix(cli): reject empty normalized bucket path in cors#81
overtrue merged 1 commit intomainfrom
codex/cors-empty-bucket-path-gap

Conversation

@overtrue
Copy link
Copy Markdown
Contributor

@overtrue overtrue commented Apr 3, 2026

Summary

The new bucket CORS commands accept paths in the alias/bucket form and normalize trailing slashes before talking to the backend. One untested edge case was alias///: 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_path only 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-commit because this repository does not define that target or a Makefile. I ran the equivalent required checks from AGENTS.md:

  • cargo fmt --all --check
  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace

@overtrue overtrue marked this pull request as ready for review April 3, 2026 14:38
Copilot AI review requested due to automatic review settings April 3, 2026 14:38
@overtrue overtrue merged commit b61a78d into main Apr 3, 2026
15 checks passed
@overtrue overtrue deleted the codex/cors-empty-bucket-path-gap branch April 3, 2026 14:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_path to 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()))
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

2 participants