csrf-protection

csrf-protection is a skill for Claude Code from latestaiagents/agent-skills. It costs 61 tokens per session (2,173 once invoked), scanned C, original, MIT.

A guide to preventing Cross-Site Request Forgery, an attack that tricks a logged-in browser into sending unwanted changes to a website. It covers forms, cookies, request tokens, and other protections.

In plain words
What is it for?
Use it when securing browser forms, session cookies, or POST, PUT, and DELETE requests that change application data.
Why use it?
It helps stop attackers from making state-changing requests with a user's existing browser session.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the common-security plugin — 2 skills shipped together , and of security, latestaiagents

Good fit Use it when securing browser forms, session cookies, or POST, PUT, and DELETE requests that change application data.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/latestaiagents/agent-skills/csrf-protection
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add latestaiagents/agent-skills --skill csrf-protection
Clone the repo
git clone --depth 1 https://github.com/latestaiagents/agent-skills

Made for: Claude Code.

Or install common-security, the plugin that ships this one along with the rest of its 2 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for csrf-protection

README.md
[![agentmods](https://agentmods.dev/badge/skills/latestaiagents/agent-skills/csrf-protection/github.svg)](https://agentmods.dev/skills/latestaiagents/agent-skills/csrf-protection)
Your own site
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/csrf-protection"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/csrf-protection/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for csrf-protection

Your own site · 80×15
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/csrf-protection"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/csrf-protection.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 61 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,173 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 3 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00061 $0.02173
Opus 5 $0.00030 $0.01086
Sonnet 5 $0.00012 $0.00435
Haiku 4.5 $0.00006 $0.00217

Measured 6d ago against content hash fc690e009df2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade C, and why

csrf-protection scanned grade C with 3 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Hidden instructionshighPrompt injection

Directives inside HTML comments, invisible characters or bidirectional overrides are read by the model and not by the person reviewing the file.

<!-- Test 3: Image tag (for GET requests) -->

Sends data to an external URLlowData exfiltration

A POST to an outside endpoint may be telemetry or may be exfiltration; either way the mod talks to somewhere, and you should know where.

fetch('http://target.com/api/update', { method: 'POST',

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

return fetch(url, {
skills/security/common-security/csrf-protection/SKILL.md · 365 lines

How it starts

The opening of the file, as written. The whole thing — 365 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CSRF Protection

Prevent Cross-Site Request Forgery attacks on your web application.

When to Use

  • Implementing forms that change state
  • Building APIs consumed by browsers
  • Setting up session cookies
  • Reviewing authentication flows
  • Any state-changing POST/PUT/DELETE requests

How CSRF Works

<!-- Attacker's malicious page -->
<html>
  <body onload="document.forms[0].submit()">
    <form action="https://bank.com/transfer" method="POST">
      <input name="to" value="attacker" />
      <input name="amount" value="10000" />
    </form>
  </body>
</html>
<!-- Victim visits this page while logged into bank.com -->
<!-- Their session cookie is sent automatically! -->

Protection Methods

1. SameSite Cookies (Primary Defense)

// Express session with SameSite
app.use(session({
  secret: process.env.SESSION_SECRET,
  cookie: {
    httpOnly: true,
    secure: true,  // HTTPS only
    sameSite: 'strict',  // Or 'lax' for better UX
    maxAge: 3600000
  }
}));

// Set-Cookie header result:
// Set-Cookie: sessionId=abc123; HttpOnly; Secure; SameSite=Strict

SameSite Options:

Value Behavior
Strict Cookie never sent cross-site
Lax Sent on top-level navigation (default)
None Always sent (requires Secure)

2. CSRF Tokens (Defense in Depth)

const csrf = require('csurf');

// Setup CSRF middleware
const csrfProtection = csrf({
  cookie: {
    httpOnly: true,
    secure: process.env.NODE_ENV === 'production',
    sameSite: 'strict'
  }
});

// Apply to routes
app.get('/form', csrfProtection, (req, res) => {
  res.render('form', { csrfToken: req.csrfToken() });
});

app.post('/submit', csrfProtection, (req, res) => {
  // Token automatically validated by middleware
  // Process form...
});
<!-- In your form template -->
<form method="POST" action="/submit">
  <input type="hidden" name="_csrf" value="<%= csrfToken %>">
  <!-- Other form fields -->
  <button type="submit">Submit</button>
</form>

Read the full file on GitHub · 365 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 365 lines · 61 tokens per session scan C fc690e009df2

Subscribe to this mod's changes

csrf-protection is a skill published in the GitHub repository latestaiagents/agent-skills (5 stars, last pushed 4mo ago), licensed MIT. It adds 61 tokens to every session and 2,173 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it C with 3 findings (hidden instructions, sends data to an external url, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.