Skip to content

Forms

A form that anyone can send without signing in (a sign-up, a registration, a contact form) is guarded three ways, each catching what the one before lets through: a hidden field for the bots that fill in every field, Cloudflare Turnstile for the ones that don’t, and a filter on what it says for the pitches people and their tools type by hand. None of them asks anything of most people, and none of them loses a real person’s answers to a mistake it can make.

SVRBC’s doreancon.org is the example, and the code to copy: api/src/lib.rs (its submit), api/src/turnstile.rs, api/src/spam.rs and the page, src/components/SignupForm.astro.

Every form whose answers are kept or mailed to someone, sent by a visitor who hasn’t signed in. A form behind sign-in needs none of it: the session says who sent it. A sign-in form, which mails a link to the address typed in, isn’t covered yet (Open questions).

The form is a plain HTML form, <form method="post" action="/api/forms/<id>">, posted to the site’s Rust function, so it works without JavaScript. The function answers with a redirect back to the page, the outcome in the fragment (/contact#sent, #error), which the page shows with :target. It is on the site’s own origin, through CloudFront, and the function URL refuses a request without CloudFront’s secret header, so nothing can post to the function around the distribution.

The form has a text field named website that a person never sees and a bot that fills in every field does:

<div class="trap" aria-hidden="true">
<label>Website <input name="website" type="text" tabindex="-1" autocomplete="off" /></label>
</div>
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
  • Moved off the screen, not hidden: not type="hidden" or display: none, which a bot can tell isn’t meant to be filled in. aria-hidden keeps it from a screen reader, tabindex="-1" from the keyboard, and autocomplete="off" from the browser’s autofill, which would otherwise fill it in for a person.
  • The API drops a submission with it filled in, and thanks the sender as for any other (#sent): nothing is kept and nobody is mailed, and the bot learns nothing it could change.
  • The name is the API’s: no form has a field of its own called website, and the API’s tests hold its forms to that.

Turnstile is Cloudflare’s check that a visitor is a person. It is free, needs no Cloudflare in front of the site, and shows most people nothing: no puzzle, no pictures of buses. It catches the bots that fill in only the fields a person sees. Decided 2026-11-26.

  • The page puts the widget beside the Send button, and Cloudflare’s script at the end:

    <div class="cf-turnstile" data-sitekey="0x4AAA…" data-appearance="interaction-only"></div>
    <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>

    interaction-only shows it only when Cloudflare needs the person to tick it. The widget adds its token to the form as cf-turnstile-response.

  • The API checks the token by posting it, with the secret key, to https://challenges.cloudflare.com/turnstile/v0/siteverify:

    • Passed: on to the next check.
    • Failed, a missing token included: refused, back to the page at #error, and Cloudflare’s error codes logged.
    • Cloudflare didn’t answer, or not as it should: kept, with a warning in the log. Losing a family’s registration is worse than letting one bot through, and the other two checks still apply.
  • Only a new submission is checked. A change sent with its edit key has proved itself with the key.

  • One widget a site, named <domain> forms, listing the domains its forms are on. The site’s AGENTS.md names the widget and the Cloudflare account it is in.

  • The site key is public, in the site’s configuration (src/site.ts), and empty under astro dev, where the local API asks for no token. Empty, the page carries no widget and loads no script.

  • The secret key is in SSM, a SecureString an administrator makes at /svrbc/<site>-api/turnstile-secret (/svrbc/doreancon-org-api/…), which the function’s stack in infra/ gives it as TURNSTILE_SECRET. Without it the API asks nothing of the token, as in its tests.

  • The site key ships first. Release the pages with the site key, and only then give the function the secret: a function with the secret and pages without the widget refuses everyone. To turn it off, take the secret away first.

Sales pitches (search-engine optimization, web design, “may I send you a price list?”) come typed by people, or by tools that fill in only the fields a person sees, so they pass both checks above. The API reads what they say: the free-text answers (text and textarea fields, a group’s included; not addresses, choices or numbers), lowercased, and suspects a submission when

  • two or more of its phrases are there (“seo”, “your business”, “backlink”, “price list”, …), each counted once and matched as words of their own, so that “geo” isn’t “geography” and “leads” isn’t “pleads”; or
  • its first line greets the site’s own address, short and starting with a greeting (“Hello http://doreanfest.org,”, “Hey team doreanfest.org,”), which nobody writing to the site’s people does.

A suspect submission is kept aside, not dropped: beside the real ones in a place of its own (doreancon.org’s sheet has a tab for each form’s, its name and “ spam”), so one caught by mistake can still be found and answered. Nobody is mailed, not the site’s people and not the sender, who would otherwise get mail from the site at an address anyone could have typed. The browser is thanked as for any other (#sent).

The tests are the list’s record. A pitch that gets through goes into the tests as it came, and its phrases into the list; beside them, messages people have sent (or would) that must not be caught: a question about parking, a small business offering to sponsor a table, a geography teacher. A test also holds that only free text is read.

A person changes or removes their own answers with a link mailed to them, not by signing in and never by typing their address again, which anyone could type for them. A new submission gets a random key (32 bytes, base64url) in the link, /<slug>?edit=<key>; the store keeps only its SHA-256. Opened with it, the page fills the form in, and the API takes a change or a removal only with the key.

What happened The page shows What’s kept Who’s mailed
The hidden field was filled in #sent nothing nobody
Turnstile failed #error nothing nobody
It reads like a pitch #sent the answers, set aside nobody
It passed #sent the answers the sender (their edit link) and the site’s people

When Cloudflare doesn’t answer, the submission goes on as if it had passed. Each outcome but the last is logged in a line with the form’s id and why.

svrbc-audit’s form-protection finds a site’s forms by its API taking a posted form (axum’s Form extractor in api/src/), and warns when the API doesn’t verify Turnstile’s token or the pages carry no widget or no hidden field. What a filter catches can’t be checked from outside; its tests do that.

  • A sign-in form that mails a link or a code to the address typed in (Accounts): whether it takes Turnstile too, to keep it from mailing strangers.