mcl-rag#23: the local HTTP API refuses a rebound Host, a non-JSON write and a cross-site Origin #24

Manually merged
terra merged 2 commits from uranus/23-http-guard into main 2026-12-01 12:56:54 +00:00
Member

Refs #23. Purpose (security): a web page the owner opens can neither write to nor read the corpus through the loopback HTTP API.

mcl_rag_http_guard is a cowboy middleware that runs ahead of cowboy_router, so every route passes it before a handler runs or a body is read:

  • a Host other than localhost, 127.0.0.1, ::1 or a name in the new MCL_RAG_HTTP_HOSTS gets 400 host_not_allowed, on every method;
  • a request that is not a GET or HEAD must be application/json, parameters allowed, or it gets 415;
  • if such a request sends an Origin, it must name an allowed host, null included, or it gets 403.

Tests: test/mcl_rag_http_guard_SUITE.erl (10 cases) goes over a raw socket. Each refused write is checked against the store and has stored nothing.

  • Red first: e788b77 alone fails 7 of the 10.
  • One mutant per check (Host always allowed, any Content-Type taken, any Origin taken) each fails its own cases.
  • Run locally on c191c6b, all green: rebar3 lint, eunit (233), ct (74) and dialyzer.

Threat model: issue comment 7330. Done-when 3 holds: no new check or job.

Refs #23. Purpose (security): a web page the owner opens can neither write to nor read the corpus through the loopback HTTP API. `mcl_rag_http_guard` is a cowboy middleware that runs ahead of `cowboy_router`, so every route passes it before a handler runs or a body is read: - a `Host` other than localhost, 127.0.0.1, ::1 or a name in the new `MCL_RAG_HTTP_HOSTS` gets 400 `host_not_allowed`, on every method; - a request that is not a GET or HEAD must be `application/json`, parameters allowed, or it gets 415; - if such a request sends an `Origin`, it must name an allowed host, `null` included, or it gets 403. Tests: `test/mcl_rag_http_guard_SUITE.erl` (10 cases) goes over a raw socket. Each refused write is checked against the store and has stored nothing. - Red first: e788b77 alone fails 7 of the 10. - One mutant per check (Host always allowed, any Content-Type taken, any Origin taken) each fails its own cases. - Run locally on c191c6b, all green: `rebar3 lint`, eunit (233), ct (74) and dialyzer. Threat model: issue comment 7330. Done-when 3 holds: no new check or job.
Over a raw socket to the running listener: a text/plain, form, multipart
or untyped write gets 415, a rebound Host gets 400 on a write and a read,
a cross-site or null Origin gets 403, and each refused write stores
nothing. Loopback JSON, measure.py's search and a configured name still
pass. Seven of the ten fail on main.
mcl-rag#23: a guard ahead of every HTTP route checks Host, Content-Type and Origin
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 6m49s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 1s
build-and-push / guard-1 (push) Successful in 17s
c4 model / c4-model-1 (push) Successful in 21s
c4 model / c4-model (push) Successful in 0s
build-and-push / check (push) Successful in 7m16s
build-and-push / The tested lock arrives whole (push) Has been skipped
build-and-push / test (push) Successful in 0s
build-and-push / Release (forge, v* tag) (push) Has been skipped
lint-and-test / check (push) Successful in 6m59s
lint-and-test / The tested lock arrives whole (push) Has been skipped
build-and-push / build-and-push (push) Successful in 42s
build-and-push / File the tested resolve for the signer (push) Successful in 2s
build-and-push / guard (push) Has been skipped
build-and-push / attest (push) Successful in 0s
c191c6b276
mcl_rag_http_guard is a cowboy middleware ahead of the router. A Host
other than localhost, 127.0.0.1, ::1 or a name in MCL_RAG_HTTP_HOSTS gets
400. A request that is not a GET or HEAD must be application/json (415)
and, if it sends an Origin, that must name an allowed host (403). This
stops the cross-site no-cors write and the DNS-rebinding page. Each
check's mutant fails its own tests.
terra manually merged commit c191c6b276 into main 2026-12-01 12:56:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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!24
No description provided.