
Csrf Protection
This wraps your Next.js API routes with CSRF protection using HMAC-SHA256 signed tokens that are session-bound and single-use. You fetch a token from /api/csrf before making POST/PUT/DELETE requests, include it in the X-CSRF-Token header, and withCsrf() handles verification automatically. The implementation is solid: HTTP-only cookies, SameSite=Strict, and tokens that expire after one use. Honestly, CSRF protection is one of those things that's easy to skip because nothing breaks without it, but the documentation here does a good job explaining why it matters with real examples like the 2008 router hijacking attacks. Works well layered with rate limiting for things like contact forms or account changes.
- skills.sh installs
- 206
- GitHub stars
- 18
- last updated
- Aug 21, 2026
Install
$ npx -y skills add harperaa/secure-claude-skills --skill csrf-protection --agent claude-codeInstalls into .claude/skills of the current project.
Files
CSRF Protection - Preventing Cross-Site Request Forgery
What CSRF Attacks Are
The Attack Scenario
Imagine you're logged into your banking app. In another tab, you visit a malicious website. That website contains hidden code that submits a form to your bank: "Transfer $10,000 to attacker's account." Because you're logged in, your browser automatically sends your session cookie, and the bank processes the transfer.
This is Cross-Site Request Forgery—tricking your browser into making requests you didn't intend.
Real-World CSRF Attacks
Router DNS Hijacking (2008): A CSRF vulnerability in several home routers allowed attackers to change router DNS settings by tricking users into visiting a malicious website. Victims lost no money but were redirected to phishing sites for months. Millions of routers were affected.
YouTube Actions (2012): YouTube had a CSRF vulnerability that allowed attackers to perform actions as other users (like, subscribe, etc.) by tricking them into visiting a crafted URL.
Why CSRF Is Still Common
Sponsors
Details
- Repository
- github.com/harperaa/secure-claude-skills
- Categories
- Backend & APIs, Security
- First seen
- Jun 3, 2026
More from harperaa/secure-claude-skills
All 12- Security Headers203
- Security Architecture Overview200
- Rate Limiting199
- Security Testing Verification198
- Input Validation Xss Prevention197
- Secure Error Handling197
- Security Prompts193
- Authentication Authorization Clerk187
- Payment Security Clerk Billing Stripe183
- Security Operations Deployment165
- Dependency Supply Chain Security253