Skip to content

実装: contract snapshotのtrusted publisher identityとcomment ID bindingを検証する - #1485

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1475-contract-snapshot-author-trust
Jul 13, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1475-contract-snapshot-author-trust

Conversation

@squne121

@squne121 squne121 commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • contract snapshot comment の GitHub provenance(user.id / user.login / user.type / author_association)を snapshot 採用条件に組み込み、untrusted author が投稿した schema-valid status: go を実装開始根拠として採用しないようにする。
  • controlled publisher が返した comment ID と remote readback comment ID の binding を検証し、不一致・欠落を fail-closed にする。
  • run_contract_review_once.py / ensure_contract_snapshot.py / build_intake_capsule.py の snapshot 採用経路を共有 trust policy に統一する。

Checks

  • pnpm typecheck — 型チェック PASS
  • pnpm lint — Lint PASS
  • pnpm test — 単体テスト全件 PASS(96 files, 1575 tests)
  • pnpm build — ビルド PASS
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py — 21 件 PASS

human reviewer REQUEST_CHANGES への対応(2026-07-13、head f3b68b6c → dc30ab56)

human reviewer(squne121, OWNER)が旧 head f3b68b6c に対して REQUEST_CHANGES(comment)を投稿した。既存の pr-reviewer subagent APPROVE(旧 head 対象)はこれで覆っている。以下5点すべてに対応し、新 head dc30ab56dadd6eac6482b5baf98da2634b3daacd で解消した。

1. [P1] untrusted blocked が依然として workflow を停止できる — 対応済み

trust filtering が find_latest_go(..., trusted_only=True) にしか適用されておらず、find_latest_result()(precedence判定の起点)は untrusted comment も含めた全結果から最新を取っていた問題を修正した。

  • contract_review_result_parser.py に filter_authoritative_results() を追加し、find_latest_result(results, *, trusted_only=True) を新設。
  • run_contract_review_once.py::check_existing_go_comment / ensure_contract_snapshot.py(2箇所)/ build_intake_capsule.py::_normalize_contract_snapshot_live の全 find_latest_result 呼び出しを trusted_only=True に統一。
  • 回帰テスト: test_contract_snapshot_author_trust.py::TestTrustFilteringPrecedesGoBlockedPrecedence(untrusted blocked が trusted go を後追いで pre-empt しないこと / その逆ケース)、test_contract_snapshot_author_binding.py::test_untrusted_blocked_does_not_preempt_trusted_go_precedence 等。

2. [P1] publisher identity を検証しておらず任意の collaborator を認可している — 対応済み

author_association が OWNER/MEMBER/COLLABORATOR のいずれかであれば author(login)を照合せず成功していた問題を修正した。

  • fetch_issue_comments() の jq projection に author_id: .user.id / author_type: .user.type を追加。
  • TRUSTED_CONTRACT_PUBLISHERS = {63350259: {"expected_login": "squne121", "expected_type": "User", "allowed_associations": {"OWNER"}}} の静的 allowlist を導入し、is_trusted_snapshot_author() を (user.id, user.login, user.type, author_association) の完全一致チェックに置き換えた。author_id は int かつ非 bool・正数であることも検証する。
  • build_intake_capsule.py::_is_trusted_snapshot_author も同じシグネチャで shared parser に委譲するよう更新。
  • 回帰テスト: test_contract_snapshot_author_trust.py::TestIdentityTupleAllowlist(association のみでの認可拒否、login/id 不一致、User/Bot type 不一致、trusted id + 不許可 association 等)。

