mcl-bookclub#12 (Phoenix twin): Host allow-list, Origin on POST, and the console socket's Origin #19

Closed
mercurius wants to merge 0 commits from mercurius/12-host-allow-list into main
Member

Purpose (fix): a web page outside the LAN cannot send a command to the Phoenix admin, read from it, or drive its console, by rebinding its own name to the box's LAN address. This is the Phoenix twin of macula-services/mcl-bookclub PR #13.

Stacked on PR #18 (base mercurius/4-pr5b-service), so it reuses PR 18's test helpers in the same file, as the Erlang twin does. Land after #18.

Threat model and Done-when: macula-services/mcl-bookclub#12 (comment)

  • 42ad091 red first: on #18's tip, 5 tests fail (a rebound Host on POST, on GET, on the console and on assets; a listed name; a foreign Origin; a rebound page's LiveView socket gets 101). The IP/localhost/own-Origin cases pass.
  • 0abbab9 MclBookclubPhoenixWeb.AllowedHost, first plug in the endpoint: the Host must be an IP literal, localhost or a name in MCL_ADMIN_HOSTS, otherwise 403 host_not_allowed. A POST's Origin must be its own, otherwise 403 origin_not_allowed. The LiveView socket is dispatched before plugs, so check_origin (it was false) now calls AllowedHost.origin_allowed?/1. test_helper.exs lists www.example.com, the Host build_conn/0 sends. Docs: README, architecture, Containerfile, CHANGELOG, and the #9 plug/router comments.

Local (OTP 28.4.3, Elixir 1.18.4): format, compile --warnings-as-errors, credo --strict, 266 tests 0 failures, dialyzer clean. Mutant: with origin_allowed?/1 always true, the socket test fails (1 of 20).

Refs macula-services/mcl-bookclub#12

Purpose (fix): a web page outside the LAN cannot send a command to the Phoenix admin, read from it, or drive its console, by rebinding its own name to the box's LAN address. This is the Phoenix twin of macula-services/mcl-bookclub PR #13. **Stacked on PR #18** (base `mercurius/4-pr5b-service`), so it reuses PR 18's test helpers in the same file, as the Erlang twin does. Land after #18. Threat model and Done-when: https://git.macula.io/macula-services/mcl-bookclub/issues/12#issuecomment-7400 - 42ad091 red first: on #18's tip, 5 tests fail (a rebound Host on POST, on GET, on the console and on assets; a listed name; a foreign Origin; a rebound page's LiveView socket gets 101). The IP/localhost/own-Origin cases pass. - 0abbab9 `MclBookclubPhoenixWeb.AllowedHost`, first plug in the endpoint: the Host must be an IP literal, localhost or a name in `MCL_ADMIN_HOSTS`, otherwise 403 `host_not_allowed`. A POST's Origin must be its own, otherwise 403 `origin_not_allowed`. The LiveView socket is dispatched before plugs, so `check_origin` (it was `false`) now calls `AllowedHost.origin_allowed?/1`. `test_helper.exs` lists `www.example.com`, the Host `build_conn/0` sends. Docs: README, architecture, Containerfile, CHANGELOG, and the #9 plug/router comments. Local (OTP 28.4.3, Elixir 1.18.4): format, compile --warnings-as-errors, credo --strict, 266 tests 0 failures, dialyzer clean. Mutant: with `origin_allowed?/1` always true, the socket test fails (1 of 20). Refs macula-services/mcl-bookclub#12
mcl-bookclub#12 review: a rebound Host that starts with localhost or an IP, or wraps a listed name, is refused
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
c4 model / c4-model-1 (push) Successful in 6s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 7m9s
ee4d318368
Pins exact matching in AllowedHost: a prefix, suffix or substring match on
a listed name, a "localhost" <> _ clause or an IP-prefix parse each
survived the suite before.
mercurius changed target branch from mercurius/4-pr5b-service to main 2026-12-01 14:21:21 +00:00
Member

Landed by fast-forward: main is ee4d318368 (from 4350b75a). This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is ee4d3183688d4d3c8e7ee8fef4ef700b1884204a (from 4350b75a). This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-01 14:32:12 +00:00
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
c4 model / c4-model-1 (push) Successful in 6s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 7m9s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-bookclub-phoenix!19
No description provided.