Skip to content

[wrangler] fix: validate --preview-alias client-side and suggest sanitized value#14408

Open
matingathani wants to merge 4 commits into
cloudflare:mainfrom
matingathani:fix/preview-alias-validate-manual-input
Open

[wrangler] fix: validate --preview-alias client-side and suggest sanitized value#14408
matingathani wants to merge 4 commits into
cloudflare:mainfrom
matingathani:fix/preview-alias-validate-manual-input

Conversation

@matingathani

@matingathani matingathani commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #14345.

Currently wrangler versions upload --preview-alias <value> passes the value through to the API without any client-side validation. When a user passes a branch name directly (e.g. feature/my-feature), they get an opaque API error rather than a clear message about why the value is invalid.

This PR adds client-side validation of manually-supplied preview aliases before the upload request is made:

  • Rejects values that exceed 63 characters (DNS label limit) with a message showing the character count.
  • Rejects values that don't match the ALIAS_VALIDATION_REGEX (/^[a-z](?:[a-z0-9-]*[a-z0-9])?$/i) with a clear message and a Did you mean "..."? suggestion built via sanitizeBranchName.
  • Exports ALIAS_VALIDATION_REGEX and MAX_PREVIEW_ALIAS_LENGTH from @cloudflare/deploy-helpers so consumers share the same constants.

Auto-generated aliases (via getCIGeneratePreviewAlias()) are unaffected — those already go through sanitizeBranchName inside generatePreviewAlias.


  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: error-message-only behaviour change, no new flags or APIs

Open in Devin Review

…tized value

Fixes cloudflare#14345. Manually-supplied preview aliases (via `--preview-alias`) were
not validated, so values like `feature/my-feature` passed through to the API
and returned an opaque error. Now wrangler validates the alias against DNS
label rules before upload and throws a clear UserError — including a
`Did you mean "..."?` suggestion built with `sanitizeBranchName`.

Also exports `ALIAS_VALIDATION_REGEX` and `MAX_PREVIEW_ALIAS_LENGTH` from
`@cloudflare/deploy-helpers` so callers can reference the same constraints.
Copilot AI review requested due to automatic review settings June 24, 2026 08:36
@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 56a14eb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jun 24, 2026
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team June 24, 2026 08:37
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/preview-alias-validate-manual-input.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/deploy/helpers/preview-alias.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/config-args-merging.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/merge-config-args.ts: [@cloudflare/wrangler]

@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14408

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14408

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14408

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14408

miniflare

npm i https://pkg.pr.new/miniflare@14408

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14408

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14408

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14408

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14408

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14408

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14408

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14408

wrangler

npm i https://pkg.pr.new/wrangler@14408

commit: 56a14eb

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 4 potential issues.

Open in Devin Review

Comment thread packages/wrangler/src/deployment-bundle/merge-config-args.ts Outdated
Comment thread packages/wrangler/src/deployment-bundle/merge-config-args.ts Outdated
Comment thread packages/wrangler/src/deployment-bundle/merge-config-args.ts
Comment on lines +192 to +196
if (args.previewAlias.length > MAX_PREVIEW_ALIAS_LENGTH) {
throw new UserError(
`Preview alias "${args.previewAlias}" is too long (${args.previewAlias.length} characters). Aliases must be at most ${MAX_PREVIEW_ALIAS_LENGTH} characters.`,
{ telemetryMessage: 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.

🚩 Manual alias length validation uses MAX_DNS_LABEL_LENGTH (63) without accounting for script name

The auto-generated alias in generatePreviewAlias (preview-alias.ts:93) computes available space as MAX_DNS_LABEL_LENGTH - scriptName.length - 1, accounting for the fact that the final DNS label combines alias + separator + script name. However, the manual validation here only checks args.previewAlias.length > MAX_PREVIEW_ALIAS_LENGTH (63 characters) without considering the script name. This means a user could provide a 60-character alias that passes client-side validation but might still exceed the DNS label limit when combined with the script name on the server side. This may be intentional (the server handles the full label check), but it's an asymmetry worth noting.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

matingathani and others added 3 commits June 25, 2026 11:20
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… before display

- Replace `telemetryMessage: true` with static strings to avoid sending
  raw user input as telemetry data
- Only show the 'Did you mean' suggestion when sanitizeBranchName actually
  produces a value that differs from the original input AND passes
  ALIAS_VALIDATION_REGEX (e.g. digit-prefixed inputs like '123abc' no longer
  suggest themselves as a fix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

wrangler versions upload --preview-alias rejects raw WORKERS_CI_BRANCH values containing slashes in Workers Builds

3 participants