Skip to content

fix(app): HEAD on a write lane answers 405 instead of executing the write - #258

Closed
Jr-kenny wants to merge 1 commit into
flop-labs:mainfrom
Jr-kenny:head-write-refusal
Closed

Jr-kenny wants to merge 1 commit into
flop-labs:mainfrom
Jr-kenny:head-write-refusal

Conversation

@Jr-kenny

Copy link
Copy Markdown

Closes #257.

Problem

Starlette infers {GET, HEAD} for every function route, so a HEAD request to any write lane dispatched onto the write handler and performed the write: monitors, link checkers, prefetchers and URL unfurlers that sent a metadata request were creating rooms and notes under their own rate budget. A metadata request is assumed side-effect-free by every HTTP client; on this service it was an unauthenticated write.

Fix

WriteRoute, a small Route subclass used for the four write routes (say, say-signed, set, set-signed). It pins methods to {GET} exactly — Starlette force-adds HEAD in Route.__init__ whenever GET is present, so setting the set after init is the only way to refuse HEAD while keeping the route function-based. Read routes keep normal HEAD semantics. No handler changed; allowed_methods() already reads route.methods, so the existing 405 machinery emits the correct Allow: GET (and the shared-path cases now say GET, POST) with no further change.

Size/cap impact: +3 core code lines; sz-baseline.json bumped to 2024 total / app.py 980, per CONTRIBUTING's three-lines-over-a-primitive rule. Abuse impact: none — this removes writes from a verb, adds no surface.

Testing

  • uv run ruff check . && uv run ruff format --check . && uv run ty check — clean
  • uv run coverage run -m pytest tests -q && uv run coverage report — 394 passed, 97.51% over the 96% floor
  • uv run sz.py --caps — exit 0, at cap exactly
  • contract check vs /openapi.json: 10 failures on this branch vs 11 on vanilla main under the same seed/limits (pre-existing schema noise such as x-schemathesis-unknown-property; none added)
  • New tests/http/test_head_writes.py: fails on vanilla main (HEAD returns 200 and lands the write), passes here — verified in a clean worktree against unmodified main
  • Live smoke: HEAD /r/x/say/a/b -> 405 with allow: GET and room count stays 0; GET /r/y/say/a/b -> 200 unchanged; HEAD /r/ -> 200 read

One judgment call: I updated the pinned expectation in test_a_405_carries_allow_and_names_every_verb_the_path_takes rather than preserving Allow: GET, HEAD on write paths — that header advertised a verb that executed a write, which is the bug.

…rite

Starlette infers {GET, HEAD} for every function route, so the four write
routes dispatched HEAD onto their handlers: any monitor, link checker,
prefetcher or URL unfurler that sent a metadata request created rooms and
notes under its own rate budget. WriteRoute pins methods to GET exactly;
read routes keep normal HEAD semantics. The 405 body already names the
lanes the path takes via allowed_methods(), which reads route.methods, so
Allow is correct with no further change.
@Jr-kenny Jr-kenny closed this Aug 26, 2026
@sv

sv commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for this — and for the reproduction in #257, which is what made the fix concrete.

Closing as superseded: #135 landed the same fix in b6f90f1. It took the same approach (drop Starlette's implicit HEAD from the four write lanes, 405 with Allow: GET, read lanes untouched), and your review note there about the signed lane is in it — a HEAD probe on set-signed was moving /kv/room-nonce/<room>, and that is now pinned by a test.

One thing here that #135 does not have, and that I would still take as its own PR: test_a_head_to_a_read_path_stays_a_read_even_where_post_lives. The dual-lane paths are the case where HEAD has to match the read route rather than fall through, and #135 only covers the room half, not /kv/<ns>/<key>.

Jr-kenny pushed a commit to Jr-kenny/technocore-chat that referenced this pull request Sep 9, 2026
flop-labs#135 pinned the room half of the dual-lane paths; this pins /kv/<ns>/<key>:
a HEAD there must answer from the reader (200 on a stored note, 404 on an
absent one) rather than fall through to the POST writer. Requested in the
close-out of flop-labs#258.
Jr-kenny pushed a commit to Jr-kenny/technocore-chat that referenced this pull request Sep 21, 2026
flop-labs#135 pinned the room half of the dual-lane paths; this pins /kv/<ns>/<key>:
a HEAD there must answer from the reader (200 on a stored note, 404 on an
absent one) rather than fall through to the POST writer. Requested in the
close-out of flop-labs#258.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HEAD requests execute the write: a metadata request from any monitor or prefetcher creates rooms and notes

2 participants