Owasp top 10 prevention
Skill VersoXBT/claude-initial-setup/skills/security/owasp-top-10-prevention
Prevent OWASP Top 10 vulnerabilities in web applications. Activate whenever the user writes API endpoints, form handlers, database queries, authentication logic, file uploads, HTML rendering, or any code that handles user input or external data. Also activate when the user asks about security, hardening, or vulnerability prevention.From its SKILL.md
npx -y skills add VersoXBT/claude-initial-setup --skill owasp-top-10-preventionAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.3 KB, ~1.4k tokens by cl100k_base, as published. Nobody here has run it
OWASP Top 10 Prevention
Prevent the most critical web application security risks by applying proven defensive patterns. This skill covers injection, XSS, CSRF, SSRF, broken authentication, security headers, insecure deserialization, and IDOR vulnerabilities.
When to Use
- Writing or reviewing API endpoints that accept user input
- Building authentication or authorization logic
- Rendering user-generated content in HTML
- Making server-side HTTP requests based on user input
- Writing database queries with dynamic parameters
- Handling file uploads or downloads
- Setting up HTTP response headers
Core Patterns
SQL Injection Prevention
Never concatenate user input into SQL queries. Always use parameterized queries or an ORM.
// WRONG: SQL injection vulnerability
const query = `SELECT * FROM users WHERE email = '${email}'`;
await db.query(query);
// CORRECT: Parameterized query
const query = 'SELECT * FROM users WHERE email = $1';
await db.query(query, [email]);
// CORRECT: Using an ORM (Prisma)
const user = await prisma.user.findUnique({
where: { email },
});
XSS Prevention
Sanitize all user-generated content before rendering. Use framework-provided escaping.
// WRONG: Direct HTML insertion
element.innerHTML = userComment;
// CORRECT: Use textContent for plain text
element.textContent = userComment;
// CORRECT: Sanitize HTML when rich text is needed
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userComment);
// CORRECT: React auto-escapes by default, but avoid dangerouslySetInnerHTML
function Comment({ text }: { text: string }) {
return <p>{text}</p>; // Auto-escaped
}
CSRF Protection
Validate origin and use anti-CSRF tokens for state-changing requests.
// Express middleware for CSRF protection
import csrf from 'csurf';
const csrfProtection = csrf({ cookie: true });
app.use(csrfProtection);
app.post('/api/transfer', csrfProtection, (req, res) => {
// Token automatically validated by middleware
processTransfer(req.body);
});
// Also validate Origin header
function validateOrigin(req: Request): boolean {
const origin = req.headers.origin;
const allowedOrigins = [process.env.FRONTEND_URL];
return allowedOrigins.includes(origin);
}
SSRF Prevention
Never allow user input to control server-side HTTP request destinations without validation.
// WRONG: User controls the URL
app.get('/proxy', async (req, res) => {
const response = await fetch(req.query.url as string);
res.send(await response.text());
});
// CORRECT: Allowlist of permitted domains
const ALLOWED_HOSTS = new Set(['api.example.com', 'cdn.example.com']);
app.get('/proxy', async (req, res) => {
const url = new URL(req.query.url as string);
if (!ALLOWED_HOSTS.has(url.hostname)) {
return res.status(403).json({ error: 'Domain not allowed' });
}
if (url.protocol !== 'https:') {
return res.status(403).json({ error: 'HTTPS required' });
}
const response = await fetch(url.toString());
res.send(await response.text());
});
Broken Authentication Prevention
Use secure session management, strong password hashing, and rate limiting.
import bcrypt from 'bcrypt';
import rateLimit from 'express-rate-limit';
// Hash passwords with sufficient rounds
const SALT_ROUNDS = 12;
const hashedPassword = await bcrypt.hash(password, SALT_ROUNDS);
// Rate limit login attempts
const loginLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 5,
message: 'Too many login attempts, try again later',
});
app.post('/api/login', loginLimiter, loginHandler);
// Secure session configuration
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: true,
httpOnly: true,
sameSite: 'strict',
maxAge: 3600000,
},
}));
Security Headers
Set proper HTTP headers to prevent common attacks.
import helmet from 'helmet';
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", "data:", "https:"],
},
},
hsts: { maxAge: 31536000, includeSubDomains: true },
referrerPolicy: { policy: 'strict-origin-when-cross-origin' },
}));
IDOR Prevention
Always verify the requesting user has access to the requested resource.
// WRONG: No authorization check
app.get('/api/orders/:id', async (req, res) => {
const order = await db.orders.findById(req.params.id);
res.json(order);
});
// CORRECT: Verify ownership
app.get('/api/orders/:id', authenticate, async (req, res) => {
const order = await db.orders.findById(req.params.id);
if (!order) {
return res.status(404).json({ error: 'Not found' });
}
if (order.userId !== req.user.id) {
return res.status(403).json({ error: 'Forbidden' });
}
res.json(order);
});
Anti-Patterns
- Using
eval(),new Function(), or template literals for SQL/HTML construction - Storing passwords in plaintext or with weak hashing (MD5, SHA1)
- Trusting client-side validation as the sole defense
- Returning different error messages for "user not found" vs "wrong password" (enables enumeration)
- Disabling CORS entirely with
Access-Control-Allow-Origin: *on authenticated endpoints - Logging sensitive data (passwords, tokens, PII) in application logs
Quick Reference
| Vulnerability | Defense |
|---|---|
| SQL Injection | Parameterized queries, ORM |
| XSS | Output encoding, CSP, DOMPurify |
| CSRF | Anti-CSRF tokens, SameSite cookies |
| SSRF | URL allowlisting, block internal IPs |
| Broken Auth | bcrypt, rate limiting, secure sessions |
| Security Headers | helmet middleware, strict CSP |
| IDOR | Authorization checks on every resource access |
| Deserialization | Validate/schema-check before deserializing, avoid native deserialization of untrusted data |
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 3 of the 12 instructions most security skills give in ~1.4k tokens
Counted across 666 of the 889 authors here whose files we hold, read 2026-09-06
- Use parameterized queries for database accesshere, and in 82 of 666, across 79 files
- Hash passwords with BCryptin 55 of 666, across 39 files
- Implement rate limiting for public endpointshere, and in 48 of 666, across 34 files
- Use environment variables for secretsin 35 of 666
- Scan dependencies for vulnerabilitiesin 35 of 666, across 24 files
- Validate and sanitize all user inputin 35 of 666, across 32 files
- Add security headers to all responseshere, and in 34 of 666, across 20 files
- Validate all external input at the system boundaryin 26 of 666, across 25 files
- Use parameterized queries to prevent SQL injectionin 25 of 666, across 13 files
- Store secrets in Vault or environment variablesin 25 of 666, across 10 files
- Run containers as a non-root userin 21 of 666, across 18 files
- Validate all input using Bean Validationin 19 of 666, across 5 files
Said here and by no other author read
- validate origin for state-changing requests
- validate destinations for server-side HTTP requests
- validate data before deserialization
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.