@'
name: security-audit
description: Audits codebases for security vulnerabilities, secrets exposure, auth risks, dependency health, and misconfigurations.
version: 1.0.0
author: software-engineering
tags: [security, audit, devsecops, claude-code]
Security Audit Skill
Execute a comprehensive, end-to-end security audit on the current codebase. Inspect source code, configurations, dependencies, and environment files to identify and remediate security vulnerabilities across 19 critical checkpoints.
🎯 Scope & Objectives
When invoked (/security-audit or when asked to perform a security check), analyze the repository against the following 6 domain modules:
Module 1: Dependencies & Package Health
- Remove Unused Packages: Identify unused npm, pip, go, or cargo dependencies and propose removal.
- Update Dependencies: Scan for out-of-date or vulnerable package versions (
npm audit, pip-audit, cargo audit, or equivalent).
Module 2: Secrets & Environment Management
- Check Git for Secrets: Scan commit history and stage area for hardcoded keys, JWT secrets, passwords, or tokens using tools like
trufflehog or regex pattern matching.
- Hide API Keys: Verify that external API keys are excluded from source control and loaded strictly via environment variables.
- Check Environment Variables: Audit
.env.example templates to ensure sensitive defaults are not checked into Git, and verify proper runtime validation of required .env keys.
- Check Exposed Files: Ensure sensitive files (
.env, .pem, .key, id_rsa, .DS_Store, database dumps, build artifacts) are properly listed in .gitignore.
Module 3: Authentication & Access Control
- Proper Authentication: Verify session management, token handling (HTTP-only cookies vs. local storage), and token expiration/invalidation strategies.
- Hash Passwords Properly: Ensure password hashing uses strong, modern algorithms (e.g., Argon2id, bcrypt with cost factor ≥12, scrypt) with appropriate salts—never plain SHA-256 or MD5.
- Check User Access: Audit Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC) implementation across authorization middleware.
- Protect Admin Routes: Verify that privileged routes and endpoints require explicitly validated administrator scopes/roles and cannot be bypassed via parameter tampering.
Module 4: API & Endpoint Protection
- Secure API Endpoints: Ensure all public/private endpoints validate authorization headers, enforce proper HTTP verbs, and avoid mass assignment vulnerabilities.
- Add Rate Limiting: Verify rate-limiting middleware is applied to sensitive endpoints (login, password reset, public APIs, payment routes) to prevent brute-force and DoS attacks.
- Check CORS Settings: Inspect Cross-Origin Resource Sharing configurations to ensure wildcard origins (
*) are prohibited in production setups with credentials.
- Secure DB Access: Check for parameterized queries / ORM usage to prevent SQL/NoSQL injection, and verify database connection strings use SSL/TLS with least-privilege accounts.
Module 5: Input Handling & Frontend Security
- Sanitize Forms: Ensure all user inputs undergo strict server-side validation and sanitization.
- Protect Against XSS: Audit template engines, React/Vue/Svelte renders, and HTML outputs to ensure proper contextual escaping and absence of unsafe functions (e.g.,
dangerouslySetInnerHTML, eval(), innerHTML).
Module 6: System Configuration & Hardening
- Disable Debug Mode: Verify debug flags, detailed stack traces, and verbose logging are disabled for production builds.
- Add Security Headers: Ensure defensive HTTP response headers are set (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy).
- Full Security Audit Integration: Synthesize findings across all 18 rules into a consolidated risk matrix with clear severity scores (Critical, High, Medium, Low).
🛠️ Execution Instructions for Claude Code
When executing this skill:
Information Gathering:
- Scan package manifests (
package.json, requirements.txt, Cargo.toml, go.mod, pom.xml).
- Inspect build configurations,
.gitignore, .env templates, server entry points, and routing files.
- Run native package vulnerability commands if accessible (e.g.,
npm audit --json).
Codebase Inspection:
- Run pattern-matching scans for credentials and secrets across the workspace.
- Trace authentication workflows, route protection middleware, and database queries.
- Audit response headers and application settings.
Report Generation:
- Group findings by severity (Critical, High, Medium, Low).
- Provide concrete code references (
file_path:line_number).
- Deliver actionable code patches and remediation commands for every identified vulnerability.
📋 Output Format
Format the audit output using the following markdown structure:
# 🛡️ Security Audit Findings
## Executive Summary
- **Total Issues Found:** X
- **Risk Breakdown:** 🔴 Critical: A | 🟠 High: B | 🟡 Medium: C | 🟢 Low: D
---
## 🔴 Critical & High Vulnerabilities
### 1. [Vulnerability Title]
- **Category:** [e.g., Secrets Exposure / Module 2]
- **File:** `path/to/file.ext:42`
- **Impact:** [Brief description of real-world exploitation risk]
- **Current Code:**
```language
// Problematic snippet
1---2name: security-audit-23description: @'4---5@'6---7name: security-audit8description: Audits codebases for security vulnerabilities, secrets exposure, auth risks, dependency health, and misconfigurations.9version: 1.0.010author: software-engineering11tags: [security, audit, devsecops, claude-code]12---1314# Security Audit Skill1516Execute a comprehensive, end-to-end security audit on the current codebase. Inspect source code, configurations, dependencies, and environment files to identify and remediate security vulnerabilities across 19 critical checkpoints.1718---1920## 🎯 Scope & Objectives2122When invoked (`/security-audit` or when asked to perform a security check), analyze the repository against the following 6 domain modules:2324### Module 1: Dependencies & Package Health251. **Remove Unused Packages:** Identify unused npm, pip, go, or cargo dependencies and propose removal.262. **Update Dependencies:** Scan for out-of-date or vulnerable package versions (`npm audit`, `pip-audit`, `cargo audit`, or equivalent).2728### Module 2: Secrets & Environment Management293. **Check Git for Secrets:** Scan commit history and stage area for hardcoded keys, JWT secrets, passwords, or tokens using tools like `trufflehog` or regex pattern matching.304. **Hide API Keys:** Verify that external API keys are excluded from source control and loaded strictly via environment variables.315. **Check Environment Variables:** Audit `.env.example` templates to ensure sensitive defaults are not checked into Git, and verify proper runtime validation of required `.env` keys.326. **Check Exposed Files:** Ensure sensitive files (`.env`, `.pem`, `.key`, `id_rsa`, `.DS_Store`, database dumps, build artifacts) are properly listed in `.gitignore`.3334### Module 3: Authentication & Access Control357. **Proper Authentication:** Verify session management, token handling (HTTP-only cookies vs. local storage), and token expiration/invalidation strategies.368. **Hash Passwords Properly:** Ensure password hashing uses strong, modern algorithms (e.g., Argon2id, bcrypt with cost factor ≥12, scrypt) with appropriate salts—never plain SHA-256 or MD5.379. **Check User Access:** Audit Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC) implementation across authorization middleware.3810. **Protect Admin Routes:** Verify that privileged routes and endpoints require explicitly validated administrator scopes/roles and cannot be bypassed via parameter tampering.3940### Module 4: API & Endpoint Protection4111. **Secure API Endpoints:** Ensure all public/private endpoints validate authorization headers, enforce proper HTTP verbs, and avoid mass assignment vulnerabilities.4212. **Add Rate Limiting:** Verify rate-limiting middleware is applied to sensitive endpoints (login, password reset, public APIs, payment routes) to prevent brute-force and DoS attacks.4313. **Check CORS Settings:** Inspect Cross-Origin Resource Sharing configurations to ensure wildcard origins (`*`) are prohibited in production setups with credentials.4414. **Secure DB Access:** Check for parameterized queries / ORM usage to prevent SQL/NoSQL injection, and verify database connection strings use SSL/TLS with least-privilege accounts.4546### Module 5: Input Handling & Frontend Security4715. **Sanitize Forms:** Ensure all user inputs undergo strict server-side validation and sanitization.4816. **Protect Against XSS:** Audit template engines, React/Vue/Svelte renders, and HTML outputs to ensure proper contextual escaping and absence of unsafe functions (e.g., `dangerouslySetInnerHTML`, `eval()`, `innerHTML`).4950### Module 6: System Configuration & Hardening5117. **Disable Debug Mode:** Verify debug flags, detailed stack traces, and verbose logging are disabled for production builds.5218. **Add Security Headers:** Ensure defensive HTTP response headers are set (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy).5319. **Full Security Audit Integration:** Synthesize findings across all 18 rules into a consolidated risk matrix with clear severity scores (Critical, High, Medium, Low).5455---5657## 🛠️ Execution Instructions for Claude Code5859When executing this skill:60611. **Information Gathering:**62 - Scan package manifests (`package.json`, `requirements.txt`, `Cargo.toml`, `go.mod`, `pom.xml`).63 - Inspect build configurations, `.gitignore`, `.env` templates, server entry points, and routing files.64 - Run native package vulnerability commands if accessible (e.g., `npm audit --json`).65662. **Codebase Inspection:**67 - Run pattern-matching scans for credentials and secrets across the workspace.68 - Trace authentication workflows, route protection middleware, and database queries.69 - Audit response headers and application settings.70713. **Report Generation:**72 - Group findings by severity (Critical, High, Medium, Low).73 - Provide concrete code references (`file_path:line_number`).74 - Deliver actionable code patches and remediation commands for every identified vulnerability.7576---7778## 📋 Output Format7980Format the audit output using the following markdown structure:8182```markdown83# 🛡️ Security Audit Findings8485## Executive Summary86- **Total Issues Found:** X87- **Risk Breakdown:** 🔴 Critical: A | 🟠 High: B | 🟡 Medium: C | 🟢 Low: D8889---9091## 🔴 Critical & High Vulnerabilities9293### 1. [Vulnerability Title]94- **Category:** [e.g., Secrets Exposure / Module 2]95- **File:** `path/to/file.ext:42`96- **Impact:** [Brief description of real-world exploitation risk]97- **Current Code:**98 ```language99 // Problematic snippet