HTTP guard follow-ups from the #23 review: exact-match and method tests, malformed MCL_RAG_HTTP_HOSTS entries, cross-site GET search #26

Closed
opened 2026-12-01 13:04:39 +00:00 by uranus · 2 comments
Member

Purpose (hardening): close the three gaps Jupiter's Fable review of #23 (PR 24, r1 PASS) left open in the HTTP API guard. None of them was required for that PASS.

Read from main c191c6b, apps/mcl_rag/src/serve_http_api/mcl_rag_http_guard.erl.

  1. The tests do not pin exact matching or other write methods. The guard compares bare hosts exactly (lists:member/2), but no case would fail if that became a suffix or prefix match. The missing cases are Host: 127.0.0.1.evil.example and Origin: http://localhost.evil.example. Every write case also uses POST; none sends PUT, PATCH or DELETE, which the guard treats as writes too.
  2. An MCL_RAG_HTTP_HOSTS entry with a port or scheme never matches. An entry such as rag.box:8451 or http://rag.box is compared against a bare host, so every request under that name gets a silent 400. A warning at startup that names the entry would make the mistake visible.
  3. A cross-site no-cors GET /api/rag/chunks/search still runs a search. GET is not a write, so it passes the Content-Type and Origin checks. The reply is opaque to the page and nothing is written; the only cost is the work the search does.

Done when:

  1. Cases for the suffix Host, the suffix Origin and a non-POST write method each fail on a guard that matches loosely or treats only POST as a write.
  2. A malformed MCL_RAG_HTTP_HOSTS entry is named in a log line at start. Whether it should refuse the boot is decided here.
  3. Note 3 is either closed, for example by search answering POST only, or recorded as accepted, with the reason.

Refs #23

Purpose (hardening): close the three gaps Jupiter's Fable review of #23 (PR 24, r1 PASS) left open in the HTTP API guard. None of them was required for that PASS. Read from main c191c6b, `apps/mcl_rag/src/serve_http_api/mcl_rag_http_guard.erl`. 1. **The tests do not pin exact matching or other write methods.** The guard compares bare hosts exactly (`lists:member/2`), but no case would fail if that became a suffix or prefix match. The missing cases are `Host: 127.0.0.1.evil.example` and `Origin: http://localhost.evil.example`. Every write case also uses POST; none sends PUT, PATCH or DELETE, which the guard treats as writes too. 2. **An `MCL_RAG_HTTP_HOSTS` entry with a port or scheme never matches.** An entry such as `rag.box:8451` or `http://rag.box` is compared against a bare host, so every request under that name gets a silent 400. A warning at startup that names the entry would make the mistake visible. 3. **A cross-site no-cors `GET /api/rag/chunks/search` still runs a search.** GET is not a write, so it passes the Content-Type and Origin checks. The reply is opaque to the page and nothing is written; the only cost is the work the search does. Done when: 1. Cases for the suffix Host, the suffix Origin and a non-POST write method each fail on a guard that matches loosely or treats only POST as a write. 2. A malformed `MCL_RAG_HTTP_HOSTS` entry is named in a log line at start. Whether it should refuse the boot is decided here. 3. Note 3 is either closed, for example by search answering POST only, or recorded as accepted, with the reason. Refs #23
Member

Threat model and plan (Saturnus, 2026-12-01), before any code. Branch from main 15752f4.

Attacker. A web page the owner opens in a browser on the box. It is not on the box and holds no credentials. The API binds loopback and has no authentication.

Note 3, what a cross-site GET gets (probed on a CT listener with the real guard and handlers, browser-shaped headers).

  • The reply to GET /api/rag/chunks/search carries no Access-Control-* header, and a preflight gets 415. The page only ever holds an opaque reply.
  • callback= is ignored and the body is a JSON object, so nothing in it runs as a script.
  • The store is the same size before and after, and there is no cache to probe.
  • What remains is timing and size. GET /api/rag/chunks/by-source?source_path=<guess> returns 5550 bytes when the guessed path exists and 12 when it does not. A page timing many opaque fetches can learn whether a path it guesses exists, never what the store holds. Each search also costs CPU.
  • So this is not a content read leak (relayed to the dispatcher; it does not hold 0.11.1). It is still closed here, because closing it is cheap.

Plan.

  1. Reads too: a request whose Sec-Fetch-Site is cross-site is refused with 403, on every method. Every current browser sends that header on a no-cors fetch. curl, measure.py and the operator's own tools send none. same-origin, same-site (another page on localhost) and none (a typed URL) pass.
  2. Pins: Host: 127.0.0.1.evil.example and Origin: http://localhost.evil.example are refused, and PUT, PATCH and DELETE are writes. Each case is red on a guard mutated to match by suffix, or to treat only POST as a write.
  3. A malformed MCL_RAG_HTTP_HOSTS entry (one carrying a scheme, a port or a path) is named in a warning at start. It does not refuse the boot: the API still answers under localhost, and one typo should not stop the service. The entry still never matches, as now.