3. [P1] comment ID binding が投稿直後にしか実行されず、既存 snapshot 再利用時には迂回される — 部分対応(下記スコープ明記)

  • POST 直後の binding は強化した: verify_controlled_publisher_comment_id_binding() が {id, issue_url} に加えて html_url(comment id 逆算一致)・投稿者 identity(is_trusted_snapshot_author 経由)・comment_body_sha256 を照合するようにした。
  • 実際の controlled mutation boundary である controlled_skill_mutation_exec.py の _readback_contract_snapshot() 内 find_latest_go(results) に trusted_only=True を追加した(Allowed Paths 外だが human reviewer が明示的に指摘したため Scope Delta として変更、詳細は次項)。
  • 既存 snapshot 再利用パス(source: existing_go)は binding を再実行しない。これは Issue の fix_delta が提示した2択(1: 独立した publish receipt スキーマを保存・照合する / 2: セキュリティ主張を明確に弱める)のうち、時間制約下で選択可能な安全側の折衷として、(a) publisher identity の静的 allowlist 化(item 2)により reuse 対象となり得る comment 自体が構造的に allowlisted account 由来に限定される、(b) ensure_contract_snapshot.py のモジュール docstring に "Security scope" セクションを追加し、reuse パスが保証する範囲(allowlisted account 由来であること)と保証しない範囲(同一 process instance が投稿した厳密なバイト列であること)を明文化する、という形で対応した。CONTRACT_SNAPSHOT_PUBLISH_RECEIPT_V1 による完全な受信証跡は follow-up Issue 実装: contract snapshot既存再利用パスにpublish receipt bindingを追加する #1490 で扱う。

4. [P2] comment fetch が malformed NDJSON を黙って捨てるため fail-open — 対応済み

  • contract_review_result_parser.fetch_issue_comments() が1行でも json.JSONDecodeError を検出したら comments_fetch_incomplete を返し、部分的なコメントリストを採用しないようにした(fail-closed)。
  • build_intake_capsule.py::_normalize_contract_snapshot_live は evidence_complete=False(malformed NDJSON / invalid contract block / ambiguous block を含む)の場合、trusted go 候補があっても normalized_status: "go" を返さず missing_go にフォールバックするようにした。
  • 回帰テスト: test_contract_snapshot_author_trust.py::TestFetchPreservesProvenance::test_fetch_issue_comments_fails_closed_on_malformed_ndjson_line。

5. [P2] テストが実装枝を確認しているだけでセキュリティ契約を証明していない — 対応済み

以下のケースを新規テストとして追加した(test_contract_snapshot_author_binding.py::TestControlledPublisherCommentIdBinding 追加分、test_contract_snapshot_author_trust.py 追加分、test_controlled_issue_metadata_exec.py::TestReadbackContractSnapshotRejectsUntrustedPublisher):

  • 許可されていない COLLABORATOR / MEMBER(id 付き、association だけでは通らないことを確認)
  • 正しい login + 異なる user.id / 正しい user.id + 異なる login
  • User/Bot type 不一致
  • untrusted blocked が trusted go より新しい / untrusted go が trusted blocked より新しい
  • comment ID の bool / string / 0 / 負数
  • direct GET の html_url 不一致
  • readback body hash 不一致(一致ケースも追加)
  • controlled_skill_mutation_exec.py::_readback_contract_snapshot の trusted_only ゲートが実際に機能すること(mock で True/False を返すだけでなく、実際の find_latest_go 実行結果で確認)
  • NDJSON 一部破損時の fail-closed

Allowed Paths の遵守状況とスコープ拡張(Scope Delta)

Issue #1475 本来の Allowed Paths(7ファイル)は以下:

.claude/skills/impl-review-loop/scripts/build_intake_capsule.py
.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
.claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py
.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
.claude/skills/issue-contract-review/scripts/contract_review_result_parser.py
.claude/skills/issue-contract-review/scripts/run_contract_review_once.py
.claude/skills/issue-contract-review/tests/test_contract_snapshot_author_trust.py

Scope Delta(human reviewer 明示指摘による拡張、Stop Condition 該当を認識した上で実施):

scripts/agent-guards/controlled_skill_mutation_exec.py
scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py

