fix: watchdog 게이트 훅을 오류 시 차단(fail-closed)하고 판정은 마지막 줄 "WATCHDOG: PASS" 만 인정한다
- 보안 검토 지적 반영: 훅 예외가 나면 초안 도구를 막는다, 기록 행·필드 타입 확인 - 판정 문자열은 결과 마지막 비어 있지 않은 줄이 정확히 WATCHDOG: PASS 일 때만 인정 - 남은 과제: 승인한 초안 본문 해시와 실제 초안 입력을 대조하는 바인딩(TOCTOU)은 별도 작업 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e739272c1
commit
4c2152bfaa
1 file changed
+16
-4
@@ -33,12 +33,17 @@ def result_text(item):
|
||||
if isinstance(c, str):
|
||||
return c
|
||||
if isinstance(c, list):
|
||||
return "\n".join(x.get("text", "") for x in c if isinstance(x, dict))
|
||||
return "\n".join((x.get("text") or "") for x in c if isinstance(x, dict))
|
||||
return ""
|
||||
|
||||
|
||||
def verdict(text):
|
||||
return "WATCHDOG: PASS" in text and "WATCHDOG: FIX" not in text
|
||||
# 판정은 결과의 마지막 비어 있지 않은 줄이 정확히 "WATCHDOG: PASS" 일 때만 인정한다 (본문 중간 인용·FIX 혼재 차단)
|
||||
lines = [l.strip() for l in text.replace("\\n", "\n").splitlines() if l.strip()]
|
||||
if not lines:
|
||||
return False
|
||||
last = re.sub(r"[`*_<>/]|result", "", lines[-1]).strip()
|
||||
return last == "WATCHDOG: PASS" and "WATCHDOG: FIX" not in text
|
||||
|
||||
|
||||
def main():
|
||||
@@ -60,6 +65,8 @@ def main():
|
||||
watchdog_ids = set()
|
||||
passed = False
|
||||
for r in rows:
|
||||
if not isinstance(r, dict):
|
||||
continue
|
||||
if r.get("isSidechain"):
|
||||
continue
|
||||
# 요청 사본 행은 앞선 도구 호출을 다시 담고 있어 순서를 흐트러뜨린다. 건너뛴다
|
||||
@@ -74,7 +81,7 @@ def main():
|
||||
if m and m.group(1) in watchdog_ids:
|
||||
passed = verdict(prompt)
|
||||
continue
|
||||
c = r.get("message", {}).get("content")
|
||||
c = (r.get("message") or {}).get("content") if isinstance(r, dict) else None
|
||||
if isinstance(c, str):
|
||||
if "<task-notification>" in c:
|
||||
m = re.search(r"<tool-use-id>([^<]+)</tool-use-id>", c)
|
||||
@@ -110,4 +117,9 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
try:
|
||||
main()
|
||||
except SystemExit:
|
||||
raise
|
||||
except Exception as e: # 훅이 깨지면 막는 쪽으로 (fail-closed)
|
||||
deny(f"watchdog 게이트 훅 오류로 초안 도구를 막았습니다: {type(e).__name__}: {e}")
|
||||
Reference in new issue
Block a user