HTTP API on 127.0.0.1:8451: any page in the owner's browser can write the corpus (no Host, Origin or Content-Type check) #23
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 (security): a web page the owner opens cannot write to, or read, the corpus through mcl-rag's loopback HTTP API.
Same class as macula-services/mcl-bookclub#12. Read from main
fd58629.What is there.
mcl_rag_sup:http_listener/0binds 127.0.0.1:8451 (deploy:network_mode: host), with no auth. Nothing checksHostorOrigin, andmcl_rag_http:read_json_body/1decodes the body whatever itsContent-Type.Routes. Writes (POST):
/api/rag/knowledge/add,/api/rag/knowledge/upload,/api/rag/documents/{ingest,embed,retire,prune,classify-topics},/api/rag/seed,/api/rag/corpus/changes/detect,/api/rag/corpus/reembed/schedule. Reads:/api/rag/chunks/{search,by-source,:chunk_id},/api/rag/sources[/:source_id],/api/rag/queries/{answer,rerank}.Attacker. An outside page in the owner's browser.
fetch('http://127.0.0.1:8451/api/rag/knowledge/add', {method: 'POST', mode: 'no-cors', body: '{…}'})goes out astext/plainwith no preflight and is decoded as JSON. The page plants or retires corpus content, which every agent then retrieves. (Chrome's local-network-access prompt slows this down. Firefox and Safari have nothing like it.)evil.example:8451rebinds to 127.0.0.1. Same-origin JSON POSTs, and GET reads of the corpus with their replies readable.Fix shape (small, as in mcl-bookclub#12 and #9). In one place every handler passes (the listener, or a cowboy middleware): refuse a
Hostthat is not127.0.0.1/localhost/[::1](plus a configured name) before anything is read; on POST, refuse a non-application/jsonContent-Typewith 415 and refuse a cross-siteOrigin.Done when:
Host: evil.example:8451and one withContent-Type: text/plainare each refused and change nothing. Red first.measure.py) still work. The existing suites pass.Refs macula-services/mcl-bookclub#12
Threat model and plan (Uranus, building; Jupiter reviews). Base: main
fd58629.Attacker: an outside web page open in the owner's browser. It is the only attacker this covers. A local process on the box is already inside and is out of scope. The mesh RPC path is not touched.
text/plain, form or multipart POST goes out with no preflight, andread_json_body/1decodes it anyway.evil.examplerebinds to 127.0.0.1. The page's requests are then same-origin, so it can send JSON writes and read the GET replies.Fix: one cowboy middleware,
mcl_rag_http_guard, ahead ofcowboy_router. Every route passes it before a handler or a body read.localhost,127.0.0.1and::1, plus the names inhttp_hosts(MCL_RAG_HTTP_HOSTS, comma separated, default empty). Any other Host gets 400host_not_allowed, on every method, reads included. Same answer as mcl-whiteboard's AllowedHosts.application/json(parameters allowed), or it gets 415unsupported_media_type. A missing header is refused too.Originheader that is present must name an allowed host, or it gets 403origin_not_allowed. That includesnull. An absent Origin (curl, measure.py) passes.Tests, red first: a new CT suite over a raw socket on the test listener. Each refusal is followed by
rag_store:list_chunks_by_source/2on the deposit's label, which must be empty. Loopback JSON, measure.py's request shape and a configured name must all still pass.Done when is as in the issue body.
Done, and live on msi00 since 2026-12-01 16:21 CET (mcl-rag 0.11.1, fleet#85 at main 8639310).
Done when:
text/plainPOST refused, red first. Red:e788b77addedtest/mcl_rag_http_guard_SUITE.erl, and seven of its ten cases failed on main. Green:c191c6b,mcl_rag_http_guard, a cowboy middleware ahead of the router (PR 24). Live check on msi00: a GET search withHost: evil.example:8451returned400 {"error":"host_not_allowed"}.Host: localhost:8451returned 200. The mesh RPC path is untouched. CI on the 0.11.1 prep tip: 6349 and 6350, both green..githubor.forgejo.Purpose met: a page the owner opens can no longer write to or read the corpus over 127.0.0.1:8451. The running image is
git.macula.io/macula-pub/mcl-rag@sha256:fa47c1e8d54543f8990e71cd63df53698d72128e8e6ebfc536988b3503f7b4e3, signed and pinned.Follow-ups stay on mcl-rag#26 (guard notes).