xss-csrf
Skill0 starsChanged 8 months agoMITView on GitHub
Use when rendering user content, building forms, or handling POST requests
In this repository11 other files it gives its agents.
- access-controlSkill
- accessibilitySkill
- accessibility-testingSkill
- api-securitySkill
- authenticationSkill
- dependency-securitySkill
- injection-preventionSkill
- input-validationSkill
- secrets-managementSkill
- security-contextSkill
- security-headersSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Never render unsanitized user content.
- Distinctive: line 14
Use your framework's auto-escaping.
- Distinctive: line 50
Every POST, PUT, DELETE request must include a CSRF token.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
XSS & CSRF Prevention
Never render unsanitized user content. Always include anti-forgery tokens on state-changing requests.
Related: input-validation, security-headers, security-context
Rule 1: Never Insert Raw User Content Into HTML
Use your framework's auto-escaping. If you bypass it, sanitize first.
// WRONG — innerHTML with user content
element.innerHTML = userComment;
// RIGHT — use textContent (auto-escapes)
element.textContent = userComment;
// If you MUST render HTML, sanitize first
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userComment);# WRONG — marking user input as safe in Jinja2
{{ user_comment | safe }}
# RIGHT — auto-escaped by default
{{ user_comment }}Rule 2: Escape Output Based on Context
HTML context, attribute context, JavaScript context, and URL context all need different escaping.
// WRONG — user input in an attribute without escaping
`<img src="${userUrl}" alt="${userName}">`
// RIGHT — encode for HTML attributes
`<img src="${encodeURI(userUrl)}" alt="${escapeHtml(userName)}">`Rule 3: Include Anti-Forgery Tokens on All Forms
Every POST, PUT, DELETE request must include a CSRF token.
<!-- WRONG — form without CSRF token -->
<form method="POST" action="/delete">
<button type="submit">Delete</button>
</form>
<!-- RIGHT — CSRF token included -->
<form method="POST" action="/delete">
<input type="hidden" name="_csrf" value="{{csrfToken}}">
<button type="submit">Delete</button>
</form>Rule 4: Set SameSite on Cookies
Prevent CSRF by restricting cookie behavior.
// WRONG — no SameSite attribute
res.cookie('session', token);
// RIGHT — SameSite restricts cross-origin requests
res.cookie('session', token, {
sameSite: 'strict',
httpOnly: true,
secure: true
});Rule 5: Set Content Security Policy
CSP is your last line of defense against XSS. It blocks inline scripts and unauthorized sources.
// WRONG — no CSP header (any script can run)
// RIGHT — restrictive CSP
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:;Quick Reference
| Do | Don't |
| Use framework auto-escaping | Insert raw user content with innerHTML |
| Sanitize with DOMPurify if rendering HTML | Mark user input as "safe" in templates |
| Include CSRF tokens on all forms | Submit state-changing requests without tokens |
Set SameSite: strict on cookies | Leave cookies without SameSite attribute |
| Set Content Security Policy header | Allow inline scripts from any source |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