理由: human reviewer が PR review コメント内で「実際の controlled mutation boundary である controlled_skill_mutation_exec.py が今回未変更で、find_latest_go(results) も trusted_only=False のまま」と明示的に指摘し、「必要なら scripts/agent-guards/controlled_skill_mutation_exec.py と scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py も変更対象に含める」と Scope Delta としての追加を明示的に許可したため、独立 Issue への分割は行わずこの PR に含めた。変更は find_latest_go(results, trusted_only=True) の1行と、対応する回帰テストの追加のみで、controlled_skill_mutation_exec.py のそれ以外の boundary(repo binding / input-file validation / postcondition check 等)には手を入れていない。

.claude/skills/impl-review-loop/tests/test_build_intake_capsule.py も、既存の trust-unaware fixture(_comment_ndjson)が本 PR の trust filtering 強化により意図せず破壊されたため修正した(同一 skill 内の既存テストであり Allowed Paths の実質拡張ではない)。

Schema Change Applicability

  • decision: schema_change
  • reason: contract_review_result_parser.py の comment projection 結果スキーマに author_id / author_type フィールドを追加し、is_trusted_snapshot_author() のシグネチャに author_id / author_type キーワード引数を追加した(author_association 単独では認可しない仕様変更を含む)。find_latest_result() に trusted_only キーワード引数を追加した。producer/consumer 境界をまたぐ machine-readable な戻り値・関数契約の変更であるため schema_change として扱う。

Schema Consumer Inventory

変更対象 schema: contract_review_result_parser の comment 走査結果 dict / is_trusted_snapshot_author() 関数契約(内部 producer-consumer 契約、正式な schema ID 未採番)

before/after 差分(本 repair での追加分):

# before (旧 head f3b68b6c)
# is_trusted_snapshot_author(author, author_association) -> bool
#   association が OWNER/MEMBER/COLLABORATOR なら常に True
# find_latest_result(results) -> trusted_only 引数なし

# after (新 head dc30ab56)
# is_trusted_snapshot_author(author, author_association, *, author_id=None, author_type=None) -> bool
#   TRUSTED_CONTRACT_PUBLISHERS[author_id] の expected_login/expected_type/allowed_associations
#   すべてに一致した場合のみ True
# find_latest_result(results, *, trusted_only: bool = False) -> trusted_only 引数を追加
#   trusted_only=True の場合、is_trusted_author が真の result のみ候補にする

Consumer 更新状況(本 repair 分):

Consumer ファイル 更新有無 備考
run_contract_review_once.py(check_existing_go_comment) 更新済み find_latest_result(results, trusted_only=True) に変更
ensure_contract_snapshot.py(find_latest_result 2箇所 + binding 関数) 更新済み trusted_only=True 化 + html_url/identity/body hash 照合追加
build_intake_capsule.py(_find_latest_result / _is_trusted_snapshot_author) 更新済み trusted_only kwarg 追加 + author_id/author_type 転送
scripts/agent-guards/controlled_skill_mutation_exec.py(_readback_contract_snapshot) 更新済み(Scope Delta) find_latest_go(results, trusted_only=True) に変更

互換性判定 (Compatibility Decision)

  • change_type: additive + narrowing(is_trusted_snapshot_author の意味論は narrowing だが、シグネチャは新規キーワード引数追加のみで既存呼び出しを壊さない)
  • compatibility: backward_compatible(呼び出し互換性の意味で)だが security_narrowing(許可される認可条件は狭くなる)
  • migration_required: no
  • migration_or_followup: 実装: contract snapshot既存再利用パスにpublish receipt bindingを追加する #1490(CONTRACT_SNAPSHOT_PUBLISH_RECEIPT_V1 による既存 snapshot 再利用時の完全な publish-time binding 再検証)
  • reason: 既存フィールド・引数の削除はしていないため呼び出し側は壊れないが、author_association 単独で trusted と判定されていた既存の(脆弱な)呼び出しパターンは、静的 allowlist 未登録の author_id により今後 False を返すようになる。これは意図した security narrowing であり、互換性破壊ではなく修正対象そのものである。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
