Skip to content
validating-csrf-protection logo

Validating CSRF Protection

validating-csrf-protection

Validate CSRF protection implementations for security gaps. Use when

SKILL.md

Full skill instructions

Validating CSRF Protection

Overview

Validate Cross-Site Request Forgery protection across web application endpoints, forms, and API routes. This skill examines synchronizer token patterns, double-submit cookie implementations, SameSite cookie attributes, Origin/​Referer header validation, and custom header requirements to identify state-changing operations vulnerable to CSRF attacks.

Prerequisites

  • Access to the target codebase and configuration files in ${CLAUDE_SKILL_DIR}/
  • Familiarity with the web framework in use (Express, Django, Rails, Spring, Laravel, etc.)
  • Standard shell utilities and Grep/​Glob available for codebase scanning
  • Reference: ${CLAUDE_SKILL_DIR}/​references/​README.md for CSRF protection methods, OWASP CSRF Prevention Cheat Sheet, and framework-specific API examples

Instructions

  1. Inventory all state-changing endpoints by scanning for POST, PUT, PATCH, and DELETE route handlers using Grep. Include form action attributes in HTML templates, AJAX calls in JavaScript, and API route definitions.
  2. For each state-changing endpoint, verify that at least one CSRF protection mechanism is in place: synchronizer token, double-submit cookie, SameSite cookie attribute, Origin validation, or custom header requirement.
  3. Validate synchronizer token implementation: confirm tokens are generated server-side using a CSPRNG, bound to the user session, included in forms as hidden fields or request headers, and validated on every state-changing request. Flag tokens that are static, predictable, or reused across sessions as CWE-352 (Cross-Site Request Forgery).
  4. Check double-submit cookie patterns: verify the cookie value matches the request body or header value, the cookie uses Secure and HttpOnly attributes, and the comparison is timing-safe to prevent token extraction.
  5. Assess SameSite cookie attributes on session cookies: verify SameSite=Strict or SameSite=Lax is set. Flag SameSite=None without Secure as severity high. Note that SameSite=Lax permits top-level GET navigations, which may be insufficient for GET endpoints that trigger state changes.
  6. Verify Origin/​Referer header validation: check that the server validates the Origin header against an allowlist on state-changing requests. Flag implementations that fall back to no protection when the header is absent.
  7. For API endpoints using token-based auth (JWT in Authorization header), confirm that cookies are not also sent -- if cookies are used alongside bearer tokens, CSRF protection remains necessary.
  8. Check for CSRF bypass vectors: look for state-changing GET endpoints, JSONP endpoints, content-type sniffing (missing Content-Type enforcement), and Flash/​Silverlight crossdomain.xml files.
  9. Classify each finding by severity (critical for unprotected financial/​admin endpoints, high for other state-changing endpoints, medium for defense-in-depth gaps).
  10. Generate remediation guidance with framework-specific CSRF middleware configuration examples.

Output

  • Endpoint inventory: Table of all state-changing endpoints with their CSRF protection status (Protected, Partially Protected, Unprotected)
  • Findings report: Each finding includes severity, CWE-352 reference, affected endpoint/​file, attack scenario description, and remediation code
  • Protection coverage: Percentage of state-changing endpoints with validated CSRF protection
  • SameSite cookie audit: Table of all session/​auth cookies with their SameSite, Secure, HttpOnly, and Path attributes
  • Remediation guide: Framework-specific middleware setup (e.g., csurf for Express, @csrf_protect for Django, csrf_meta_tags for Rails)

Error Handling

ErrorCauseSolution
No state-changing endpoints foundUnconventional routing patterns or SPA architectureCheck for client-side routing frameworks (React Router, Vue Router) and trace API calls from frontend code
CSRF middleware detected but not applied globallyMiddleware applied per-route rather than globallyVerify every state-changing route has the middleware applied; flag gaps in coverage
Token generation source unclearFramework abstracts CSRF token generationCheck framework documentation for default CSPRNG usage; inspect framework source if needed
SameSite attribute not set in codeCookie attributes set at infrastructure layerCheck reverse proxy, load balancer, or CDN cookie rewriting rules
Mixed protection strategiesDifferent endpoints use different CSRF mechanismsDocument each strategy and verify consistency; recommend standardizing on one approach

Examples

Express.js CSRF Token Validation

Scan ${CLAUDE_SKILL_DIR}/​src/​routes/ for router.post and router.put handlers. Verify each includes csurf middleware or equivalent token validation. Flag any POST handler that directly processes req.body without csrfProtection middleware as CWE-352, severity critical for financial operations, high for other state changes.

Django CSRF Middleware Audit

Grep ${CLAUDE_SKILL_DIR}/​settings.py for django.middleware.csrf.CsrfViewMiddleware in the MIDDLEWARE list. Scan views for @csrf_exempt decorators -- flag each exempted view as a potential CSRF vulnerability requiring justification. Verify templates include {% csrf_token %} in all form tags.

SPA + API CSRF Assessment

For a React frontend calling a REST API, verify that the API enforces a custom header requirement (e.g., X-Requested-With) or uses double-submit cookies. Check that the SPA reads the CSRF token from a cookie and includes it in the X-CSRF-Token header. Flag API endpoints that accept application/​x-www-form-urlencoded without CSRF validation as severity high (exploitable via HTML forms).

Resources

More Security skills

supabase logo
Security

supabase

Handles the full Supabase workflow from schema changes to deployment, with built-in security guardrails that catch common traps like RLS...

2.7K 308.9K
View

Comprehensive guides and best practices for Neon Serverless Postgres, covering setup, connection methods, authentication, and platform APIs.

98 216.2K
View

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.

462 163.8K
View

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

462 127.7K
View

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

462 125.1K
View

Complete Better Auth server and client setup with database adapters, session management, plugins, and security configuration.

222 118.2K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View
cloudflare logo
Security

cloudflare

Complete Cloudflare platform integration with decision trees for compute, storage, AI, networking, security, and infrastructure-as-code.

3K 110.7K
View

Run Azure compliance and security audits with azqr plus Key Vault expiration checks. Covers best-practice assessment, resource review, policy/compliance validation, and security posture checks. WHEN: compliance scan, security audit, BEFORE running azqr (compliance cli tool), Azure best practices, Key Vault expiration check, expired certificates, expiring secrets, orphaned resources, compliance assessment.

253 103K
View
gws-gmail logo
Security

gws-gmail

Send, read, and manage Gmail messages, drafts, labels, and account settings.

31.2K 78.9K
View

Comprehensive website auditing across 230+ rules in 21 categories including SEO, performance, security, and accessibility.

94 72.3K
View
gws-shared logo
Security

gws-shared

Shared authentication, CLI syntax, and output formatting patterns for gws Google Workspace commands.

31.2K 63.4K
View

Security AI tools

StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
GeoSpy logo
Security

GeoSpy

GeoSpy: Pricing, Features, FAQs, and Alternatives for AI Teams

Free
View

Detect AI-generated voices to protect against audio fraud.

Paid
View

Ensure Your Content's Originality with AI Plagiarism Checker

Freemium
View
Img Upscaler logo
Security

Img Upscaler

Upscale images by 400% without quality loss

Freemium
View
AICheatCheck logo
Security

AICheatCheck

Accurately Detect AI-Generated Content with TheChecker.AI

Free
View
D
Security

Detect GPT

Chrome extension that detects and flags AI-generated content

Free
View