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/08-cors-headers.sh

View on GitHub
#!/usr/bin/env bash
# Phase 7 — CORS & security headers.
# Tests: arbitrary-Origin reflection, wildcard + credentials misconfiguration,
#        presence of HSTS/X-Content-Type-Options/X-Frame-Options/CSP/Referrer-Policy.
#
# Reads:
#   TARGET
#   ORIGIN_ALLOWED (optional) — origin that *should* be reflected (for sanity check)
#   PROBE_PATH     (default /)
# Writes: out/findings.jsonl

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

require_env TARGET
PROBE_PATH="${PROBE_PATH:-/}"
EVIL_ORIGIN="https://evil.example.com"

# ---------------------------------------------------------------------------
# Helper — extract a header value (case-insensitive) from $RESP_HEADERS
# ---------------------------------------------------------------------------
header_value() {
  local name="$1"
  awk -v IGNORECASE=1 -v h="^${name}:" '
    $0 ~ h {
      sub(/^[^:]+:[[:space:]]*/, "", $0)
      sub(/\r$/, "", $0)
      print
      exit
    }
  ' "$RESP_HEADERS"
}

# ---------------------------------------------------------------------------
# Check 1 — Arbitrary Origin reflection
# ---------------------------------------------------------------------------
log_info "CORS reflection probe with Origin: $EVIL_ORIGIN ..."
http_request GET "$PROBE_PATH" \
  -H "Origin: $EVIL_ORIGIN" \
  --max-time 10 >/dev/null || true

allow_origin=$(header_value "access-control-allow-origin")
allow_credentials=$(header_value "access-control-allow-credentials")

if [ "$allow_origin" = "$EVIL_ORIGIN" ]; then
  evidence=$(build_evidence \
    "sent_origin=$EVIL_ORIGIN" \
    "access_control_allow_origin=$allow_origin" \
    "access_control_allow_credentials=$allow_credentials" \
    "path=$PROBE_PATH")
  if [ "${allow_credentials,,}" = "true" ]; then
    sev="critical"
    impact="Server reflects arbitrary Origin AND allows credentials — any malicious site can read authenticated responses cross-origin."
  else
    sev="high"
    impact="Server reflects arbitrary Origin in Access-Control-Allow-Origin — defeats the CORS-based isolation model."
  fi
  emit_finding \
    "CORS-001" "$sev" "API8:2023 Security Misconfiguration" \
    "GET $PROBE_PATH (Origin: $EVIL_ORIGIN)" \
    "$impact" \
    "Validate Origin against an explicit allowlist; never reflect untrusted values. If credentials must be allowed, the allowlist must be strict (no wildcard, no regex with .*)." \
    "$evidence"
fi

# ---------------------------------------------------------------------------
# Check 2 — Wildcard + credentials combination
# ---------------------------------------------------------------------------
http_request GET "$PROBE_PATH" \
  -H "Origin: $EVIL_ORIGIN" \
  --max-time 10 >/dev/null || true

allow_origin=$(header_value "access-control-allow-origin")
allow_credentials=$(header_value "access-control-allow-credentials")

if [ "$allow_origin" = "*" ] && [ "${allow_credentials,,}" = "true" ]; then
  evidence=$(build_evidence \
    "access_control_allow_origin=*" \
    "access_control_allow_credentials=true" \
    "path=$PROBE_PATH")
  emit_finding \
    "CORS-002" "critical" "API8:2023 + CVE-2025-34291 class" \
    "GET $PROBE_PATH" \
    "Server returns Access-Control-Allow-Origin: * AND Access-Control-Allow-Credentials: true — combination is forbidden by the CORS spec but is honored by some HTTP clients (curl, httpx), enabling SSRF and data exfiltration vectors." \
    "Use an explicit allowlist when credentials=true. Never combine wildcard origins with credentials." \
    "$evidence"
fi

# ---------------------------------------------------------------------------
# Check 3 — Required security headers
# ---------------------------------------------------------------------------
log_info "Security headers checklist on $PROBE_PATH..."
http_request GET "$PROBE_PATH" --max-time 10 >/dev/null || true

declare -a required_headers=(
  "strict-transport-security|HSTS|max-age|HSTS-001"
  "x-content-type-options|nosniff|nosniff|HEADER-001"
  "x-frame-options|DENY or SAMEORIGIN|DENY,SAMEORIGIN|HEADER-002"
  "content-security-policy|CSP|default-src|HEADER-003"
  "referrer-policy|Referrer-Policy|origin,no-referrer,strict-origin|HEADER-004"
)

for entry in "${required_headers[@]}"; do
  IFS='|' read -r name pretty expected_pat finding_id <<< "$entry"
  value=$(header_value "$name")
  if [ -z "$value" ]; then
    evidence=$(build_evidence "header=$name" "found=" "expected=$pretty" "path=$PROBE_PATH")
    emit_finding \
      "$finding_id" "low" "API8:2023 Security Misconfiguration" \
      "GET $PROBE_PATH" \
      "Required security header '$name' is missing. Browser-side defenses ($pretty) are not active." \
      "Set this header at the framework or reverse-proxy level." \
      "$evidence"
  else
    # Soft sanity: check that the value contains an expected substring
    matched=0
    IFS=',' read -ra patterns <<< "$expected_pat"
    for pat in "${patterns[@]}"; do
      if echo "$value" | grep -qiE "$pat"; then
        matched=1
        break
      fi
    done
    if [ "$matched" = "0" ]; then
      evidence=$(build_evidence "header=$name" "found=$value" "expected_contains=$expected_pat" "path=$PROBE_PATH")
      emit_finding \
        "${finding_id}-WEAK" "info" "API8:2023 Security Misconfiguration" \
        "GET $PROBE_PATH" \
        "Header '$name' is set ('$value') but value does not match expected pattern ($expected_pat) — review configuration." \
        "Confirm the header value matches OWASP / your security policy." \
        "$evidence"
    fi
  fi
done

log_ok "CORS / headers probes 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