Skip to content
Development
Command

/security-audit

Run comprehensive security audit on codebase

From plugin
claude-plugin-prd-workflow
1227 skills17 agents27 commands

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/security-audit

Context preview

What this command does when you run it.

Run comprehensive security audit on codebase

Command definition

security-audit.md
name: security-audit
description: Run comprehensive security audit on codebase
category: Security & Quality

Security Audit Command

Perform comprehensive security analysis using multiple tools and best practices.

Purpose

Detect security vulnerabilities before they reach production:

  • Dependency vulnerabilities (npm audit)
  • Code security issues (ESLint security rules)
  • Hardcoded secrets (git-secrets, pattern matching)
  • Common vulnerability patterns (XSS, SQL injection, etc.)
  • Security best practices compliance

Workflow

Step 1: Determine Scope

Ask user or auto-detect:

๐Ÿ”’ **Security Audit**

Scope options:
1. ๐ŸŽฏ Current PRD (feat/PRD-003-design-system)
2. ๐Ÿ“ฆ Entire codebase
3. ๐Ÿ“‚ Specific directory

Select scope: (1-3)

Step 2: Dependency Scanning

Run npm/yarn audit:

npm audit --json > .claude/security-audit-deps.json
npm audit

Parse results:

  • Critical vulnerabilities
  • High severity issues
  • Moderate/low issues
  • Recommended fixes

Step 3: Code Security Analysis

Run ESLint with security plugins:

npx eslint . \
  --ext .js,.jsx,.ts,.tsx \
  --config .eslintrc.security.json \
  --format json > .claude/security-audit-code.json

Check for:

  • `eval()` usage
  • `dangerouslySetInnerHTML` without sanitization
  • Unvalidated redirects
  • Hardcoded credentials patterns
  • Unsafe RegExp
  • Prototype pollution vectors

Step 4: Secret Detection

Scan for hardcoded secrets:

# Pattern-based detection
grep -r -E "(api[_-]?key|password|secret|token)[\s]*=[\s]*['\"][^'\"]+['\"]" \
  --include="*.ts" --include="*.js" --include="*.tsx" --include="*.jsx" \
  --exclude-dir=node_modules \
  --exclude-dir=.git \
  .

Common patterns to detect:

  • API keys
  • Database passwords
  • JWT secrets
  • AWS credentials
  • Private keys

Step 5: Security Best Practices Check

Validate:

  • **Environment Variables**: Sensitive data in `.env` files?
  • **.gitignore**: Are `.env`, `credentials.json`, etc. ignored?
  • **HTTPS**: Are external API calls using HTTPS?
  • **Input Validation**: Are user inputs validated?
  • **Authentication**: Proper auth implementation?
  • **CORS**: Properly configured?

Step 6: Generate Security Report

๐Ÿ”’ **Security Audit Report - PRD-003: Design System**

**Date**: 2025-10-25
**Scope**: feat/PRD-003-design-system branch
**Duration**: 45 seconds

---

## ๐Ÿšจ Critical Issues (0)

โœ… No critical vulnerabilities found

---

## โš ๏ธ High Severity (2)

### 1. Dependency Vulnerability: lodash@4.17.20
- **Severity**: High
- **CVE**: CVE-2021-23337
- **Impact**: Prototype pollution
- **Affected**: `packages/ui/package.json`
- **Fix**: `npm install lodash@4.17.21`

### 2. Hardcoded API URL
- **File**: `packages/ui/src/utils/api.ts:12`
- **Issue**: Hardcoded production API URL
- **Risk**: Exposed internal endpoint
- **Fix**: Move to environment variable

```typescript
// โŒ Current (line 12)
const API_URL = "https://internal-api.acmecorp.com/v1";

// โœ… Recommended
const API_URL = process.env.NEXT_PUBLIC_API_URL;

---

โšก Medium Severity (3)

3. Missing Input Sanitization

  • **File**: `packages/ui/src/components/Input.tsx:45`
  • **Issue**: User input not sanitized before rendering
  • **Risk**: XSS vulnerability
  • **Fix**: Use DOMPurify or escape HTML

4. Weak Password Validation

  • **File**: `apps/web/src/utils/validation.ts:23`
  • **Issue**: Password regex allows weak passwords
  • **Fix**: Enforce min 12 chars, special chars, numbers

5. CORS Wildcard

  • **File**: `apps/api/src/middleware/cors.ts:8`
  • **Issue**: `Access-Control-Allow-Origin: *`
  • **Risk**: Any domain can access API
  • **Fix**: Whitelist specific domains

---

โ„น๏ธ Low Severity (5)

  • Missing security headers (X-Frame-Options, CSP)
  • Console.log statements in production build
  • Overly permissive file permissions
  • Missing rate limiting
  • No CSRF protection

---

โœ… Best Practices Compliance

| Category | Status | Notes | |----------|--------|-------| | Secrets Management | โš ๏ธ Partial | Some hardcoded values found | | HTTPS Enforcement | โœ… Pass | All external calls use HTTPS | | Input Validation | โš ๏ธ Partial | Missing in 3 components | | Authentication | โœ… Pass | JWT properly implemented | | Authorization | โœ… Pass | RBAC correctly applied | | Error Handling | โœ… Pass | No sensitive data in errors | | Dependency Updates | โš ๏ธ Needs Update | 2 high-severity deps |

---

๐Ÿ“Š Summary

  • **Critical**: 0 โŒ
  • **High**: 2 ๐Ÿ”ด
  • **Medium**: 3 ๐ŸŸก
  • **Low**: 5 ๐Ÿ”ต
  • **Total**: 10 issues

**Overall Grade**: B- (needs improvement)

**Action Required**: Fix 2 high-severity issues before PR merge

---

๐Ÿ› ๏ธ Recommended Actions

Immediate (Block PR)

1. โœ… Update lodash to 4.17.21: `npm install lodash@4.17.21` 2. โœ… Move API_URL to environment variable

Before Production

3. Add input sanitization to Input component 4. Strengthen password validation 5. Restrict CORS to specific domains

Nice to Have

6. Add security headers 7. Remove console.logs from production 8. Implement rate limiting 9. Add CSRF tokens

---

๐Ÿ”ง Auto-Fix Available

Would you like me to fix the high-severity issues automatically? (Y/n)


### Step 7: Offer Auto-Fix

If user approves, automatically fix:
- Update vulnerable dependencies
- Move hardcoded values to `.env`
- Add basic sanitization
- Update `.gitignore` if needed

Commit changes:
```bash
git add .
git commit -m "security: Fix high-severity vulnerabilities

- Updated lodash to 4.17.21 (CVE-2021-23337)
- Moved hardcoded API URL to environment variable
- Added input sanitization to Input component

๐Ÿค– Generated by /security-audit"

Step 8: Save Report

Save to `.claude/security-audit-{date}.md` for historical tracking.

Configuration

Uses these config settings:

{
  "security": {
    "enabled": true,
    "scan_dependencies": true,
    "scan_code": true,
    "fail_on_high_severity": true,
    "ignore_patterns": [
      "**/node_modules/**",
      "**/dist/**"
    ],
    "tools": {
      "npm_au
Read more
Ships withclaude-plugin-prd-workflow

The complete Claude Code plugin for Product-Driven Development Transform PRDs from ideas to shipped features with AI-powered review, guided implementation, and automated quality gates. Never ship unclear requirements again.

Get the whole plugin

Other commands on claude-plugin-prd-workflow.