Skip to content

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
View on GitHub

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 -y

Installs 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

Similar to Csrf Protection

More Security