Repository navigation
fix(serve): warn once about ignored PW_SERVE_ALLOWED_HOSTS entries; README FORWARDED_ALLOW_IPS note - #46
Merged
Conversation
…EADME FORWARDED_ALLOW_IPS note - serve: an override entry that is not a plain host/IP (unbracketed IPv6 like fd7a::1, wildcards, 0.0.0.0, userinfo) was dropped silently, so a typo gave a bare 403 "forbidden host". Each such entry now prints one stderr warning (the repo's convention), checked once at startup in main() too. - README: a TLS proxy on another machine also needs FORWARDED_ALLOW_IPS, since uvicorn only trusts X-Forwarded-Proto from loopback by default; otherwise every POST is 403 "forbidden origin". Follow-up from the independent review of #43. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follow-up from the independent review of #43 (item 4 of overnight task W6-passiveworkers-4243fu). Branched from origin/main at f497835, after #43 merged. Items 1–3 are in #45.
What changed
passiveworkers/serve.py(finding fix(serve,judge): exact-origin check, strict Host, PW_SERVE_ALLOWED_HOSTS; country inside spotlight #43-3, Low): previously, aPW_SERVE_ALLOWED_HOSTSentry that isn't a plain host/IP was dropped silently, so a typo gave a bare403 forbidden host. Examples: unbracketed IPv6fd7a::1,*,0.0.0.0,bad@x. Each such entry now prints one stderr warning per process. That follows the repo's convention: the package has nologging, and other warnings useprint(..., file=sys.stderr).main()runs the check once beforeuvicorn.run, so the warning appears at startup, not on the first request. Allow-list behaviour is unchanged: it still fails closed.README.md(finding fix(serve,judge): exact-origin check, strict Host, PW_SERVE_ALLOWED_HOSTS; country inside spotlight #43-2, Low-Medium; one line): a TLS proxy on another machine also needsFORWARDED_ALLOW_IPS=<proxy IP>. uvicorn trustsX-Forwarded-Protoonly from loopback by default (FORWARDED_ALLOW_IPSdefaults to127.0.0.1,::1in the installed uvicorn 0.54.0,uvicorn/config.py:363). Without it, every POST gets403 forbidden origin.Verification (run locally,
.venv)python -m py_compile $(git ls-files '*.py')→ exit 0ruff check . && pytest tests/ -q --cov=passiveworkers --cov-fail-under=75→ exit 0,726 passed, 9 skipped, coverage 80.60%tests/test_serve.py::test_ignored_allowed_hosts_entries_warn_once_eachfails on old code (1 of 1, run withserve.pyreverted to origin/main) and passes now. Across three request rounds it checks that each of 4 bad entries warns exactly once, and that valid entries (desk.ts.net,[fd7a::2]:8770) don't warn.PW_SERVE_PORT=18779 PW_SERVE_ALLOWED_HOSTS='desk.ts.net,fd7a::1' python -m passiveworkers.serveon loopback for 6 s. It printedwarning: PW_SERVE_ALLOWED_HOSTS entry 'fd7a::1' ignored: …once, before the banner.curl -H 'Host: desk.ts.net' /reportsreturned 200, and-H 'Host: [fd7a::1]'returned 403, with no repeat warning.Unverified
FORWARDED_ALLOW_IPSadvice was checked against uvicorn's source, not through a real reverse proxy on a second host.🤖 Generated with Claude Code