csrf-protection

Implement HMAC-SHA256 CSRF token protection for POST, PUT, and DELETE API routes.

15|1|Updated Oct 20, 2025
One-click install
npx skills add https://github.com/harperaa/secure-claude-skills --skill csrf-protection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csrf-protection
Source: https://github.com/harperaa/secure-claude-skills/tree/main/csrf-protection
Command: npx skills add https://github.com/harperaa/secure-claude-skills --skill csrf-protection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the risk of cross-site request forgery attacks that could trick users into making unintended requests, protecting your application from unauthorized actions like account takeovers or data manipulation.

Core Features & Use Cases

  • HMAC-SHA256 Protection: Industry-standard cryptographic token validation that prevents forgery.
  • Single-Use Session Tokens: Each token expires after one use, making intercepted tokens useless.
  • Use Case: Imagine you have a banking application with transfer functionality. Use this Skill to automatically protect all POST/PUT/DELETE endpoints, ensuring that only legitimate requests from your authenticated users can perform sensitive actions.

Quick Start

Protect your API endpoint from cross-site request forgery attacks by wrapping the handler with CSRF middleware.

Frequently Asked Questions about csrf-protection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect API endpoints from cross-site request forgery attacks?

Cross-site request forgery (CSRF) protection secures API endpoints by enforcing cryptographic tokens that verify requests originate from your application, not malicious third-party sites. Apply CSRF middleware to POST, PUT, and DELETE endpoints to block unauthorized cross-origin requests automatically.

What's the difference between HMAC-SHA256 token validation and standard session cookies?

HMAC-SHA256 token validation uses industry-standard cryptographic signing to make tokens tamper-proof and forgery-resistant, while standard cookies alone can be exploited. This Skill combines HMAC-SHA256 tokens with HTTP-only cookies and SameSite=Strict to prevent both token interception and cross-origin request acceptance.

Can I use CSRF protection with single-use tokens in my web application?

Yes. This Skill implements single-use session-bound tokens that expire after one use, rendering intercepted tokens useless. Each new request requires a fresh token exchange, eliminating replay attacks while maintaining session integrity across POST, PUT, and DELETE operations.

How do I implement automatic token rotation for API security?

This Skill handles automatic token rotation through middleware enforcement and client-token exchange workflows. Tokens are generated session-bound and rotate after each use, requiring no manual intervention while satisfying cryptographic signing and verification requirements.

Do I need to modify client code to use CSRF middleware protection?

Yes, clients must participate in the token exchange workflow. The Skill provides middleware enforcement on the server; clients receive tokens via HTTP-only cookies and must include them in request headers for POST, PUT, and DELETE operations to pass verification.

What attacks does SameSite=Strict prevent alongside CSRF tokens?

SameSite=Strict prevents the browser from sending cookies on cross-site requests, blocking cookie-based attacks even if tokens are compromised. Combined with HMAC-SHA256 tokens and HTTP-only cookies, it creates defense-in-depth against cross-origin request forgery and related exploits.