feat(security): reviewed false positives outside the repo, MEDUSA in the sandbox
security.py runs medusa with HOME inside its temporary directory, since medusa creates ~/.medusa on start and the sandboxed home is read-only. security.py accept records a reviewed finding (rule, path, sha1 of the stripped line, reason) in <council root>/security-accepted.jsonl; the watch hook keeps it in ~/.local/state/agents-council/ next to the queue history, and a scan drops matching findings from the score as accepted until the line changes. Accepted so far: MEDUSA-MM-SCAN-058 x3 and MEDUSA-FTSCAN-231 x2 (false positives in tokens.py and score.py), WEB-CMDI-001 and SAST-EXEC-003 on watch.py shell=True (by design, operator config). 🎯 Fix: 93 % 💥 Break: 3 % 💸 Cost: 119 % ⏱️ Time: – 🛡️ Security: 100 % 💰 Value: ? 🏆 Score: 76 🚦 Gate: ⚠️ cost 119 % > 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b18a481d8c
commit
3dc80a1954
4 files changed
+206
-26
No files matched your search
@@ -4,9 +4,10 @@
|
||||
Usage:
|
||||
watch.py watch hook (UserPromptSubmit, PostToolUse): measure at most once
|
||||
per interval machine-wide, act on the stage, show alerts,
|
||||
and append the kvb-org-queue history rows of
|
||||
<root>/queue-history.jsonl whose id it lacks to
|
||||
~/.local/state/agents-council/queue-history.jsonl
|
||||
and append the rows of <root>/queue-history.jsonl
|
||||
(kvb-org-queue) and <root>/security-accepted.jsonl
|
||||
(kvb-check-security) whose id it lacks to the same name
|
||||
under ~/.local/state/agents-council/
|
||||
watch.py block hook (PreToolUse on Bash): exit 2 for a heavy job while the
|
||||
stage is stop or critical, or while a kvb-org-radio mayday
|
||||
holds radio silence (<root>/radio-silence.json, until > now)
|
||||
@@ -60,8 +61,12 @@ STAGES = ("ok", "warn", "stop", "critical")
|
||||
STATE = ROOT / "watch.json"
|
||||
SILENCE = ROOT / "radio-silence.json"
|
||||
ALERTS = ROOT / "alerts.jsonl"
|
||||
KEPT = Path.home() / ".local" / "state" / "agents-council"
|
||||
HISTORY = ROOT / "queue-history.jsonl"
|
||||
KEPT_HISTORY = Path.home() / ".local" / "state" / "agents-council" / "queue-history.jsonl"
|
||||
KEPT_HISTORY = KEPT / "queue-history.jsonl"
|
||||
ACCEPTED = ROOT / "security-accepted.jsonl"
|
||||
KEPT_ACCEPTED = KEPT / "security-accepted.jsonl"
|
||||
MIRRORED = ((HISTORY, KEPT_HISTORY), (ACCEPTED, KEPT_ACCEPTED))
|
||||
ALERT_TTL = 3600
|
||||
LOCK_TTL = 1800
|
||||
GB = 1e9
|
||||
@@ -200,28 +205,33 @@ def history_rows(text: str) -> list[tuple[str, str]]:
|
||||
return rows
|
||||
|
||||
|
||||
def keep_history() -> None:
|
||||
def keep_rows(origin: Path, target: Path) -> None:
|
||||
# The agents' sandbox cannot write ~/.local/state and /tmp is wiped on reboot, so this hook keeps the rows.
|
||||
# The kept file takes the source's mtime: an unchanged source is skipped without parsing.
|
||||
try:
|
||||
source = HISTORY.stat().st_mtime_ns
|
||||
if KEPT_HISTORY.exists() and KEPT_HISTORY.stat().st_mtime_ns == source:
|
||||
source = origin.stat().st_mtime_ns
|
||||
if target.exists() and target.stat().st_mtime_ns == source:
|
||||
return
|
||||
KEPT_HISTORY.parent.mkdir(parents=True, exist_ok=True)
|
||||
with KEPT_HISTORY.open("a+", encoding="utf-8") as kept:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with target.open("a+", encoding="utf-8") as kept:
|
||||
fcntl.flock(kept, fcntl.LOCK_EX)
|
||||
kept.seek(0)
|
||||
known = {row_id for row_id, _ in history_rows(kept.read())}
|
||||
for row_id, line in history_rows(HISTORY.read_text(encoding="utf-8")):
|
||||
for row_id, line in history_rows(origin.read_text(encoding="utf-8")):
|
||||
if row_id not in known:
|
||||
known.add(row_id)
|
||||
kept.write(line + "\n")
|
||||
kept.flush()
|
||||
os.utime(KEPT_HISTORY, ns=(source, source))
|
||||
os.utime(target, ns=(source, source))
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
|
||||
def keep_history() -> None:
|
||||
for origin, target in MIRRORED:
|
||||
keep_rows(origin, target)
|
||||
|
||||
|
||||
def cmd_watch(cfg: dict) -> int:
|
||||
payload = json.load(sys.stdin)
|
||||
keep_history()
|
||||
|
||||
Reference in new issue
Block a user