fix(kvb-org-organize): no hook runs a binary planted on the inherited PATH
Hooks run outside the sandbox but inherit a PATH whose directories sandboxed agents of the same uid can write (a virtualenv's bin activated first by the shell profile), so a file planted there under the name of docker, git or notify-send ran unsandboxed. hookpath.py keeps only the PATH directories that, with every parent, belong to another uid and that neither group nor others can write, as real paths; inside the sandbox's user namespace root shows as the overflow uid and still counts as sealed. watch.py, radio.py and council.py set that PATH before they start anything, and the cleanup child runs with -I. Both reminder hooks pin PATH=/usr/bin:/bin, and the install registers them with /usr/bin/bash and moves older bare bash and python3 entries to the absolute paths. 🎯 Fix: 90 % 💥 Break: 4 % 💸 Cost: 100 % ⏱️ Time: 100 % 🛡️ Security: 100 % 💰 Value: ? 🏆 Score: 86 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94542e7b92
commit
454670a77e
13 files changed
+193
-5
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
export PATH=/usr/bin:/bin
|
||||
|
||||
hours="${COACH_STAMP_DIR:-${HOME}/.claude/.coach-hours}"
|
||||
hour="${COACH_HOUR:-$(date +%Y-%m-%dT%H)}"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
export PATH=/usr/bin:/bin
|
||||
|
||||
interval="${DREAM_INTERVAL_SECONDS:-43200}"
|
||||
stamps="${DREAM_STAMP_DIR:-${HOME}/.claude/.dream-stamps}"
|
||||
|
||||
@@ -6,6 +6,7 @@ Environment:
|
||||
/tmp/agents-council unless set, because all agents must agree on it.
|
||||
CLAUDE_CODE_SESSION_ID: the caller's session, taken over --session; other
|
||||
runtimes pass --session.
|
||||
PATH: filtered to the directories hookpath.py trusts before git runs.
|
||||
|
||||
Exit codes:
|
||||
0 done, 2 usage error, 3 office held by a live session,
|
||||
@@ -282,6 +283,7 @@ def main() -> int:
|
||||
listing.set_defaults(func=cmd_list)
|
||||
sub.add_parser("gate").set_defaults(func=cmd_gate)
|
||||
args = parser.parse_args()
|
||||
os.environ["PATH"] = sibling("hookpath").trusted(os.environ.get("PATH", ""))
|
||||
return args.func(args)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def sealed(directory: Path) -> bool:
|
||||
try:
|
||||
stats = [part.stat() for part in (directory, *directory.parents)]
|
||||
except OSError:
|
||||
return False
|
||||
me = os.getuid()
|
||||
return all((st.st_uid != me or st.st_uid == 0) and not st.st_mode & 0o022 for st in stats)
|
||||
|
||||
|
||||
def trusted(path: str) -> str:
|
||||
"""Filter a PATH value.
|
||||
|
||||
Args:
|
||||
path: the PATH value, os.pathsep-separated.
|
||||
|
||||
Returns:
|
||||
The real paths of its directories that, with every parent, belong to
|
||||
root or another uid and that neither group nor others can write, in
|
||||
their order.
|
||||
"""
|
||||
kept: list[str] = []
|
||||
for entry in filter(None, path.split(os.pathsep)):
|
||||
try:
|
||||
real = Path(entry).resolve(strict=True)
|
||||
except OSError:
|
||||
continue
|
||||
if sealed(real) and str(real) not in kept:
|
||||
kept.append(str(real))
|
||||
return os.pathsep.join(kept)
|
||||
@@ -32,6 +32,8 @@ Environment:
|
||||
its commands outside the sandbox; a Docker daemon the sandbox can
|
||||
reach still writes it. Without a config file every command exits 0 and does
|
||||
nothing.
|
||||
PATH: filtered to the directories hookpath.py trusts before any command
|
||||
runs, the config's commands included.
|
||||
|
||||
Config keys, all required: disk, thresholds_gb {warn, stop, critical},
|
||||
projection_minutes, interval_seconds, cache_interval_seconds, heavy_commands,
|
||||
@@ -73,7 +75,8 @@ def sibling(name: str) -> ModuleType:
|
||||
|
||||
|
||||
nofollow = sibling("nofollow")
|
||||
ROOT = Path(os.environ.get("AGENTS_COUNCIL_ROOT", "/tmp/agents-council"))
|
||||
hookpath = sibling("hookpath")
|
||||
ROOT =Path(os.environ.get("AGENTS_COUNCIL_ROOT", "/tmp/agents-council"))
|
||||
CONFIG = Path(
|
||||
os.environ.get(
|
||||
"AGENTS_COUNCIL_CONFIG",
|
||||
@@ -209,7 +212,7 @@ def notify(cfg: dict, text: str) -> None:
|
||||
|
||||
def spawn_cleanup(mode: str) -> None:
|
||||
subprocess.Popen(
|
||||
[sys.executable, str(Path(__file__).resolve()), "cleanup", mode],
|
||||
[sys.executable, "-I", str(Path(__file__).resolve()), "cleanup", mode],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
start_new_session=True,
|
||||
)
|
||||
@@ -523,6 +526,7 @@ def main() -> int:
|
||||
mode.add_argument("--full", action="store_true")
|
||||
sub.add_parser("status")
|
||||
args = parser.parse_args()
|
||||
os.environ["PATH"] = hookpath.trusted(os.environ.get("PATH", ""))
|
||||
refused = guard_root(hook=args.cmd in ("watch", "block"))
|
||||
if refused is not None:
|
||||
return refused
|
||||
|
||||
@@ -9,6 +9,8 @@ Environment:
|
||||
of a mayday; ~/.claude/agents-council/config.json unless set.
|
||||
CLAUDE_CODE_SESSION_ID: the calling session; hooks read the payload's
|
||||
session_id first, other runtimes pass --session.
|
||||
PATH: filtered to the directories the kvb-org-organize hookpath.py
|
||||
trusts before the notify argv runs.
|
||||
|
||||
Args:
|
||||
send <class> "<text>" [--to <name> ...] [--wake] [--session <id>]: add a
|
||||
@@ -468,6 +470,7 @@ def main() -> int:
|
||||
p.add_argument("--session")
|
||||
p.set_defaults(func=cmd_show)
|
||||
args = parser.parse_args()
|
||||
os.environ["PATH"] = organize("hookpath").trusted(os.environ.get("PATH", ""))
|
||||
refused = organize("watch").guard_root(hook=args.command in ("hook", "tool", "listen"))
|
||||
if refused is not None:
|
||||
return refused
|
||||
|
||||
Reference in new issue
Block a user