server: bind loopback by default, name the address, and refuse a bad PF_HOST (#1527) #1639
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1639
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/1116-0835"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #1527 (item 1: the bind; item 2, the WebSocket
Origincheck, landed in #1629; item 3, the bearer token, is deliberately not here - there is no credential store to protect yet, seedocs/plans/server-exposure.md), so the issue stays open.What was wrong
server/index.jscalledserver.listen(PORT)with no host, so Node bound0.0.0.0/::- every interface. The banner saidLocal: http://localhost:8000regardless, so nothing in the log disagreed with a reader who assumed the server was local. A simulator on a cafe network, or one behind a reverse proxy, was reachable from anything that could route to it.What changed
PF_HOST, default127.0.0.1. Exposure is now something an operator asks for:PF_HOST=0.0.0.0 npm start. TheDockerfilesetsPF_HOST=0.0.0.0, because a published port has to be reachable from the host -docker run -p 8000:8000keeps working.server.address()rather than a hard-codedlocalhost, and says whether that is this machine only or reachable from other hosts.PF_HOSTis refused in words.EADDRNOTAVAIL/ENOTFOUNDnow exit1with a message naming the address andPF_HOST, an IPv6 literal is bracketed, andPF_HOST=127.0.0.1:8000(ahost:portcopied out of a URL) is named as that specific mistake. The old text blamedPORTand advised leaving it "unset to listen on all interfaces" - false on both counts, and it now says what is actually wrong.test/server-bind.test.js(23 assertions) spawns the real server four ways: default answers on127.0.0.1and nothing accepts on the machine's first non-loopback IPv4;PF_HOST=0.0.0.0does answer there and the banner stops claiming local-only;PF_HOST=192.0.2.123(TEST-NET-1) exits 1 naming it with no stack trace;PF_HOST=127.0.0.1:<port>reports where the port belongs. The off-loopback half is skipped on a host with no non-loopback address.SECURITY.mdscope,README.mdquick start (source and Docker), a paragraph indocs/ARCHITECTURE.md"The server", a CHANGELOG entry, anddocs/plans/server-exposure.mdstep 1 marked landed.Notes for the merge
PF_HOST=0.0.0.0, so a container started from this Dockerfile keeps answering on its published port, but a host-sidedocker runthat mounts the sources without the image's env needsPF_HOST=0.0.0.0explicitly. Worth one check on that host after merge.scripts/cf-access-bypass.jsalready reads aPF_HOSTof its own for the forge hostname (git.jayw.uk). The collision is harmless in a fresh shell, and a shell that carries it now gets a clear refusal naming the value, but the script would be better off renaming its variable - not done here to keep this PR to one subject.Tests
node scripts/syntax-check.js- 346 files, all OK.test/server-bind.test.js- 23 passed, 0 failed.test/startup-error.test.js- 25 passed, 0 failed.test/ws-origin.test.js- 16 passed, 0 failed;scripts/smoke-http.js- clean;test/server-persistence.test.js- 13 passed.npm testat the committed tree - 276 suites, 9873 assertions, 0 failed.node scripts/check-doc-citations.js- same 7 pre-existing suspects, no new ones;check-dockerfile.jsandcheck-control-bytes.jspass.64e2fa867104498b960d