mcl-kanban#7: a request under a rebound Host gets 400 (whiteboard AllowedHosts port) #8

Manually merged
terra merged 2 commits from uranus/7-allowed-hosts into main 2026-12-01 13:44:33 +00:00
Member

Refs #7. Purpose (security): a web page the owner opens cannot read the crew board by rebinding its own name to 127.0.0.1.

Threat model: an outside page in the owner's browser at evil.example:4010 rebinds that name to 127.0.0.1. Its fetch('/') is then same-origin, and the static render of / is the whole ladder. Writes were already refused by check_origin on the socket. A local process is out of scope.

Fix: MclKanbanWeb.AllowedHosts is mcl-whiteboard's module ported, with the names changed and the moduledoc adjusted.

  • It is registered with @before_compile after use Phoenix.Endpoint, so it wraps the whole call/2, socket dispatch included.
  • Any Host other than localhost, 127.0.0.1, ::1 and the hosts of MCL_HTTP_ORIGINS gets 400.
  • config/runtime.exs builds allowed_hosts from the same origin list as check_origin.
  • An MCL_HTTP_ORIGINS entry with no host now refuses the boot, naming the entry.

Tests: allowed_hosts_test.exs has 5 cases.

  • GET / and /?card=x under evil.example get 400, and the ladder is not in the body.
  • 127.0.0.1, localhost and [::1] still render the ladder.
  • The real runtime.exs, read with MCL_HTTP_ORIGINS set, yields the expected list.
  • Red first: 084b098 alone fails 4 of the 5.
  • Two mutants, the check always passing and the origin hosts dropped, each fail their case.

owner_ladder_live_test.exs now builds its conn with the host localhost, as the tunnel sends. Without that, build_conn's www.example.com would be refused.

Local run on 15b4c5e: format, compile with warnings as errors, credo, mix test (133, 0 failures) and dialyzer are all green. Done-when 3 holds: no new check or job.

Refs #7. Purpose (security): a web page the owner opens cannot read the crew board by rebinding its own name to 127.0.0.1. **Threat model:** an outside page in the owner's browser at `evil.example:4010` rebinds that name to 127.0.0.1. Its `fetch('/')` is then same-origin, and the static render of `/` is the whole ladder. Writes were already refused by `check_origin` on the socket. A local process is out of scope. **Fix:** `MclKanbanWeb.AllowedHosts` is mcl-whiteboard's module ported, with the names changed and the moduledoc adjusted. - It is registered with `@before_compile` after `use Phoenix.Endpoint`, so it wraps the whole `call/2`, socket dispatch included. - Any `Host` other than `localhost`, `127.0.0.1`, `::1` and the hosts of `MCL_HTTP_ORIGINS` gets 400. - `config/runtime.exs` builds `allowed_hosts` from the same origin list as `check_origin`. - An `MCL_HTTP_ORIGINS` entry with no host now refuses the boot, naming the entry. **Tests:** `allowed_hosts_test.exs` has 5 cases. - `GET /` and `/?card=x` under `evil.example` get 400, and the ladder is not in the body. - 127.0.0.1, localhost and `[::1]` still render the ladder. - The real runtime.exs, read with `MCL_HTTP_ORIGINS` set, yields the expected list. - Red first: 084b098 alone fails 4 of the 5. - Two mutants, the check always passing and the origin hosts dropped, each fail their case. `owner_ladder_live_test.exs` now builds its conn with the host `localhost`, as the tunnel sends. Without that, `build_conn`'s `www.example.com` would be refused. **Local run on 15b4c5e:** format, compile with warnings as errors, credo, `mix test` (133, 0 failures) and dialyzer are all green. Done-when 3 holds: no new check or job.
GET / and /?card= under a foreign Host get 400 and the board is not in
the reply; 127.0.0.1, localhost and [::1] still render. The allowed list
is read from the real config/runtime.exs with MCL_HTTP_ORIGINS set.
mcl-kanban#7: every request must name a local host or one of MCL_HTTP_ORIGINS
Some checks failed
ci / guard (pull_request) Has been skipped
ci / guard-1 (pull_request) Has been skipped
ci / elixir in . (pull_request) Has been skipped
c4 model / c4-model-1 (pull_request) Successful in 8s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Failing after 8s
ci / elixir in . (container) (pull_request) Successful in 15s
ci / Dependency advisories (pull_request) Successful in 0s
ci / image (amd64) (pull_request) Has been skipped
ci / attest (pull_request) Has been skipped
ci / guard (push) Has been skipped
ci / guard-1 (push) Has been skipped
ci / elixir in . (push) Has been skipped
c4 model / c4-model-1 (push) Successful in 3s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Failing after 3s
ci / elixir in . (container) (push) Successful in 10s
ci / Dependency advisories (push) Successful in 0s
ci / image (amd64) (push) Has been skipped
ci / attest (push) Has been skipped
15b4c5e848
MclKanbanWeb.AllowedHosts, ported from mcl-whiteboard, wraps the
endpoint's call/2 (socket dispatch included) and answers 400 to any other
Host, so a page that rebinds its name to 127.0.0.1 cannot read the ladder
from the static render of /. runtime.exs builds the list from the same
parse as check_origin; an entry with no host refuses the boot. The ladder
LiveView tests now ask under localhost, as the tunnel does.
terra manually merged commit 15b4c5e848 into main 2026-12-01 13:44:33 +00:00
Member

Landed by fast-forward: main is 15b4c5e848 (from d0c531cf), PASS r=1 Jupiter. Accepted reds (pre-existing, tracked in #4): gates (OTP 28.4.3 / Elixir 1.18.4) and ci.yml (run 6316): the checkout step has no node in the image, as on main run 3205. mix test never ran in CI; Jupiter ran the full suite offline on 15b4c5e8: 0 failures. Run 6315 c4-model green.

Landed by fast-forward: main is 15b4c5e8481fe3a3e13071e540737b02957001ca (from d0c531cf), PASS r=1 Jupiter. Accepted reds (pre-existing, tracked in #4): `gates (OTP 28.4.3 / Elixir 1.18.4)` and `ci.yml` (run 6316): the checkout step has no node in the image, as on main run 3205. mix test never ran in CI; Jupiter ran the full suite offline on 15b4c5e8: 0 failures. Run 6315 c4-model green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 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-kanban!8
No description provided.