ADR-0023: The human check as built, and a 33 KB budget for the React entry
- Status: Accepted (decision 5, the budget, superseded by ADR-0028)
- Date: 2026-11-21
- Extends: ADR-0019, decisions 4 and 5. ADR-0019 stays as written.
- Supersedes in part: ADR-0006, the size budget of
@boldare/askdare/reactin an app's bundle (32 KB). The rest of ADR-0006 stands.
Context
ADR-0019 decided on an optional HumanVerifier with a Cloudflare Turnstile adapter, and an opt-in limits.requireSharedStore. It left the names and the details to task 0.5-4.
The challenge has to render inside the chat, because the loader has about 100 bytes of its 5 KB budget left. That means a HumanCheck primitive in @boldare/askdare/react, at about 400 bytes gzipped. The entry was at 32,457 of its 32,768 bytes.
Decision
- Public surface (added to the list in ADR-0006):
security.humanVerifierindefineBot;- the
HumanVerifierport, withHumanChallengeandHumanCheckContext; - the
turnstile({ siteKey, secretKey?, hostnames? })adapter and itsTurnstileOptionstype; - the
TURNSTILE_SECRET_KEYvariable; limits.requireSharedStoreincreateChatHandler;- the
HumanCheckprimitive and its parthuman-check; ChatConfig.humanCheckwith itsChatHumanChecktype (exported from@boldare/askdare/reactand@boldare/askdare/next), andChatState.humanCheck;- the text keys
humanCheck.labelanderror.humanCheck.
- How the check runs:
- It runs only when a new session starts, after the session rate limit and with a 10 s timeout.
- Renewing a live session needs no new check for 24 hours after the visitor passed one. The access token carries the time of the check (an
hvclaim), and a renewal keeps it, so the 24 hours can't be extended by renewing. After them, or for a token without the claim (issued before the bot turned the check on), the server asks again; the client sends the check with the old token, so the visitor keeps their session. Bots without a verifier issue and renew tokens as before. - The chat renders the widget with the bot's id as Turnstile's
action(cut to Turnstile's 32 characters), and the server refuses a token whose siteverifyactiondiffers. Thehostnamecheck is optional (hostnames): behind a proxy that serves the app under another name it would refuse every visitor, and the widget's hostname list in the Cloudflare dashboard already limits where it runs. Cloudflare's test secret keys return noactionand alwaysexample.com, so with them neither is checked. - Turnstile retries transient errors by itself (
retry: 'auto'); the chat fails the check at the thirderror-callback. identify()with a token opens a session at once, to find that user's conversation, so signed-in visitors meet the check as the chat loads. Anonymous visitors meet it at their first action; signing out without a session opens none.- A failed token answers
unauthorizedwitherror.humanCheck. - A check that can't run refuses the session (fails closed). Only bots that turn the check on are affected.
- The browser receives only
{ provider, siteKey }.
- CSP: for bots with a verifier only, the iframe adds
https://challenges.cloudflare.comtoscript-srcandframe-src. Bots without one keep the 0.4 policy, pinned by a test.- Trust: Cloudflare's
api.jsthen runs with the chat origin's access: in the iframe, your app's origin, and in inline mode the host page. It can read the conversation on screen and the resume token. Cloudflare updates the script in place, so there is no Subresource Integrity. Turning the check on means trusting Cloudflare with that; the docs say so.
- Trust: Cloudflare's
requireSharedStore:createChatHandlerthrows when the route loads, in any environment, if the option is on and the store isn't shared. Off by default.- Budget:
@boldare/askdare/reactmay take up to 33 KB gzipped in an app's bundle. The headless budget (12 KB forRootanduseChat) is unchanged.
Consequences
- Teams with a public chat can require a human check without custom work.
- The React entry has room for this release. ADR-0017's rule that a further addition needs room made first applies again from 33 KB.
- Not yet verified in a live browser: Turnstile under the widened CSP, and how it looks in the panel. No e2e test yet, because siteverify can't be pointed at the mock server without a new seam.
- A solved challenge buys at most 24 hours of renewals, and tokens issued before the check was turned on don't count as checked.
Alternatives considered
- Render the challenge in the loader: there's no room in its 5 KB budget, and it would load Cloudflare's script on every host page.
- Make room in the React entry first: this needs refactoring outside the task. A 1 KB increase is cheaper than delaying the feature.
- Fail open when Cloudflare is unreachable: a bot that turned the check on would silently lose the protection it asked for.