mcl-bookclub#9: the admin API takes a write only as application/json (415 otherwise) #10
Loading…
Reference in a new issue
No description provided.
Delete branch "mercurius/9-admin-json-only"
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?
Refs macula-services/mcl-bookclub#9 (threat model and Done-when: #9 (comment)). Security-adjacent: Opus build, Fable review (Jupiter), on the Supervisor's ruling.
What
mcl_bookclub_admin:init/2refuses aPOSTwhoseContent-Typeis notapplication/jsonwith415 {ok: false, error: unsupported_media_type}, beforeread_params/2reads the body. Nothing is dispatched.json_body/2usescowboy_req:parse_header/2, which lowercases type and subtype; parameters (; charset=utf-8) are allowed. A missing or unparsable header counts as not JSON.GETis unchanged. Auth and the bind address are unchanged, as ruled.The guide (
guides/admin_ui.md) states the rule and gives a curl line; the CHANGELOG has an entry. The operator UI already sendsContent-Type: application/json(priv/admin/app.js:114).One deviation from the Done-when comment: the check runs for every
POSTunder/api/before the dispatch table. A non-JSONPOSTto an unknown route therefore gets 415 instead of 404. Keeping 404 there would need a second route table besidedispatch/3; the CHANGELOG says so.Red first
a8f4225adds only the tests. In the CI image on msi00,mcl_bookclub_admin_testsgives Failed 3, Passed 7:a_text_plain_post_is_refused_and_dispatches_nothing:{badmatch,{200,…}}. The text/plain register was accepted on main.every_body_a_page_can_send_unpreflighted_is_refused: urlencoded, multipart andTEXT/PLAIN; charset=utf-8are not 415.a_post_with_no_content_type_is_refused(bare socket, because httpc always names a type): expected 415, got the write.json_with_a_charset_is_acceptedpasses on main and after, as a regression guard.Each refusal also asserts the member's stream is empty (
evoq_event_store:read/5), not only the status.Checks (msi00, forge CI image macula-ci-otp:20261124-0509) at
81754b1lint 0, eunit 0 (all 129 passed), dialyzer 0.
The Phoenix half follows in mcl-bookclub-phoenix PR 5b (#4), with the same rule and tests.