/harness-claude:owasp-csrf-protectionfrom harness-claude
Prevents CSRF attacks using SameSite cookies, synchronizer token pattern, double-submit cookie pattern, and origin header validation. Includes Express/NestJS middleware examples.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:owasp-csrf-protection still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Prevent cross-site request forgery by validating request origin and requiring unpredictable tokens for state-changing operations
Modern browsers support SameSite=Strict or SameSite=Lax which blocks CSRF for most cases:
res.cookie('session_id', sessionId, {
httpOnly: true,
secure: true,
sameSite: 'strict', // cross-site requests never send this cookie
maxAge: 15 * 60 * 1000,
});
Strict — cookie never sent on cross-site requests (strongest, may break OAuth flows)Lax — cookie sent on top-level GET navigations, not POST; good balanceNone — must pair with Secure: true and add CSRF tokensFor forms and traditional server-rendered pages:
import csrf from 'csurf';
// Express — csurf middleware
const csrfProtection = csrf({ cookie: { sameSite: 'strict', httpOnly: true } });
app.get('/form', csrfProtection, (req, res) => {
// Pass token to the template
res.render('form', { csrfToken: req.csrfToken() });
});
app.post('/submit', csrfProtection, (req, res) => {
// csurf validates _csrf field automatically
res.json({ ok: true });
});
<!-- Include hidden CSRF field in every form -->
<form method="POST" action="/submit">
<input type="hidden" name="_csrf" value="<%= csrfToken %>" />
<!-- form fields -->
</form>
For SPAs where the backend is stateless:
import crypto from 'crypto';
function csrfMiddleware(req: Request, res: Response, next: NextFunction) {
if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) return next();
const cookieToken = req.cookies['csrf-token'];
const headerToken = req.headers['x-csrf-token'];
if (!cookieToken || !headerToken || cookieToken !== headerToken) {
return res.status(403).json({ error: 'CSRF validation failed' });
}
next();
}
// On session creation, set the cookie
function setCSRFCookie(res: Response) {
const token = crypto.randomBytes(32).toString('hex');
res.cookie('csrf-token', token, {
secure: true,
sameSite: 'strict',
// NOT httpOnly — frontend JS must be able to read it
});
}
// SPA — send CSRF token on every mutating request
const csrfToken = document.cookie
.split('; ')
.find((row) => row.startsWith('csrf-token='))
?.split('=')[1];
fetch('/api/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken ?? '',
},
body: JSON.stringify(data),
});
Simplest approach for API-only backends that don't serve HTML:
const ALLOWED_ORIGINS = new Set(['https://app.example.com', 'https://www.example.com']);
function originValidator(req: Request, res: Response, next: NextFunction) {
if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) return next();
const origin = req.headers.origin || req.headers.referer;
if (!origin) return res.status(403).json({ error: 'Missing origin' });
const url = new URL(origin);
const originBase = `${url.protocol}//${url.host}`;
if (!ALLOWED_ORIGINS.has(originBase)) {
return res.status(403).json({ error: 'Invalid origin' });
}
next();
}
CSRF is only possible when:
APIs using Bearer tokens in Authorization header are immune to CSRF — browsers do not automatically send Authorization headers cross-origin. Only protect cookie-authenticated routes.
Defense selection guide:
SameSite=Strict + CSRF tokenSameSite=Strict + double-submit cookieNestJS — CsrfGuard:
import { CsrfGuard } from '@tekuconcept/nestjs-csrf';
@UseGuards(CsrfGuard)
@Post('transfer')
transfer(@Body() dto: TransferDto) { ... }
https://owasp.org/www-project-top-ten/
SameSite cookie is wired through middleware. Deciding this requires framework-aware data-flow analysis; a pattern-based "missing CSRF protection" check would be noisy, and a noisy security gate is worse than this advisory. Use /harness:security-review for a semantic assessment.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job