AUTH4D-409 atomic magic-link verification
POST /t/{tenantId}/email/magic-link/verify (AUTH4D-142 (repository file docs/api-spec/auth4d-142.md)) used to read the link’s
challenge out of the Durable Object, check the browser cookie, and put the challenge back when the
cookie did not match. For a moment in between, the challenge did not exist. A second request that
arrived in that window, such as the real player’s browser while a mail scanner or another browser
was being turned away, was told invalid_link. Request and response shapes do not change.
Behaviour
The cookie check and the removal of the challenge are now one atomic Durable Object operation
(takeIfBound on the atomic state store). The store removes the challenge only when the SHA-256
digest of one of the request’s __Host-auth4_flow_{flowId} cookies equals the challenge’s
browser-binding digest for its own flow, compared in constant time.
| Request | Result | Challenge |
|---|---|---|
| Cookie of the flow that asked for the link | 200 with the proof, as before |
Consumed |
| Another flow’s cookie, or no flow cookie | 409 {"error": "different_device"} |
Left untouched |
| Unknown, expired, used or other-tenant challenge | 400 {"error": "invalid_link"} |
Nothing to take |
| Two legitimate requests at once | One 200, the other 400 invalid_link |
Consumed once |
Nothing is restored after an unauthorized attempt, because nothing was removed. Tenant scoping,
the ten-minute expiry, the per-IP verify budget and the sanitized error bodies are unchanged. A
store without takeIfBound makes the endpoint answer 503 rather than fall back to the old
sequence.
Contract additions
AtomicStateStore.takeIfBound?<T>(key, { selectorField, digestField, digests }) returns
{ status: "taken", value }, { status: "mismatch" } or { status: "missing" }. It is optional in
the shared interface, so existing in-memory stores keep compiling.
Source: docs/api-spec/auth4d-409.md