version: 1
kind: action
name: Security Check
description: Basic security audit and vulnerability scanning
prompt: |
  Perform comprehensive security audits including dependency scanning and vulnerability detection.
  Scan for known security issues in code and validate configurations.
  Provide actionable recommendations with prioritized remediation steps.
  Generate detailed security reports for ensuring security best practices.
enhanced-prompt: |-
  # 🔒 Security Audit Workflow

  ## Dependency Vulnerability Scan
  ```bash
  # Run npm security audit
  npm audit --json > audit-report.json

  # Check critical and high vulnerabilities
  CRITICAL=$(cat audit-report.json | jq '.metadata.vulnerabilities.critical // 0')
  HIGH=$(cat audit-report.json | jq '.metadata.vulnerabilities.high // 0')

  echo "Critical vulnerabilities: $CRITICAL"
  echo "High vulnerabilities: $HIGH"

  # Auto-fix if possible
  npm audit fix
  ```

  ## Code Security Pattern Analysis
  ```bash
  # Scan for hardcoded secrets
  grep -r "password\|secret\|key\|token" --include="*.js" --include="*.ts" src/

  # Check for SQL injection patterns
  grep -r "SELECT.*+\|INSERT.*+" --include="*.js" --include="*.ts" src/

  # Detect XSS vulnerabilities
  grep -r "innerHTML\|document.write\|eval" --include="*.js" --include="*.ts" src/

  # Find insecure HTTP usage
  grep -r "http://" --exclude-dir=node_modules .
  ```

  ## Configuration Security Review
  ```bash
  # Check environment file protection
  if [ -f ".env" ]; then
    grep -q "\.env" .gitignore || echo "WARNING: .env not in .gitignore"
  fi

  # Validate package.json security
  grep -q "sudo\|postinstall" package.json && echo "WARNING: Potentially unsafe scripts"

  # Docker security check
  if [ -f "Dockerfile" ]; then
    grep -q "USER" Dockerfile || echo "WARNING: Running as root user"
  fi
  ```

  ## Security Middleware Validation
  ```bash
  # Check for security packages
  grep -q "helmet" package.json && echo "✅ Security headers configured"
  grep -q "cors" package.json && echo "✅ CORS configured"
  grep -q "rate-limit" package.json && echo "✅ Rate limiting configured"
  ```

  **🎯 Result:** Comprehensive security assessment with prioritized remediation recommendations
