fix(loader-client): /env exposes server-only NANOFORGE_SERVER_* variables to the browser

Aperta Adatta ai principianti
#132 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript
Ambito
backend, security

Direzione di ricerca

Inizia da apps/client/src/env.ts e dalla sua funzione getGameEnv, poi esamina il corrispondente apps/server/src/env.ts e gli unit test esistenti. Aggiungi test che verifichino che l’output dell’ambiente client escluda i valori NANOFORGE_SERVER_* e che l’output del server escluda i valori NANOFORGE_CLIENT_*. Il lavoro è completato quando nessuno dei due loader espone le variabili con il prefisso dell’altra parte.

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

Descrizione

app:client app:server bug
Which app is this bug report for?

client

Issue description

Security. /env can return server-only environment variables to any browser that loads the game.

The CLI splits .env into client and server values (NANOFORGE_CLIENT_* / NANOFORGE_SERVER_*), but its runner starts the client loader with { ...process.env, ...clientEnv } (cli runner.ts#L79). So a NANOFORGE_SERVER_* variable exported in the shell or set by CI reaches the client process.

The client loader's getGameEnv keeps every NANOFORGE_* key and /env returns them all, prefix stripped. The server binds to all interfaces, so the value can be read from the local network, not only from localhost.

Reproduced on the local build with a dummy value:

$ NANOFORGE_SERVER_DB_PASSWORD=dummy bun apps/client/dist/server.js -p 39171 -d <empty dir>
$ curl localhost:39171/env
{"SERVER_DB_PASSWORD":"dummy","tlsEnabled":false}

The same happens the other way: the server loader (env.ts) receives NANOFORGE_CLIENT_*.

Expected: /env never returns NANOFORGE_SERVER_* values.

Suggested fix: in apps/client/src/env.ts, drop keys starting with NANOFORGE_SERVER_ (and in apps/server/src/env.ts, drop NANOFORGE_CLIENT_), with a unit test. A follow-up in the CLI can stop the runner from forwarding those prefixes from process.env.

Related to #87 (optional auth on the loader routes): auth would not fix this, since server-only values should never be sent to the client at all.

Found during a read-only audit of main @ 044c766 (2026-11-11).

Code sample
const PREFIX = "NANOFORGE_";

export const getGameEnv = () => {
  return Object.fromEntries(
    Object.entries(process.env)
      .filter(([key]) => key.startsWith(PREFIX)) // NANOFORGE_SERVER_* passes too
      .map(([key, value]) => [key.replace(PREFIX, ""), value]),
  );
};
Versions
  • @nanoforge-dev/loader-client / @nanoforge-dev/loader-server / @nanoforge-dev/loader-website 1.7.0 (main @ 044c766)
  • Bun 1.3.14
  • Linux x86_64
Issue priority

High (immediate attention needed)

I have tested this issue on a development release

044c766

Lingua principale
TypeScript
Stelle
1
Fork
0
Merge medio
17h 25m
PR unite (30g)
11

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 NanoForge-dev/Loader

Tutte le issue di NanoForge-dev/Loader

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.