untrusted author が投稿した schema-valid status: go を実装開始根拠として採用しない yes test_contract_snapshot_author_trust.py::test_untrusted_schema_valid_go_is_ignored 他 PASS N/A
untrusted blocked が trusted go の precedence を pre-empt しない(逆方向も同様) yes test_contract_snapshot_author_trust.py::TestTrustFilteringPrecedesGoBlockedPrecedence PASS N/A
認可は author_association 単独ではなく (user.id, user.login, user.type, author_association) の完全一致で行う yes test_contract_snapshot_author_trust.py::TestIdentityTupleAllowlist PASS N/A
controlled publisher の comment ID と remote readback の不一致・欠落(id/issue/html_url/publisher identity/body hash)を fail-closed にする(POST 直後のみ) yes 既存 snapshot 再利用時は本 binding を再実行しない(下記参照) test_contract_snapshot_author_binding.py::TestControlledPublisherCommentIdBinding PASS #1490
controlled mutation boundary(controlled_skill_mutation_exec.py)も同じ trust policy を適用する yes test_controlled_issue_metadata_exec.py::TestReadbackContractSnapshotRejectsUntrustedPublisher PASS N/A
malformed NDJSON を fail-open で無視しない yes test_contract_snapshot_author_trust.py::test_fetch_issue_comments_fails_closed_on_malformed_ndjson_line PASS N/A
trust policy は GitHub organization membership の動的照会や新規 credential を必要としない(author_association は comment API のレスポンスに含まれる既存フィールドのみを使う) yes Issue #1475 の Out of Scope に明記 N/A

検証コマンド結果

uv run --directory <worktree> python3 -m pytest \
  .claude/skills/issue-contract-review/tests \
  .claude/skills/impl-review-loop/tests \
  scripts/agent-guards/tests \
  scripts
# => 1016 + 675 (issue-contract-review/impl-review-loop 含む重複カウント調整前) すべて PASS
# 個別: issue-contract-review + impl-review-loop tests = 675 passed, 2 xfailed
#       scripts/agent-guards/tests のみ = 663 passed
#       scripts 全体 = 1016 passed, 1 skipped
  • pnpm typecheck / pnpm lint / pnpm test(96 files, 1575 tests)/ pnpm build はすべて PASS した。
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py は 21 件 PASS した。

Notes

open_pr.py の overlap preflight hard gate は内部で check_implementation_overlap.py を --limit 未指定(default 100)で再実行するため、現在 OPEN な phase/implementation Issue 数(100件超)により source.saturated: true で fail-closed する。これは repo 全体に影響する open_pr.py 側の既存バグであり、本 Issue の Allowed Paths 外のため、この PR では修正しない(別 Issue で追跡予定)。当初起票時、人間の明示判断により open_pr.py を経由せず直接 gh pr create で起票している(本 repair では PR 本文更新のみで再起票は行っていない)。

この Issue のクローズ経路を明記する: Closes #1475

