feat(orchestrator): reveal withheld diff content under a passkey signature (019)
staged_diff masks only the secret rule hits and seals each masked file's clear patch apart; reviews and asks store the sealed patches next to their diff, delete them once the item leaves pending, and the hub sweeps orphans. POST /api/diffs/<kind>/<id>/reveal/sign and /reveal hand the clear patches to a signed request; page-diff.js offers Reveal per hidden file and Reveal all, keeps the clear text in the page only and forgets it once the item leaves the inbox. Requirement 019, unit, hub and e2e tests. Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): approval.py FTSCAN-231 WEB-SSRF RH005; permission_hook.py MM-SCAN-058 WEB-SSRF RH005; staged_diff.py SAST-ENV-001 AI-BACKDOOR-006 B603; hub.py MEX-SCAN-1167 INF-SCAN-589; page-load.js EXA002; hub_case.py TC001-TC009 INF-SCAN-2057/2206/2440/2457 EXA002 EXA006 PL002 B603 FTSC-SCAN-089. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 88 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
78d4e4a6aa
commit
af3555e88b
24 files changed
+928
-111
No files matched your search
@@ -10,13 +10,16 @@ from .signed import limits
|
||||
|
||||
DIFF_LIMIT = limits.DIFF_LIMIT
|
||||
DIFF_BODY_LIMIT = limits.DIFF_BODY_LIMIT
|
||||
SEALED_LIMIT = limits.SEALED_LIMIT
|
||||
FILE_CAP = limits.FILE_CAP
|
||||
PATH_LIMIT = limits.PATH_LIMIT
|
||||
STATUSES = ("A", "M", "D", "R", "B")
|
||||
DIFF_KEYS = ("path", "status", "mode", "additions", "deletions", "patch", "note")
|
||||
NOTES = ("", limits.WITHHELD)
|
||||
HIDDEN = (limits.WITHHELD, limits.MASKED)
|
||||
NOTES = ("", *HIDDEN)
|
||||
MODE = re.compile(r"[0-7]{6}(?: => [0-7]{6})?")
|
||||
DIFF_SUFFIX = {"review": ".review-diff.json", "ask": ".ask-diff.json"}
|
||||
SEALED_SUFFIX = {"review": ".review-sealed.json", "ask": ".ask-sealed.json"}
|
||||
|
||||
|
||||
def counted(value: object) -> bool:
|
||||
@@ -33,8 +36,8 @@ def diff_entry(entry: object) -> dict:
|
||||
raise ToolError("mode must be a git file mode, or old => new for a changed one")
|
||||
if not counted(entry["additions"]) or not counted(entry["deletions"]) or not isinstance(patch, str) or (entry["status"] == "B" and patch):
|
||||
raise ToolError("additions and deletions must be counts, patch text, empty for a binary file")
|
||||
if entry["note"] not in NOTES or (entry["note"] and patch):
|
||||
raise ToolError(f"note must be empty or {limits.WITHHELD!r}, the latter with an empty patch")
|
||||
if entry["note"] not in NOTES or (entry["note"] == limits.WITHHELD and patch):
|
||||
raise ToolError(f"note must be empty, {limits.MASKED!r} or {limits.WITHHELD!r}, the latter with an empty patch")
|
||||
return {key: entry[key] for key in DIFF_KEYS}
|
||||
|
||||
|
||||
@@ -52,10 +55,44 @@ def valid_diff(value: object) -> list[dict]:
|
||||
return entries
|
||||
|
||||
|
||||
def valid_sealed(value: object, diff: list[dict] | None) -> dict[str, str]:
|
||||
"""Returns:
|
||||
The clear patches a request seals apart from its diff, checked: an
|
||||
object from the path of a masked or withheld file of diff to its
|
||||
patch text, at most SEALED_LIMIT bytes of JSON-encoded text in all;
|
||||
none without a diff.
|
||||
"""
|
||||
hidden = {entry["path"] for entry in diff or [] if entry["note"] in HIDDEN}
|
||||
if not isinstance(value, dict) or not all(isinstance(patch, str) for patch in value.values()) or not set(value) <= hidden:
|
||||
raise ToolError("sealed must map the path of a masked or withheld file of the diff to its patch text")
|
||||
if sum(len(json.dumps(patch, ensure_ascii=False).encode("utf-8")) for patch in value.values()) > SEALED_LIMIT:
|
||||
raise ToolError(f"the sealed patches must stay within {SEALED_LIMIT} bytes")
|
||||
return dict(value)
|
||||
|
||||
|
||||
def diff_bytes(diff: list[dict]) -> bytes:
|
||||
return json.dumps({"diff": diff}, ensure_ascii=False).encode("utf-8")
|
||||
|
||||
|
||||
def sealed_bytes(sealed: dict[str, str]) -> bytes:
|
||||
return json.dumps({"sealed": sealed}, ensure_ascii=False).encode("utf-8")
|
||||
|
||||
|
||||
def sealed_file(folder: Path, kind_name: str, item_id: str) -> Path:
|
||||
return folder / f"{item_id}{SEALED_SUFFIX[kind_name]}"
|
||||
|
||||
|
||||
def store_sealed(folder: Path, kind_name: str, item_id: str, sealed: dict[str, str]) -> None:
|
||||
write_atomic(sealed_file(folder, kind_name, item_id), sealed_bytes(sealed))
|
||||
|
||||
|
||||
def stored_sealed(folder: Path, kind_name: str, item_id: str) -> dict[str, str]:
|
||||
data = read_json(sealed_file(folder, kind_name, item_id))
|
||||
if not isinstance(data, dict) or not isinstance(data.get("sealed"), dict):
|
||||
raise Missing(item_id)
|
||||
return data["sealed"]
|
||||
|
||||
|
||||
def store_diff(folder: Path, kind_name: str, item_id: str, diff: list[dict]) -> None:
|
||||
write_atomic(folder / f"{item_id}{DIFF_SUFFIX[kind_name]}", diff_bytes(diff))
|
||||
|
||||
|
||||
Reference in new issue
Block a user