Repository navigation
[vite-plugin] Normalize v1 relative asset redirects - #16860
petebacondarwin wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 6efc0c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Codeowners approval required for this PR:
|
commit: |
|
@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. |
There was a problem hiding this comment.
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
//:placeholderis 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)
isExternalis 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.examplenow redirects to//evil.example, which browsers resolve to another host. The previous code collapsed this to/evil.example. - The regression tests cover
/:splat,///:splatand//\\:splat, but not//:splat. - Fix: exclude
:from the host-character class, and add//:splatcases 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)
2df60d3 to
6efc0c4
Compare
There was a problem hiding this comment.
💬 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
//:placeholderis 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)
isExternalis 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.examplenow redirects to//evil.example, which browsers resolve to another host. The previous code collapsed this to/evil.example. - The regression tests cover
/:splat,///:splatand//\\:splat, but not//:splat. - Fix: exclude
:from the host-character class, and add//:splatcases 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)
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.
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.