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

Open
#17,190 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #17194 by @exKAZUu — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript, vite
Domain
backend, devtools

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
4.7k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
282

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.