Backend · Skill
Add Cloudflare Turnstile
add-cloudflare-turnstile
Adds Cloudflare Turnstile to a form that already has a server handler, sends the existing fields plus the token, and accepts the token only when siteverify returns success === true. Use when the user wants a Turnstile widget, a bot check on signup, or a server-side siteverify gate. Email delivery for a contact form is a different task.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/raw' -o ~/'.claude/skills/add-cloudflare-turnstile/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/LICENSE.txt' -o ~/'.claude/skills/add-cloudflare-turnstile/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/NOTICE.txt' -o ~/'.claude/skills/add-cloudflare-turnstile/NOTICE.txt'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/raw' -o '.cursor/skills/add-cloudflare-turnstile/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/LICENSE.txt' -o '.cursor/skills/add-cloudflare-turnstile/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/NOTICE.txt' -o '.cursor/skills/add-cloudflare-turnstile/NOTICE.txt'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/raw' -o '.agents/skills/add-cloudflare-turnstile/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/LICENSE.txt' -o '.agents/skills/add-cloudflare-turnstile/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cloudflare-turnstile/files/NOTICE.txt' -o '.agents/skills/add-cloudflare-turnstile/NOTICE.txt'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}Turnstile puts a widget in the browser and a check on your server. The browser never calls siteverify. The existing handler keeps doing its job. You only add a gate in front of it.
When to use
- A signup, login, or other form needs a bot check, and a server handler already exists.
- The user names Turnstile, siteverify, or cf-turnstile-response.
- You are reviewing a Turnstile gate that may be looser than it looks.
When not to use
- The form has no server handler. Say so and stop. Do not invent a backend, a Worker, or a proxy just to hold the check.
- The user only wants the form emailed. Use build-contact-form-with-email. Add Turnstile only if they ask for a bot check.
- They want a score threshold like reCAPTCHA v3. Turnstile answers true or false. It has no score.
Steps
- Find the existing submit handler and every field it already reads.
- Render the widget on that form. The token field is cf-turnstile-response. Keep the other controls.
- On submit, send the existing payload plus the token. A signup form that already collects email must post email and the token together. Posting only the token drops the user's data. That is the bug in the upstream Next.js App Router example (cloudflare/skills issue 281).
- On the server, POST the token to https://challenges.cloudflare.com/turnstile/v0/siteverify as form-urlencoded fields: secret, response, and the client IP. Set a timeout of about ten seconds. If the network fails, the status is not OK, or the body is not JSON, fail closed.
- Accept the request only when result.success === true, the action matches this form, and the hostname is on this deployment's allowlist. Write the test as result.success !== true. Do not write if (!result.success). A non-empty string, a number, or an object is truthy, so the loose test can accept them (issue 282). Live responses use a JSON boolean. The strict test matches the contract anyway.
- Run the existing handler only after that gate. Do not replace its behavior.
- Store the secret as TURNSTILE_SECRET in the platform secret store or a gitignored env file. Confirm git ignores the file before you write it. Never put the secret in client code, a NEXT_PUBLIC variable, the chat, or a shell argument.
- Keep localhost and 127.0.0.1 off the production hostname allowlist. They may be registered on the widget for local dev. Production must check the real frontend host only.
- Tokens are single use. If the page stays open after submit, reset that widget's id before the user can retry.
- Prove one fresh token succeeds through the real handler, then prove a replay is rejected. If you cannot run the handler, say validation is pending. Do not claim the gate works.
Submit body
Read the fields the form already has. Add the token. Do not replace the body.
async function onSubmit(formData: FormData) {
const email = String(formData.get("email") ?? "");
const token = String(formData.get("cf-turnstile-response") ?? "");
await fetch("/api/signup", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ email, token }),
});
}
Add any other existing fields the same way. The comment to keep: the token is extra, not a replacement.
Server gate
if (result.success !== true) return replyForbidden();
if (result.action !== expectedAction) return replyForbidden();
if (!expectedHostnames.has(result.hostname)) return replyForbidden();
expectedHostnames comes from server config for this deployment. An empty allowlist fails closed. Call siteverify only from the server.
Upstream scripts
This skill does not ship the upstream shell scripts. If you meet them elsewhere, do not copy the two open bugs.
- auth-probe.sh can print status ok after a failed cleanup DELETE (issue 283). If a probe creates a widget and the delete fails, the result must not look clean. Report cleanup_failed and the sitekey so the leftover widget is visible.
- validate.sh assigns WIDGET_SECRET without clearing the export flag (issue 284). If that name was already exported, curl and python inherit the secret. Run unset WIDGET_SECRET, or export -n WIDGET_SECRET, before you read the secret from stdin. Do not pass it as an argument. Do not print it.
Gotchas
- A client-side check is not the gate. Anyone can skip the widget and post the handler.
- A production allowlist that includes localhost will accept a token minted for a local page.
- Do not ask the user to paste the widget secret into chat.
- Migrated reCAPTCHA code that looked at a score should now reject when success is not true.
Portability
Works with any server that can POST form fields. If you use Next.js, Express, Rails, or a Worker, the gate is the same and only the request object changes.
Example prompt
"Add Cloudflare Turnstile to my signup form. Keep the email field in the submit body, and accept the token only when siteverify says success === true."
Done when
- The submit body still contains the form's existing fields, plus the token.
- The server accepts only result.success === true, the expected action, and an allowlisted hostname.
- A replay of the same token fails, or you have said that run is still pending.
- The secret is not in git and not in the browser bundle.
- A failed widget cleanup is reported. It is not a silent ok.
---
Modified from "turnstile-spin" in cloudflare/skills (Apache-2.0). Attribute to Cloudflare (cloudflare/skills). The upstream LICENSE keeps the unfilled template line. See LICENSE.txt.
Bundled files
Licence
Adapted from Cloudflare (cloudflare/skills) (Copyright [yyyy] [name of copyright owner]. The cloudflare/skills LICENSE keeps that Apache template line unfilled. Attribute this skill to Cloudflare (cloudflare/skills).), Apache License 2.0. Modified by TheSkillVault on 2026-11-24. Rewritten as a short integration guide. Open bugs are fixed in the guidance: the submit body keeps existing fields (issue 281), the gate requires success === true (issue 282), a failed widget cleanup must not report ok (issue 283), and a secret variable is unset before it is read so it is not exported to child processes (issue 284). The upstream shell scripts were not shipped. Not the original file.
Licence: Apache License 2.0. Attribution when you reuse it: Based on work by Cloudflare (cloudflare/skills) (Copyright [yyyy] [name of copyright owner]. The cloudflare/skills LICENSE keeps that Apache template line unfilled. Attribute this skill to Cloudflare (cloudflare/skills)., Apache License 2.0), https://github.com/cloudflare/skills/tree/ff191de7d903788eceaf516a514ae7d3b56b924a/skills/turnstile-spin; adapted by TheSkillVault, https://theskillvault.ai