Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
secondsky avatar

Csrf Protection

  • 328 installs
  • 202 repo stars
  • Updated August 4, 2026
  • secondsky/claude-skills

csrf-protection is a Claude Code skill from secondsky/claude-skills that implements CSRF defenses using synchronizer tokens, double-submit cookies, and SameSite attributes for web forms and state-changing HTTP endpoints.

About

csrf-protection is a security skill in the secondsky/claude-skills security-skills suite that guides CSRF hardening for production web applications. It covers synchronizer tokens, double-submit cookies, and SameSite cookie attributes for JavaScript stacks including Express and React, plain HTML forms, and Python backends. Developers invoke it when securing login flows, payment or settings forms, and any state-changing POST, PUT, or DELETE route vulnerable to cross-site request forgery. The skill emphasizes defense-in-depth alongside authentication layers rather than replacing auth entirely. It ships beside access-control-rbac, xss-prevention, and security-headers-configuration in a six-skill security bundle installable via /plugin install security-skills@claude-skills. Reach for csrf-protection during pre-launch security passes or when audit findings flag missing anti-CSRF middleware on session-backed applications.

  • csrf-protection

Csrf Protection by the numbers

  • 328 all-time installs (skills.sh)
  • +12 installs in the week ending Jul 27, 2026 (Skillselion tracking)
  • Ranked #1,236 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/secondsky/claude-skills --skill csrf-protection

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs328
repo stars202
Last updatedAugust 4, 2026
Repositorysecondsky/claude-skills

How do you add CSRF protection to web forms?

Use csrf-protection for development tasks

Who is it for?

Full-stack developers shipping session-backed web apps in Express, React, HTML, or Python who need concrete CSRF mitigation patterns before production.

Skip if: Teams building stateless JWT-only APIs with no cookie sessions where CSRF risk is negligible and other threat models take priority.

When should I use this skill?

Trigger when securing web forms, protecting state-changing endpoints, or implementing defense-in-depth authentication against CSRF attacks.

What you get

CSRF token middleware, double-submit cookie configuration, and SameSite attribute hardening on protected routes and forms.

  • csrf middleware configuration
  • cookie attribute policy

By the numbers

  • Documents three CSRF defense patterns: synchronizer tokens, double-submit cookies, and SameSite attributes
  • Bundled in the six-skill security-skills suite on secondsky/claude-skills

Files

SKILL.mdMarkdownGitHub ↗

CSRF Protection

Defend against Cross-Site Request Forgery attacks using multiple protection layers.

Protection Methods

MethodHow It WorksBrowser Support
Synchronizer TokenHidden form field validated server-sideAll
Double SubmitCookie + header must matchAll
SameSite CookieBrowser blocks cross-origin requestsModern

Token-Based Protection (Express)

const crypto = require('crypto');

function generateToken() {
  return crypto.randomBytes(32).toString('hex');
}

// Middleware
app.use((req, res, next) => {
  if (!req.session.csrfToken) {
    req.session.csrfToken = generateToken();
  }
  res.locals.csrfToken = req.session.csrfToken;
  next();
});

// Validation
app.post('*', (req, res, next) => {
  const token = req.body._csrf || req.headers['x-csrf-token'];
  if (!token || !crypto.timingSafeEqual(
    Buffer.from(token),
    Buffer.from(req.session.csrfToken)
  )) {
    return res.status(403).json({ error: 'Invalid CSRF token' });
  }
  next();
});

SameSite Cookies

app.use(session({
  cookie: {
    httpOnly: true,
    secure: true,
    sameSite: 'strict', // or 'lax'
    maxAge: 3600000
  }
}));

HTML Form Integration

<form method="POST" action="/transfer">
  <input type="hidden" name="_csrf" value="<%= csrfToken %>">
  <button type="submit">Submit</button>
</form>

Best Practices

  • Apply to all state-changing requests (POST, PUT, DELETE)
  • Use SameSite=Strict for sensitive cookies
  • Validate Origin/Referer headers
  • Never use GET for modifications
  • Implement token expiration (1 hour typical)
  • Combine multiple defense layers

Additional Implementations

See references/python-react.md for:

  • Flask-WTF complete CSRF setup
  • React hooks for CSRF token management
  • Double submit cookie pattern

Common Mistakes

  • Assuming authentication prevents CSRF
  • Reusing tokens across sessions
  • Storing tokens in localStorage
  • Missing token expiration

Related skills

How it compares

Pair csrf-protection with xss-prevention and security-headers-configuration for layered web app hardening.

FAQ

Which CSRF techniques does csrf-protection cover?

csrf-protection covers synchronizer tokens, double-submit cookies, and SameSite cookie attributes. It applies these patterns to Express and React JavaScript stacks, HTML forms, and Python backends protecting state-changing endpoints.

When should developers use csrf-protection?

csrf-protection fits when web applications use cookie-backed sessions and expose forms or state-changing routes like login, checkout, or settings updates. Stateless token APIs without cookies typically need different threat modeling.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.