mcl-bookclub#9: the admin API takes a write only as application/json (415 otherwise) #10

Manually merged
terra merged 3 commits from mercurius/9-admin-json-only into main 2026-12-01 13:01:15 +00:00
Member

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/2 refuses a POST whose Content-Type is not application/json with 415 {ok: false, error: unsupported_media_type}, before read_params/2 reads the body. Nothing is dispatched. json_body/2 uses cowboy_req:parse_header/2, which lowercases type and subtype; parameters (; charset=utf-8) are allowed. A missing or unparsable header counts as not JSON. GET is 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 sends Content-Type: application/json (priv/admin/app.js:114).

One deviation from the Done-when comment: the check runs for every POST under /api/ before the dispatch table. A non-JSON POST to an unknown route therefore gets 415 instead of 404. Keeping 404 there would need a second route table beside dispatch/3; the CHANGELOG says so.

Red first

a8f4225 adds only the tests. In the CI image on msi00, mcl_bookclub_admin_tests gives 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 and TEXT/PLAIN; charset=utf-8 are 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_accepted passes 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 81754b1

lint 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.

Refs macula-services/mcl-bookclub#9 (threat model and Done-when: https://git.macula.io/macula-services/mcl-bookclub/issues/9#issuecomment-7299). Security-adjacent: Opus build, Fable review (Jupiter), on the Supervisor's ruling. ## What `mcl_bookclub_admin:init/2` refuses a `POST` whose `Content-Type` is not `application/json` with `415 {ok: false, error: unsupported_media_type}`, before `read_params/2` reads the body. Nothing is dispatched. `json_body/2` uses `cowboy_req:parse_header/2`, which lowercases type and subtype; parameters (`; charset=utf-8`) are allowed. A missing or unparsable header counts as not JSON. `GET` is 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 sends `Content-Type: application/json` (`priv/admin/app.js:114`). **One deviation from the Done-when comment:** the check runs for every `POST` under `/api/` before the dispatch table. A non-JSON `POST` to an unknown route therefore gets 415 instead of 404. Keeping 404 there would need a second route table beside `dispatch/3`; the CHANGELOG says so. ## Red first `a8f4225` adds only the tests. In the CI image on msi00, `mcl_bookclub_admin_tests` gives 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 and `TEXT/PLAIN; charset=utf-8` are 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_accepted` passes 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 81754b1 lint 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.
mcl-bookclub#9: the admin API refuses a POST that is not application/json, before reading its body
All checks were successful
wall tree / wall-tree-1 (pull_request) Successful in 4s
wall tree / wall-tree (pull_request) Successful in 0s
c4 model / c4-model-1 (pull_request) Successful in 7s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m36s
81754b14a1
mcl-bookclub#9: say what the 415 stops and what it does not (DNS rebinding, #12); a malformed Content-Type is refused
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
wall tree / wall-tree-1 (pull_request) Successful in 5s
wall tree / wall-tree (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 4m28s
c4 model / c4-model-1 (push) Successful in 3s
c4 model / c4-model (push) Successful in 0s
wall tree / wall-tree-1 (push) Successful in 7s
wall tree / wall-tree (push) Successful in 0s
lint-and-test / check (push) Successful in 4m32s
e63d74c968
terra manually merged commit e63d74c968 into main 2026-12-01 13:01:15 +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-bookclub!10
No description provided.