#!/usr/bin/env bash # cors-wildcard-allowlist.sh — Audit 2026-05-10 CRIT-3 ratchet. # # middleware.CORSWildcard (formerly middleware.CORS) emits # Access-Control-Allow-Origin: * unconditionally, ignoring the operator's # CERTCTL_CORS_ORIGINS knob (CWE-942). It is ONLY safe to use on endpoints # that (a) carry no credentials and (b) must be reachable from any origin # (health probes, version probes, the GUI's pre-login auth-info probe). # # This guard greps for every middleware.CORSWildcard call site, extracts # the nearest preceding r.mux.Handle("…") route string, and asserts that # the route appears in the documented ALLOWLIST below. Adding a new # wildcard-CORS wrap therefore requires either: # # 1. Adding the route to ALLOWLIST below AND documenting why in the # commit body, or # 2. Switching the call site to middleware.NewCORS(reg.CorsCfg). # # Closes CRIT-3 of cowork/auth-bundles-audit-2026-05-10.md. See also # internal/api/middleware/middleware.go::CORSWildcard for the doc block. set -euo pipefail ROUTER=internal/api/router/router.go # Routes allowed to use middleware.CORSWildcard. Every entry must be a # credential-free endpoint that operators expect to be reachable from any # origin (Kubernetes probes, Prometheus, the pre-login GUI). ALLOWLIST=( "GET /health" # K8s/Docker liveness probe "GET /ready" # K8s/Docker readiness probe "GET /api/v1/version" # rollout probes; pre-auth "GET /api/v1/auth/info" # GUI reads before login ) if [[ ! -f "$ROUTER" ]]; then echo "FAIL: $ROUTER not found (run from certctl/ root)" exit 1 fi # Extract every (route, wrap) pair from the router by finding each # r.mux.Handle("ROUTE", ...) block and checking whether its wrapping list # contains middleware.CORSWildcard. python3 - <