Files
skills/hub/client/verifier.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 8ba45efd04 feat(hub): kvb-hub review hub with passkey-signed approvals
The kvb-hub is a local review hub in a container bound to 127.0.0.1: one page, JSON APIs and an MCP endpoint for the operator's inbox, asks, decisions, staged-commit reviews, the radio stream, the agent graph, the worktree tree, push-to-talk and read-aloud radio (Piper, whisper.cpp) and an optional LLM command line. The hub is only a relay. The host executors in hub/client (the runner user service, the PermissionRequest hook and the approval CLI the commit skills call) verify a WebAuthn passkey signature against keys pinned outside every sandbox, refuse replays and fail closed. scripts/hub.sh with make hub-install, hub-check, hub-pin, hub-runner and hub-hook installs and checks the hub; hub-hook writes ~/.claude/settings.json after a backup. make watch-check shows a stuck watch hook. The new kvb-git-diff skill and the commit skills route reviews through the hub; the test_hub_* suites replace test_hub.py.

Security review (kvb-think-criticize, three skeptics) fixed four holes: signed rules auto-approved chained shell commands; the client and LLM openers followed redirects, the LLM one with its bearer key; the worktree scan ran git fsmonitor and filter commands from agent-writable repos; compose set no memory, pids or health limits. Documented until core requirement 093, on the operator's word: the hub page is trusted while signing and pinning, local processes can forge the unsigned operator actions, and the container reads the host /tmp. Committed on the operator's word despite the gate: the passkey path is not yet verified live.

Accepted MEDUSA false positives (137 findings on 115 lines, rows in security-accepted.jsonl): EXA002 x17, MEDUSA-MM-SCAN-058 x12, B603 x8, MEDUSA-FTSC-SCAN-089 x7, MEDUSA-PRIV-SCAN-762 x6, AIC-EXFIL-005 x5, EXA006 x5, MEDUSA-FTSCAN-231 x5, WEB-SSRF x5, MEDUSA-INF-SCAN-2057 x3, RH005 x3, TC001 x3, LO002 x2, MEDUSA-AEXP-SCAN-096 x2, MEDUSA-CGS-SCAN-028 x2, MEDUSA-INF-SCAN-1350 x2, MEDUSA-INF-SCAN-2369 x2, MEDUSA-INF-SCAN-2440 x2, MEDUSA-INF-SCAN-2638 x2, MLSC-SERIAL-002 x2, PL002 x2, PQC005 x2, SAST-PATH-001 x2, TC004 x2, TC005 x2, TC006 x2, TC007 x2, AA-146, EXA007, FINE-050, GB-ENCODE-001, GB-ENCODE-003, MEDUSA-CGS-SCAN-029, MEDUSA-CGS-SCAN-103, MEDUSA-DP-SCAN-1034, MEDUSA-DP-SCAN-1916, MEDUSA-DP-SCAN-954, MEDUSA-EXF26-TOOL-004, MEDUSA-FT-TRIGGER-005, MEDUSA-INF-SCAN-2206, MEDUSA-INF-SCAN-2457, MEDUSA-INF-WEB-003, MEDUSA-INFRA-SCAN-030, MEDUSA-MP-SCAN-1135, MEDUSA-RLHF-POISON-002, MEDUSA-RT-SCAN-006, MM-ENCODE-001, MP-124, PQC001, PQC002, PQC006, RP001, TC009, TC010, WEB-FLASK-004.

🎯 Fix: 80 %
💥 Break: 4 %
💸 Cost: 129 %
⏱️ Time: –
🛡️ Security: 100 %
💰 Value: ?
🏆 Score: 60
🚦 Gate: ⛔ fix 80 % < 90; cost 129 % > 100: ask the operator before the commit

```
/home/kevinveenbirkenbach/Repositories/github.com/kevinveenbirkenbach/skills/.worktrees/feature/kvb-hub
```

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:46:40 +00:00

125 lines
5.1 KiB
Python

