Repository navigation
feat(#823): rtk boundary shadow guard hook を shadow mode で追加する - #875
Conversation
- `.claude/hooks/rtk_boundary_shadow_guard.sh` を追加: mutating git / gh / dependency mutation コマンドを JSONL に記録し常に exit 0 で通過する - `.claude/settings.json` の PreToolUse hooks に Bash ツール対象の shadow guard を登録 - `.claude/hooks/tests/test_rtk_boundary_shadow_guard.py` を追加: 36 テストケース(AC3 exit0 / malformed / missing_jq / unwritable_log / empty_stdin / fixture matrix / schema 検証) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Preview URLPreview removed (PR #875 closed). |
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: true
reviewed_head_sha: "05f72b4c5ee2309d77c5db66fc72959ac0bf4780"
pr: 875
issue: 823
contract_snapshot_url: "https://github.com/squne121/loop-protocol/issues/823#issuecomment-4698464869"
required_auto_actions: []
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
expected_paths:
- .claude/hooks/rtk_boundary_shadow_guard.sh
- .claude/hooks/tests/test_rtk_boundary_shadow_guard.py
- .claude/settings.json
actual_changed_paths:
- .claude/hooks/rtk_boundary_shadow_guard.sh
- .claude/hooks/tests/test_rtk_boundary_shadow_guard.py
- .claude/settings.json
verdict: exact_match
ac_results:
AC1:
status: pass
evidence: "test -f .claude/hooks/rtk_boundary_shadow_guard.sh → 存在確認"
AC2:
status: pass
evidence: "rg -n rtk_boundary_shadow_guard .claude/settings.json → line 108 に登録確認"
AC3:
status: pass
evidence: "uv run pytest -k 'exit0 or malformed or missing_jq or unwritable_log or empty_stdin' → 14/14 PASS"
AC4:
status: pass
evidence: "pnpm test → 585/585 PASS"
review_observations:
- key: no_set_euo_pipefail
status: ok
detail: "hook が set -euo pipefail を使わず、全操作で個別エラーハンドリングを行い常に exit 0 を保証している"
- key: no_raw_command_in_jsonl
status: ok
detail: "JSONL に full_command / command_line / command / raw_command は存在しない。command_sha256 + command_preview_redacted のみ記録"
- key: command_preview_redacted_leakage
status: ok
detail: "Authorization: / GH_TOKEN / GITHUB_TOKEN / --header / -H / HEREDOC / URL query token が redact されること、TestJsonlSchema::test_gh_token_redacted_in_preview で検証済み"
- key: guard_name_field
status: ok
detail: "JSONL に guard_name: rtk_boundary_shadow_guard が含まれ、TestJsonlSchema::test_guard_name_is_correct で検証済み"
- key: settings_json_integrity
status: ok
detail: "PR 前後で hooks キー(PostToolUse / PreCompact / PreToolUse / Stop / SubagentStop)は全て保持。PreToolUse が 2→3 に増加のみ(新規追加のみ)。jq で valid JSON 確認済み"
- key: stdout_always_empty
status: ok
detail: "TestJsonlSchema::test_stdout_is_always_empty で全ケース確認済み"
- key: fixture_matrix_13_entries
status: ok
detail: "TestClassificationMatrix 13 ケース全て PASS。contract 契約の fixture matrix と完全一致"
- key: curl_env_out_of_scope
status: ok
detail: "curl/wget は out_of_scope_logged で記録のみ。contract の In Scope 記述と合致"
findings: []
fix_delta: nullレビュー結論
APPROVE。AC1〜AC4 全て独立照合で PASS。Allowed Paths は exact_match。
独立照合した主要観点
JSONL に raw command を保存していないこと: test_no_raw_command_in_jsonl でテスト済み。full_command / command_line / command / raw_command のいずれも JSONL に存在しない。記録は command_sha256 と command_preview_redacted(200 bytes 上限・redact 済み)のみ。
hook が常に exit 0 であること: set -euo pipefail を使わず、全操作を個別エラーハンドリングで処理。malformed stdin / missing jq / unwritable log / empty stdin の 14 ケース全て exit 0 確認。
settings.json への追記が既存 hook を削除・変更していないこと: main → PR で hook キー集合は同一(PostToolUse / PreCompact / PreToolUse / Stop / SubagentStop)。PreToolUse エントリが 2→3 に増加のみ(新規追加のみ、既存エントリは変更なし)。
guard_name フィールドが JSONL に含まれること: test_guard_name_is_correct で rtk_boundary_shadow_guard を確認済み。
Allowed Paths 外のファイルを変更していないこと: git diff origin/main...origin/worktree-issue-823-rtk-boundary-shadow-guard --name-only の結果が contract Allowed Paths と exact_match。
敵対的レビュー結論判定: REQUEST_CHANGES / Draft 維持。 確認した関連文脈#823 は #816 の child で、目的は「Codex 側 AGENTS.md の rtk 境界に対して Claude 側の観測手段がない」問題を埋め、direct risky command を shadow JSONL に記録するだけの PreToolUse hook を追加することです。enforce / exit 2 block は out of scope です。 既存レビューは ブロッカー1. GitHub Actions が failure のままhead SHA 修正: PR body を日本語比率 gate に通る形へ修正してください。hook-only PR なので runtime preview の有無より、この CI failure の解消が優先です。 2.
|
…wrapper bypass, stash/worktree classification - gh api -f/-F/--raw-field/--field/--input now classified as mutating_gh_api (implicit POST) - explicit --method GET with field flags correctly classified as safe_readonly_gh - Authorization: Bearer/token headers and quoted -H headers fully redacted before truncation - access_token URL query param redacted - git -C <path> <subcmd> correctly extracts subcmd for classification - bash -lc / command wrapper patterns detected as mutating or out_of_scope_logged - git checkout/switch/restore reclassified as mutating_git - git stash (bare/push/pop) reclassified as mutating_git - git stash list/show remain safe_readonly_git - git worktree add/remove reclassified as mutating_git - git worktree list remains safe_readonly_git - jq -cn compact output in fallback write path (JSONL per-line parse compatibility) - Added 26 new test cases: TestGhApiFieldFlags, TestAuthSecretsRedacted, TestWrapperBypassPatterns, TestMutatingGitSubcommands - Total: 62 tests (was 36), all passing Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: true
reviewed_head_sha: e63649bd7ef8a5993b674b828912b258345eb22a
required_auto_actions: []
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
expected_contract_fingerprint: "sha256:55753fabb48a5e9b9e1b44e00991db9ce2672d6a3614b6e97a7339a7ea582147"
contract_source_kind: issue_comment
contract_source_id: "squne121/loop-protocol/issues/823#issuecomment-4698464869"
changed_files:
- .claude/hooks/rtk_boundary_shadow_guard.sh
- .claude/hooks/tests/test_rtk_boundary_shadow_guard.py
- .claude/settings.json
allowed_paths:
- .claude/hooks/rtk_boundary_shadow_guard.sh
- .claude/hooks/tests/test_rtk_boundary_shadow_guard.py
- .claude/settings.json
outside_allowed_paths: []
gate_result: all_within_allowed_paths
ac_verification:
AC1:
status: pass
evidence: "git diff base...head --name-only に .claude/hooks/rtk_boundary_shadow_guard.sh が存在する"
AC2:
status: pass
evidence: "settings.json の PreToolUse[matcher=Bash] に rtk_boundary_shadow_guard.sh が登録済み。既存 secret_boundary_guard / guard-japanese-prose.sh と競合なし"
AC3:
status: pass
evidence: "TestAlwaysExit0 (14件) が exit0_risky_git_commit / exit0_risky_git_push / exit0_malformed_stdin_not_json / exit0_unwritable_log / exit0_missing_jq 等を網羅。CI python-test: pass"
AC4:
status: pass
evidence: "CI test (585/585 pass) / lint / typecheck / build / e2e 全 pass"
iteration1_fixes_verified:
gh_api_field_flags:
status: verified
detail: "TestGhApiFieldFlags: -f/--raw-field/-F/--field/--input → mutating_gh_api。--method GET 例外も pass"
auth_header_redaction:
status: verified
detail: "TestAuthSecretsRedacted: Bearer/token/quoted -H 全体を truncation 前に redact。test_redact_before_truncation が SHORTTOKEN 漏洩がないことを確認"
wrapper_bypass_tests:
status: verified
detail: "TestWrapperBypassPatterns: git -C push → mutating_git、bash -lc 'git push' → mutating_git or out_of_scope_logged、command git push → 同上"
checkout_switch_restore_mutating:
status: verified
detail: "TestMutatingGitSubcommands: checkout/switch/restore → mutating_git。stash list/show → safe_readonly_git。worktree list → safe_readonly_git。add/remove/push/bare → mutating_git"
no_raw_command_in_jsonl:
status: verified
detail: "test_no_raw_command_in_jsonl: full_command/command_line/command/raw_command キーが JSONL に含まれないことを確認"
ci_status:
pr_body_japanese_check: pass
test: pass # 585/585
python_test: pass # 62 tests
build: pass
lint: pass
typecheck: pass
e2e: pass
actionlint: pass
findings: []
fix_delta: nullレビュー所見
Allowed Paths Gate
独立再計算: PR の changed files (git diff 86338c72...e63649bd --name-only) は下記 3 ファイルのみであり、Issue contract の Allowed Paths と完全一致する。contract fingerprint (sha256:55753fabb48a5e9b9e1b44e00991db9ce2672d6a3614b6e97a7339a7ea582147) は issue body の SHA256 と照合済み。gate: ok。
前回指摘事項の充足確認
-
gh api field flags 分類:
-f/--raw-field/-F/--field/--inputをmutating_gh_apiに分類する実装を確認。--method GET明示時はsafe_readonly_ghの例外も実装済み。TestGhApiFieldFlags (5件) で検証済み。 -
Authorization header redaction 強化: redact は truncation (200 bytes) より前に full command 全体に適用される実装になっており、機密がバッファ後半に来ても漏洩しない。quoted
-H 'Authorization: ...'および--header形式の全体 redact も実装済み。 -
wrapper/bypass テスト:
git -C <path> <subcmd>のサブコマンド抽出、bash -lc/commandwrapper 内 mutating git/gh の検出が実装済み。テストは意図的にmutating_git or out_of_scope_loggedの範囲で検証しており、deny 方向に倒す保守的設計。 -
checkout/switch/restore/stash/worktree 精緻化: branch 切り替え・ファイル上書き系はすべて
mutating_git。stash list/stash show/worktree listのみsafe_readonly_git。 -
JSONL に raw command を含まない:
test_no_raw_command_in_jsonlがfull_command/command_line/command/raw_commandキーの不在を確認。 -
shadow log 集計コマンド: PR body に
jq集計コマンドが記載されており、誤検知率確認方法が明示されている。
追加確認事項
stdoutは常に空であることをtest_stdout_is_always_emptyで検証済み。command_sha256のsha256:prefix をtest_command_sha256_formatで検証済み。command_preview_redactedの最大 200 bytes をtest_command_preview_redacted_max_200_bytesで検証済み。- settings.json の既存 hooks (secret_boundary_guard / guard-japanese-prose.sh / session_manifest 等) に競合なし。
判定根拠
全 AC が CI で検証済み。Allowed Paths 外変更なし。前回指摘 6 点すべて対処済みかつテストで証跡化されている。fail-open 設計(jq 不在・unwritable log・malformed stdin でも exit 0)が担保されている。APPROVE。
概要
Issue #823 の実装。Claude 側の rtk trust boundary を shadow mode で監視する PreToolUse hook を追加する。
.claude/hooks/rtk_boundary_shadow_guard.sh: mutating git / gh / dependency mutation を JSONL に記録し、常に exit 0 で通過.claude/settings.json: PreToolUse hooks に Bash ツール対象として追加.claude/hooks/tests/test_rtk_boundary_shadow_guard.py: 62 テストケース(PR レビュー指摘を反映した追加テスト含む)変更内容
hook スクリプトの改善点
-f/--raw-field/-F/--field/--inputフラグが含まれる場合は暗黙的 POST としてmutating_gh_apiに分類(--method GETが明示されている場合は除外)Bearer/token形式および quoted ヘッダー全体(-H 'Authorization: ...')を redact 対象に追加。truncation より先に full command に redact を適用して機密漏洩を防止git -C <path> <subcmd>形式でも<subcmd>を正しく分類bash -lc/commandwrapper 内の mutating git コマンドをmutating_gitまたはout_of_scope_loggedとして記録git checkout/git switch/git restore→mutating_git(branch 切り替え・ファイル上書き)git stash(bare)/git stash push/git stash pop→mutating_gitgit stash list/git stash show→safe_readonly_gitgit worktree add/git worktree remove→mutating_gitgit worktree list→safe_readonly_gitjq -cnでコンパクト JSON を出力(per-line parse 互換)テスト追加(26 テストケース追加)
TestGhApiFieldFlags:-f/-F/--input/--method GETの分類検証TestAuthSecretsRedacted: Authorization header / access_token URL query の redaction 検証(parametrize)TestWrapperBypassPatterns:git -C/bash -lc/commandwrapper パターンの検証TestMutatingGitSubcommands: checkout/switch/restore/stash/worktree の分類検証shadow log 集計コマンド(誤検知率確認方法)
誤検知率の確認は以下のコマンドで集計する:
検証結果
.claude/hooks/rtk_boundary_shadow_guard.sh存在確認 — PASS.claude/settings.jsonにrtk_boundary_shadow_guard登録 — PASSuv run pytest .claude/hooks/tests/test_rtk_boundary_shadow_guard.py -v— 62/62 PASSpnpm test— 585/585 PASS関連 Issue(クローズ対象)
本 PR は Issue #823 をクローズする。
Closes #823