{"name":"add-cloudflare-turnstile","description":"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.","category":"backend","tags":["cloudflare","forms","turnstile"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/add-cloudflare-turnstile","api_url":"https://theskillvault.ai/api/skills/add-cloudflare-turnstile","raw_url":"https://theskillvault.ai/api/skills/add-cloudflare-turnstile/raw","body":"# Add Cloudflare Turnstile\n\nTurnstile 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.\n\n## When to use\n- A signup, login, or other form needs a bot check, and a server handler already exists.\n- The user names Turnstile, siteverify, or cf-turnstile-response.\n- You are reviewing a Turnstile gate that may be looser than it looks.\n\n## When not to use\n- 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.\n- The user only wants the form emailed. Use build-contact-form-with-email. Add Turnstile only if they ask for a bot check.\n- They want a score threshold like reCAPTCHA v3. Turnstile answers true or false. It has no score.\n\n## Steps\n1. Find the existing submit handler and every field it already reads.\n2. Render the widget on that form. The token field is cf-turnstile-response. Keep the other controls.\n3. 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).\n4. 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.\n5. 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.\n6. Run the existing handler only after that gate. Do not replace its behavior.\n7. 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.\n8. 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.\n9. Tokens are single use. If the page stays open after submit, reset that widget's id before the user can retry.\n10. 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.\n\n## Submit body\nRead the fields the form already has. Add the token. Do not replace the body.\n\n```tsx\nasync function onSubmit(formData: FormData) {\n  const email = String(formData.get(\"email\") ?? \"\");\n  const token = String(formData.get(\"cf-turnstile-response\") ?? \"\");\n  await fetch(\"/api/signup\", {\n    method: \"POST\",\n    headers: { \"content-type\": \"application/json\" },\n    body: JSON.stringify({ email, token }),\n  });\n}\n```\n\nAdd any other existing fields the same way. The comment to keep: the token is extra, not a replacement.\n\n## Server gate\n```js\nif (result.success !== true) return replyForbidden();\nif (result.action !== expectedAction) return replyForbidden();\nif (!expectedHostnames.has(result.hostname)) return replyForbidden();\n```\n\nexpectedHostnames comes from server config for this deployment. An empty allowlist fails closed. Call siteverify only from the server.\n\n## Upstream scripts\nThis skill does not ship the upstream shell scripts. If you meet them elsewhere, do not copy the two open bugs.\n\n- 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.\n- 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.\n\n## Gotchas\n- A client-side check is not the gate. Anyone can skip the widget and post the handler.\n- A production allowlist that includes localhost will accept a token minted for a local page.\n- Do not ask the user to paste the widget secret into chat.\n- Migrated reCAPTCHA code that looked at a score should now reject when success is not true.\n\n## Portability\nWorks 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.\n\n## Example prompt\n\"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.\"\n\n## Done when\n- The submit body still contains the form's existing fields, plus the token.\n- The server accepts only result.success === true, the expected action, and an allowlisted hostname.\n- A replay of the same token fails, or you have said that run is still pending.\n- The secret is not in git and not in the browser bundle.\n- A failed widget cleanup is reported. It is not a silent ok.\n\n---\nModified 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.","files":["LICENSE.txt","NOTICE.txt"],"license":"Apache-2.0","license_name":"Apache License 2.0","license_url":"https://www.apache.org/licenses/LICENSE-2.0","attribution":"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","install":{"claude_code":"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":"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'","agents":"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'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-29T03:42:30.374Z"}}