Skip to content

[vite-plugin] Normalize v1 relative asset redirects - #16860

Open
petebacondarwin wants to merge 1 commit into
codex/vite-v1-runtime-20261112from
codex/vite-v1-backport-16527
Open

petebacondarwin wants to merge 1 commit into
codex/vite-v1-runtime-20261112from
codex/vite-v1-backport-16527

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Backport #16527 to the retained workers-shared asset worker used directly by v1's CustomAssetWorker. After placeholder substitution, normalize only relative pathnames, preserving query values, fragments and explicit external targets (including scheme-less URLs). Captured separators stay on the site's path.

The remaining diff is the shared worker implementation and its original worker-level regression tests, plus a plugin patch changeset. Pages source and dependency tests are absent from v1 and are not restored. The preceding runtime PR supplies Miniflare's corresponding fix; that does not update the private worker bundled by the plugin for development.

Stacked above the November 12 runtime backport in native GitHub stack #16900. Merge in stack order.

Validation: pnpm build and pnpm test:ci pass on the combined stack, including all 292 asset-worker tests, 65 router-worker tests and 267 plugin tests.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: fixes existing v1 behavior without adding configuration.

Note

This is a contribution from an AI agent: Codex.

Further validation: pnpm check passes all 58 tasks; affected Vite 8 asset playgrounds pass in development (14 passed, 7 skipped) and build/preview (20 passed, 1 skipped). Full Vite/OS/package-manager E2E matrix and credentialed remote tests were not run.

Retained integration validation also passes: pnpm test:fixtures (6 tasks), including all 30 dev-registry tests, 5 test-harness Vitest tests and both test-harness browser tests.

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6efc0c4

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/vite-plugin 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

@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team November 12, 2026 14:04
@workers-devprod

workers-devprod commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/deploy-config
  • ✅ @cloudflare/wrangler

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@cloudflare/vite-plugin@16860

commit: 6efc0c4

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@petebacondarwin (verified author of #16527) and @dario-piotrowicz (latest qualifying pre-merge human ant-core approver, October 30 11:23:06Z): please check this v1 backport and approve it if it looks good.

V1 directly bundles the retained workers-shared asset worker for development, so its redirect fix and original worker tests remain necessary even though #16859 supplies the corresponding published Miniflare runtime fix. Pages source/tests are not restored. Build, all 58 checks, all 292 asset-worker tests, plugin tests and affected asset playgrounds pass. This PR belongs to native stack #16738 above #16859.

devin-ai-integration[bot]

This comment was marked as resolved.

clanky-the-clanker[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 6efc0c4a.

This review, of 2df60d3d

💬 Approved with comments — The change is sound overall. One WARNING: a //:placeholder redirect template is now treated as an external target, so a value captured from the request can choose the redirect host. That only happens for rules written in that form.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #16860.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Security] A redirect template of the form `//:placeholder` is classified as external, so a value captured from the request becomes the redirect host (open redirect). The previous code collapsed this to a relative path.
- **File:** packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163

🔒 Security: ⚠️ 1 warning

A //:placeholder redirect template is classified as external, which allows an open redirect controlled by the request.

Recommendation: 📝 Minor Comments

  • [WARNING] A redirect template of the form //:placeholder is classified as external, so a value captured from the request becomes the redirect host (open redirect). The previous code collapsed this to a relative path. (packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163)
View full review

Placeholder in host position is treated as an explicit external target (packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163)

  • isExternal is tested on the unsubstituted template with /^(?:\w+:\/\/|\/\/[^/\\\s?#])/.
  • In //:splat, the : that starts the placeholder satisfies [^/\\\s?#], so the template counts as external and the substituted value is returned without normalization.
  • With the rule /foo/* -> //:splat, a request to /foo/evil.example now redirects to //evil.example, which browsers resolve to another host. The previous code collapsed this to /evil.example.
  • The regression tests cover /:splat, ///:splat and //\\:splat, but not //:splat.
  • Fix: exclude : from the host-character class, and add //:splat cases to both test files.

✅ All other checks passed

🚀 Release: ✅ LGTM

Low risk. The plugin patch changeset is present.


📖 AGENTS.md: ✅ LGTM


📋 Code Quality: ✅ LGTM

The refactor is clean and the regression tests cover the intended cases.


⚡ Performance: ✅ LGTM

The regexes run in linear time on short strings for each redirect.


📝 Documentation: ✅ LGTM


Reviewed commit: 2df60d3d — same changes as 8fc98b4a, so this is that commit's review (no new review was run; line numbers are as of 8fc98b4a)

@petebacondarwin
petebacondarwin force-pushed the codex/vite-v1-backport-16527 branch from 2df60d3 to 6efc0c4 Compare November 16, 2026 20:47

@clanky-the-clanker clanky-the-clanker 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.

💬 Approved with comments — The change is sound overall. One WARNING: a //:placeholder redirect template is now treated as an external target, so a value captured from the request can choose the redirect host. That only happens for rules written in that form.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #16860.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Security] A redirect template of the form `//:placeholder` is classified as external, so a value captured from the request becomes the redirect host (open redirect). The previous code collapsed this to a relative path.
- **File:** packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163

🔒 Security: ⚠️ 1 warning

A //:placeholder redirect template is classified as external, which allows an open redirect controlled by the request.

Recommendation: 📝 Minor Comments

  • [WARNING] A redirect template of the form //:placeholder is classified as external, so a value captured from the request becomes the redirect host (open redirect). The previous code collapsed this to a relative path. (packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163)
View full review

Placeholder in host position is treated as an explicit external target (packages/workers-shared/asset-worker/src/utils/rules-engine.ts:163)

  • isExternal is tested on the unsubstituted template with /^(?:\w+:\/\/|\/\/[^/\\\s?#])/.
  • In //:splat, the : that starts the placeholder satisfies [^/\\\s?#], so the template counts as external and the substituted value is returned without normalization.
  • With the rule /foo/* -> //:splat, a request to /foo/evil.example now redirects to //evil.example, which browsers resolve to another host. The previous code collapsed this to /evil.example.
  • The regression tests cover /:splat, ///:splat and //\\:splat, but not //:splat.
  • Fix: exclude : from the host-character class, and add //:splat cases to both test files.

✅ All other checks passed

🚀 Release: ✅ LGTM

Low risk. The plugin patch changeset is present.


📖 AGENTS.md: ✅ LGTM


📋 Code Quality: ✅ LGTM

The refactor is clean and the regression tests cover the intended cases.


⚡ Performance: ✅ LGTM

The regexes run in linear time on short strings for each redirect.


📝 Documentation: ✅ LGTM


Reviewed commit: 6efc0c4a — same changes as 8fc98b4a, so this is that commit's review (no new review was run; line numbers are as of 8fc98b4a)

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.

3 participants