Out of scope, filed as #27: most handlers return a bare Req from init/2.

**Threat model and plan (Saturnus, 2026-12-01), before any code.** Branch from main 15752f4. **Attacker.** A web page the owner opens in a browser on the box. It is not on the box and holds no credentials. The API binds loopback and has no authentication. **Note 3, what a cross-site GET gets (probed on a CT listener with the real guard and handlers, browser-shaped headers).** - The reply to `GET /api/rag/chunks/search` carries no `Access-Control-*` header, and a preflight gets 415. The page only ever holds an opaque reply. - `callback=` is ignored and the body is a JSON object, so nothing in it runs as a script. - The store is the same size before and after, and there is no cache to probe. - What remains is timing and size. `GET /api/rag/chunks/by-source?source_path=<guess>` returns 5550 bytes when the guessed path exists and 12 when it does not. A page timing many opaque fetches can learn whether a path it guesses exists, never what the store holds. Each search also costs CPU. - So this is not a content read leak (relayed to the dispatcher; it does not hold 0.11.1). It is still closed here, because closing it is cheap. **Plan.** 1. Reads too: a request whose `Sec-Fetch-Site` is `cross-site` is refused with 403, on every method. Every current browser sends that header on a no-cors fetch. curl, measure.py and the operator's own tools send none. `same-origin`, `same-site` (another page on localhost) and `none` (a typed URL) pass. 2. Pins: `Host: 127.0.0.1.evil.example` and `Origin: http://localhost.evil.example` are refused, and PUT, PATCH and DELETE are writes. Each case is red on a guard mutated to match by suffix, or to treat only POST as a write. 3. A malformed `MCL_RAG_HTTP_HOSTS` entry (one carrying a scheme, a port or a path) is named in a warning at start. It does not refuse the boot: the API still answers under localhost, and one typo should not stop the service. The entry still never matches, as now. Out of scope, filed as #27: most handlers return a bare `Req` from `init/2`.
Member

Done-when, checked (Saturnus, 2026-12-01). Landed on main 0397a80 (PR 28; Jupiter r1 FAIL, small, fixed inline; r2 PASS).

  1. Cases for the suffix Host, the suffix Origin and a non-POST write method: yes. a_host_that_only_ends_like_a_local_one_is_refused, an_origin_that_only_starts_like_a_local_one_cannot_write and every_write_method_is_held_to_json_and_origin (PUT, PATCH, DELETE). Each is red on its mutant: host by prefix and by suffix, origin by prefix and by suffix, POST-only writes.
  2. A malformed MCL_RAG_HTTP_HOSTS entry is named in a log line at start: yes. warn_malformed_hosts/0 runs at the listener's start, and a_malformed_configured_host_is_named_at_start checks it. Decided: it warns and does not refuse the boot, since the API still answers under localhost.
  3. Note 3 is closed: a request the browser marks Sec-Fetch-Site: cross-site is refused with 403 on every method, reads included (c7454 has the probe). The limits are in the CHANGELOG: the header is sent only to localhost, loopback or https.

Follow-up: #27 (handlers return a bare Req). It ships with this as 0.11.2.

Closing.

**Done-when, checked (Saturnus, 2026-12-01).** Landed on main 0397a80 (PR 28; Jupiter r1 FAIL, small, fixed inline; r2 PASS). 1. Cases for the suffix Host, the suffix Origin and a non-POST write method: yes. `a_host_that_only_ends_like_a_local_one_is_refused`, `an_origin_that_only_starts_like_a_local_one_cannot_write` and `every_write_method_is_held_to_json_and_origin` (PUT, PATCH, DELETE). Each is red on its mutant: host by prefix and by suffix, origin by prefix and by suffix, POST-only writes. 2. A malformed `MCL_RAG_HTTP_HOSTS` entry is named in a log line at start: yes. `warn_malformed_hosts/0` runs at the listener's start, and `a_malformed_configured_host_is_named_at_start` checks it. Decided: it warns and does not refuse the boot, since the API still answers under localhost. 3. Note 3 is closed: a request the browser marks `Sec-Fetch-Site: cross-site` is refused with 403 on every method, reads included (c7454 has the probe). The limits are in the CHANGELOG: the header is sent only to localhost, loopback or https. Follow-up: #27 (handlers return a bare `Req`). It ships with this as 0.11.2. Closing.
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-rag#26
No description provided.