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/05-rate-limit.sh

View on GitHub
#!/usr/bin/env bash
# Phase 4 — Rate limiting probes (HTTP only; for k6 load see 05-burst.k6.js).
# Tests: basic burst hits 429, X-Forwarded-For rotation bypass, login brute-force protection.
#
# Reads:
#   TARGET
#   RATE_PATH   (default /api/data)
#   RATE_LIMIT  (default 100)             — expected req/min limit on RATE_PATH
#   LOGIN_PATH  (default /auth/login)
#   LOGIN_FIELD_USER (default email)
#   LOGIN_FIELD_PASS (default password)
#   TOKEN (optional)
# 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

RATE_PATH="${RATE_PATH:-/api/data}"
RATE_LIMIT="${RATE_LIMIT:-100}"
LOGIN_PATH="${LOGIN_PATH:-/auth/login}"
LOGIN_FIELD_USER="${LOGIN_FIELD_USER:-email}"
LOGIN_FIELD_PASS="${LOGIN_FIELD_PASS:-password}"

AUTH_HEADERS=()
if [ -n "${TOKEN:-}" ]; then
  AUTH_HEADERS=(-H "Authorization: Bearer $TOKEN")
fi

# Cap at 200 requests so probes finish in reasonable time even when limits are high
BURST_TOTAL=$((RATE_LIMIT + 5))
if [ "$BURST_TOTAL" -gt 200 ]; then BURST_TOTAL=200; fi

# ---------------------------------------------------------------------------
# Check 1 — Basic burst should yield at least one 429
# ---------------------------------------------------------------------------
log_info "Burst test: $BURST_TOTAL requests to $RATE_PATH..."
got_429=0
got_200=0
last_status=""
for i in $(seq 1 "$BURST_TOTAL"); do
  result=$(http_request GET "$RATE_PATH" "${AUTH_HEADERS[@]}" --max-time 5 || true)
  last_status="${result%% *}"
  case "$last_status" in
    429) got_429=$((got_429 + 1)) ;;
    200) got_200=$((got_200 + 1)) ;;
  esac
done

if [ "$got_429" = "0" ] && [ "$got_200" -gt "$RATE_LIMIT" ]; then
  evidence=$(build_evidence \
    "burst_total=$BURST_TOTAL" \
    "got_200=$got_200" \
    "got_429=$got_429" \
    "expected_limit=$RATE_LIMIT" \
    "path=$RATE_PATH")
  emit_finding \
    "RATE-001" "high" "API4:2023 Unrestricted Resource Consumption" \
    "GET $RATE_PATH" \
    "Sent $BURST_TOTAL requests, received $got_200 successful responses and zero 429s — rate limiting absent or misconfigured." \
    "Add a rate-limit middleware (sliding window for auth, token bucket for general). Recommended thresholds: ≤100/min for general API, ≤5/15min for auth." \
    "$evidence"
fi

# ---------------------------------------------------------------------------
# Check 2 — X-Forwarded-For rotation should NOT reset the limit
# ---------------------------------------------------------------------------
log_info "X-Forwarded-For bypass test on $RATE_PATH..."
spoofed_429=0
for i in $(seq 1 50); do
  result=$(http_request GET "$RATE_PATH" \
    "${AUTH_HEADERS[@]}" \
    -H "X-Forwarded-For: 10.99.0.$((i % 250 + 1))" \
    --max-time 5 || true)
  last_status="${result%% *}"
  if [ "$last_status" = "429" ]; then
    spoofed_429=$((spoofed_429 + 1))
  fi
done

# If the previous burst reached 429 but spoofed IPs still hit 200 only, that proves bypass
if [ "$got_429" -gt 0 ] && [ "$spoofed_429" = "0" ]; then
  evidence=$(build_evidence \
    "spoofed_requests=50" \
    "spoofed_429s=$spoofed_429" \
    "previous_burst_429s=$got_429" \
    "path=$RATE_PATH")
  emit_finding \
    "RATE-002" "high" "API4:2023 + API8:2023 Misconfiguration" \
    "GET $RATE_PATH (X-Forwarded-For rotation)" \
    "Rate limit can be bypassed by rotating the X-Forwarded-For header — server is using forwarded IP without trust validation." \
    "Trust X-Forwarded-For only when behind a known reverse proxy. Use the real connection remote IP, or validate the chain against a trusted proxy list." \
    "$evidence"
fi

# ---------------------------------------------------------------------------
# Check 3 — Auth endpoint brute-force protection
# ---------------------------------------------------------------------------
log_info "Brute-force probe on $LOGIN_PATH (10 wrong passwords)..."
brute_429=0
for i in $(seq 1 10); do
  payload=$(python3 -c "
import json,sys
print(json.dumps({sys.argv[1]: 'sec-probe@example.com', sys.argv[2]: f'wrong_pw_{sys.argv[3]}'}))
" "$LOGIN_FIELD_USER" "$LOGIN_FIELD_PASS" "$i")
  result=$(http_request POST "$LOGIN_PATH" \
    -H "Content-Type: application/json" \
    --data "$payload" \
    --max-time 5 || true)
  last_status="${result%% *}"
  if [ "$last_status" = "429" ]; then
    brute_429=$((brute_429 + 1))
  fi
done

if [ "$brute_429" = "0" ]; then
  evidence=$(build_evidence \
    "attempts=10" \
    "got_429=$brute_429" \
    "path=$LOGIN_PATH")
  emit_finding \
    "RATE-003" "high" "API4:2023 + API2:2023 Broken Auth" \
    "POST $LOGIN_PATH" \
    "10 failed login attempts produced zero 429s — endpoint lacks brute-force protection. Credential stuffing and password spraying are not mitigated." \
    "Apply strict per-account and per-IP rate limits on auth endpoints (e.g. 5 attempts per 15 minutes). Combine with account lockout, MFA, or CAPTCHA after threshold." \
    "$evidence"
fi

log_ok "Rate limit 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