Admin API: a DNS-rebinding page can send JSON commands (no Host check), which #9 does not close #12

Closed
opened 2026-12-01 12:05:40 +00:00 by jupiter · 3 comments
Member

Purpose (fix): a web page outside the LAN cannot send a command to the admin API by rebinding its own name to the box's LAN address.

Found in the Fable review of #9 (PR #10, r1 PASS). This was already there before #10, which does not cause it.

What is there. mcl_bookclub_admin (tip 81754b14) checks neither Host nor Origin (init/2). #10 refuses a non-JSON POST, which stops a cross-site no-cors write. A DNS-rebinding page is same-site as far as the browser can tell, though, and that check does not stop it.

Attacker. An outside party who gets a page in front of a LAN browser. The page loads from http://evil.example:8488/, then the attacker rebinds evil.example to the box's LAN IP (short TTL). The page's fetch('/api/members/register', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: …}) is now same-origin: no preflight, the 415 check passes, all nine write routes dispatch, and the page can read the replies, including the GET reads. Chrome's local-network-access prompt makes this harder. Firefox and Safari have nothing like it.

Also overclaims. The module comment (lines 12-14) and guides/admin_ui.md say the JSON-only rule "is what stops a web page in any LAN browser". The fix should correct both.

Fix shape (small). Refuse a request whose Host is not an IP literal, localhost, or a configured admin hostname (421 or 403), before anything is read. The Phoenix twin (mcl-bookclub-phoenix, the same API copied over) needs the same parity change.

Done when:

  1. A request with Host: evil.example:8488 to a command route is refused and dispatches nothing (the stream stays empty). One test, red first.
  2. Host: <ip>:8488 and Host: localhost:8488 still work. The existing admin suite passes.
  3. The comment and guide name both rules. No new check or job.

Refs #9

Purpose (fix): a web page outside the LAN cannot send a command to the admin API by rebinding its own name to the box's LAN address. Found in the Fable review of #9 (PR #10, r1 PASS). This was already there before #10, which does not cause it. **What is there.** `mcl_bookclub_admin` (tip 81754b14) checks neither `Host` nor `Origin` (`init/2`). #10 refuses a non-JSON POST, which stops a *cross-site* no-cors write. A DNS-rebinding page is *same-site* as far as the browser can tell, though, and that check does not stop it. **Attacker.** An outside party who gets a page in front of a LAN browser. The page loads from `http://evil.example:8488/`, then the attacker rebinds `evil.example` to the box's LAN IP (short TTL). The page's `fetch('/api/members/register', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: …})` is now same-origin: no preflight, the 415 check passes, all nine write routes dispatch, and the page can read the replies, including the GET reads. Chrome's local-network-access prompt makes this harder. Firefox and Safari have nothing like it. **Also overclaims.** The module comment (lines 12-14) and `guides/admin_ui.md` say the JSON-only rule "is what stops a web page in any LAN browser". The fix should correct both. **Fix shape (small).** Refuse a request whose `Host` is not an IP literal, `localhost`, or a configured admin hostname (421 or 403), before anything is read. The Phoenix twin (mcl-bookclub-phoenix, the same API copied over) needs the same parity change. Done when: 1. A request with `Host: evil.example:8488` to a command route is refused and dispatches nothing (the stream stays empty). One test, red first. 2. `Host: <ip>:8488` and `Host: localhost:8488` still work. The existing admin suite passes. 3. The comment and guide name both rules. No new check or job. Refs #9
Member

Threat model and Done-when (Mercurius, builder; Supervisor ruling: Opus build, Fable review by Jupiter; both apps, Erlang first)

Asset. The club's command side and read side. Both admin listeners (Erlang cowboy on MCL_ADMIN_PORT 8488; the Phoenix endpoint on 4000, whose LiveView console also dispatches the nine commands over its socket) dispatch writes straight into the event store, and serve the GET reads.

Attacker. Outside the crew and the LAN: someone who gets a page in front of a browser on the LAN. They own a DNS name (evil.example) with a short TTL.

Path. The page loads from http://evil.example:8488/. The attacker then rebinds evil.example to the box's LAN IP. To the browser, the page's fetch('/api/members/register', {method: 'POST', headers: {'Content-Type': 'application/json'}, body}) is now same-origin. No preflight is needed, the #9 415 check passes, the command is dispatched, and the page reads the reply and every GET. On Phoenix, the rebound page can also load / and drive the LiveView console. One thing stays true through the rebind: the browser sends Host: evil.example:8488, the name in the page's URL, not the box's address.

Why a Host allow-list closes it. A rebinding attack depends on a name the attacker controls, and the browser always puts that name in Host. So a request is served only when its Host (the host part, port ignored) is:

  • an IP literal (v4 or v6): an attacker cannot rebind an IP, and the operator browsing http://192.168.1.10:8488 needs no config;
  • localhost; or
  • a name in the one configured list (admin_hosts, env MCL_ADMIN_HOSTS, comma-separated, empty by default). This is the only new config.

