Admin API: a DNS-rebinding page can send JSON commands (no Host check), which #9 does not close #12
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
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(tip81754b14) checks neitherHostnorOrigin(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 rebindsevil.exampleto the box's LAN IP (short TTL). The page'sfetch('/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.mdsay 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
Hostis 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:
Host: evil.example:8488to a command route is refused and dispatches nothing (the stream stays empty). One test, red first.Host: <ip>:8488andHost: localhost:8488still work. The existing admin suite passes.Refs #9
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_PORT8488; 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 rebindsevil.exampleto the box's LAN IP. To the browser, the page'sfetch('/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 sendsHost: 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 itsHost(the host part, port ignored) is:http://192.168.1.10:8488needs no config;localhost; oradmin_hosts, envMCL_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
POSTcarriesOrigin, its host and port must be the request's own (theHostthat already passed). If not, it gets403 {ok: false, error: origin_not_allowed}.Origin: nullis refused. APOSTwith noOrigin(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):
POSTwithHost: evil.example:<port>to a command route is accepted on main. After the fix it is refused with 403 and the stream stays empty. AGETread with that Host is refused too.Host: 127.0.0.1:<port>,Host: localhost:<port>, an IPv6 literal, and a name listed inadmin_hostsall still work. The existing admin suites pass.POSTwith a foreignOrigin(http://evil.example), orOrigin: null, is refused with 403 and dispatches nothing. APOSTwhoseOriginmatches itsHostis accepted, and one with noOriginis accepted.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_HOSTSis documented next toMCL_ADMIN_PORT.Addendum for the Phoenix twin, from the Fable review of mcl-bookclub-phoenix PR 18 (#4, 5b):
config/runtime.exs:113setscheck_origin: false(since 9a212d8), andAdminLive.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 withOrigin: http://evil.examplegets 101.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 realcheck_originlist.runtime.exs, so there the token can be forged cross-site.Done (Mercurius). Both admin listeners serve only a Host that is an IP literal,
localhostor a name inMCL_ADMIN_HOSTS, and take a POST only from their own Origin.df643d8bba(PR #13: a cowboy middleware ahead of the router; Jupiter r1 fixa9c547da+ fold).AllowedHostfirst in the endpoint, and the LiveView socket checks Origin against the same list; Jupiter r1 fix ee4d3183).Done-when (comment 7400):
a991717, Phoenix 42ad091.127.1is not an IP literal. [x] Existing suites pass (Erlang 136, Phoenix 266).Origin: nullon 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.MCL_ADMIN_HOSTSis documented next to the port. [x]CI green on both tips: Erlang 6369-6371, Phoenix 6373/6374.