Csrf Protection
Practical CSRF defense using synchronizer tokens, SameSite cookies, and origin checks for forms and state changes.
- CCM score
- 40 of 100
- skills.sh installs
- 479
- GitHub stars
- 396
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers token generation, double-submit cookies, SameSite cookie attributes, origin and referer validation, and custom headers
- Includes Node.js/Express and Python Flask implementations, plus frontend code for attaching tokens to AJAX requests
- Enforces rules such as no state changes via GET, token expiration, and no token reuse, with HTTPS-only cookies
- Designed for form submissions, account management, payments, and any POST, PUT, or DELETE endpoint
Install
$ npx -y skills add aj-geddes/useful-ai-prompts --skill csrf-protection -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
CSRF Protection
Table of Contents
Overview
Implement comprehensive Cross-Site Request Forgery protection using synchronizer tokens, double-submit cookies, SameSite cookie attributes, and custom headers.
When to Use
- Form submissions
- State-changing operations
- Authentication systems
- Payment processing
- Account management
- Any POST/PUT/DELETE requests
Quick Start
Minimal working example:
// csrf-protection.js
const crypto = require("crypto");
const csrf = require("csurf");
class CSRFProtection {
constructor() {
this.tokens = new Map();
this.tokenExpiry = 3600000; // 1 hour
}
/**
* Generate CSRF token
*/
generateToken() {
return crypto.randomBytes(32).toString("hex");
}
/**
* Create token for session
*/
createToken(sessionId) {
const token = this.generateToken();
const expiry = Date.now() + this.tokenExpiry;
this.tokens.set(sessionId, {
// ... (see reference guides for full implementation)
Reference Guides
Details
- Repository
- github.com/aj-geddes/useful-ai-prompts
- Categories
- Security, Backend & APIs
- First seen
- Jun 3, 2026
Questions
What does the csrf-protection skill do?
The csrf-protection skill implements Cross-Site Request Forgery protection using synchronizer tokens, double-submit cookies, SameSite cookie attributes, and custom headers. It is meant for forms and any state-changing POST, PUT or DELETE requests in your app.
How do I install the csrf-protection skill?
Run npx -y skills add aj-geddes/useful-ai-prompts --skill csrf-protection -y in your project. Once installed, the csrf-protection skill guides the agent through adding CSRF tokens, SameSite cookies and origin validation to your code.
Which skills lead the Security category where csrf-protection is listed?
The csrf-protection skill is listed in the Security category alongside azure-compliance, entra-agent-id, firebase-security-rules-auditor, security-audit and cloudflare-one. Its own focus is narrower, covering only CSRF defenses for form submissions and state-changing requests.
Does the csrf-protection skill include reference guides for specific frameworks?
Yes, the csrf-protection skill ships reference guides for Node.js/Express, Python Flask, the double submit cookie pattern, frontend CSRF implementation, and origin and referer validation. Each guide gives framework-specific detail for applying CSRF protection.
More from aj-geddes/useful-ai-prompts
All 258- Developer Onboarding479
- Api Changelog Versioning478
- Deployment Automation478
- Django Application478
- Regression Modeling478
- Concurrency Patterns477
- Gcp Cloud Functions476
- Cloud Security Configuration475
- Aws Ec2 Setup474
- Api Versioning Strategy473
- Email Service Integration472
- Infrastructure Monitoring472
- Angular Module Design471
- Database Monitoring470
- Pull Request Automation470
- Session Management469
- Idempotency Handling468
- Network Analysis467
- Risk Assessment467
- Error Tracking466
- Query Caching Strategies466
- Clustering Analysis464
- Code Metrics Analysis464
- Spring Boot Application464
Similar to Csrf Protection
More Securitysession-managementaj-geddes/useful-ai-prompts469 installsSecure session management with JWT tokens, refresh cycles, session storage, logout handling, and CSRF protection.
csrf-cross-site-request-forgeryyaklang/hack-skills4.1K installsExpert CSRF playbook covering token bypasses, SameSite edge cases, JSON and multipart CSRF, and OAuth state handling.
security-headers-configurationaj-geddes/useful-ai-prompts523 installsConfiguration guide for HTTP security headers covering CSP, HSTS, X-Frame-Options, and MIME-sniffing protection across common web stacks.
wordpress-security-validationbobmatnyc/claude-mpm-skills643 installsSecurity-first WordPress guide covering nonces, sanitization, validation, and escaping against XSS, CSRF, and SQL injection.
web-securityacademind/ai-config300 installsSet of security rules that guides code toward safe defaults across XSS, auth, CSP, and data handling.