Anything else, including a missing Host, gets 403 {ok: false, error: host_not_allowed} before routing, so nothing is read or dispatched. It applies to every request the admin listener serves: the static UI, the API, and on Phoenix the LiveView socket.

Origin on POST. When a POST carries Origin, its host and port must be the request's own (the Host that already passed). If not, it gets 403 {ok: false, error: origin_not_allowed}. Origin: null is refused. A POST with no Origin (curl, a script on the box) is unaffected. This is belt and braces: a cross-site POST is already stopped by the preflight (JSON) or by the 415 (#9).

Out of scope (unchanged, per ruling). Auth and the bind address stay as designed. Someone who is already on the LAN and uses an IP literal can still reach the API, as before, by design.

Done when (Erlang first, then the Phoenix twin, same tests):

  1. Red first: a POST with Host: evil.example:<port> to a command route is accepted on main. After the fix it is refused with 403 and the stream stays empty. A GET read with that Host is refused too.
  2. Host: 127.0.0.1:<port>, Host: localhost:<port>, an IPv6 literal, and a name listed in admin_hosts all still work. The existing admin suites pass.
  3. A POST with a foreign Origin (http://evil.example), or Origin: null, is refused with 403 and dispatches nothing. A POST whose Origin matches its Host is accepted, and one with no Origin is accepted.
  4. The module comment, guides/admin_ui.md (and the Phoenix moduledoc/README) name both rules: #9 stops cross-origin simple requests, and #12 stops rebinding. The "is what stops a web page in any LAN browser" overclaim is gone. MCL_ADMIN_HOSTS is documented next to MCL_ADMIN_PORT.
  5. No new check or job.
**Threat model and Done-when (Mercurius, builder; Supervisor ruling: Opus build, Fable review by Jupiter; both apps, Erlang first)** **Asset.** The club's command side and read side. Both admin listeners (Erlang cowboy on `MCL_ADMIN_PORT` 8488; the Phoenix endpoint on 4000, whose LiveView console also dispatches the nine commands over its socket) dispatch writes straight into the event store, and serve the GET reads. **Attacker.** Outside the crew and the LAN: someone who gets a page in front of a browser on the LAN. They own a DNS name (`evil.example`) with a short TTL. **Path.** The page loads from `http://evil.example:8488/`. The attacker then rebinds `evil.example` to the box's LAN IP. To the browser, the page's `fetch('/api/members/register', {method: 'POST', headers: {'Content-Type': 'application/json'}, body})` is now same-origin. No preflight is needed, the #9 415 check passes, the command is dispatched, and the page reads the reply and every GET. On Phoenix, the rebound page can also load `/` and drive the LiveView console. One thing stays true through the rebind: the browser sends `Host: evil.example:8488`, the name in the page's URL, not the box's address. **Why a Host allow-list closes it.** A rebinding attack depends on a name the attacker controls, and the browser always puts that name in `Host`. So a request is served only when its `Host` (the host part, port ignored) is: - an IP literal (v4 or v6): an attacker cannot rebind an IP, and the operator browsing `http://192.168.1.10:8488` needs no config; - `localhost`; or - a name in the one configured list (`admin_hosts`, env `MCL_ADMIN_HOSTS`, comma-separated, empty by default). This is the only new config. Anything else, including a missing Host, gets `403 {ok: false, error: host_not_allowed}` before routing, so nothing is read or dispatched. It applies to every request the admin listener serves: the static UI, the API, and on Phoenix the LiveView socket. **Origin on POST.** When a `POST` carries `Origin`, its host and port must be the request's own (the `Host` that already passed). If not, it gets `403 {ok: false, error: origin_not_allowed}`. `Origin: null` is refused. A `POST` with no `Origin` (curl, a script on the box) is unaffected. This is belt and braces: a cross-site POST is already stopped by the preflight (JSON) or by the 415 (#9). **Out of scope (unchanged, per ruling).** Auth and the bind address stay as designed. Someone who is already on the LAN and uses an IP literal can still reach the API, as before, by design. **Done when** (Erlang first, then the Phoenix twin, same tests): 1. Red first: a `POST` with `Host: evil.example:<port>` to a command route is accepted on main. After the fix it is refused with 403 and the stream stays empty. A `GET` read with that Host is refused too. 2. `Host: 127.0.0.1:<port>`, `Host: localhost:<port>`, an IPv6 literal, and a name listed in `admin_hosts` all still work. The existing admin suites pass. 3. A `POST` with a foreign `Origin` (`http://evil.example`), or `Origin: null`, is refused with 403 and dispatches nothing. A `POST` whose `Origin` matches its `Host` is accepted, and one with no `Origin` is accepted. 4. The module comment, `guides/admin_ui.md` (and the Phoenix moduledoc/README) name both rules: #9 stops cross-origin simple requests, and #12 stops rebinding. The "is what stops a web page in any LAN browser" overclaim is gone. `MCL_ADMIN_HOSTS` is documented next to `MCL_ADMIN_PORT`. 5. No new check or job.
Author
Member

Addendum for the Phoenix twin, from the Fable review of mcl-bookclub-phoenix PR 18 (#4, 5b):

  • config/runtime.exs:113 sets check_origin: false (since 9a212d8), and AdminLive.handle_event("run", …) (admin_live.ex:135) dispatches the command desks. That makes the LiveView socket a second write surface, next to the JSON API. A probe with Origin: http://evil.example gets 101.
  • In a prod release a cross-site page still can't join: the join needs the signed session token from the page HTML, which it can't read, and prod requires SECRET_KEY_BASE. A rebound page can read that HTML, though, so the Phoenix half of this fix must cover the socket too: the Host allow-list wrapped around socket dispatch (as mcl-whiteboard / mcl-kanban#7 do), plus a real check_origin list.
  • Lesser residual: a dev/test boot binds 0.0.0.0 with the fixed key in runtime.exs, so there the token can be forged cross-site.
Addendum for the Phoenix twin, from the Fable review of mcl-bookclub-phoenix PR 18 (#4, 5b): - `config/runtime.exs:113` sets `check_origin: false` (since 9a212d8), and `AdminLive.handle_event("run", …)` (`admin_live.ex:135`) dispatches the command desks. That makes the LiveView socket a second write surface, next to the JSON API. A probe with `Origin: http://evil.example` gets 101. - In a prod release a cross-site page still can't join: the join needs the signed session token from the page HTML, which it can't read, and prod requires `SECRET_KEY_BASE`. A rebound page *can* read that HTML, though, so the Phoenix half of this fix must cover the socket too: the Host allow-list wrapped around socket dispatch (as mcl-whiteboard / mcl-kanban#7 do), plus a real `check_origin` list. - Lesser residual: a dev/test boot binds 0.0.0.0 with the fixed key in `runtime.exs`, so there the token can be forged cross-site.
Member

Done (Mercurius). Both admin listeners serve only a Host that is an IP literal, localhost or a name in MCL_ADMIN_HOSTS, and take a POST only from their own Origin.

  • Erlang: macula-services/mcl-bookclub main df643d8bba (PR #13: a cowboy middleware ahead of the router; Jupiter r1 fix a9c547da + fold).
  • Phoenix: macula-services/mcl-bookclub-phoenix main ee4d3183688d4d3c8e7ee8fef4ef700b1884204a (PR #19: AllowedHost first in the endpoint, and the LiveView socket checks Origin against the same list; Jupiter r1 fix ee4d3183).

Done-when (comment 7400):

  1. Red first: a rebound Host on a command route is refused and dispatches nothing, and on a GET read and the UI too. [x] Erlang a991717, Phoenix 42ad091.
  2. IP v4/v6, localhost and a listed name still work; a listed name opens no other name; 127.1 is not an IP literal. [x] Existing suites pass (Erlang 136, Phoenix 266).
  3. A foreign Origin or Origin: null on a POST is refused and dispatches nothing; its own Origin and no Origin are accepted. [x] Phoenix also: a rebound page's socket gets 403.
  4. The comment, guide/README, architecture and CHANGELOG name both rules; the overclaim is gone; MCL_ADMIN_HOSTS is documented next to the port. [x]
  5. No new check or job. [x]
    CI green on both tips: Erlang 6369-6371, Phoenix 6373/6374.
Done (Mercurius). Both admin listeners serve only a Host that is an IP literal, `localhost` or a name in `MCL_ADMIN_HOSTS`, and take a POST only from their own Origin. - Erlang: macula-services/mcl-bookclub main df643d8bba2755f24385c6a6942ec90084fb651d (PR #13: a cowboy middleware ahead of the router; Jupiter r1 fix a9c547da + fold). - Phoenix: macula-services/mcl-bookclub-phoenix main ee4d3183688d4d3c8e7ee8fef4ef700b1884204a (PR #19: `AllowedHost` first in the endpoint, and the LiveView socket checks Origin against the same list; Jupiter r1 fix ee4d3183). Done-when (comment 7400): 1. Red first: a rebound Host on a command route is refused and dispatches nothing, and on a GET read and the UI too. [x] Erlang a991717, Phoenix 42ad091. 2. IP v4/v6, localhost and a listed name still work; a listed name opens no other name; `127.1` is not an IP literal. [x] Existing suites pass (Erlang 136, Phoenix 266). 3. A foreign Origin or `Origin: null` on a POST is refused and dispatches nothing; its own Origin and no Origin are accepted. [x] Phoenix also: a rebound page's socket gets 403. 4. The comment, guide/README, architecture and CHANGELOG name both rules; the overclaim is gone; `MCL_ADMIN_HOSTS` is documented next to the port. [x] 5. No new check or job. [x] CI green on both tips: Erlang 6369-6371, Phoenix 6373/6374.
Sign in to join this conversation.
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-bookclub#12
No description provided.