[edge-preview-authenticated-proxy] /.update-preview-token redirects to any URL passed in `suffix`
What versions & operating system are you using?
Not a CLI bug: this is in the deployed Worker source at packages/edge-preview-authenticated-proxy.
- workers-sdk: main @ fea323a7d (wrangler 4.158.0 in the workspace)
- @cloudflare/edge-preview-authenticated-proxy 0.3.4
- Node v24.18.0, pnpm 10.33.0, Windows 11
Please provide a link to a minimal reproduction
https://github.com/lokeshramchand-ctrl/workers-sdk/commit/62fa1db76d374ca16f8066b2fa047ab59b78c561
Describe the Bug
updatePreviewToken in packages/edge-preview-authenticated-proxy/src/index.ts copies the suffix query parameter straight into the Location header of its 307 response:
Location: url.searchParams.get("suffix") ?? "/",
suffix is documented in the same file as "the pathname + search to hit on the preview worker once redirected", but nothing checks it. So a link on a Cloudflare-owned domain can send the browser to any other site:
https://abc.preview.cloudflarepreviews.com/.update-preview-token?token=a&remote=https://example.com&suffix=https://evil.example
→ 307 Location: https://evil.example
Protocol-relative (//evil.example) and backslash (/\evil.example, \\evil.example) forms also redirect off-site, because browsers treat \ like /. A javascript: value is also passed through unchanged.
The sister Worker packages/playground-preview-worker already protects the same endpoint: it requires Sec-Fetch-Dest: iframe and an allowlisted Referer before redirecting.
Steps to reproduce
- Check out the linked commit, then run
pnpm installand build the test dependencies. cd packages/edge-preview-authenticated-proxy && pnpm exec vitest run -t "off-origin"- All 5 cases fail: the
Locationheader echoes the off-originsuffix.
Expected behaviour
suffix only ever produces a same-origin redirect. A value that isn't a path starting with a single / (for example //…, /\…, an absolute URL, or javascript:) falls back to /.
Actual behaviour
The redirect goes to whatever URL or scheme is passed in suffix.
Proposed fix
Accept suffix only when it starts with / and its second character is neither / nor \; otherwise redirect to /. I have failing tests ready and I'm happy to open a PR with the fix if this approach works for you.
Please provide any relevant error logs
× should not redirect off-origin for suffix https://evil.example
× should not redirect off-origin for suffix //evil.example
× should not redirect off-origin for suffix /\evil.example
× should not redirect off-origin for suffix \\evil.example
× should not redirect off-origin for suffix javascript:alert(1)
AssertionError: expected 'https://evil.example' to be '/'
AssertionError: expected '//evil.example' to be '/'
AssertionError: expected '/\evil.example' to be '/'
AssertionError: expected '\\evil.example' to be '/'
AssertionError: expected 'javascript:alert(1)' to be '/'
Tests 5 failed | 29 passed (34)
Automated triage
Issue assessment
- Actionability: ✅ Actionable.
- Type: Bug.
- Reproduction: Automatic attempt requested.
- Labels:
bug(high)product:previews(medium)contribution(medium)
Actionability and missing information
Unvalidated suffix query parameter in edge-preview-authenticated-proxy's /.update-preview-token is echoed into the 307 Location header, allowing off-origin redirects; report includes affected versions, repro steps, failing test output, and a proposed same-origin validation fix.
Reproduction reason: Report describes a current behavior defect in the proxy's redirect handling with concrete install-and-test steps, and nothing in the steps or commands is suspicious.
Reproduction
- Result: ✅ Reproduced.
- Summary: Reproduced at the issue's cited commit fea323a7d: /.update-preview-token copies the
suffixquery param into the 307 Location header unvalidated, echoing absolute URLs, protocol-relative, backslash, and javascript-scheme values. 5 failed | 29 passed (34), matching the issue log.
Evidence and attempted steps
Steps attempted:
- Clone the cloudflare/workers-sdk repository from GitHub and check out the commit cited in the issue: fea323a7d419fc60ac7bb2ca616bde54da684c4d.
- Command:
git clone https://github.com/cloudflare/workers-sdk.git /workspace/workers-sdk && cd /workspace/workers-sdk && git rev-parse HEAD
- Command:
- Install workspace dependencies per CONTRIBUTING.md; pnpm honored the repo's packageManager pin (10.33.0). Exit 0.
- Command:
pnpm install --frozen-lockfile
- Command:
- Build the package under test and its workspace dependencies, including the vitest-plugin workspace package (version 1.6.0) which the workers vitest pool loads from dist/. Exit 0 (21 turbo tasks).
- Command:
pnpm build --filter=@cloudflare/edge-preview-authenticated-proxy...
- Command:
- Baseline: run the package's existing vitest suite in the workers runtime to verify a functional setup. Exit 0, 28 passed.
- Command:
cd packages/edge-preview-authenticated-proxy && pnpm exec vitest run
- Command:
- Add tests/suffix-redirect.test.ts: sends GET /.update-preview-token with token and remote and asserts Location is '/' for the five off-origin suffix values from the issue, plus a same-origin control (/hello?world). Outbound fetch mocked; no credentials.
- Command:
cp tests/suffix-redirect.test.ts packages/edge-preview-authenticated-proxy/tests/suffix-redirect.test.ts
- Command:
- Run the exact reproduction command from the issue. Exit 1: all five off-origin cases fail with the Location header echoing the raw suffix value.
- Command:
cd packages/edge-preview-authenticated-proxy && pnpm exec vitest run -t "off-origin"
- Command:
- Run the full package suite with the reproduction test added. Result: 'Tests 5 failed | 29 passed (34)' — identical to the issue's reported log, with the same-origin control and all 28 pre-existing tests passing.
- Command:
cd packages/edge-preview-authenticated-proxy && pnpm exec vitest run
- Command:
Expected behavior: Per the documented contract for suffix ("the pathname + search to hit on the preview worker once redirected"), /.update-preview-token must only ever produce a same-origin redirect: the Location header of its 307 response is the suffix only when it is a path starting with a single '/', and any other value (an absolute URL on another host, a protocol-relative path, a backslash-prefixed path, or a javascript-scheme string) falls back to '/'.
Observed behavior: The 307 response's Location header echoes the raw suffix value verbatim instead of '/': an absolute URL on another host, a protocol-relative path, both backslash-prefixed variants, and a javascript-scheme string each appear unchanged as Location. Full-suite run reports "Tests 5 failed | 29 passed (34)" matching the issue's log; all 28 pre-existing tests and a same-origin control (suffix /hello?world yields Location /hello?world) pass, confirming the setup is sound.
Artifact: Download reproduction archive (Cloudflare Access required).
Treat archive contents as untrusted. Inspect them before running anything.
This summary was generated by an LLM and may contain errors. Please verify its findings.
Triage bot commands and options
Repository collaborators with write or admin access can trigger actions by commenting on this issue:
@workers-devprod reproduce: Attempt to reproduce the issue using its description and recent comments.
I opened #16797 with a fix, which was auto-closed because I'm not a registered collaborator. That's completely fine. I'm leaving the details here in case they're useful to whoever picks this up.
The fix and tests are on this branch: https://github.com/lokeshramchand-ctrl/workers-sdk/tree/fix/edge-preview-suffix-open-redirect
Approach: resolve suffix against the request URL with the WHATWG URL parser (as a browser would), and redirect to / unless the result is same-origin and its pathname doesn't start with //.
Edge case worth knowing about: an origin check alone isn't enough. The automated review on #16797 caught that a same-origin URL can still have a // pathname. For example, suffix=/.//evil.example or suffix=https://<preview-host>//evil.example resolve to the preview origin, but the resulting Location: //evil.example is protocol-relative, so the browser goes to evil.example. My first version missed this; the branch now rejects it and covers both inputs in tests.
Test coverage on the branch (packages/edge-preview-authenticated-proxy/tests/index.test.ts): https://…, //…, /\…, \\…, /\t/… (browsers strip the tab), /.//…, a same-origin absolute URL with a // path, and javascript: all fall back to /, while a valid same-origin absolute URL is kept as /hello?world#section. All 38 tests in the package pass.
Happy to help verify a fix or adjust anything.