Generate and validate CAPTCHAs on your own server. Image generation, audio fallback, and rate limiting built in. Privacy-first, no tracking.
Stack
- Next.js 16 — API routes for CAPTCHA generation and validation.
- Node.js — Canvas API for server-side image rendering.
- Redis — Session storage and rate limiting.
Features
- Image and audio CAPTCHAs — Generate distorted text images and audio alternatives for accessibility.
- Self-hosted validation — No external API calls. Verify challenges on your own infrastructure.
- Rate limiting — Built-in Redis integration to prevent brute-force attacks and abuse.
Install
git clone https://github.com/yashthakur1/cap.git my-captcha
cd my-captcha
npm installEnvironment
NEXT_PUBLIC_APP_URL=http://localhost:3000
REDIS_URL=redis://localhost:6379
CAPTCHA_SECRET=your-secret-key-here
SESSION_TIMEOUT=300Walkthrough
1. Install dependencies
Clone the repo and install packages. Ensure Node.js 18+ is installed.
npm install2. Set up Redis
Install Redis locally or use a managed service. Update REDIS_URL in .env.local.
# macOS
brew install redis
brew services start redis
# Ubuntu/Debian
sudo apt-get install redis-server
sudo systemctl start redis3. Configure environment
Copy .env.example to .env.local and set CAPTCHA_SECRET to a random string. This key encrypts CAPTCHA sessions.
4. Run development server
Start the Next.js dev server and visit /captcha/demo to test generation and validation.
npm run devGotchas
- Canvas library requires native dependencies — install build tools (python, make, gcc) if npm install fails.
- Redis must be running before starting the dev server. Check with 'redis-cli ping'.
- CAPTCHA_SECRET must be the same across all server instances for distributed deployments.
- Audio CAPTCHAs use text-to-speech — verify ffmpeg is installed for audio generation.
Why not just build it yourself?
If you need advanced bot detection (behavioral analysis, risk scoring), consider a managed service like hCaptcha or Cloudflare Turnstile. This kit focuses on simple, self-hosted challenge-response.
Links
License: MIT
Got stuck, or want this shipped end-to-end for you? bitroot.club builds custom products for founders. →