Solid foundation for implementing CSRF protection across your web apps. Covers the main approaches: synchronizer tokens, double-submit cookies, SameSite attributes, and origin validation. The reference guides walk through implementations in Node.js/Express and Python Flask, plus frontend integration patterns. Worth noting it emphasizes the basics well, like never using GET for state changes and always pairing tokens with HTTPS. If you're building forms, payment flows, or anything that modifies server state, this gives you the patterns to prevent forged requests. The best practices section is actually useful, calling out common mistakes like storing tokens in localStorage.

skills.sh installs
477
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill csrf-protection --agent claude-code

Installs into .claude/skills of the current project.

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

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Security, AI & Agent Building
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258

Recommended

More Security
1aj-geddes avatarnetwork-security-groupsaj-geddes/useful-ai-promptsConfigure network security groups and firewall rules to control inbound/outbound traffic and implement network segmentation.446skills.sh installs
2davila7 avatarinformation-security-manager-iso27001davila7/claude-code-templatesSenior Information Security Manager specializing in ISO 27001 and ISO 27002 implementation for HealthTech and MedTech companies. Provides ISMS implementation, c428skills.sh installs
3syncfusion avatarsyncfusion-blazor-securitysyncfusion/blazor-ui-components-skillsConfigure Content Security Policy (CSP) for Syncfusion Blazor components across Blazor Server, WebAssembly, and Auto render modes � self-hosted and CDN scenario382skills.sh installs
4tech-leads-club avatarsecurity-best-practicestech-leads-club/agent-skillsPerform language and framework specific security best-practice reviews and suggest improvements. Use when the user explicitly requests security best practices g378skills.sh installs
5igorwarzocha avatarsecurity-nextjsigorwarzocha/opencode-workflowssecurity nextjs370skills.sh installs
6dfinity avatarcanister-securitydfinity/icskillsIC-specific security patterns for canister development in Motoko and Rust. Covers access control, anonymous principal rejection, reentrancy prevention (CallerGu324skills.sh installs