Resolve every root by marker walk-up instead of a fixed depth that only lands on the app via the .specify compat symlink, so the harness runs correctly when invoked by its real packages/casan-harness path — proven by a full gate run via that path: 64/0/0. - 95 scripts/tests: PROJECT_ROOT/ROOT "$SCRIPT_DIR/../.."-style computations -> $CASAN_APP_ROOT. - 6 leaf scripts (infra-lab, context-validate, secrets-scan, path-guard, toolchain-verify, phase2-sourcegen) now source casan-paths + use CASAN_APP_ROOT. - run-casan4: source casan-paths as a package sibling (facade-independent), PROJECT_ROOT=CASAN_APP_ROOT. - 8 Python files: project_root()/REPO_ROOT/bundle_root walk UP for the .specify marker (control-plane-settings, loop_common, model-call, context-compress, test-integrity, bundle-integrity, traceability-matrix; generate-* fixed earlier). - evidence-pack-build.py + traceability-matrix.py: domain refs -> apps/okr/domain (input/, corpus/redteam-vectors.jsonl, traceability-map.json). - ci-harness-gate.sh: export CASAN_TESTS_DIR/CASAN_TEST_MANIFEST/CASAN_BUNDLE_ROOT so the integrity Python resolves via the harness root regardless of invocation path; ROOT=CASAN_APP_ROOT. - Remove the domain compat symlinks from packages/casan-harness/security (redteam-corpus, redteam-vectors, benign-corpus) — packages now holds NO domain data. Both invocation paths pass (compat facade still present): .specify/... and packages/... Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
3.3 KiB
Bash
79 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-16 SEC-03 (H-03) — rollback-manager: no `bash -c`, structured argv only.
|
|
#
|
|
# The rollback `execute` path used to `bash -c "$rollback_command"` where the
|
|
# command was read from the unsigned transaction log — arbitrary code execution
|
|
# for anyone who can append a line. This proves:
|
|
# * a genuine checkpoint still restores the file (regression),
|
|
# * a forged free-form record with an RCE payload is REFUSED (not executed),
|
|
# * a forged structured record whose backup points outside the controlled
|
|
# backup dir is REFUSED (cannot copy an arbitrary source file).
|
|
#
|
|
# Deterministic; no model/app/network. Hermetic tx log via a temp workspace.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
|
|
PROJECT_ROOT="$CASAN_APP_ROOT"
|
|
RM="$CASAN_HARNESS_ROOT/scripts/bash/rollback-manager.sh"
|
|
TX_LOG="$CASAN_STATE_ROOT/logs/level5/rollback-transactions.jsonl"
|
|
WORK="$(mktemp -d)"
|
|
|
|
# rollback-manager uses a fixed tx-log path; back it up and restore on exit.
|
|
[[ -f "$TX_LOG" ]] && cp -p "$TX_LOG" "$WORK/tx.bak"
|
|
restore_tx() { if [[ -f "$WORK/tx.bak" ]]; then cp -p "$WORK/tx.bak" "$TX_LOG"; else rm -f "$TX_LOG"; fi; }
|
|
trap 'restore_tx; rm -f "$WORK/PWNED"; rm -rf "$WORK"' EXIT
|
|
|
|
PASS=0; FAIL=0
|
|
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
rc_of() { set +e; "$@" >/dev/null 2>&1; echo $?; set -e 2>/dev/null || true; }
|
|
|
|
echo "===== Plan-16 SEC-03: rollback-manager no bash -c (RCE) ====="
|
|
|
|
# 1) Regression: genuine checkpoint -> execute restores exact content.
|
|
TARGET="$WORK/plan.txt"; echo "ORIGINAL" > "$TARGET"
|
|
TX="$(bash "$RM" checkpoint "$TARGET" | sed -n 's/.*transaction_id=\([^ ]*\).*/\1/p')"
|
|
echo "OVERWRITTEN" > "$TARGET"
|
|
bash "$RM" execute "$TX" >/dev/null 2>&1
|
|
[[ "$(cat "$TARGET")" == "ORIGINAL" ]] \
|
|
&& pass "genuine checkpoint restores exact pre-overwrite content" \
|
|
|| fail "checkpoint did not restore (got: $(cat "$TARGET"))"
|
|
|
|
# 2) Fail-able: forged free-form record carrying an RCE payload must be REFUSED.
|
|
rm -f "$WORK/PWNED"
|
|
python3 - "$TX_LOG" "$WORK/PWNED" <<'PY'
|
|
import json, sys
|
|
log, marker = sys.argv[1], sys.argv[2]
|
|
open(log, "a", encoding="utf-8").write(json.dumps({
|
|
"transaction_id": "evil-rce", "action": "checkpoint",
|
|
"rollback_command": f"touch {marker}"}) + "\n")
|
|
PY
|
|
RC="$(rc_of bash "$RM" execute evil-rce)"
|
|
if [[ "$RC" -ne 0 && ! -f "$WORK/PWNED" ]]; then
|
|
pass "forged free-form rollback_command REFUSED, no code executed (rc=$RC)"
|
|
else
|
|
fail "RCE not prevented (rc=$RC, marker exists=$([[ -f "$WORK/PWNED" ]] && echo yes || echo no))"
|
|
fi
|
|
|
|
# 3) Fail-able: forged restore_file whose backup is outside the controlled dir.
|
|
SECRET="$WORK/secret.txt"; echo "SECRET" > "$SECRET"
|
|
python3 - "$TX_LOG" "$SECRET" "$WORK/stolen.txt" <<'PY'
|
|
import json, sys
|
|
log, backup, target = sys.argv[1], sys.argv[2], sys.argv[3]
|
|
open(log, "a", encoding="utf-8").write(json.dumps({
|
|
"transaction_id": "evil-src", "action": "checkpoint", "op": "restore_file",
|
|
"backup": backup, "target": target}) + "\n")
|
|
PY
|
|
RC="$(rc_of bash "$RM" execute evil-src)"
|
|
if [[ "$RC" -ne 0 && ! -f "$WORK/stolen.txt" ]]; then
|
|
pass "forged restore source outside backup dir REFUSED (rc=$RC)"
|
|
else
|
|
fail "arbitrary-source restore not prevented (rc=$RC)"
|
|
fi
|
|
|
|
echo ""
|
|
echo "===== SEC-03 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|