Csrf

From thejefflarson/soundcheck · View interactive version

Csrf is an AI agent skill from the GitHub repository thejefflarson/soundcheck. Detects forms and state-changing endpoints missing CSRF protection. Use when writing HTML forms that submit POST/PUT/DELETE requests, configuring session cookies, or setting up CSRF middleware for web applications. Also invoke when disabling or bypassing CSRF protections in framework configuration.

How to use this skill

Skill file

Cross-Site Request Forgery Check (A01:2025)

What this checks

Protects against cross-site request forgery, where an attacker tricks an authenticated

user's browser into submitting a state-changing request the user did not intend.

Exploitation leads to unauthorized fund transfers, account takeover, or privilege

escalation.

Vulnerable patterns

Fix immediately

Flag the vulnerable code and explain the risk. Then suggest a fix that establishes

these properties:

  1. **Every state-changing endpoint (POST/PUT/PATCH/DELETE) validates a per-session

or per-request CSRF token server-side** before any mutation. Use the framework's

documented CSRF middleware — do not roll your own.

  1. **Framework CSRF protection is never disabled or exempted on a state-changing

route.** If a route legitimately needs to opt out (a pure JSON API authenticated

by Authorization: Bearer headers, not cookies), the opt-out must be explicit

and the cookie-auth path must remain protected.

  1. **Session cookies carry SameSite=Lax at minimum, or SameSite=Strict for

sensitive flows**, plus Secure and HttpOnly. This blocks cross-origin

cookie attachment on top-level navigations or subrequests that don't need it.

  1. CSRF tokens are not exposed in URLs, logs, or Referer headers — they live

in a hidden form field or a dedicated request header, never in the query string.

  1. Forms include the token via the framework's template helper, so the token

binds to the session and is rotated as the framework intends.

Translate these principles to the audited file's language and framework. Use the

documented CSRF middleware and template helpers for that stack — do not hand-build

token comparison logic.

Verification

Confirm the following properties hold (language-agnostic):

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.