| name | security-audit |
| description | Security best practices including CSP, XSS prevention, input validation, and secrets management. Use when reviewing security or hardening applications. |
🔒 Security Audit Skill
Security Checklist
Input Validation
Authentication
Secrets
XSS Prevention
❌ Vulnerable
element.innerHTML = userInput;
document.write(userInput);
✅ Safe
element.textContent = userInput;
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);
const policy = trustedTypes.createPolicy('safe', {
createHTML: (input) => DOMPurify.sanitize(input)
});
element.innerHTML = policy.createHTML(userInput);
Content Security Policy
Manifest V3
{
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
}
}
HTTP Header
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'
SQL Injection Prevention
❌ Vulnerable
const query = `SELECT * FROM users WHERE id = '${userId}'`;
✅ Safe (Parameterized)
const result = await db.query(
'SELECT * FROM users WHERE id = $1',
[userId]
);
cursor.execute('SELECT * FROM users WHERE id = %s', (user_id,))
Secrets Management
Environment Variables
API_KEY=sk-xxxx
DATABASE_URL=postgres://...
API_KEY=your-api-key-here
DATABASE_URL=your-database-url
Load in Code
require('dotenv').config();
const apiKey = process.env.API_KEY;
console.log('API Key:', apiKey);
Chrome Extension Security
Message Validation
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (!sender.tab || !sender.tab.url.includes('trusted-domain.com')) {
return;
}
if (typeof message.type !== 'string') {
return;
}
});
External Connections
{
"host_permissions": [
"https://api.tiktok.com/*"
]
}
Common Vulnerabilities
| Vuln | Prevention |
|---|
| XSS | textContent, Trusted Types |
| SQL Injection | Parameterized queries |
| CSRF | CSRF tokens, SameSite cookies |
| Secrets leak | Env vars, .gitignore |
| Open redirect | Validate redirect URLs |
🔍 Automated Vulnerability Scanning
NPM Audit
npm audit
npm audit fix
npm audit fix --force
npm audit --json > audit-report.json
Snyk
npm install -g snyk
snyk auth
snyk test
snyk monitor
OWASP Dependency-Check
docker run --rm -v $(pwd):/src owasp/dependency-check \
--scan /src --format HTML --out /src/report
📦 Dependency Audit
Check Outdated
npm outdated
npm ls --all
npx is-my-node-ok
Security Headers Check
curl -I https://example.com | grep -i security
curl -I https://example.com | grep -i x-content-type
curl -I https://example.com | grep -i x-frame-options
Automated CI Check
- name: Security Audit
run: |
npm audit --audit-level=high
npx snyk test --severity-threshold=high
Audit Checklist