Provider Selection
Choose your captcha provider:
turnstile- Cloudflare Turnstile (recommended)recaptcha- Google reCAPTCHA v3hcaptcha- hCaptcha
Only configure environment variables for your chosen provider. You don’t need to set up all three.
Cloudflare Turnstile (Recommended)
Turnstile is Cloudflare’s privacy-focused alternative to reCAPTCHA with better user experience and no Google dependencies.Why Turnstile?
- Privacy-focused: No tracking or data collection
- Better UX: Most users never see a challenge
- Free: No limits for most use cases
- Fast: Leverages Cloudflare’s global network
Configuration
Turnstile secret key from Cloudflare dashboard.
Turnstile site key (public) from Cloudflare dashboard.Test mode key:
The test mode key always passes verification. Use only in development!
Setup Instructions
Create Turnstile site
- Log in to Cloudflare Dashboard
- Navigate to Turnstile in the sidebar
- Click Add Site
- Enter your domain (e.g.,
panel.example.com) - Choose widget mode: Managed (recommended)
Get your keys
After creating the site, copy:
- Site Key (public, used in frontend)
- Secret Key (private, used in backend)
Google reCAPTCHA v3
reCAPTCHA v3 provides invisible bot protection using risk analysis.Configuration
reCAPTCHA secret key from Google.
Minimum score required to pass verification (0.0 to 1.0).
0.0- Most lenient (may allow bots)0.5- Balanced (recommended)1.0- Strictest (may block legitimate users)
Setup Instructions
Create reCAPTCHA site
- Go to Google reCAPTCHA Admin
- Click + to create a new site
- Enter:
- Label: Your panel name
- reCAPTCHA type: reCAPTCHA v3
- Domains: Your domain (e.g.,
panel.example.com)
- Accept terms and submit
Adjusting Min Score
If you receive complaints about false positives:- Lower score (0.3-0.4): More lenient, fewer false positives, slight security reduction
- Higher score (0.6-0.7): Stricter protection, more false positives
hCaptcha
hCaptcha is a privacy-focused alternative to reCAPTCHA.Configuration
hCaptcha secret key from hCaptcha dashboard.
hCaptcha site key (public) from hCaptcha dashboard.
Setup Instructions
Create hCaptcha site
- Log in to hCaptcha Dashboard
- Click New Site
- Enter your domain (e.g.,
panel.example.com) - Choose difficulty: Auto (recommended)
- Save
Get your keys
After creating the site:
- Site Key - Displayed on the site list
- Secret Key - Available in Settings
Protected Endpoints
Captcha verification is automatically applied to these endpoints:| Endpoint | Purpose |
|---|---|
POST /api/auth/sign-in/* | User login |
POST /api/auth/sign-up/* | User registration |
POST /api/auth/forget-password | Password reset request |
Captcha integration is handled automatically by better-auth. No additional code changes are needed.
Testing Captcha
Development Mode
For local testing, use provider-specific test keys: Turnstile:Production Testing
Test login flow
Attempt to log in with correct credentials. Captcha should be validated automatically.
Troubleshooting
Captcha not appearing
Captcha not appearing
Possible causes:
NUXT_PUBLIC_TURNSTILE_SITE_KEYnot set (Turnstile)- JavaScript errors in browser console
- Content Security Policy blocking captcha scripts
- Check environment variables are set correctly
- Check browser console for errors
- Verify CSP allows captcha domains (see Security Configuration)
Verification always fails
Verification always fails
Possible causes:
- Incorrect secret key
- Domain mismatch (configured domain doesn’t match actual domain)
- Using test keys in production
- Verify
NUXT_TURNSTILE_SECRET_KEYor equivalent is correct - Check domain configuration in captcha provider dashboard
- Ensure you’re using production keys, not test keys
High false positive rate (reCAPTCHA)
High false positive rate (reCAPTCHA)
Possible causes:
NUXT_RECAPTCHA_MIN_SCOREset too high- Legitimate users flagged as suspicious
- Lower
NUXT_RECAPTCHA_MIN_SCOREto 0.3 or 0.4 - Monitor reCAPTCHA analytics to find optimal score
- Consider switching to Turnstile for better UX
CSP violations
CSP violations
Symptoms: Captcha blocked by Content Security PolicySolution:
XyraPanel’s default CSP includes necessary captcha domains:
- Turnstile:
https://challenges.cloudflare.com - reCAPTCHA: Allowed via
https:in script-src - hCaptcha: Allowed via
https:in script-src
Provider Comparison
| Feature | Turnstile | reCAPTCHA v3 | hCaptcha |
|---|---|---|---|
| Privacy | Excellent | Poor | Good |
| Free tier | Unlimited | 1M assessments/month | Unlimited |
| User friction | Very low | None (invisible) | Low-Medium |
| Accuracy | Excellent | Excellent | Very good |
| Setup difficulty | Easy | Easy | Easy |
| Google dependency | No | Yes | No |
| GDPR compliance | Yes | Requires consent | Yes |
| Accessibility | Excellent | Good | Good |
Recommendations
Best for most users
Cloudflare TurnstileExcellent privacy, UX, and performance. No Google dependencies. Free and unlimited.
Best for Google ecosystem
Google reCAPTCHA v3Good if you’re already using Google services. Invisible to users but raises privacy concerns.
Best for privacy-first organizations
hCaptchaGood privacy and GDPR compliance. Slightly more visible to users than Turnstile.
Security Best Practices
Rotate keys periodically
Rotate keys periodically
Rotate your captcha keys every 6-12 months as part of security maintenance.
Monitor analytics
Monitor analytics
Regularly check your captcha provider’s dashboard for unusual patterns or verification failures.
Combine with rate limiting
Combine with rate limiting
Captcha works best alongside rate limiting. See Security Configuration.
Don't rely solely on captcha
Don't rely solely on captcha
Captcha is one layer of defense. Always implement other security measures like rate limiting, account lockouts, and monitoring.
Keep secret keys secure
Keep secret keys secure
Never commit secret keys to version control. Use environment variables and secure secret management.
Switching Providers
To switch captcha providers:Next Steps
Security Configuration
Configure rate limiting and CORS
Environment Variables
View all configuration options