Standard production layout: the OKR app (was nested under AINative_OKR_CASAN5/) is now
the repository root. No more wrapper directory.
- Promote AINative_OKR_CASAN5/* -> repo root (backend/ frontend/ packages/ apps/
.specify/ docs/ infra/ nginx/ scripts/ + configs). Merge tool dirs: .gitea (kept the
active deploy ci.yml, added harness-ci.yml + runbooks), .claude (agents/commands +
launch.json), .github moved up.
- Remove redundant: 00_SUBMISSION_PACKAGE, scattered root notes (FPT_CASAN_Full.md,
tu-tuong-casan.md, casan-tu-sinh..., casan_harness_assessment.md, source-review...,
README_CASAN5_REFINED.md), casan-next-plans/ and optimize-docs/ (competition/planning
artifacts — roadmap + design history preserved in git log / commit messages).
- Update all references to the old layout:
- .gitea/workflows/{ci,harness-ci}.yml, .github/workflows/{ci,deploy}.yml:
working-directory .; drop AINative_OKR_CASAN5/ prefix; .specify/{tests,scripts}
-> packages/casan-harness/... (.specify/logs state kept)
- .claude/launch.json, .gitea/*-runbook.md: path prefixes
- CLAUDE.md, README.md: docs/input -> apps/okr/domain/input
- policy-bundle.yaml: 8 policy paths -> packages/casan-harness/...; manifest re-signed
- secrets-scan.sh: fixture excludes -> new package/domain paths.
Full gate from the new root: PASS=64 FAIL=0 SKIP=3.
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
|