| name | security-essentials |
| description | Security best practices, OWASP compliance, authentication patterns, and vulnerability prevention |
| triggers | ["security","auth","authentication","authorization","OWASP","vulnerability","encryption","secure","XSS","CSRF","SQL injection"] |
| version | 1.0.0 |
| agents | ["security-specialist","senior-fullstack-developer","qa-testing-engineer"] |
| context_levels | {"minimal":"Critical security rules and quick checklist","detailed":"OWASP Top 10 and implementation patterns","full":"Security scanning scripts and remediation guides"} |
Security Essentials Skill
Overview
This skill provides comprehensive security guidance following OWASP standards and industry best practices. It ensures secure code development and vulnerability prevention.
When to Use This Skill
- Implementing authentication/authorization
- Handling sensitive user data
- Security reviews before production
- API security hardening
- Compliance requirements (GDPR, SOC2)
- Vulnerability remediation
Critical Security Rules (Level 1 - Always Loaded)
🔴 MUST Requirements
SEC-1: Input Validation (CRITICAL)
import { z } from 'zod';
const userSchema = z.object({
email: z.string().email().max(255),
password: z.string().min(8).max(128),
name: z.string().min(1).max(100).regex(/^[a-zA-Z\s]+$/),
});
function createUser(input: unknown) {
const validated = userSchema.parse(input);
return userService.create(validated);
}
function createUser(input: any) {
return userService.create(input);
}
SEC-2: Output Sanitization (CRITICAL)
import DOMPurify from 'isomorphic-dompurify';
function displayUserContent(html: string) {
const clean = DOMPurify.sanitize(html, {
ALLOWED_TAGS: ['p', 'br', 'strong', 'em'],
ALLOWED_ATTR: []
});
return <div dangerouslySetInnerHTML={{ __html: clean }} />;
}
function displayUserContent(html: string) {
return <div dangerouslySetInnerHTML={{ __html: html }} />;
}
SEC-3: Secrets Management (CRITICAL)
const config = {
apiKey: process.env.API_KEY,
dbPassword: process.env.DB_PASSWORD,
jwtSecret: process.env.JWT_SECRET,
};
if (!config.apiKey || !config.dbPassword || !config.jwtSecret) {
throw new Error('Missing required environment variables');
}
const config = {
apiKey: 'sk-1234567890abcdef',
dbPassword: 'admin123',
jwtSecret: 'my-secret-key',
};
SEC-4: Never Log Sensitive Data (CRITICAL)
logger.info('User login attempt', {
userId: user.id,
email: user.email,
});
logger.info('User login', {
email: user.email,
password: user.password,
creditCard: user.creditCard,
});
SEC-5: Authentication Best Practices
import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
async function hashPassword(password: string): Promise<string> {
const saltRounds = 12;
return bcrypt.hash(password, saltRounds);
}
async function verifyPassword(password: string, hash: string): Promise<boolean> {
return bcrypt.compare(password, hash);
}
function generateToken(userId: string): string {
return jwt.sign(
{ userId },
process.env.JWT_SECRET!,
{
expiresIn: '1h',
algorithm: 'HS256',
}
);
}
function savePassword(password: string) {
db.(, [password]);
}
SEC-6: SQL Injection Prevention
async function getUserByEmail(email: string) {
return db.query(
'SELECT * FROM users WHERE email = $1',
[email]
);
}
async function getUserByEmail(email: string) {
return db.query(
`SELECT * FROM users WHERE email = '${email}'`
);
}
SEC-7: CSRF Protection
import csrf from 'csurf';
import cookieParser from 'cookie-parser';
app.use(cookieParser());
app.use(csrf({ cookie: true }));
app.get('/form', (req, res) => {
res.render('form', { csrfToken: req.csrfToken() });
});
app.post('/submit', (req, res) => {
res.send('Data processed');
});
SEC-8: Secure Headers
import helmet from 'helmet';
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "'unsafe-inline'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", "data:", "https:"],
},
},
hsts: {
maxAge: 31536000,
includeSubDomains: true,
preload: true,
},
}));
app.use(session({
secret: process.env.SESSION_SECRET!,
cookie: {
secure: true,
httpOnly: true,
sameSite: 'strict',
maxAge: 3600000,
},
}));
Security Checklist (Quick Reference)
Before deploying to production:
OWASP Top 10 Quick Reference
- Broken Access Control → Implement proper authorization checks
- Cryptographic Failures → Use strong encryption, TLS everywhere
- Injection → Parameterized queries, input validation
- Insecure Design → Security by design, threat modeling
- Security Misconfiguration → Secure defaults, minimal permissions
- Vulnerable Components → Keep dependencies updated
- Authentication Failures → MFA, secure session management
- Data Integrity Failures → Verify data integrity, use signatures
- Logging Failures → Log security events, protect logs
- SSRF → Validate URLs, whitelist allowed domains
Detailed Patterns (Level 2 - Load on Request)
See companion files:
owasp-guide.md - Detailed OWASP Top 10 implementations
auth-patterns.md - JWT, OAuth2, MFA implementations
encryption-guide.md - Encryption at rest and in transit
Security Tools (Level 3 - Load When Needed)
See scripts directory:
scripts/security-scan.sh - Run comprehensive security scan
scripts/dependency-check.sh - Check for vulnerable dependencies
scripts/secret-scan.sh - Scan for exposed secrets
Integration with Agents
security-specialist:
- Primary agent for security reviews
- Uses this skill for all security assessments
- Read-only access (no code modification)
senior-fullstack-developer:
- Uses this skill when implementing auth/security features
- References patterns for secure implementation
qa-testing-engineer:
- Uses this skill for security test cases
- Validates against security checklist
Common Vulnerabilities & Fixes
XSS (Cross-Site Scripting)
function renderHTML(userInput: string) {
document.innerHTML = userInput;
}
import DOMPurify from 'isomorphic-dompurify';
function renderHTML(userInput: string) {
const clean = DOMPurify.sanitize(userInput);
document.innerHTML = clean;
}
Path Traversal
app.get('/file/:filename', (req, res) => {
const file = path.join(__dirname, req.params.filename);
res.sendFile(file);
});
app.get('/file/:filename', (req, res) => {
const filename = path.basename(req.params.filename);
const file = path.join(__dirname, 'uploads', filename);
if (!file.startsWith(path.join(__dirname, 'uploads'))) {
return res.status(403).send('Forbidden');
}
res.sendFile(file);
});
NoSQL Injection
function findUser(username: string) {
return db.users.findOne({ username });
}
function findUser(username: string) {
if (typeof username !== 'string') {
throw new ValidationError('Username must be a string');
}
return db.users.findOne({ username });
}
Emergency Response
If a security vulnerability is discovered:
- Contain: Disable affected feature if critical
- Assess: Determine scope and impact
- Fix: Apply patch immediately
- Test: Verify fix doesn't break functionality
- Deploy: Emergency deployment with monitoring
- Notify: Inform stakeholders if data breach
- Postmortem: Document incident and prevention
Version 1.0.0 | OWASP Top 10 Compliant | GDPR Aware