[vite-plugin] Requests forwarded to the Worker gain `sec-fetch-mode: cors` and `accept-language: *`

Aperta
#17,190 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #17194 di @exKAZUu — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript, vite
Ambito
backend, devtools

Direzione di ricerca

Start by tracing how the Vite plugin forwards incoming requests to the Worker during vite dev and vite preview, then inspect the use of undici's fetch described in the report. Reproduce with the three-file example and the supplied curl command, comparing the headers received by the Worker with wrangler dev. Done when absent sec-fetch-mode and accept-language headers stay absent in both Vite modes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What versions & operating system are you using?
System:
  OS: macOS 27.2.1
Binaries:
  Node: 26.13.1
  npm: 11.20.0
  bun: 1.4.5
npmPackages:
  @cloudflare/vite-plugin: 1.70.2 (same result with 2.0.0-rc.5)
  wrangler: 4.168.0
  vite: 7
Please provide a link to a minimal reproduction

Inline below (three files).

Describe the Bug

Under vite dev and vite preview, a request that carries no sec-fetch-mode and no accept-language header reaches the Worker with sec-fetch-mode: cors and accept-language: *. wrangler dev passes the same request through without them. The plugin forwards the incoming request with undici's fetch, which fills in both headers when they are absent.

This changes what a Worker sees for non-browser clients (curl, server-to-server calls, Playwright's request API). For example, a CSRF check that enforces an origin only when fetch-metadata headers are present rejects, locally, requests it accepts when deployed.

vite.config.ts

import { cloudflare } from '@cloudflare/vite-plugin';
import { defineConfig } from 'vite';
export default defineConfig({ plugins: [cloudflare()] });

wrangler.jsonc

{ "name": "repro", "main": "src/index.ts", "compatibility_date": "2026-10-01" }

src/index.ts

export default {
  fetch(request: Request): Response {
    return Response.json(Object.fromEntries(request.headers));
  },
};

Steps: start the server, then curl -s -X POST -d a http://localhost:<port>/x.

Header names the Worker receives:

  • wrangler dev: accept, accept-encoding, cf-connecting-ip, content-length, content-type, host, user-agent
  • vite dev and vite preview: the above plus accept-language (*), sec-fetch-mode (cors), connection, x-forwarded-host

Expected: the Worker receives sec-fetch-mode and accept-language only when the client sent them, as with wrangler dev.

Please provide any relevant error logs

None.

Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
282

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.