cloudflare: `_headers` stacks values from overlapping rules and is misplaced with `baseURL`

Aperta
#3 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@ichiken26 ci sta già lavorando.

Dal 27/11/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
devops

Direzione di ricerca

Read nitrojs/nitro#4914 for the small backport: it fixes _headers and _redirects placement when baseURL is set, while respecting a custom output.publicDir. The issue also describes a separate, larger overlapping-rule rewrite from nitrojs/nitro#3938, with unresolved wildcard behavior and real-deploy validation. Confirm which fix is intended and what deploy check is available before changing code.

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

Descrizione

bug preset:cloudflare

Tracker for two Cloudflare _headers problems on v2, picked up from nitrojs/nitro#3938 (closed so it can be redone in smaller pieces).

1. Overlapping rules stack header values. Cloudflare applies every _headers block that matches a path and joins the values. Nested route rules therefore produce duplicated or conflicting values. For example, Nuxt's /_nuxt/**, /_nuxt/builds/** and /_nuxt/builds/meta/** rules give /_nuxt/builds/meta/x a cache-control with all three values comma-joined. nuxt-security's / + /** headers end up doubled on / (Baroshem/nuxt-security#575, nitrojs/nitro#2909). Main has the same behavior.

nitrojs/nitro#3938 fixed this by rewriting _headers generation as a tree with ! header detach lines. Reasons it wasn't merged on v2:

  • It is a ~160 line rewrite and changes the order of the generated file.
  • It only understands a trailing /**. * or :param mid-path become literal children.
  • It was never checked on a real Cloudflare deploy, in particular whether a value set in the same block as its own ! detach line is kept.

A fix should come with a real deploy check, and ideally land on main first.

2. _headers is written under baseURL. With a baseURL, _headers (and _redirects) are written to public/<baseURL>/ instead of the assets root, so Cloudflare ignores them. Main fixed this in nitrojs/nitro#4914. A small backport of nitrojs/nitro#4914 is the way to go. nitrojs/nitro#3938 hardcoded output.dir/public, which ignores a custom output.publicDir.

Opened with AI assistance.

Lingua principale
TypeScript
Stelle
1
Fork
6
Merge medio
1g 2h
PR unite (30g)
20

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

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 nitrojs/nitro-v2

Tutte le issue di nitrojs/nitro-v2

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.