Physically move the pure-code subtrees out of .specify into the package, leaving compat symlinks at the old .specify/<dir> paths so every existing reference (internal CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put. Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/ .specify/<dir> -> packages/casan-harness/<dir> (+ .specify/<dir> symlink) Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/ init-options.json traceability-map.json Python `.resolve()` self-location followed the compat symlink into packages and lost the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed parent depth (fixes "missing trace files" in run-casan4). Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs close to the 600s default and can tip over under load; this is timing variance, not a regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
1.3 KiB
Bash
40 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-16 SEC-28 (X-04) — path-traversal / symlink guard.
|
|
#
|
|
# A tool that takes a file path as input/output can be pointed at an arbitrary
|
|
# location via `..` or a symlink (e.g. a symlink named "input.txt" -> /etc/passwd),
|
|
# reading or writing outside the workspace. This resolves the REAL path (following
|
|
# every symlink) and refuses anything that escapes the allowed root.
|
|
#
|
|
# Usage: path-guard.sh <path> [allowed-root] (default root: repo workspace)
|
|
# Exit: 0 inside the root, 1 outside / unresolvable.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
|
|
|
TARGET="${1:-}"
|
|
ROOT="${2:-$PROJECT_ROOT}"
|
|
if [[ -z "$TARGET" ]]; then
|
|
echo "Usage: path-guard.sh <path> [allowed-root]" >&2
|
|
exit 64
|
|
fi
|
|
|
|
python3 - "$TARGET" "$ROOT" <<'PY'
|
|
import os
|
|
import sys
|
|
|
|
target, root = sys.argv[1], sys.argv[2]
|
|
# realpath resolves symlinks in every existing path component and normalizes "..";
|
|
# for a not-yet-created leaf it resolves the existing parent chain.
|
|
real_target = os.path.realpath(target)
|
|
real_root = os.path.realpath(root)
|
|
|
|
if real_target == real_root or real_target.startswith(real_root + os.sep):
|
|
print(f"PATH_OK {real_target}")
|
|
sys.exit(0)
|
|
sys.stderr.write(f"PATH_ESCAPES_ROOT target={target} real={real_target} root={real_root}\n")
|
|
sys.exit(1)
|
|
PY
|