feat: plan 16 P1 (SEC-08/09/19/20/21) — fail-open/DoS/authz hardening
- SEC-08 pii-mask: fail-closed on missing rules / broken regex (no unmasked leak) - SEC-09: input-size cap + fail-closed reads (security-check/drift-detect/context-compress); non-UTF8 no longer crashes - SEC-19: control-plane store POSIX flock + atomic tmp+rename write - SEC-20: new toolchain-verify.sh (missing/PATH-shadowed/in-workspace binary -> refuse); wired into harness-preflight - SEC-21: model-call timeout 180->60s configurable + per-run call budget - SEC-11 realized by SEC-17 prod profile (no code) - 5 fail-able test suites wired into ci-harness-gate.sh; test-integrity manifest regenerated Verify: SEC+integrity gate 16/0, run-casan4 0-FAIL, adversarial 44/44, no regressions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
8c3c5e8bff
commit
e70f0815ab
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# CASAN Plan-16 SEC-08 (M-06) — pii-mask fails CLOSED.
|
||||
#
|
||||
# Previously a missing rules file, an unreadable file, or a broken rule regex made
|
||||
# pii-mask emit the RAW stdin — silently leaking the very PII a mask rule was meant
|
||||
# to hide. Now any such condition emits NOTHING and exits non-zero. Normal masking
|
||||
# with valid rules is unchanged.
|
||||
#
|
||||
# Deterministic; hermetic; no model/network.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
PM="$PROJECT_ROOT/.specify/scripts/bash/pii-mask.py"
|
||||
RULES="$PROJECT_ROOT/.specify/security/pii-rules.yaml"
|
||||
WORK="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
PASS=0; FAIL=0
|
||||
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
||||
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
||||
|
||||
echo "===== Plan-16 SEC-08: pii-mask fail-closed ====="
|
||||
|
||||
# 1) Valid rules still mask (regression).
|
||||
OUT="$(printf 'contact bob@example.com now' | python3 "$PM" "$RULES" 2>/dev/null)"
|
||||
if [[ "$OUT" == *"MASKED"* && "$OUT" != *"bob@example.com"* ]]; then
|
||||
pass "valid rules mask the email (no leak)"
|
||||
else
|
||||
fail "valid masking broken (out='$OUT')"
|
||||
fi
|
||||
|
||||
# 2) Missing rules file → no output, non-zero, and NO raw email leaks.
|
||||
set +e
|
||||
OUT="$(printf 'secret bob@example.com' | python3 "$PM" "$WORK/nope.yaml" 2>/dev/null)"; RC=$?
|
||||
set -e 2>/dev/null || true
|
||||
if [[ "$RC" -ne 0 && -z "$OUT" ]]; then
|
||||
pass "missing rules file → empty output, non-zero (fail-closed)"
|
||||
else
|
||||
fail "missing rules leaked (rc=$RC out='$OUT')"
|
||||
fi
|
||||
|
||||
# 3) Broken regex → no output, non-zero (that PII type would otherwise leak).
|
||||
printf -- '- id: email\n type: "email"\n regex: "([unterminated"\n action: mask\n' > "$WORK/bad.yaml"
|
||||
set +e
|
||||
OUT="$(printf 'secret bob@example.com' | python3 "$PM" "$WORK/bad.yaml" 2>/dev/null)"; RC=$?
|
||||
set -e 2>/dev/null || true
|
||||
if [[ "$RC" -ne 0 && -z "$OUT" ]]; then
|
||||
pass "broken rule regex → empty output, non-zero (fail-closed)"
|
||||
else
|
||||
fail "broken regex leaked (rc=$RC out='$OUT')"
|
||||
fi
|
||||
|
||||
# 4) No rules argument at all → fail-closed.
|
||||
set +e
|
||||
OUT="$(printf 'secret bob@example.com' | python3 "$PM" 2>/dev/null)"; RC=$?
|
||||
set -e 2>/dev/null || true
|
||||
if [[ "$RC" -ne 0 && -z "$OUT" ]]; then
|
||||
pass "no rules argument → empty output, non-zero (fail-closed)"
|
||||
else
|
||||
fail "no-arg leaked (rc=$RC out='$OUT')"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "===== SEC-08 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
||||
[[ "$FAIL" -eq 0 ]] || exit 1
|
||||
Reference in New Issue
Block a user