Skip to main content
Magic-code and password sign-in attract abuse. Bot networks spam send-code to every known email to phish, run credential-stuffing dictionaries against /password/login, or use up SMS quotas through /phone/send-code. Pylon’s built-in CAPTCHA gate protects those endpoints. Set one env var pair, and Pylon blocks unauthenticated bots before they reach the rate limiter. Three providers are built in:
  • hCaptcha — independent, privacy-focused, free up to ~1M/month
  • Cloudflare Turnstile — invisible challenge, free for any volume
  • Google reCAPTCHA — v2 + v3 token shapes

Gated endpoints

When PYLON_CAPTCHA_PROVIDER + PYLON_CAPTCHA_SECRET are both set, these endpoints require a captchaToken in the request body: When the env vars are unset, Pylon skips the gate. Existing apps keep working unchanged.

Configuration

Provider aliases:
  • turnstile and cloudflare both select Turnstile.
  • recaptcha and google both select reCAPTCHA.
The framework calls each provider’s siteverify endpoint with the supplied token and the request’s peer IP:
  • hCaptcha: https://api.hcaptcha.com/siteverify
  • Turnstile: https://challenges.cloudflare.com/turnstile/v0/siteverify
  • reCAPTCHA: https://www.google.com/recaptcha/api/siteverify
The client-side public site key lives in your frontend; the server-side secret lives in PYLON_CAPTCHA_SECRET. Get both from the provider’s dashboard.

Client integration

For Turnstile, the form input is cf-turnstile-response; for reCAPTCHA it’s g-recaptcha-response. All three map to a single captchaToken field in the request to Pylon.

Verify behavior

Missing or invalid token returns 400 CAPTCHA_FAILED:
Pylon logs the provider response (error codes like missing-input-response, invalid-input-response) server-side with tracing::warn!. Operators can debug from logs. The client does not learn which check failed. The gate runs before the rate limiter and before any DB or email work. Bots that fail the challenge do not consume rate-limit budget or trigger later actions.

Where to go next