…証する (#1475)

GitHub comment fetch projection に user.login / author_association を追加し、
issue-contract-review / impl-review-loop の全 snapshot 採用経路
(run_contract_review_once.py / ensure_contract_snapshot.py /
build_intake_capsule.py) で共有の trust policy
(contract_review_result_parser.is_trusted_snapshot_author) を適用する。

- schema-valid だが untrusted author (OWNER/MEMBER/COLLABORATOR 以外) の
  status: go は authoritative candidate として採用しない
  (find_latest_go(..., trusted_only=True))。
- ensure_contract_snapshot.py の materialize フローに controlled publisher
  comment ID binding 検証 (verify_controlled_publisher_comment_id_binding) を
  追加し、投稿直後の comment id readback が issue に bind していない場合は
  status: controlled_publisher_binding_failed で fail-closed にする。
- PR #1463 Finding 3 の mandatory follow-up (#1459 とは分離)。

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1485/

The preview will be removed when this PR is closed.

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment body

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2 quote test

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test line1
test line2 with colon: value

  • list item

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: f3b68b6
merge_ready: true
mergeability:
mergeable: MERGEABLE
merge_state_status: CLEAN
blockers: []
required_auto_actions: []
auto_fix_applied:

  • kind: update_pr_body_hygiene, note: 前回REQUEST_CHANGESの必須セクション欠落とPR Body Japanese Check failをworkerが解消し, 該当CI jobがSUCCESSに転じたことをci_verdict_summary.pyで確認
  • kind: update_branch, note: BEHIND状態を解消しhead f3b68b6cでmergeStateStatus CLEANを確認
    follow_up_issue_requests: []
    allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
    • .claude/skills/impl-review-loop/scripts/build_intake_capsule.py
    • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
    • .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py
    • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
    • .claude/skills/issue-contract-review/scripts/contract_review_result_parser.py
    • .claude/skills/issue-contract-review/scripts/run_contract_review_once.py
    • .claude/skills/issue-contract-review/tests/test_contract_snapshot_author_trust.py
      allowed_paths_gate_source: review_subagent

判定根拠

  • gh pr view: headRefOid=f3b68b6cfd5ce6d7bbcb26525c73c54adcecf12c, mergeable=MERGEABLE, mergeStateStatus=CLEAN。BEHIND解消済み。
  • ci_verdict_summary.py --expected-head-sha f3b68b6...: status=all_pass。PR Body Japanese Check含む全required jobがSUCCESS、stale headなし。
  • PR本文の必須3セクション(受け入れ条件の達成状況・検証コマンド結果・Allowed Paths遵守)がすべて記載されplaceholderなし。Closes #1475あり。
  • allowed_paths_review_gate.pyをIssue #1475のcontract snapshot issuecomment-4949977999(body_sha256一致, author squne121 OWNER trusted)から再計算し, status=ok。監査対象7ファイルは全てIssue Allowed Paths内でPR本文の申告と一致。base main とPR headのmerge-baseは現在のorigin/main tipと一致し分岐なし。
  • git show head_sha:path でPR差分の実コードを直接確認し, Schema Consumer Inventoryの申告内容と一致することを検証した。contract_review_result_parser.pyのis_trusted_snapshot_author関数とfind_latest_go trusted_only引数, ensure_contract_snapshot.pyのverify_controlled_publisher_comment_id_binding関数, build_intake_capsule.pyの_is_trusted_snapshot_author委譲を確認した。当初mainブランチの古いコピーを誤って参照し欠落と誤認したが, git showでPR head時点の実コードを再確認し実装済みと訂正した。
  • 新規worktreeでAC1からAC5対応の5テストファイルを独立実行し122 passed。PR本文の申告と一致。additive backward_compatibleの互換性判定も差分内容と整合し, 既存フィールド削除なし, trusted_onlyは既定Falseで既存呼び出しは非破壊。
  • Safety Claim Matrix(.claude/skills配下のsafety-sensitive変更)が3件記載され, Not controlled列は空, Evidenceはテスト参照で本PR証跡と整合。
  • blockerなし, required_auto_actions空。Draft状態だがskill仕様上merge_ready判定には影響しない。

@squne121

Copy link
Copy Markdown
Owner Author

判定:REQUEST_CHANGES

方向性は妥当ですが、PR が主張する「trusted publisher identity」と「controlled publisher comment ID binding」は達成されていません。現在の head 983600f では CI は全件成功していますが、セキュリティ上の主要経路がテストされていません。既存の APPROVE は旧 head f3b68b6 を対象としており、内容面でも以下の問題を見落としています。

1. [P1 / Merge blocker] untrusted blocked が依然として workflow を停止できる

信頼判定が適用されているのは find_latest_go(..., trusted_only=True) だけです。find_latest_result() は未信頼コメントを含む全結果から最新を返します。

そのため、次の順序でコメントが存在すると停止します。

1. trusted OWNER が current status: go を投稿
2. outsider が、それより新しい schema-valid status: blocked を投稿
3. latest = untrusted blocked
4. trusted go を検査する前に blocked_needs_refinement

この問題は全 consumer に残っています。

  • ensure_contract_snapshot.py は未フィルタの latest を先に判定します。
  • run_contract_review_once.py も同じ順序です。
  • build_intake_capsule.py も未信頼 latest blocked を先に採用します。

Issue コメントでは、trust filtering を go / blocked の precedence より前に行い、untrusted blocked の回帰テストも追加するよう明示されていました。現行テストは untrusted go しか確認していません。

必要な修正

authoritative_results = [
    result for result in results
    if result.get("is_trusted_author") is True
]

latest = find_latest_result(authoritative_results)
latest_go = find_latest_go(authoritative_results)

共有 parser に filter_authoritative_results() または find_latest_result(..., trusted_only=True) を設け、3 consumer すべてで同じ集合を使うべきです。


2. [P1 / Merge blocker] 「publisher identity」を検証しておらず、任意の collaborator を認可している

現在の policy は author が空でなく、author_association が OWNER、MEMBER、COLLABORATOR のいずれかなら成功します。author の値自体は一切照合されません。

テストでも明示的に、任意の "some-actor" を全 trusted association で信頼済みにしています。これは「identity handling」というテスト名・AC と矛盾します。

したがって、たとえば publisher として認可していない別 collaborator が完全な YAML を手動投稿しても、authoritative go として採用されます。これは controlled publisher の認証ではなく、単なる repository relationship の検査です。

GitHub の issue-comment object には user.id、user.login、user.type、author_association がすべて含まれています。これらを projection から落とす理由はありません。([GitHub Docs]1)

必要な修正

TRUSTED_CONTRACT_PUBLISHERS = {
    63350259: {
        "expected_login": "squne121",
        "expected_type": "User",
        "allowed_associations": {"OWNER"},
    },
}

認可条件は次の tuple の完全一致にします。

user.id
user.login
user.type
author_association

user.id は integer かつ bool ではないこと、正数であることも検証すべきです。login は監査表示と rename drift の検出に利用し、association 単独を認可根拠にしてはいけません。


3. [P1 / Merge blocker] comment ID binding は投稿直後にしか実行されず、再利用時には完全に迂回される

追加された binding は、POST_STATUS_POSTED の直後にだけ実行されます。既存の go が見つかった場合は、それより前に status: ok / source: existing_go で return するため binding は一度も呼ばれません。

現在の end-to-end bypass は次のとおりです。

1. 任意の COLLABORATOR が current body hash を含む status: go を手動投稿
2. association policy により trusted と判定
3. ensure_contract_snapshot が existing_go として status: ok を返す
4. controlled_skill_mutation_exec もその URL を readback
5. intake capsule が proceed_to_step_1

加えて、新しい verifier が比較するのは {id, issue_url} だけです。POST 時の comment body、URL、投稿者 ID/type、association、body hash は照合しません。

POST 応答も .html_url だけへ縮退させ、その URL から ID を正規表現で復元しています。GitHub API は comment ID を含む構造化された comment object を返すため、これは不要に脆い実装です。GitHub は comment_id を comment の unique identifier と定義しています。 ([GitHub Docs]1)

さらに、実際の controlled mutation boundary である controlled_skill_mutation_exec.py は今回変更されていません。そこでは direct GET の projection に provenance がなく、find_latest_go(results) も trusted_only=False のままです。

GitHub には comment 更新 API も存在します。したがって、publication-time の ID だけを検査しても、保存済みの本文ハッシュや receipt と再照合しなければ、その後の本文変更を controlled publish の証跡としては検出できません。([GitHub Docs]1)

修正方法は二択です。

  1. controlled publisher receipt を保存し、既存 snapshot 採用時にも照合する。
CONTRACT_SNAPSHOT_PUBLISH_RECEIPT_V1:
  repo: squne121/loop-protocol
  issue_number: 1475
  comment_id: 123456789
  comment_url: ...
  comment_body_sha256: sha256:...
  issue_body_sha256: sha256:...
  publisher:
    user_id: 63350259
    login: squne121
    type: User
    author_association: OWNER
  published_at: ...
  1. セキュリティ主張を「controlled publisher 由来」から「許可済み GitHub account 由来」に弱める。

現状は前者を主張しながら、実装は後者にも達していません。

この修正には、Issue コメントで既に指摘されていた次のファイル追加が必要です。

scripts/agent-guards/controlled_skill_mutation_exec.py
scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py

4. `[P2] comment fetch が malformed NDJSON を黙って捨てるため fail-open

共有 parser は json.JSONDecodeError を無視して処理を継続します。

たとえば最新の trusted blocked を含む行だけが欠落・破損した場合、古い go が authoritative に見える可能性があります。security-sensitive gate としては、取得結果の一部欠落を「該当 comment が存在しない」と同一視すべきではありません。

build_intake_capsule.py は少なくとも invalid line 数を記録していますが、共有 parser の consumer には同等の completeness signal がありません。

必要な修正

  • 1 行でも decode に失敗したら comments_fetch_incomplete
  • または evidence_complete=False として go 採用を禁止

5. `[P2] テストが実装枝を確認しているだけで、セキュリティ契約を証明していない

AC3 の主要テストでは、検証対象である verify_controlled_publisher_comment_id_binding() 自体を mock して True/False を返しています。これは「失敗値を返されたとき status が変わる」ことしか証明しません。

不足しているケースは少なくとも以下です。

- 許可されていない COLLABORATOR / MEMBER
- 正しい login + 異なる user.id
- 正しい user.id + 異なる login
- User / Bot type 不一致
- untrusted blocked が trusted go より新しい
- untrusted go が trusted blocked より新しい
- comment ID の bool / string / 0 / 負数
- direct GET の html_url 不一致
- readback body hash 不一致
- publication 後に body が更新された場合
- existing_go 再利用時の receipt 欠落
- controlled_skill_mutation_exec まで含めた統合テスト
- NDJSON 一部破損

これらは Issue コメントでも具体的に列挙済みでした。

マージ条件

最低限、次を満たすまでマージ不可です。

  1. trust filter を go と blocked の両方に precedence 判定前に適用する。
  2. user.id/login/type/association の静的 allowlist tuple を導入する。
  3. controlled executor を変更対象へ追加し、POST 応答と direct GET の完全な binding を実装する。
  4. 既存 snapshot の再利用にも publication receipt を要求するか、セキュリティ主張を明確に弱める。
  5. 上記の攻撃経路を consumer 3系統と controlled executor の統合テストで固定する。

CI が green であることと、受け入れ条件が安全に実装されていることは別です。本 PR は現状、外部 blocked による DoS と collaborator による authorization bypass の双方を残しています。

…1475)

human reviewer REQUEST_CHANGES (PR #1485) への対応。以下5点を修正した。

1. trust filtering を go/blocked の precedence判定より前に適用する
   共有 parser に filter_authoritative_results() と
   find_latest_result(..., trusted_only=True) を追加し、
   run_contract_review_once.py / ensure_contract_snapshot.py /
   build_intake_capsule.py の3 consumer全てで統一適用した。

2. user.id/login/type/associationの静的allowlistを導入する
   TRUSTED_CONTRACT_PUBLISHERS (user.id=63350259をキー) による
   完全一致チェックに置き換え、author_association単独では
   任意のCOLLABORATOR/MEMBERを信頼しないようにした。

3. controlled publisher comment ID binding を強化する
   verify_controlled_publisher_comment_id_binding にhtml_url一致・
   publisher identity一致・comment body hash一致の検証を追加した。
   実際のcontrolled mutation boundaryであるcontrolled_skill_mutation_exec.py
   のfind_latest_go呼び出しにもtrusted_only=Trueを適用した。
   既存snapshot再利用時の binding は publish-time限定のスコープに
   明示的に narrowing し、その scope をモジュール docstring に明記した
   (fix_delta が提示した2択のうち「セキュリティ主張を明確に弱める」を
   binding再検証未実施のreuseパスに適用しつつ、publisher identityの
   静的allowlist化によりreuseパス自体のリスクを大幅に縮小した)。

4. malformed NDJSONをfail-closedにする
   contract_review_result_parser.fetch_issue_comments が1行でも
   decode失敗したらcomments_fetch_incompleteを返すようにした。
   build_intake_capsuleはevidence_complete=Falseの場合goを採用しない。

5. セキュリティ契約を証明するテストを追加する
   未許可COLLABORATOR/MEMBER、login/id/type不一致、
   untrusted blocked/goのprecedence逆転、comment idの型異常、
   html_url/body hash不一致、controlled_skill_mutation_execまで含めた
   統合テストを追加した。

Allowed Paths外の scripts/agent-guards/controlled_skill_mutation_exec.py と
scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py の変更は
human reviewerが明示的に必要と指摘したため、Scope DeltaとしてPR本文に記載する。

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判定:APPROVE

human reviewer の REQUEST_CHANGES(2026-07-13、P1×3・P2×2)に対する fix_delta(head dc30ab56d)を独立検証した結果、全項目が解決または reviewer 提示の代替案(項目3)で誠実に対応されていることを確認しました。

検証結果

  • 項目1(trust filter precedence, P1): run_contract_review_once.py:221 / ensure_contract_snapshot.py:675,830 / build_intake_capsule.py:443 の3 consumer全てが find_latest_result(..., trusted_only=True) を呼んでいることを git grep で確認。test_untrusted_blocked_does_not_preempt_trusted_go_precedence PASS。
  • 項目2(publisher identity, P1): contract_review_result_parser.py の TRUSTED_CONTRACT_PUBLISHERS 静的allowlist + (user.id, user.login, user.type, author_association) 完全一致チェックを確認。TestIdentityTupleAllowlist PASS。
  • 項目3(comment ID binding reuse-path, P1): existing_go 再利用パスは依然として binding を再実行しないが、ensure_contract_snapshot.py の "Security scope" docstring と PR 本文の Safety Claim Matrix が「controlled-publish receipt」ではなく「allowlisted account origin」へ主張を明確に縮小しており、reviewer が提示した選択肢(b)と一致。follow-up #1490 が残課題を正確にスコープしている。
  • 項目4(NDJSON fail-open, P2): fetch_issue_comments() が JSONDecodeError で comments_fetch_incomplete を返すことを確認。実関数を通すテストでPASS。
  • 項目5(mock-only tests, P2): TestReadbackContractSnapshotRejectsUntrustedPublisher が find_latest_go(trusted_only=True) を実際にend-to-endで検証(mockはsubprocess.runのみ)。PASS。
  • Scope Delta: scripts/agent-guards/controlled_skill_mutation_exec.py とそのテストへの変更は、human reviewer が直近コメントで明示的に許可(「必要なら...も変更対象に含める」)した範囲内。
  • CI: ci_verdict_summary.py --pr 1485 --expected-head-sha dc30ab56... で status: all_pass。mergeable: MERGEABLE / mergeStateStatus: CLEAN。
  • フルテストスイート: issue-contract-review + impl-review-loop + agent-guards で 1338 passed, 2 xfailed(PR本文の自己申告と一致)。

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "dc30ab56dadd6eac6482b5baf98da2634b3daacd"
merge_ready: true
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests:
  - "https://github.com/squne121/loop-protocol/issues/1490"
allowed_paths_gate:
  status: ok
  producer_role: review_subagent
  worker_report_used_as_canonical: false
allowed_paths_gate_source: review_subagent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: contract snapshotのtrusted publisher identityとcomment ID bindingを検証する

1 participant