Skip to content

[wrangler] Add --infer-origin-from-routes flag to opt out of route-based origin rewriting in local dev - #14865

Open
TheSaiEaranti wants to merge 1 commit into
cloudflare:mainfrom
TheSaiEaranti:fix-local-origin-optout
Open

[wrangler] Add --infer-origin-from-routes flag to opt out of route-based origin rewriting in local dev#14865
TheSaiEaranti wants to merge 1 commit into
cloudflare:mainfrom
TheSaiEaranti:fix-local-origin-optout

Conversation

@TheSaiEaranti

@TheSaiEaranti TheSaiEaranti commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #14683.

In local wrangler dev, a configured routes entry makes the Worker see request.url, the Host header, and any present Origin header rewritten to the route's host, even though the client genuinely connected to http://localhost:PORT. Origin/Host-sensitive logic then behaves differently only under local dev — the issue's example is a CORS check allowlisting http://localhost:* that receives http://<route-host> and returns 403, with no indication the headers were altered.

The rewrite is intentional (it makes request.url match production routes), so this PR does not change the default. It adds the opt-out the issue asks for:

wrangler dev --infer-origin-from-routes=false

Why this shape: the switch already exists internally — StartDevWorkerOptions.dev.inferOriginFromRoutes gates getInferredHost() in ConfigController and is set to false today only by the API test harness. This PR exposes that existing switch as a documented wrangler dev flag and threads it through start-dev.ts (and the exhaustive args object in api/dev.ts); no behavioral logic changes. With the flag set to false and no explicit host, origin.hostname stays undefined, so miniflare never rewrites and the Worker sees the real local origin. An explicit --host, --local-upstream, or dev.host continues to take precedence either way — covered by a test.

Tests: two new cases in the existing local upstream block of dev.test.ts: with routes configured and the flag false, config.dev.origin?.hostname is undefined (on main, the route host); with dev.host also set, the explicit host still wins. Full dev.test.ts: 203/203 pass. pnpm prettify clean; the wrangler build (including dts) passes.


  • 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: the flag is documented in its --help text and the changeset; happy to file a cloudflare-docs PR for the wrangler dev page if you'd like one.

Open in Devin Review

…sed origin rewriting in local dev

When routes are configured, local dev infers the origin from the first route,
so the Worker sees request.url, Host, and Origin rewritten to the route's host
even though the client connected to localhost. This silently breaks
Host/Origin-sensitive logic: a CORS check allowlisting http://localhost:*
receives http://<route-host> and rejects the request only under local dev.

The inference is intentional and stays the default. The internal
StartDevWorkerOptions switch (dev.inferOriginFromRoutes) already existed for
the test harness; this exposes it as a documented wrangler dev flag. Passing
--infer-origin-from-routes=false preserves the real local origin without
removing routes from the config. An explicit --host, --local-upstream, or
dev.host continues to take precedence either way.

Fixes cloudflare#14683
@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9edaa7e

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

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@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

@workers-devprod
workers-devprod requested review from a team and jamesopstad and removed request for a team July 26, 2026 19:39
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/infer-origin-from-routes-flag.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/dev.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/dev.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/dev.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/dev/start-dev.ts: [@cloudflare/wrangler]

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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.

wrangler dev rewrites in-Worker Host/Origin/request.url to the routes host in local mode, breaking origin-based auth/CORS checks

2 participants