Skip to content

fix: validate bucket names against the server's naming rules - #326

Closed
AndrewGanzha wants to merge 1 commit into
rustfs:mainfrom
AndrewGanzha:fix/bucket-name-validation
Closed

AndrewGanzha wants to merge 1 commit into
rustfs:mainfrom
AndrewGanzha:fix/bucket-name-validation

Conversation

@AndrewGanzha

Copy link
Copy Markdown
Contributor

Description

The Create Bucket dialog accepted names the server rejects. getBucketNameError only checked the length (3–63 after trim()) and uppercase letters, so a name pasted with spaces or zero-width characters passed client validation, the CreateBucket request failed server-side, and the name field showed no validation error at all — the user saw only a generic failure toast (rustfs/rustfs#9805).

This PR makes the dialog's validation mirror the server's own strict bucket name validation (rustfs/rustfs, crates/ecstore/src/bucket/utils.rs, check_bucket_name_common):

Rule Message
whitespace / invisible characters (incl. zero-width, bidi marks, soft hyphen) Bucket names cannot contain spaces or invisible characters
character set a-z0-9.- Bucket names can only contain lowercase letters, numbers, periods, and hyphens
starts and ends with a letter or number Bucket names must start and end with a lowercase letter or number
no .., .-, -. Bucket names must not contain consecutive periods or a period next to a hyphen
not IP-address-shaped Bucket names must not look like an IP address
reserved name rustfs Bucket name is reserved

Whitespace and invisible characters get their own message on purpose: they survive trim() and look correct in the field, which is exactly what made #9805 confusing. Message keys are added to all 15 locale files, in alphabetical position, fully translated.

Files: lib/bucket-name.ts, tests/lib/bucket-name.test.ts, tests/lib/form-interaction.test.ts, i18n/locales/*.json (15).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • Security fix

Testing

  • Unit tests added/updated
  • Manual testing completed

tests/lib/bucket-name.test.ts covers every new rule, the exact pasted name from the report (s\u200bu\u200bport-service-files), bidi/format characters, and names that must stay valid (bucket.demo, 1-bucket.2026). tests/lib/form-interaction.test.ts mounts BucketNewForm with the real validator, pastes the reported name, and asserts the inline error text renders, the Create button is disabled, and no createBucket request is made.

pnpm test:run        # 1324 tests, 0 failures
pnpm type-check      # clean
pnpm lint            # clean
pnpm format:check    # clean

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • TypeScript types are properly defined
  • All commit messages are in English (Conventional Commits)
  • All existing tests pass
  • No new dependencies added, or they are justified

Related Issues

Fixes rustfs/rustfs#9805 — the report is filed against the Console bucket dialog but lives in the server repository.

Screenshots (if applicable)

I could not capture before/after screenshots: the Console cannot be logged into without a running RustFS backend, so the dialog is unreachable locally. The behaviour is instead pinned by the dialog test above (error text in the field, Create disabled, no request sent). Happy to add screenshots if you prefer to review the visual state — the dialog reuses the existing FieldError styling, no markup changed.

Additional Notes

  • Scope is deliberately limited to client-side validation; no server or API behaviour changes.
  • Validation is applied on the trimmed name, which is what use-bucket.ts already sends, so the console never accepts a name it would then send differently.
  • Unrelated observation while preparing this branch: pnpm-lock.yaml on main currently contains two YAML documents (a stray pnpm self-management lockfile block at lines 1–101, then ---, then the real lockfile). pnpm install --frozen-lockfile fails on a clean clone because of it. I left the file untouched here as it is out of scope.

The Create Bucket dialog only rejected names shorter than 3 characters or
containing uppercase letters. A name pasted with spaces or zero-width
characters therefore passed client validation, failed on the server, and
reported nothing in the name field (rustfs/rustfs#9805).

getBucketNameError now mirrors the server's strict bucket name validation
(rustfs/rustfs, crates/ecstore/src/bucket/utils.rs, check_bucket_name_common):
allowed character set, names starting and ending with a letter or number,
no periods next to each other or to a hyphen, no IP-address-shaped names,
and no reserved name. Whitespace and invisible characters get their own
message because they survive trim() and look correct in the field. All new
messages are translated for every locale, and the dialog test reproduces
the pasted zero-width name from the report.
@cxymds

cxymds commented Nov 30, 2026

Copy link
Copy Markdown
Member

same #325

@cxymds cxymds closed this Nov 30, 2026
@AndrewGanzha
AndrewGanzha deleted the fix/bucket-name-validation branch November 30, 2026 11:05

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the thorough bucket-name validation parity work. Requesting changes because this PR currently has merge conflicts and missing CI results:

  1. Merge conflict after rustfs/console#325 landed: rustfs/console#325 has been merged into main to address rustfs/rustfs#9805 (adding INVALID_BUCKET_NAME_CHARACTER in lib/bucket-name.ts, locale strings across i18n/locales/*.json, and hasValidBucketName / aria-describedby / capability-check updates in components/buckets/new-form.tsx). As a result, this branch now conflicts across lib/bucket-name.ts, all 15 i18n/locales/*.json files, tests/lib/bucket-name.test.ts, and tests/lib/form-interaction.test.ts.
  2. Missing CI checks: No CI check runs are currently reported on fix/bucket-name-validation.

If you plan to follow up with the additional S3/server-parity rules (INVISIBLE_BUCKET_NAME_PATTERN, BUCKET_NAME_EDGE_PATTERN, INVALID_BUCKET_NAME_SEQUENCE_PATTERN, IP_ADDRESS_PATTERN, RESERVED_BUCKET_NAMES) on top of main:

  • Please rebase onto main and resolve the conflicts while keeping the form and accessibility updates from #325 in components/buckets/new-form.tsx.
  • Minor note on lib/bucket-name.ts: IP_ADDRESS_PATTERN = /^(\d+\.){3}\d+$/ matches any 4 dot-separated digit groups including out-of-range octets (e.g. 999.999.999.999); please verify whether that matches the server check or should restrict octets to 0–255.
  • Once rebased, please ensure all CI checks run and pass.

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.

Couldn't make new bucket with correct name

3 participants