← Back to Pull requests

[vite-plugin-cloudflare] fix: preserve :authority and port in HTTP/2 requests #15519

Merged
devaniketh merged 3 files (287 lines) on Sep 07, 2026 11:27 UTC
View on GitHub
devaniketh devaniketh commented on Sep 05, 2026 03:16 UTC
Author

Fixes #14931.

When Vite dev server is served over HTTPS with HTTP/2 enabled, browsers communicate using HTTP/2 where the host and port are passed via the :authority pseudo-header rather than the HTTP/1.1 Host header.

Previously, request conversion in createRequestForIncomingMessage omitted pseudo-headers when creating the Web Standard Request, causing headers.get("Host") to be null and falling back to "localhost", discarding non-default ports (such as :5173). Consequently, X-Forwarded-Host was not set in toMiniflareRequest, breaking OAuth and Clerk handshake redirects.

This change:
1. Extracts authority and non-default port from req.headers[":authority"] and req.authority.
2. Extracts scheme from req.headers[":scheme"] and req.scheme.
3. Ensures Host header is populated on the created Request.
4. Falls back to new URL(request.url).host in toMiniflareRequest to guarantee X-Forwarded-Host preserves the host and port.

---

  • Tests

  • - [x] 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):
    - [x] Documentation not necessary because: Internal dev server request adaptation fix.
    <!-- devin-review-badge-begin -->

    ---

    <a href="https://cloudflare.devinenterprise.com/review/cloudflare/workers-sdk/pull/15519" target="_blank">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=3">
    <img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=3" alt="Devin Review">
    </picture>
    </a>
    <!-- devin-review-badge-end -->

    Diff: 287 lines (+283 / -4) across 3 files Reviewer: dario-piotrowicz Review duration: 3370m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.63) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 287 lines diff across 3 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.93 · 5 substantive comment(s)
    0.93
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    92%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.339
    Sensitive Paths sensitive_paths
    0.063
    Real PR Conversation Timeline
    15 items
    changeset-bot[bot] changeset-bot[bot] commented on Sep 05, 2026 03:16 UTC
    Bot

    🦋 Changeset detected

    Latest commit: aad2ccf75c508c53f4f25fb234c51b98d7174a31

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

    <details><summary>This PR includes changesets to release 1 package</summary>

    | Name | Type |
    | ----------------------- | ----- |
    | @cloudflare/vite-plugin | Patch |

    </details>

    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 commented on Sep 05, 2026 03:17 UTC
    Contributor

    Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
  • <details><summary>Show detailed file reviewers</summary>

    </details>

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 05, 2026 03:18 UTC
    Code Review
    packages/vite-plugin-cloudflare/src/utils.ts:1
    @@ -144,8 +144,13 @@ function createRequestForIncomingMessage(
     	const headers = createHeaders(req);
     	const protocol =
     		options?.protocol ??
    +		getScheme(req) ??
     		("encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:");
    -	const host = options?.host ?? headers.get("Host") ?? "localhost";
    +	const host =
    +		options?.host ?? headers.get("Host") ?? getAuthority(req) ?? "localhost";

    <!-- devin-review-comment {"id": "BUG_pr-review-job-7a6be943511548b3b1d7de6077099aa2_0001", "file_path": "packages/vite-plugin-cloudflare/src/utils.ts", "start_line": 149, "end_line": 150, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->

    🟡 HTTP/2 authority loses to stale Host

    When an HTTP/2 request also carries Host, createRequestForIncomingMessage uses it instead of :authority. A proxy-added Host without the port still breaks redirect origins.

    	const host =
    		options?.host ?? getAuthority(req) ?? headers.get("Host") ?? "localhost";
    

    <!-- devin-review-badge-begin -->
    <a href="https://cloudflare.devinenterprise.com/review/cloudflare/workers-sdk/pull/15519" target="_blank">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=3">
    <img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=3" alt="Devin Review">
    </picture>
    </a>
    <!-- devin-review-badge-end -->

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

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Sep 05, 2026 03:18 UTC
    Reviewer

    Devin Review found 1 potential issue.

    2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

    <!-- devin-review-badge-begin -->
    <a href="https://cloudflare.devinenterprise.com/review/cloudflare/workers-sdk/pull/15519" target="_blank">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=3">
    <img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=3" alt="Devin Review">
    </picture>
    </a>
    <!-- devin-review-badge-end -->

    pkg-pr-new[bot] pkg-pr-new[bot] commented on Sep 05, 2026 03:20 UTC
    Bot

    <details><summary><b>@cloudflare/autoconfig</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/build-output-utils</b></summary><p>

      npm i https://pkg.pr.new/@cloudflare/build-output-utils@15519
      


    </p></details>

    <details><summary><b>@cloudflare/codemods</b></summary><p>

      npm i https://pkg.pr.new/@cloudflare/codemods@15519
      


    </p></details>

    <details><summary><b>@cloudflare/config</b></summary><p>

      npm i https://pkg.pr.new/@cloudflare/config@15519
      


    </p></details>

    <details><summary><b>create-cloudflare</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/deploy-helpers</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/kv-asset-handler</b></summary><p>

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


    </p></details>

    <details><summary><b>miniflare</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/pages-functions</b></summary><p>

      npm i https://pkg.pr.new/@cloudflare/pages-functions@15519
      


    </p></details>

    <details><summary><b>@cloudflare/pages-shared</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/unenv-preset</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/vite-plugin</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/vitest-plugin</b></summary><p>

      npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15519
      


    </p></details>

    <details><summary><b>@cloudflare/workers-auth</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/workers-editor-shared</b></summary><p>

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


    </p></details>

    <details><summary><b>@cloudflare/workers-utils</b></summary><p>

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


    </p></details>

    <details><summary><b>wrangler</b></summary><p>

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


    </p></details>

    _commit: <a href="https://github.com/cloudflare/workers-sdk/runs/101718792638"><code>aad2ccf</code></a>_

    devaniketh devaniketh commented on code on Sep 05, 2026 03:22 UTC
    Code Review
    packages/vite-plugin-cloudflare/src/utils.ts:1
    @@ -144,8 +144,13 @@ function createRequestForIncomingMessage(
     	const headers = createHeaders(req);
     	const protocol =
     		options?.protocol ??
    +		getScheme(req) ??
     		("encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:");
    -	const host = options?.host ?? headers.get("Host") ?? "localhost";
    +	const host =
    +		options?.host ?? headers.get("Host") ?? getAuthority(req) ?? "localhost";

    cool fixed it

    devaniketh devaniketh commented on Sep 05, 2026 13:32 UTC
    Author

    @dario-piotrowicz hey can you look into the PR , let me know if there are any changes to made

    dario-piotrowicz dario-piotrowicz commented on Sep 07, 2026 10:02 UTC
    Contributor

    @dario-piotrowicz hey can you look into the PR , let me know if there are any changes to made

    Sorry I wasn't around, I'm reviewing the PR now 👍

    dario-piotrowicz dario-piotrowicz approved these changes on Sep 07, 2026 10:31 UTC
    Approved Reviewer

    LGTM thanks @devaniketh 🙂

    workers-devprod workers-devprod approved these changes on Sep 07, 2026 10:31 UTC
    Approved Reviewer

    Codeowners reviews satisfied

    devaniketh devaniketh commented on Sep 07, 2026 10:34 UTC
    Author

    @dario-piotrowicz thanks can we merge it ?

    dario-piotrowicz dario-piotrowicz commented on Sep 07, 2026 10:36 UTC
    Contributor

    @dario-piotrowicz thanks can we merge it ?

    no worries 🙁 , sure, we can merge this PR as soon as CI goes green 👍

    devaniketh devaniketh commented on Sep 07, 2026 11:23 UTC
    Author

    cool all checks passed @dario-piotrowicz

    dario-piotrowicz dario-piotrowicz commented on Sep 07, 2026 11:27 UTC
    Contributor

    cool all checks passed @dario-piotrowicz

    merged 🙂

    Assignees
    devaniketh devaniketh
    Labels
    risk: low confidence: 92% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.0% (MEDIUM) · Higher = larger blast radius
    63.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 92% · Lower = rushed or shallow review
    92%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5% · Safe to merge
    5%