from __future__ import annotations
import datetime
import fcntl
import json
import os
import tempfile
from pathlib import Path
from typing import NamedTuple
from passkey import verify_assertion
from signing import (
Refused,
checked_approval,
checked_rule,
item_hash,
load_pinned,
rule_allows,
)
class Trust(NamedTuple):
approvers: Path
replay: Path
origin: str
def pinned(path: Path) -> list[dict]:
entries = load_pinned(path)
if not entries:
raise Refused("no key is pinned")
return entries
def write_private(path: Path, data: dict) -> None:
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
descriptor, name = tempfile.mkstemp(dir=path.parent, prefix=f".{path.name}-")
try:
with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
json.dump(data, handle, indent=1, sort_keys=True)
handle.flush()
os.fsync(handle.fileno())
os.replace(name, path)
except OSError:
Path(name).unlink(missing_ok=True)
raise
def pin(path: Path, entry: dict, now: float) -> list[dict]:
stamp = datetime.datetime.fromtimestamp(now, datetime.UTC).isoformat(timespec="seconds")
entries = [old for old in load_pinned(path) if old["id"] != entry["id"]] + [{**entry, "pinned": stamp}]
write_private(path, {"credentials": entries})
return entries
def read_store(store: Path) -> dict:
try:
data = json.loads(store.read_text(encoding="utf-8"))
except FileNotFoundError:
return {"used": {}, "counts": {}}
except (OSError, ValueError, RecursionError) as error:
raise Refused(f"the replay store {store} is unreadable") from error
counts = data.get("counts") if isinstance(data, dict) else None
shaped = isinstance(counts, dict) and all(isinstance(last, dict) and isinstance(last.get("count"), int) and isinstance(last.get("nonce"), str) for last in counts.values())
if not shaped or not isinstance(data.get("used"), dict):
raise Refused(f"the replay store {store} is malformed")
return data
def consume(store: Path, key: str, expires: int, credential: str, count: int, nonce: str, now: float) -> None:
"""Args:
store: the executor's own replay store, outside the hub's reach.
key: the one-time id, nonce and item hash.
expires: until when the id must stay known.
credential: the id of the key that signed.
count: its signature counter; 0 when the authenticator keeps none.
nonce: the payload nonce; one bulk signature carries one counter.
now: the current time in epoch seconds.
"""
store.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
descriptor = os.open(store.with_name(f"{store.name}.lock"), os.O_RDWR | os.O_CREAT, 0o600)
try:
fcntl.flock(descriptor, fcntl.LOCK_EX)
state = read_store(store)
used = {name: until for name, until in state["used"].items() if isinstance(until, int | float) and until > now}
if key in used:
raise Refused("this signature was already used for this item")
last = state["counts"].get(credential)
if last is not None and not (count > last["count"] or (count == last["count"] and (count == 0 or nonce == last["nonce"]))):
raise Refused("the signature counter did not grow: a cloned authenticator or a replay")
write_private(store, {"used": {**used, key: expires}, "counts": {**state["counts"], credential: {"count": count, "nonce": nonce}}})
finally:
os.close(descriptor)
def check(proof: object, item: dict, gate: str, trust: Trust, now: float) -> None:
"""Args:
proof: {"payload", "assertion"} the kvb-hub relayed for the item.
item: the executor's own item, built from what it is about to do.
gate: pass or fail as the executor itself saw it; a rule approves a
review on pass only.
trust: the pinned keys, the executor's replay store and the origin.
now: the current time in epoch seconds.
Raises:
Refused with the reason, unless a pinned key signed an unexpired
approval that lists the item and is used here for the first time, or
an unexpired rule whose pattern the item matches.
"""
if not isinstance(proof, dict) or set(proof) != {"payload", "assertion"}:
raise Refused("no signature")
payload = proof["payload"]
if isinstance(payload, dict) and payload.get("kind") == "rule":
checked_rule(payload, now)
verify_assertion(proof["assertion"], payload, pinned(trust.approvers), trust.origin)
if not rule_allows(payload, item, gate, now):
raise Refused("the signed rule does not match this item")
return
checked_approval(payload, now)
count = verify_assertion(proof["assertion"], payload, pinned(trust.approvers), trust.origin)
digest = item_hash(item)
if digest not in payload["items"]:
raise Refused("the signature does not list this item")
consume(trust.replay, f"{payload['nonce']}:{digest}", payload["expires"], proof["assertion"]["id"], count, payload["nonce"], now)