fcakyon/claude-codex-settings / plugins/cloudflare-skills/skills/turnstile-spin
turnstile-spin
VerifiedSet up, repair, or migrate to Cloudflare Turnstile bot verification in an existing frontend and backend, including server-side Siteverify.
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 3.8 KB |
| SKILL.md | skill md | 28.2 KB |
| references/astro.md | markdown | 5.8 KB |
| references/hugo.md | markdown | 3.8 KB |
| references/nextjs-app.md | markdown | 7.5 KB |
| references/nextjs-pages.md | markdown | 2.7 KB |
| references/skill-feedback.md | markdown | 2.7 KB |
| references/sveltekit.md | markdown | 5.4 KB |
| references/vanilla-html.md | markdown | 5.6 KB |
| scripts/auth-probe.shexecutable | script | 11.0 KB |
| scripts/persist-skill.shexecutable | script | 3.6 KB |
| scripts/validate.shexecutable | script | 4.3 KB |
| scripts/widget-create.shexecutable | script | 4.1 KB |
| tests/test_persist_skill.py | script | 3.1 KB |
| tests/validation.md | markdown | 3.2 KB |
scripts/validate.sh
View on GitHub#!/usr/bin/env bash
# Validates a Turnstile widget without placing its secret in arguments,
# exported environment variables, logs, or temporary files.
set +x
set -euo pipefail
usage() {
echo "Usage: printf '%s' \"\$TURNSTILE_SECRET\" | $0 --sitekey <sitekey> --account-id <account-id> --expected-domains '<json-array>'" >&2
exit 2
}
need_arg() {
if [[ -z "${2-}" || "$2" == --* ]]; then
usage
fi
}
SITEKEY=""
ACCOUNT_ID=""
EXPECTED_DOMAINS_JSON=""
while [[ $# -gt 0 ]]; do
case "$1" in
--sitekey)
need_arg "$1" "${2-}"
SITEKEY="$2"
shift 2
;;
--account-id)
need_arg "$1" "${2-}"
ACCOUNT_ID="$2"
shift 2
;;
--expected-domains)
need_arg "$1" "${2-}"
EXPECTED_DOMAINS_JSON="$2"
shift 2
;;
*) usage ;;
esac
done
[[ -n "$SITEKEY" && -n "$ACCOUNT_ID" && -n "$EXPECTED_DOMAINS_JSON" ]] || usage
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN must be set}"
API_TOKEN="$CLOUDFLARE_API_TOKEN"
unset CLOUDFLARE_API_TOKEN
[[ "$API_TOKEN" =~ ^[A-Za-z0-9_-]+$ ]] || {
echo "validate: CLOUDFLARE_API_TOKEN has an invalid format" >&2
exit 1
}
for command_name in curl jq python3; do
command -v "$command_name" >/dev/null 2>&1 || {
echo "validate: $command_name is required" >&2
exit 1
}
done
if ! jq -e '
type == "array" and
length > 0 and
all(.[]; type == "string" and length > 0)
' <<<"$EXPECTED_DOMAINS_JSON" >/dev/null; then
echo "validate: --expected-domains must be a non-empty JSON array of domains" >&2
exit 2
fi
WIDGET_SECRET=""
IFS= read -r -d '' WIDGET_SECRET || true
trap 'unset API_TOKEN WIDGET_SECRET WIDGET_API_SECRET WIDGET_RESPONSE SITEVERIFY_RESPONSE' EXIT
if [[ -z "$WIDGET_SECRET" || "$WIDGET_SECRET" =~ [[:space:]] ]]; then
echo "validate: standard input must contain one non-empty secret without whitespace" >&2
exit 1
fi
ACCOUNT_ENCODED="$(python3 -I -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "$ACCOUNT_ID")"
SITEKEY_ENCODED="$(python3 -I -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "$SITEKEY")"
if ! WIDGET_RESPONSE="$(
printf 'header = "Authorization: Bearer %s"\n' "$API_TOKEN" |
curl --disable --config - --fail --silent --show-error \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ENCODED/challenges/widgets/$SITEKEY_ENCODED"
)"; then
echo "validate: widget metadata lookup failed" >&2
exit 1
fi
if ! printf '%s' "$WIDGET_RESPONSE" | jq -e --arg sitekey "$SITEKEY" --argjson expected "$EXPECTED_DOMAINS_JSON" '
. as $widget
| (.success == true) and
(.result.sitekey == $sitekey) and
((.result.clearance_level | type) == "string") and
(.result.clearance_level as $clearance | ["no_clearance", "interactive", "managed", "jschallenge"] | index($clearance) != null) and
((.result.domains | type) == "array") and
(all($expected[]; . as $domain | $widget.result.domains | index($domain) != null))
' >/dev/null; then
echo "validate: widget sitekey, domains, or clearance level was invalid" >&2
exit 1
fi
if ! WIDGET_API_SECRET="$(printf '%s' "$WIDGET_RESPONSE" | jq -er '.result.secret | select(type == "string" and test("^\\S+$"))')"; then
echo "validate: widget metadata did not include a valid secret" >&2
exit 1
fi
if [[ "$WIDGET_API_SECRET" != "$WIDGET_SECRET" ]]; then
echo "validate: secret does not belong to the requested sitekey" >&2
exit 1
fi
unset WIDGET_API_SECRET
unset WIDGET_RESPONSE
if ! SITEVERIFY_RESPONSE="$(
printf '%s' "$WIDGET_SECRET" |
python3 -I -c 'import sys,urllib.parse; print(urllib.parse.urlencode({"secret":sys.stdin.read(),"response":"XXXX.DUMMY.TOKEN.XXXX"}),end="")' |
curl --disable --fail --silent --show-error \
"https://challenges.cloudflare.com/turnstile/v0/siteverify" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-binary @-
)"; then
echo "validate: dummy-token siteverify request failed" >&2
exit 1
fi
if ! jq -e '
(.success == false) and
((.["error-codes"] | type) == "array") and
((.["error-codes"] | index("invalid-input-response")) != null) and
((.["error-codes"] | index("invalid-input-secret")) == null)
' <<<"$SITEVERIFY_RESPONSE" >/dev/null; then
echo "validate: siteverify did not confirm the widget secret" >&2
exit 1
fi
unset WIDGET_SECRET SITEVERIFY_RESPONSE
echo '{"status":"ok","metadata_check":"ran","dummy_siteverify":"ran"}'
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |