Skip to content

Accept SOUNDBOX_ALLOWED_HOSTS in the Host check; let dev mode leave localhost - #26

Merged
HamSanders merged 1 commit into
mainfrom
fix/allowed-hosts
Oct 24, 2026
Merged

HamSanders merged 1 commit into
mainfrom
fix/allowed-hosts

Conversation

@HamSanders

Copy link
Copy Markdown
Owner

What this changes

Two bugs that stop people reaching Soundbox from another machine or through a reverse proxy. Both came from shopsD's comment on #22: they had to run Caddy to get off localhost, SOUNDBOX_ALLOWED_HOSTS "didn't work", and Vite's __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS did.

1. Server (built app / desktop). The DNS-rebinding onRequest hook in app.ts only accepted loopback and the CLI's --host. SOUNDBOX_ALLOWED_HOSTS was read only by origins.ts (CORS, the MCP Origin check) and the MCP Host check. So soundbox on 127.0.0.1 behind Caddy/nginx, which forward Host: soundbox.example.lan, got 403 Forbidden host on every request, even though INSTALL.md, the README and docker-compose.yml say setting the variable fixes it. Docker hides the bug because its 0.0.0.0 bind turns the check off.

  • origins.ts now owns one parser (allowedHostEntries, isListedHost, and hostnameOf, moved from app.ts and re-exported from it). The app Host check, the MCP Host check and the trusted-origin rule all use it.
  • Matching rule, the same in every check: a bare host matches that name on any port, and host:port matches only that port. The MCP check used to be exact-string, so a bare host entry now also matches a non-default port there. That is the only widening, and it is still opt-in.

2. Dev mode (npm run dev). vite.config.ts set neither server.host nor server.allowedHosts.

  • SOUNDBOX_ALLOWED_HOSTS goes to Vite's server.allowedHosts, with ports dropped because Vite takes bare hostnames.
  • New SOUNDBOX_DEV_HOST sets Vite's server.host. When unset, Vite stays on localhost. scripts/dev.mjs warns when it is set to something other than loopback, because Vite proxies the whole unauthenticated API. The server stays on 127.0.0.1. The Vite string-shorthand proxy sets changeOrigin: true, so the server sees a loopback Host, and the browser's Origin is trusted via the same list.

Docs: a new "Reverse proxy or another machine" section in docs/INSTALL.md, a corrected Docker paragraph (it said the UI and /api/* are never behind the Host check, which is only true for wildcard binds), a troubleshooting entry for 403 Forbidden host, env-table rows for both variables, and the Host-allowlist bullet in SECURITY.md. CHANGELOG has entries under Unreleased → Fixed.

How it was tested

  • npm run typecheck (plus tsc -p app/tsconfig.node.json for vite.config.ts, which the app typecheck doesn't cover)
  • npm run lint
  • npm test (server npx vitest run: 40 files, 516 tests)
  • Tried it against a real server: SOUNDBOX_ALLOWED_HOSTS=soundbox.example.lan npx tsx src/cli.ts --port 17611 --no-ui with a scratch data dir. curl -H "Host: soundbox.example.lan" /api/health → 200, Host: evil.example → 403, POST /mcp with the listed Host → 400 (past the Host check). Loaded vite.config.ts through Vite's loadConfigFromFile with SOUNDBOX_ALLOWED_HOSTS="a.lan:8443,[fd00::1]:5,b.lan" → allowedHosts: ['a.lan', '[fd00::1]', 'b.lan'], host: undefined. I did not run a browser through a real Caddy proxy.

New tests in server/test/requestGuards.test.ts: listed host on any port, host:port held to its port, look-alikes refused, unset means loopback only, /mcp passes the same name, and the parser's edge cases. hardening.test.ts has a host:port origin case.

Checklist

  • Docs updated (README.md, docs/) if behaviour or the API changed
  • CHANGELOG.md updated under Unreleased for user-visible changes
  • Any new model entry states its licence and commercial-use status accurately (n/a)
  • No secrets, tokens or personal data in the diff
  • Screenshots are of the real app with real data (n/a, no UI change)

…ocalhost

The server's DNS-rebinding Host check only knew loopback and the CLI's
--host, so `soundbox` on 127.0.0.1 behind Caddy or nginx answered 403
"Forbidden host" to every request even with SOUNDBOX_ALLOWED_HOSTS set;
the variable only reached CORS and /mcp. Docker hid this because its
0.0.0.0 bind turns the check off.

One parser in origins.ts now feeds the app Host check, the MCP Host check
and the trusted origins: a bare host matches any port, host:port only that
port.

In dev, vite.config.ts hands SOUNDBOX_ALLOWED_HOSTS to server.allowedHosts
and a new SOUNDBOX_DEV_HOST sets server.host. Both unset keeps loopback.

Reported by shopsD on #22.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HamSanders
HamSanders merged commit a9c6628 into main Oct 24, 2026
4 checks passed
@HamSanders
HamSanders deleted the fix/allowed-hosts branch October 24, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant