Skip to content

Bruno-Cunha-Souza/ValarMindSkills / skills/code-security-review

code-security-review

Flagged

Web/API security lifecycle for Go, Next.js, Python, and Bun — design controls, active testing, supply-chain/CI-CD, and LLM/agentic/MCP coverage. Maps to OWASP Web Top 10 2025 + API 2023 + LLM 2025 + Agentic 2026. Triggers: 'security review', 'revisão de segurança', 'auditar segurança', 'pentest', '/code-security-review'.

FileKindSize
SKILL.mdskill md17.3 KB
references/AI_SECURITY.mdmarkdown9.5 KB
references/DESIGN_CONTROLS.mdmarkdown18.0 KB
references/REPORT_TEMPLATE.mdmarkdown2.6 KB
references/SUPPLY_CHAIN_CICD.mdmarkdown9.1 KB
references/TESTING_PHASES.mdmarkdown17.5 KB
references/WEB_VULNERABILITIES.mdmarkdown22.1 KB
references/golang/API.mdmarkdown27.6 KB
references/golang/MIDDLEWARE.mdmarkdown14.4 KB
references/golang/PATCHES.mdmarkdown15.0 KB
references/golang/TESTING_PAYLOADS.mdmarkdown10.9 KB
references/golang/VULNERABILITIES.mdmarkdown20.6 KB
references/nextjs/API.mdmarkdown38.5 KB
references/nextjs/CONFIGURATION.mdmarkdown15.7 KB
references/nextjs/PATCHES.mdmarkdown16.7 KB
references/nextjs/TESTING_PAYLOADS.mdmarkdown11.9 KB
references/nextjs/VULNERABILITIES.mdmarkdown35.7 KB
references/python/API.mdmarkdown36.0 KB
references/python/CONFIGURATION.mdmarkdown22.4 KB
references/python/PATCHES.mdmarkdown12.1 KB
references/python/TESTING_PAYLOADS.mdmarkdown12.8 KB
references/python/VULNERABILITIES.mdmarkdown28.1 KB
scripts/00-pre-checks.shexecutablescript3.7 KB
scripts/01-auth-probes.shexecutablescript5.4 KB
scripts/02-jwt-attacks.pyexecutablescript10.1 KB
scripts/03-bola-probes.shexecutablescript6.4 KB
scripts/04-injection-probes.shexecutablescript7.3 KB
scripts/05-burst.k6.jsscript1.9 KB
scripts/05-rate-limit.shexecutablescript5.0 KB
scripts/06-info-disclosure.shexecutablescript5.2 KB
scripts/07-supply-chain.shexecutablescript7.9 KB
scripts/08-cors-headers.shexecutablescript5.5 KB
scripts/09-cicd-workflows.shexecutablescript6.1 KB
scripts/10-secrets-scan.shexecutablescript5.2 KB
scripts/11-ai-llm-probes.shexecutablescript8.8 KB
scripts/README.mdmarkdown8.0 KB
scripts/lib/common.shscript4.8 KB
scripts/lib/report.pyscript5.4 KB
scripts/run-all.shexecutablescript4.8 KB

scripts/10-secrets-scan.sh

View on GitHub
#!/usr/bin/env bash
# Phase 9 — Secrets scan (static, no live target).
# Prefers gitleaks, then trufflehog (verified-only), then a regex fallback over tracked files.
#
# Reads:
#   PROJECT_ROOT (default $PWD)   — repo root to scan
# Writes: out/findings.jsonl
#
# No TARGET and no authorization gate — reads files only.
# Matched values are ALWAYS redacted (first 4 + last 4 chars) before being written.

set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
source "$SCRIPT_DIR/lib/common.sh"

PROJECT_ROOT="${PROJECT_ROOT:-$PWD}"
log_info "Secrets scan root: $PROJECT_ROOT"

# Redact a secret to first4…last4 (keeps it useless but greppable in context).
redact() {
  local s="$1" n
  n=${#s}
  if [ "$n" -le 8 ]; then printf '****'; else printf '%s…%s' "${s:0:4}" "${s: -4}"; fi
}

# ---------------------------------------------------------------------------
# Preferred: gitleaks (fast pattern scan over tree + history).
# ---------------------------------------------------------------------------
if command -v gitleaks >/dev/null 2>&1; then
  log_info "Running gitleaks..."
  report="$OUT_DIR/.gitleaks.json"
  if gitleaks detect --source "$PROJECT_ROOT" --no-banner \
       --report-format json --report-path "$report" >/dev/null 2>&1; then
    log_ok "gitleaks found no secrets."
  else
    n=0
    if [ -f "$report" ] && command -v python3 >/dev/null 2>&1; then
      n=$(python3 -c 'import json,sys;
try:
    d=json.load(open(sys.argv[1]));print(len(d) if isinstance(d,list) else 0)
except Exception:
    print(0)' "$report" 2>/dev/null || echo 0)
    fi
    emit_finding \
      "SECRETS-GL-001" "high" "A07:2025 Authentication Failures / CWE-798" \
      "$PROJECT_ROOT (gitleaks)" \
      "gitleaks detected $n potential committed secret(s). A leaked credential in git history stays exploitable until rotated, even if later removed." \
      "Rotate every exposed credential first, then purge it from history. Add a gitleaks pre-commit hook." \
      "$(build_evidence "tool=gitleaks" "count=$n" "report=$report")"
  fi
  log_ok "Secrets scan complete."
  exit 0
fi

# ---------------------------------------------------------------------------
# Second choice: trufflehog (verifies whether the credential is still live).
# ---------------------------------------------------------------------------
if command -v trufflehog >/dev/null 2>&1; then
  log_info "Running trufflehog (verified only)..."
  if out=$(trufflehog filesystem "$PROJECT_ROOT" --only-verified --json 2>/dev/null); then
    if [ -n "$out" ]; then
      n=$(printf '%s\n' "$out" | grep -c . || echo 0)
      emit_finding \
        "SECRETS-TH-001" "critical" "A07:2025 Authentication Failures / CWE-798" \
        "$PROJECT_ROOT (trufflehog)" \
        "trufflehog confirmed $n LIVE credential(s) — verified as still active against their provider. This is confirmed, exploitable exposure." \
        "Rotate immediately, then purge from history and audit for misuse." \
        "$(build_evidence "tool=trufflehog" "verified_count=$n")"
    else
      log_ok "trufflehog found no verified secrets."
    fi
  fi
  log_ok "Secrets scan complete."
  exit 0
fi

# ---------------------------------------------------------------------------
# Fallback: regex over tracked files only (never scans out/ or untracked junk).
# ---------------------------------------------------------------------------
log_warn "Neither gitleaks nor trufflehog installed — using regex fallback. (brew install gitleaks)"

if ! command -v git >/dev/null 2>&1 || ! git -C "$PROJECT_ROOT" rev-parse >/dev/null 2>&1; then
  log_warn "Not a git repo — regex fallback needs 'git ls-files'. Skipping."
  log_ok "Secrets scan complete."
  exit 0
fi

# Patterns: AWS key, GitHub token, Slack token, PEM private key, generic assignment.
declare -a PATTERNS=(
  'AKIA[0-9A-Z]{16}'
  'gh[pousr]_[A-Za-z0-9]{36}'
  'xox[baprs]-[A-Za-z0-9-]{10,}'
  '-----BEGIN [A-Z ]*PRIVATE KEY-----'
  '(api[_-]?key|secret|token|passwd|password)["'"'"' ]*[:=]["'"'"' ]*[A-Za-z0-9_\-]{20,}'
)

hits=0
sample=""
while IFS= read -r file; do
  [ -f "$PROJECT_ROOT/$file" ] || continue
  case "$file" in out/*|*.lock|*.min.js) continue ;; esac
  for pat in "${PATTERNS[@]}"; do
    while IFS= read -r m; do
      [ -n "$m" ] || continue
      hits=$((hits + 1))
      val="$(printf '%s' "$m" | grep -oiE "$pat" | head -n1)"
      [ -n "$sample" ] && sample="$sample; "
      sample="$sample$file:$(redact "$val")"
    done < <(grep -aoiE "$pat" "$PROJECT_ROOT/$file" 2>/dev/null | head -n 3)
  done
done < <(git -C "$PROJECT_ROOT" ls-files 2>/dev/null)

if [ "$hits" -gt 0 ]; then
  excerpt=$(printf '%s' "$sample" | head -c 600 | tr -d '\000-\031')
  emit_finding \
    "SECRETS-RX-001" "high" "A07:2025 Authentication Failures / CWE-798" \
    "$PROJECT_ROOT (regex fallback)" \
    "$hits high-entropy/secret-shaped string(s) found in tracked files. Heuristic — verify each (some may be examples/placeholders). Values are redacted in evidence." \
    "Confirm each match; rotate any real credential and move it to a secret store. Install gitleaks/trufflehog for higher-fidelity scanning." \
    "$(build_evidence "tool=regex" "hits=$hits" "sample=$excerpt")"
else
  log_ok "Regex fallback found no secret-shaped strings."
fi

log_ok "Secrets scan complete."
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall