dev: false "reachable from the network" warning when `devServer.host` is a `*.localhost` subdomain

Aperta Adatta ai principianti
#1,644 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #1649 di @paoValle — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
cli, networking

Direzione di ricerca

Trova l’implementazione di listen e i due controlli che usano LOOPBACK_HOSTS.has(hostname), da cui dipendono l’avviso e l’indicazione Network:. Leggi quei controlli e cerca i test esistenti sulla classificazione degli host o sull’output del server di sviluppo. Considera i sottodomini di .localhost come indirizzi loopback in entrambi i punti; il lavoro è concluso quando non attivano più l’avviso di rete né compaiono come URL di rete.

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

Descrizione

Environment
  • @nuxt/cli: 4.0.1
  • nuxt: 4.6.2
  • Node.js: 24.21.0
  • OS: macOS
Reproduction
// nuxt.config.ts
export default defineNuxtConfig({
  devServer: { host: 'my-app.localhost' },
})
nuxt dev
Describe the bug

The CLI prints:

The dev server is reachable from the network without authentication: anyone who can connect can read the app, build errors and source code.

The server is not reachable from the network. my-app.localhost resolves to loopback only (dns.lookup('my-app.localhost', { all: true }) returns ::1 and 127.0.0.1), so the listener is bound to loopback just like with localhost.

Per RFC 6761 §6.3, localhost and every name under .localhost resolve to loopback. Browsers resolve them that way without DNS and treat them as secure contexts. *.localhost names are a common way to run several local apps side by side.

Cause

In listen the warning only checks an exact-match set:

const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1'])
// ...
if (announce && (anyHost || !LOOPBACK_HOSTS.has(hostname))) logger.warn('The dev server is reachable from the network ...')

my-app.localhost is not in the set, so it is treated as a public host. The same check also drives the Network: hint shown under the URLs.

Suggested fix

Treat any .localhost name as loopback, e.g.:

const isLoopbackHost = host => LOOPBACK_HOSTS.has(host) || host.endsWith('.localhost')

and use it in both places that currently call LOOPBACK_HOSTS.has(hostname).

Workaround

Leave devServer.host unset and pass --publicURL http://my-app.localhost:3000 to nuxt dev, so the CLI shows that URL without the warning.

Lingua principale
TypeScript
Stelle
402
Fork
125
Merge medio
2g 9h
PR unite (30g)
37

Preparare l'ambiente

Apri in Codespaces

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

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 nuxt/cli

Tutte le issue di nuxt/cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.