Repository navigation
Accept SOUNDBOX_ALLOWED_HOSTS in the Host check; let dev mode leave localhost - #26
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_HOSTSdid.1. Server (built app / desktop). The DNS-rebinding
onRequesthook inapp.tsonly accepted loopback and the CLI's--host.SOUNDBOX_ALLOWED_HOSTSwas read only byorigins.ts(CORS, the MCP Origin check) and the MCP Host check. Sosoundboxon 127.0.0.1 behind Caddy/nginx, which forwardHost: soundbox.example.lan, got 403 Forbidden host on every request, even though INSTALL.md, the README anddocker-compose.ymlsay setting the variable fixes it. Docker hides the bug because its0.0.0.0bind turns the check off.origins.tsnow owns one parser (allowedHostEntries,isListedHost, andhostnameOf, moved fromapp.tsand re-exported from it). The app Host check, the MCP Host check and the trusted-origin rule all use it.hostmatches that name on any port, andhost:portmatches only that port. The MCP check used to be exact-string, so a barehostentry 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.tsset neitherserver.hostnorserver.allowedHosts.SOUNDBOX_ALLOWED_HOSTSgoes to Vite'sserver.allowedHosts, with ports dropped because Vite takes bare hostnames.SOUNDBOX_DEV_HOSTsets Vite'sserver.host. When unset, Vite stays on localhost.scripts/dev.mjswarns 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 setschangeOrigin: 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 inSECURITY.md. CHANGELOG has entries under Unreleased → Fixed.How it was tested
npm run typecheck(plustsc -p app/tsconfig.node.jsonforvite.config.ts, which the app typecheck doesn't cover)npm run lintnpm test(servernpx vitest run: 40 files, 516 tests)SOUNDBOX_ALLOWED_HOSTS=soundbox.example.lan npx tsx src/cli.ts --port 17611 --no-uiwith a scratch data dir.curl -H "Host: soundbox.example.lan" /api/health→ 200,Host: evil.example→ 403,POST /mcpwith the listed Host → 400 (past the Host check). Loadedvite.config.tsthrough Vite'sloadConfigFromFilewithSOUNDBOX_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:portheld to its port, look-alikes refused, unset means loopback only,/mcppasses the same name, and the parser's edge cases.hardening.test.tshas ahost:portorigin case.Checklist
README.md,docs/) if behaviour or the API changedCHANGELOG.mdupdated under Unreleased for user-visible changes