Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(server): keep the Host-header check when binding to all interfaces

Puspo Aditya98b8c6c581ce
diff --git a/.env.example b/.env.example
index ea4346d8f..77eb1bd8a 100644
--- a/.env.example
+++ b/.env.example
@@ -108,6 +108,11 @@ PORT=4173
# networks you trust, and consider the GEV_RATELIMIT_* throttles above.
# HOST=localhost
# HOST=0.0.0.0
+# Optional: comma-separated LAN hostnames to accept, in addition to localhost
+# and IP addresses, for example GEV_ALLOWED_HOSTS=globe.lan,globe.internal.
+# Binding HOST=0.0.0.0 alone does NOT trust every Host header; suffix and
+# wildcard entries are ignored.
+# GEV_ALLOWED_HOSTS=
# Optional: NASA FIRMS live active fires. SERVER-SIDE ONLY (never reaches the
# browser — the client polls the /api/firms proxy). Free key:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5724d1c87..77254c956 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,13 @@
## [Unreleased]
+- Keep the Host-header check when binding to all interfaces. `HOST=0.0.0.0`
+ used to accept any Host; the dev and preview servers now accept IP
+ addresses, `localhost` and the LAN hostnames listed in `GEV_ALLOWED_HOSTS`
+ (suffix and wildcard entries are ignored), which also keeps DNS-rebinding
+ names out in LAN mode. The `.local` suffix is no longer accepted by default;
+ list such a name explicitly (Puspo Aditya, #97, fixes #21).
+
- Throttle the cost-bearing proxies by default instead of on request. The
OpenAI endpoints (`/api/realtime/token`, `/api/openai/hud-summary`) now allow
30 requests per minute per client IP and the Google Places endpoints
diff --git a/README.md b/README.md
index cc9f142ad..85e66938d 100644
--- a/README.md
+++ b/README.md
@@ -512,7 +512,7 @@ Everything above is the deliberately cheap baseline — enough to get a real tas
### 🔒 Sharing an instance
-By default nobody else can reach your server — it binds to localhost. To share on your LAN, opt in explicitly (`npm run dev -- --host 0.0.0.0 --port 4173`, or `HOST=0.0.0.0 ./scripts/dev-fresh.sh` on macOS/Linux) — but know that ⚠️ **a LAN-visible server brokers your configured API keys to anyone who can reach it.** Per-IP throttles on the cost-bearing endpoints are on by default (`GEV_RATELIMIT_OPENAI_PER_MIN`, `GEV_RATELIMIT_GOOGLE_PER_MIN` — see `.env.example` to tune them), but before anything else, **configure provider quotas, usage limits, and billing alerts**: app-level throttles are not billing caps, and a budget alert alone does not stop spending. Full threat model in [SECURITY.md](SECURITY.md).
+By default nobody else can reach your server — it binds to localhost. To share on your LAN, opt in explicitly (`npm run dev -- --host 0.0.0.0 --port 4173`, or `HOST=0.0.0.0 ./scripts/dev-fresh.sh` on macOS/Linux). IP addresses work as they are; if you use a LAN hostname, add it with `GEV_ALLOWED_HOSTS=globe.lan`, since binding to `0.0.0.0` does not trust arbitrary Host headers. But know that ⚠️ **a LAN-visible server brokers your configured API keys to anyone who can reach it.** Per-IP throttles on the cost-bearing endpoints are on by default (`GEV_RATELIMIT_OPENAI_PER_MIN`, `GEV_RATELIMIT_GOOGLE_PER_MIN` — see `.env.example` to tune them), but before anything else, **configure provider quotas, usage limits, and billing alerts**: app-level throttles are not billing caps, and a budget alert alone does not stop spending. Full threat model in [SECURITY.md](SECURITY.md).
Provider Settings is disabled when the server is shared, so remote users cannot
access the key-entry panel.
diff --git a/SECURITY.md b/SECURITY.md
index f12efbdbd..5d5040564 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -71,14 +71,14 @@ The data proxies under `server/providers/` are written so the browser cannot tur
- **Sanitized errors** — internal error details are not echoed back to clients.
- **Coalesced OAuth refresh** and cached successful responses only (OpenSky).
- **Redacted debug logging.** The voice debug log (`.gev-logs/`, gitignored) strips API keys, bearer tokens, client secrets, and image data URLs before writing.
-- **Cross-site gate on cost/log endpoints.** The cost-bearing (`/api/realtime/token`, `/api/openai/hud-summary`, `/api/google/nearby-places`) and log (`/api/realtime/debug-log`) endpoints refuse cross-site browser requests: a foreign or opaque `Origin`, a `Sec-Fetch-Site` other than `same-origin`/`none` (this is what blocks an `<img>`/navigation that carries no `Origin`), or any reverse-proxy/CDN forwarding header returns `403`. Non-browser loopback tools (the repo QA harnesses POST the token endpoint with no `Origin`) and the explicit `HOST=0.0.0.0` LAN opt-in keep working — the gate deliberately does not require a loopback remote address; that stricter requirement belongs only to the credential panel (`admitKeySetupRequest`). **Limit: this gate does not survive DNS rebinding in the `HOST=0.0.0.0` mode.** By default Vite's host check (`allowedHosts`) rejects a rebinding `Host` before any handler runs, and the gate is defense in depth behind it. The LAN opt-in turns that host check off, so an attacker-controlled name that resolves to the operator's address yields a page whose `Origin` and `Host` agree and whose `Sec-Fetch-Site` is a truthful `same-origin`; all three checks pass. In that mode protection rests on the operator's network, not on `Origin`/`Host` agreement (see Network exposure below).
+- **Cross-site gate on cost/log endpoints.** The cost-bearing (`/api/realtime/token`, `/api/openai/hud-summary`, `/api/google/nearby-places`) and log (`/api/realtime/debug-log`) endpoints refuse cross-site browser requests: a foreign or opaque `Origin`, a `Sec-Fetch-Site` other than `same-origin`/`none` (this is what blocks an `<img>`/navigation that carries no `Origin`), or any reverse-proxy/CDN forwarding header returns `403`. Non-browser loopback tools (the repo QA harnesses POST the token endpoint with no `Origin`) and the explicit `HOST=0.0.0.0` LAN opt-in keep working — the gate deliberately does not require a loopback remote address; that stricter requirement belongs only to the credential panel (`admitKeySetupRequest`). Vite's host check (`allowedHosts`) rejects a rebinding `Host` before any handler runs, in every mode, and the gate is defense in depth behind it: the LAN opt-in keeps that check and accepts only IP addresses, `localhost` and names listed in `GEV_ALLOWED_HOSTS`. **Limit:** a name you list there is trusted like the app's own address, so list only names you control.
- **Full Content-Security-Policy.** The dev and preview servers send a real CSP (`script-src 'self' 'unsafe-eval' blob:`: no inline script and no script from any other origin; `blob:` covers the object URLs Cesium's bundled workers bootstrap through in the built app), alongside the existing `X-Frame-Options: DENY` and `frame-ancestors 'none'`. `'unsafe-eval'` stays because Knockout, bundled inside Cesium's widgets package, resolves the global object with `eval` at load time and the globe does not initialize without it; styles permit `'unsafe-inline'` and Google Fonts because Vite's dev client injects `<style>` elements.
## Network exposure — the operator threat model
The dev server is a **key broker**: every server-side key above is spendable by anyone who can send HTTP requests to it. That shapes the defaults:
-- **Local-only by default.** `./scripts/dev-fresh.sh` (and the Vite config itself) bind to `localhost`, so only your machine can reach the server — and only local names are accepted (`allowedHosts` stays restricted, which also blunts DNS-rebinding tricks).
+- **Local-only by default.** `./scripts/dev-fresh.sh` (and the Vite config itself) bind to `localhost`, so only your machine can reach the server — and only local names are accepted (`allowedHosts` stays restricted, which also blunts DNS-rebinding tricks). Binding to all interfaces keeps that restriction: IP addresses and `localhost` work, and LAN hostnames must be listed in `GEV_ALLOWED_HOSTS` (for example `GEV_ALLOWED_HOSTS=globe.lan`); suffix and wildcard entries are ignored.
- **LAN exposure is an explicit opt-in**: `HOST=0.0.0.0 ./scripts/dev-fresh.sh`. The launcher prints a prominent warning plus your LAN URL. Understand what opting in means: **every device on that network can drive the proxies and spend your OpenAI / Google / OpenSky / AISStream / TomTom / FIRMS quota** for as long as the server runs. Do this only on networks you trust.
- **App-level throttles (on by default):** `GEV_RATELIMIT_OPENAI_PER_MIN` (default `30`) and `GEV_RATELIMIT_GOOGLE_PER_MIN` (default `120`) — the values the Pinokio build already ships — cap the cost-bearing endpoints per client IP per minute (over-limit requests receive a sanitized `429`). Both defaults sit well above what the app itself generates; set either to exactly `0` to run unthrottled. They are **per-IP, process-local, in-memory guards** — they reset on restart, a caller with several addresses gets a bucket per address, and they are **not billing caps**.
- **Provider-side budgets are the real backstop.** For hard spend protection, configure limits where the money is: OpenAI platform usage limits, Google Cloud budget alerts + per-API quotas, and equivalent controls for any other keyed provider.
diff --git a/build/allowedHosts.js b/build/allowedHosts.js
new file mode 100644
index 000000000..1848ea7ab
--- /dev/null
+++ b/build/allowedHosts.js
@@ -0,0 +1,26 @@
+/**
+ * Host header allowlist for the Vite dev/preview server. The configuration
+ * factory passes the configured names in; this module reads no environment.
+ *
+ * Binding to a wildcard interface only controls which network interfaces accept
+ * connections. It must not turn into a wildcard Host-header policy: this server
+ * brokers configured API keys through local proxy routes.
+ */
+export const DEFAULT_ALLOWED_HOSTS = Object.freeze(['localhost', '127.0.0.1']);
+
+/**
+ * Resolve Vite's allowedHosts setting from an optional comma-separated list.
+ * Empty entries and suffix/wildcard entries are ignored; repeated names keep
+ * their first occurrence. Vite treats leading-dot values as suffix wildcards,
+ * which would defeat an explicit host policy.
+ *
+ * @param {string|undefined|null} configuredHosts
+ * @returns {string[]}
+ */
+export function resolveAllowedHosts(configuredHosts) {
+ const hosts = String(configuredHosts ?? '')
+ .split(',')
+ .map((host) => host.trim())
+ .filter((host) => host && !host.startsWith('.') && !host.includes('*'));
+ return [...new Set([...DEFAULT_ALLOWED_HOSTS, ...hosts])];
+}
diff --git a/build/vite.js b/build/vite.js
index 4af19e42e..f0966393b 100644
--- a/build/vite.js
+++ b/build/vite.js
@@ -1,5 +1,6 @@
import { applicationHtmlPlugin } from './application-html.js';
import cesium from 'vite-plugin-cesium';
+import { DEFAULT_ALLOWED_HOSTS } from './allowedHosts.js';
import { embedFramingPlugin } from './embed-framing.js';
import { panelBuildPlugin } from './panel.js';
@@ -45,6 +46,7 @@ export function createBrowserViteConfig({
cesiumToken,
host = 'localhost',
port = 4173,
+ allowedHosts = DEFAULT_ALLOWED_HOSTS,
command,
} = {}) {
return {
@@ -73,10 +75,10 @@ export function createBrowserViteConfig({
server: {
host: host || 'localhost',
port: parseInt(port, 10) || 4173,
- allowedHosts:
- host === '0.0.0.0' || host === '::'
- ? true
- : ['localhost', '127.0.0.1', '.local'],
+ // A wildcard bind only chooses interfaces; it never disables Vite's
+ // Host-header check. LAN hostnames are added explicitly (see
+ // build/allowedHosts.js); IP addresses are always accepted.
+ allowedHosts: [...allowedHosts],
fs: {
deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**', '**/ENVIRONMENT'],
},
diff --git a/scripts/format-scope.json b/scripts/format-scope.json
index 901eab7bb..52f76357b 100644
--- a/scripts/format-scope.json
+++ b/scripts/format-scope.json
@@ -55,6 +55,7 @@
"server/standalone/vite.config.js",
"vite.config.js",
"src/tooling/viteBuild.test.mjs",
+ "src/tooling/allowedHosts.test.mjs",
"server/providers/common/http.js",
"server/providers/common/query.js",
"server/providers/aircraft/opensky.js",
diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json
index efcf4c507..1c86aff2b 100644
--- a/scripts/package-boundaries.json
+++ b/scripts/package-boundaries.json
@@ -31,6 +31,7 @@
"modules": [
"build/vite.js",
"build/application-html.js",
+ "build/allowedHosts.js",
"build/embed-framing.js",
"build/panel.js"
],
diff --git a/server/standalone/vite.config.js b/server/standalone/vite.config.js
index 8cb3679ef..6a8181490 100644
--- a/server/standalone/vite.config.js
+++ b/server/standalone/vite.config.js
@@ -1,5 +1,6 @@
import { fileURLToPath } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
+import { resolveAllowedHosts } from '../../build/allowedHosts.js';
import { createBrowserViteConfig } from '../../build/vite.js';
import { localProviderPlugins } from '../providers/local.js';
import { localMcpPlugin } from '../mcp/plugin.js';
@@ -24,6 +25,7 @@ export default defineConfig(({ command, mode }) => {
cesiumToken: process.env.CESIUM_ION_TOKEN,
host: process.env.HOST,
port: process.env.PORT,
+ allowedHosts: resolveAllowedHosts(process.env.GEV_ALLOWED_HOSTS),
command,
});
});
diff --git a/src/tooling/allowedHosts.test.mjs b/src/tooling/allowedHosts.test.mjs
new file mode 100644
index 000000000..d4f6df41e
--- /dev/null
+++ b/src/tooling/allowedHosts.test.mjs
@@ -0,0 +1,34 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {
+ DEFAULT_ALLOWED_HOSTS,
+ resolveAllowedHosts,
+} from '../../build/allowedHosts.js';
+
+test('uses the restricted local host allowlist by default', () => {
+ assert.deepEqual(resolveAllowedHosts(), DEFAULT_ALLOWED_HOSTS);
+ assert.equal(resolveAllowedHosts().includes(true), false);
+});
+
+test('adds explicitly configured LAN hostnames without widening the allowlist', () => {
+ assert.deepEqual(
+ resolveAllowedHosts('globe.lan, globe.internal ,globe.lan'),
+ ['localhost', '127.0.0.1', 'globe.lan', 'globe.internal'],
+ );
+});
+
+test('ignores empty configured host entries', () => {
+ assert.deepEqual(resolveAllowedHosts(' , , globe.lan, '), [
+ 'localhost',
+ '127.0.0.1',
+ 'globe.lan',
+ ]);
+});
+
+test('rejects suffix and wildcard entries so every LAN hostname is explicit', () => {
+ assert.deepEqual(resolveAllowedHosts('.local,*.example,globe.lan'), [
+ 'localhost',
+ '127.0.0.1',
+ 'globe.lan',
+ ]);
+});
diff --git a/src/tooling/viteBuild.test.mjs b/src/tooling/viteBuild.test.mjs
index a297ccdcb..c634c731f 100644
--- a/src/tooling/viteBuild.test.mjs
+++ b/src/tooling/viteBuild.test.mjs
@@ -15,11 +15,7 @@ test('explicit build inputs preserve browser-only defines, plugin order and loop
assert.equal(config.plugins[2], plugin);
assert.equal(config.server.host, 'localhost');
assert.equal(config.server.port, 4173);
- assert.deepEqual(config.server.allowedHosts, [
- 'localhost',
- '127.0.0.1',
- '.local',
- ]);
+ assert.deepEqual(config.server.allowedHosts, ['localhost', '127.0.0.1']);
assert.ok(config.server.fs.deny.includes('**/ENVIRONMENT'));
assert.ok(config.server.fs.deny.includes('.env.*'));
assert.equal(config.server.headers['X-Frame-Options'], 'DENY');
@@ -39,10 +35,18 @@ test('explicit build inputs preserve browser-only defines, plugin order and loop
'import.meta.env.GOOGLE_MAPS_API_KEY': '"browser-fixture"',
'import.meta.env.CESIUM_ION_TOKEN': '"ion-fixture"',
});
- assert.equal(
- createBrowserViteConfig({ host: '0.0.0.0', port: '4800' }).server
- .allowedHosts,
- true,
+ // A wildcard bind keeps the Host-header check; LAN names are explicit.
+ for (const host of ['0.0.0.0', '::'])
+ assert.deepEqual(
+ createBrowserViteConfig({ host, port: '4800' }).server.allowedHosts,
+ ['localhost', '127.0.0.1'],
+ );
+ assert.deepEqual(
+ createBrowserViteConfig({
+ host: '0.0.0.0',
+ allowedHosts: ['localhost', '127.0.0.1', 'globe.lan'],
+ }).server.allowedHosts,
+ ['localhost', '127.0.0.1', 'globe.lan'],
);
assert.equal(
createBrowserViteConfig({ host: '::', port: '4800' }).server.port,