Skip to content

実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#813"
goal_ref: "context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する"
change_kind: workflow

Parent Issue

#813

Parent Goal Ref

#813 の目標「context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する」に対し、#827 は ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離し、fetch tool が安全に使えるか使用禁止かを artifact で証明する child 4 である。

mcp__context-mode__ctx_fetch_and_index は #856(PR MERGED)により committed project policy で明示 deny 済みだが、#827 はその deny を維持したまま CTX_FETCH_STRICT=1 が runtime effective であることと URL policy matrix の block 動作を artifact で証明する責務を持つ。これが完了するまで ctx_fetch_and_index は通常運用で使わない。

Current Objective

ctx_fetch_and_index を local / private network への fetch 経路として悪用できないよう、committed deny を維持しつつ CTX_FETCH_STRICT=1 が runtime effective であることを artifact で証明し、URL policy matrix / adversarial cases / mutation test を含む network negative test suite を整備する。

Current Validated Scope

調査完了(2026-06-12)。#856 で mcp__context-mode__ctx_fetch_and_index は project-shared plugin 上に registered され、.claude/settings.json の permissions.deny に明示設定済み(PR MERGED)。context-mode version は v1.0.162 を前提とするが、#827 artifact に version / package path hash / fetched_at を再記録し、1.0.161 との混在を防ぐ。

#827 の実装変更対象:

  • .claude/artifacts/context-mode/**(fetch-strict negative test artifact、policy snapshot)
  • scripts/test_context_mode_fetch_strict.py(settings.json 構造化 parse / effective strict probe script)
  • tests/context_mode/test_fetch_strict_policy.py(URL policy matrix / adversarial cases / mutation test)
  • tests/context_mode/test_fetch_strict_artifact.py(artifact schema / redaction / stale guard)
  • docs/dev/agent-ops/context-mode-fetch-policy.md(通常利用条件、禁止条件、prompt injection 扱い、cache/purge、実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 依存記録)

upstream context-mode の fetch policy / cache / storage semantics の変更があった場合は Stop Conditions を参照する。

Background

context-mode upstream の README では CTX_FETCH_STRICT=1 により loopback / RFC1918 / ULA などの private network を block できると説明しているが、strict は「追加安全策」であり既定安全ではない(loopback / RFC1918 / ULA は strict なしでは local dev/internal fetch 用に許可される設計)。

loop-protocol の用途では外部 URL fetch は必須ではないため、初期導入では ctx_fetch_and_index を deny したまま、strict が runtime effective であることを負例テストで証明する方針とする。

ctx_fetch_and_index の安全性は「設定上 CTX_FETCH_STRICT が存在する」だけでは証明できない。context-mode process に環境変数が伝達されているか、cache hit で fetch 経路を迂回していないか、redirect/DNS rebinding で private network に到達していないかを artifact で示す必要がある。

#856 で mcp__context-mode__ctx_fetch_and_index は deny 済みだが、runtime probe が必要な場合は commit されない local probe profile のみで一時許可し、probe_profile_committed: false / deny_restored: true を artifact に記録してから deny を復元する。

Outcome

committed deny を維持したまま、CTX_FETCH_STRICT=1 が runtime effective policy として artifact 化され、URL policy matrix(loopback / RFC1918 / ULA / link-local / metadata endpoint variants / adversarial cases)の block 動作が hermetic fixture / stub で証明される。artifact は context_mode_fetch_strict_negative_test_v1 schema を満たし、raw body / credential / token-like value / placeholder を含まない。次の実装者が #827 本文だけを読んで安全な negative test 実装に着手できる。

In Scope

  • committed project policy で mcp__context-mode__ctx_fetch_and_index が deny のままであることを settings.json 構造化 parse で検証する
  • CTX_FETCH_STRICT=1 が設定上だけでなく effective policy として artifact に記録されること(ctx_fetch_strict_configured: true / ctx_fetch_strict_effective: true)
  • URL classification matrix による negative test(loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants)
  • adversarial cases(redirect-to-private / DNS-to-private / IPv6-mapped IPv4 / numeric IPv4 / URL credentials / non-http(s) scheme)を fixture / stub で検証する
  • loopback trap server を使う場合は block 前に socket 接続されないこと(server_hit_count: 0)
  • CI での allowed public URL smoke は classifier-only に限定し、manual network smoke を分離する
  • CONTEXT_MODE_DIR を isolated temp/root で使い、TTL/cache 汚染を防ぐ(ttl: 0 または force: true 相当)
  • artifact schema context_mode_fetch_strict_negative_test_v1 の定義と validation(null / pending / unknown / <...> placeholder / raw body / credential を fail とする)
  • mutation test(CTX_FETCH_STRICT 無効化 / deny entry 除去 / private range blocklist 緩和のいずれかが検出されること)
  • fetch strict 固有の cleanup proof(isolation + post-test purge)
  • docs/dev/agent-ops/context-mode-fetch-policy.md 作成(通常利用条件、禁止条件、prompt injection 扱い、cache/purge、実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 への依存)
  • context_mode_version / package path hash / fetched_at を 実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827 artifact に再記録する

Out of Scope

  • committed .claude/settings.json 上で mcp__context-mode__ctx_fetch_and_index を allow に変更すること
  • private / link-local / metadata endpoint への実 network request を送ること
  • CI での実 public URL fetch を必須化すること(classifier-only smoke に限定)
  • 全体の persistence / purge / ELv2 policy ドキュメント(実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 の責務)
  • context-mode binary / source の repo vendoring

Remaining Parent Gaps

#827 クローズ後、#813 の残存 gap:

Required Skills

Runtime Verification Applicability

decision: deferred
reason: 実装ターゲットファイル(tests/context_mode/test_fetch_strict_policy.py / test_fetch_strict_artifact.py)が未作成のため、VC は実装前には実行不可。実装完了後に全 AC の pytest / test -f / rg を実行して green を確認する。
deferred_destination: PR の Checks セクションに全 AC の pytest / test -f / rg が green であることを記録し、Draft PR レビュー時に確認する。
deferred_verification_condition: 実装 PR の CI / 手動 VC 実行で全 AC の VC が green(exit 0)になること。
applicable_acs: []
execution_environment:
  cli_tools:
    - uv
    - pytest
  auth_required: false
  network_required: false
  notes: hermetic loopback trap server と isolated CONTEXT_MODE_DIR を使用。実 private network への接続は行わない。fake / synthetic URL のみ使用
skip_conditions:
  - context-mode plugin not installed (exit 77)
  - test files not yet created (expected collection error at baseline)
fallback_policy:
  fallback_success_is_pass: false
  notes: skip condition を満たす場合もゼロ件 pass を成功とみなさない
artifact_requirements:
  - ".claude/artifacts/context-mode/fetch-strict-negative-test.json (schema: context_mode_fetch_strict_negative_test_v1)"

Acceptance Criteria

  • AC1: .claude/settings.json / permission artifact を構造化 parse し、committed project policy では mcp__context-mode__ctx_fetch_and_index が deny のままであることを検証している。rg 文字列一致だけでは不可。
  • AC2: CTX_FETCH_STRICT=1 が設定上だけでなく effective policy として artifact に記録されている。ctx_fetch_strict_configured: true / ctx_fetch_strict_effective: true を含む。
  • AC3: loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants が block されることを URL policy matrix で検証している。実 private network service には接続しない。
  • AC4: redirect-to-private、DNS-to-private、IPv6-mapped IPv4、numeric IPv4、URL credentials、non-http(s) scheme の adversarial cases を fixture / stub で検証している。
  • AC5: loopback trap server を使う場合、block 前に socket 接続されないことを server_hit_count: 0 として artifact に記録している。
  • AC6: allowed public URL は CI 必須の実 fetch にしない。classifier-only smoke と manual network smoke を分離し、manual smoke の SKIP を PASS 扱いしない。
  • AC7: CONTEXT_MODE_DIR は isolated temp/root を使い、TTL/cache 汚染を防ぐため ttl: 0 または force: true 相当を artifact に記録している。
  • AC8: .claude/artifacts/context-mode/fetch-strict-negative-test.json が schema context_mode_fetch_strict_negative_test_v1 を満たし、raw HTML/body、URL credential、token-like value、unredacted home path、null、pending、unknown、<...> placeholder を含まない。
  • AC9: mutation test で CTX_FETCH_STRICT 無効化、deny entry 除去、private range blocklist 緩和のいずれかが検出される。
  • AC10: docs/dev/agent-ops/context-mode-fetch-policy.md に通常利用条件、禁止条件、prompt injection 扱い、cache/purge、実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 への依存関係が記録されている。

Verification Commands

# AC1
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "committed_deny"

# AC2
$ uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v -k "effective_strict"

# AC3
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "url_policy_matrix"

# AC4
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "adversarial"

# AC5
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "trap_server"

# AC6
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "ci_smoke"

# AC7
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "isolation"

# AC8
$ uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v

# AC9
$ uv run pytest tests/context_mode/test_fetch_strict_policy.py -v -k "mutation"

# AC10
$ test -f docs/dev/agent-ops/context-mode-fetch-policy.md
$ uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v -k "fetch_policy_docs"

Allowed Paths

  • .claude/settings.json
  • .claude/hooks/**
  • .claude/artifacts/context-mode/**
  • docs/dev/agent-ops/**
  • scripts/test_context_mode_fetch_strict.py
  • tests/context_mode/test_fetch_strict_policy.py
  • tests/context_mode/test_fetch_strict_artifact.py
  • tests/fixtures/context-mode/**

Stop Conditions

  • committed .claude/settings.json 上で mcp__context-mode__ctx_fetch_and_index を allow に変更する必要が出た場合
  • private / link-local / metadata endpoint へ実 network request を送らないと検証できない場合
  • CTX_FETCH_STRICT=1 が設定上は存在するが runtime effective であることを証明できない場合
  • URL classifier / redirect / DNS resolution を hermetic fixture または controlled probe で検証できない場合
  • artifact に raw response body、credential 付き URL、token-like value、unredacted home path、null、pending、unknown、<...> placeholder が含まれる場合
  • public URL smoke test が network unavailable で SKIP されたのに PASS として扱われる場合
  • context-mode upstream の fetch policy / cache / storage semantics が変わり、既存 test vector の意味が不明になった場合

Delivery Rule

Activity

  1. added
    state/queued
    on Jun 12, 2026
  2. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #827 の方向性は正しいです。ctx_fetch_and_index は「read-only」に見えても、外部 URL 取得・HTML/Markdown 化・chunk/index・TTL cache を伴うため、SSRF、metadata endpoint 接触、DNS/redirect 経由の private network 到達、外部コンテンツ由来の prompt injection、index 汚染を同時に扱う必要があります。context-mode upstream も ctx_fetch_and_index を URL fetch/index tool として説明し、TTL cache は既定 24h、保存先 content DB、force/ttl 指定を持つと説明しています。(GitHub) (GitHub)

    ただし、現行 #827 は 「CTX_FETCH_STRICT という文字列がある」「artifact ファイルがある」「docs ファイルがある」だけで pass し得る契約です。#827 本体は open / comments 0 で、AC は localhost/private/ULA/metadata endpoint 風 URL block と artifact/docs を要求していますが、runtime effective strict、実接続未発生、redirect/DNS rebinding、cache bypass、artifact schema、mutation test を要求していません。

    主要ブロッカー

    Severity | 指摘 | 修正方針 -- | -- | -- High | rg -n "CTX_FETCH_STRICT" は AC1 の検証にならない。設定に文字列があっても、context-mode process に有効化されているとは限らない。 | ctx_fetch_strict_configured: true と ctx_fetch_strict_effective: true を artifact に記録し、設定 source と runtime/probe source を分ける。 High | #856 で ctx_fetch_and_index は project-shared plugin 上に registered され、mcp__context-mode__ctx_fetch_and_index は deny されています。#827 は「deny したままどう negative test するか」を定義していない。 | committed policy は deny 維持。runtime probe が必要なら commit されない local probe profile でのみ一時許可し、probe_profile_committed: false / deny_restored: true を artifact 化する。 High | upstream README 上、loopback / RFC1918 / ULA は既定では local dev/internal fetch 用に許可され、CTX_FETCH_STRICT=1 で追加 block される設計です。つまり strict は「追加安全策」であり、既定安全ではない。 | #827 は “strict が設定された” ではなく “strict により block 判定が実効した” ことを証明する Issue にする。(GitHub) High | private network negative test が薄い。127.0.0.1 / localhost / RFC1918 / ULA だけでは、IPv6-mapped IPv4、numeric IPv4、redirect、DNS rebinding、link-local、cloud metadata variants を逃す。 | URL classification matrix を明示し、redirect/DNS は fixture/stub で検証する。実 private service には接続しない。 High | cache が block 結果を偽装し得る。TTL cache hit なら fetch 経路を通らず、strict block の検証にならない。 | isolated CONTEXT_MODE_DIR、unique URL、ttl: 0 または force: true、post-test purge/cleanup を必須化する。(GitHub) High | artifact が存在確認だけ。#825/#826 で既に null / pending / を見落とす問題が出ている。 | context_mode_fetch_strict_negative_test_v1 schema を作り、null / pending / unknown / <...> / token-like value / raw body を fail にする。 Medium | allowed public URL smoke test を CI で実 network にすると、flaky かつ外部 content prompt injection surface になる。 | CI は classifier/surrogate test に限定。実 public fetch は manual/runtime artifact とし、SKIP は PASS にしない。Claude Code docs も外部 content を取る MCP server の prompt injection risk を警告しています。(Claude API Docs) Medium | fetch result の persistence / purge 手順 が #828 と重複。#828 はまだ open です。 | #827 は fetch strict 固有の cleanup proof に絞り、運用 policy は #828 へ hard-link する。 Medium | Allowed Paths に tests/context_mode/** がない。#824/#825/#826 の convention と違い、まともな pytest schema test を入れると contract 違反になる。 | Allowed Paths に tests/context_mode/test_fetch_strict_policy.py と tests/context_mode/test_fetch_strict_artifact.py を追加する。 Medium | version provenance が #827 で再確認されない。#824/#856 は v1.0.162 前提だが、#880 側 artifact 文脈では 1.0.161 が出ており、継承前提は危険。 | context_mode_version, package path hash, fetched_at を #827 artifact に再記録する。

    #827 の契約修正案

    Acceptance Criteria 差し替え

    ## Acceptance Criteria
    
    • AC1: .claude/settings.json / permission artifact を構造化 parse し、committed project policy では mcp__context-mode__ctx_fetch_and_index が deny のままであることを検証している。rg 文字列一致だけでは不可。
    • AC2: CTX_FETCH_STRICT=1 が設定上だけでなく effective policy として artifact に記録されている。ctx_fetch_strict_configured: true / ctx_fetch_strict_effective: true を含む。
    • AC3: loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants が block されることを URL policy matrix で検証している。実 private network service には接続しない。
    • AC4: redirect-to-private、DNS-to-private、IPv6-mapped IPv4、numeric IPv4、URL credentials、non-http(s) scheme の adversarial cases を含む。
    • AC5: loopback trap server を使う場合、block 前に socket 接続されないことを server_hit_count: 0 として記録している。
    • AC6: allowed public URL は CI 必須の実 fetch にしない。classifier-only smoke と manual network smoke を分離し、manual smoke の SKIP を PASS 扱いしない。
    • AC7: CONTEXT_MODE_DIR は isolated temp/root を使い、TTL/cache 汚染を防ぐため ttl: 0 または force: true 相当を記録している。
    • AC8: .claude/artifacts/context-mode/fetch-strict-negative-test.json が schema context_mode_fetch_strict_negative_test_v1 を満たし、raw HTML/body、URL credential、token-like value、unredacted home path、null、pending、unknown、&lt;...&gt; placeholder を含まない。
    • AC9: mutation test で CTX_FETCH_STRICT 無効化、deny entry 除去、private range blocklist 緩和のいずれかが検出される。
    • [ ] AC10: docs/dev/agent-ops/context-mode-fetch-policy.md に通常利用条件、禁止条件、prompt injection 扱い、cache/purge、#828 への依存関係が記録されている。

    Verification Commands 修正

    # AC1 / AC2 / AC8
    uv run python scripts/test_context_mode_fetch_strict.py
    --settings .claude/settings.json
    --registered-tools .claude/artifacts/context-mode/registered-tools.json
    --permission-policy .claude/artifacts/context-mode/permission-policy.json
    --artifact .claude/artifacts/context-mode/fetch-strict-negative-test.json
    --assert-policy

    AC3-AC7 / AC9

    uv run pytest tests/context_mode/test_fetch_strict_policy.py -v

    AC8 schema/redaction/stale guard

    uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v

    AC10

    test -f docs/dev/agent-ops/context-mode-fetch-policy.md
    rg -n "ctx_fetch_and_index|CTX_FETCH_STRICT|prompt injection|purge|cache|禁止|許可|#828" docs/dev/agent-ops/context-mode-fetch-policy.md

    Allowed Paths 修正

    ## Allowed Paths

    • .claude/settings.json

    • .claude/hooks/**

    • .claude/artifacts/context-mode/**

    • docs/dev/agent-ops/**

    • scripts/test_context_mode_fetch_strict.py

    • tests/context_mode/test_fetch_strict_policy.py

    • tests/context_mode/test_fetch_strict_artifact.py

    • tests/fixtures/context-mode/**

    Stop Conditions 追加

    ## Stop Conditions

  3. committed .claude/settings.json 上で mcp__context-mode__ctx_fetch_and_index を allow に変更する必要が出た場合

  4. private / link-local / metadata endpoint へ実 network request を送らないと検証できない場合

  5. CTX_FETCH_STRICT=1 が設定上は存在するが runtime effective であることを証明できない場合

  6. URL classifier / redirect / DNS resolution を hermetic fixture または controlled probe で検証できない場合

  7. artifact に raw response body、credential 付き URL、token-like value、unredacted home path、null、pending、unknown、&lt;...&gt; placeholder が含まれる場合

  8. public URL smoke test が network unavailable で SKIP されたのに PASS として扱われる場合

  9. context-mode upstream の fetch policy / cache / storage semantics が変わり、既存 test vector の意味が不明になった場合

  10. 実装設計の推奨

    fetch-strict-negative-test.json は最低限この形にしてください。

    {
    "schema": "context_mode_fetch_strict_negative_test_v1",
    "issue": "#827",
    "status": "pass",
    "generated_at": "ISO-8601",
    "head_sha": "actual commit sha",
    "context_mode_version": "actual installed version",
    "policy": {
    "ctx_fetch_and_index_committed_permission": "deny",
    "ctx_fetch_strict_configured": true,
    "ctx_fetch_strict_effective": true,
    "probe_profile_committed": false,
    "deny_restored": true
    },
    "network_safety": {
    "real_private_network_requests": 0,
    "resolver_mode": "stubbed",
    "redirect_mode": "fixture",
    "loopback_trap_server_hit_count": 0
    },
    "cases": [
    {
    "name": "loopback_ipv4",
    "input_url_redacted": "http://127.0.0.1:<PORT>/canary",
    "expected": "blocked_before_connect",
    "actual": "blocked_before_connect",
    "cache_hit": false
    }
    ],
    "cache_and_purge": {
    "context_mode_dir_isolated": true,
    "ttl_bypass": true,
    "purge_or_tmpdir_cleanup_verified": true,
    "post_cleanup_search_hit_count": 0
    },
    "redaction": {
    "raw_response_body_absent": true,
    "url_credentials_absent": true,
    "token_like_values_absent": true,
    "home_paths_redacted": true,
    "placeholders_absent": true
    },
    "mutation_test": {
    "strict_disabled_detected": true,
    "deny_removed_detected": true,
    "private_blocklist_relaxed_detected": true
    }
    }

    URL matrix は少なくとも次を含めるべきです。

    blocked:

    allowed-classifier-only:

    配布物・ライセンス面の注意

    context-mode は Elastic License 2.0 として提供され、利用・fork・modify・distribute は可能だが、hosted/managed service 化や notice removal は禁止と説明されています。#827 では context-mode の source/binary を repo に vendoring せず、installed package の version/hash/provenance を artifact に残すだけに留めるのが安全です。(GitHub)

    GitHub secret scanning は git history だけでなく issue / PR descriptions / comments / discussions / wiki / gists も scan 対象です。fetch strict の canary、URL credential、fake token は本物の provider token 形式に似せず、artifact と PR comment に raw secret-like marker を残さない設計にしてください。(GitHub Docs)

    最終提案

    #827 はこのまま実装に進めず、まず Issue 契約を上記の形へ更新してください。特に committed deny 維持、effective strict 証明、private network への実接続ゼロ、cache/purge 証明、artifact schema test、mutation test が入るまで merge-ready な実装 Issue ではありません。

    ## 判定: REQUEST_CHANGES

    #827 の方向性は正しいです。ctx_fetch_and_index は「read-only」に見えても、外部 URL 取得・HTML/Markdown 化・chunk/index・TTL cache を伴うため、SSRF、metadata endpoint 接触、DNS/redirect 経由の private network 到達、外部コンテンツ由来の prompt injection、index 汚染を同時に扱う必要があります。context-mode upstream も ctx_fetch_and_index を URL fetch/index tool として説明し、TTL cache は既定 24h、保存先 content DB、force/ttl 指定を持つと説明しています。([GitHub]1) ([GitHub]1)

    ただし、現行 #827 は 「CTX_FETCH_STRICT という文字列がある」「artifact ファイルがある」「docs ファイルがある」だけで pass し得る契約です。#827 本体は open / comments 0 で、AC は localhost/private/ULA/metadata endpoint 風 URL block と artifact/docs を要求していますが、runtime effective strict、実接続未発生、redirect/DNS rebinding、cache bypass、artifact schema、mutation test を要求していません。

    主要ブロッカー

    Severity 指摘 修正方針
    High rg -n "CTX_FETCH_STRICT" は AC1 の検証にならない。設定に文字列があっても、context-mode process に有効化されているとは限らない。 ctx_fetch_strict_configured: true と ctx_fetch_strict_effective: true を artifact に記録し、設定 source と runtime/probe source を分ける。
    High #856 で ctx_fetch_and_index は project-shared plugin 上に registered され、mcp__context-mode__ctx_fetch_and_index は deny されています。#827 は「deny したままどう negative test するか」を定義していない。 committed policy は deny 維持。runtime probe が必要なら commit されない local probe profile でのみ一時許可し、probe_profile_committed: false / deny_restored: true を artifact 化する。
    High upstream README 上、loopback / RFC1918 / ULA は既定では local dev/internal fetch 用に許可され、CTX_FETCH_STRICT=1 で追加 block される設計です。つまり strict は「追加安全策」であり、既定安全ではない。 #827 は “strict が設定された” ではなく “strict により block 判定が実効した” ことを証明する Issue にする。([GitHub]1)
    High private network negative test が薄い。127.0.0.1 / localhost / RFC1918 / ULA だけでは、IPv6-mapped IPv4、numeric IPv4、redirect、DNS rebinding、link-local、cloud metadata variants を逃す。 URL classification matrix を明示し、redirect/DNS は fixture/stub で検証する。実 private service には接続しない。
    High cache が block 結果を偽装し得る。TTL cache hit なら fetch 経路を通らず、strict block の検証にならない。 isolated CONTEXT_MODE_DIR、unique URL、ttl: 0 または force: true、post-test purge/cleanup を必須化する。([GitHub]1)
    High artifact が存在確認だけ。#825/#826 で既に null / pending / <placeholder> を見落とす問題が出ている。 context_mode_fetch_strict_negative_test_v1 schema を作り、null / pending / unknown / <...> / token-like value / raw body を fail にする。
    Medium allowed public URL smoke test を CI で実 network にすると、flaky かつ外部 content prompt injection surface になる。 CI は classifier/surrogate test に限定。実 public fetch は manual/runtime artifact とし、SKIP は PASS にしない。Claude Code docs も外部 content を取る MCP server の prompt injection risk を警告しています。([Claude API Docs]2)
    Medium fetch result の persistence / purge 手順 が #828 と重複。#828 はまだ open です。 #827 は fetch strict 固有の cleanup proof に絞り、運用 policy は #828 へ hard-link する。
    Medium Allowed Paths に tests/context_mode/** がない。#824/#825/#826 の convention と違い、まともな pytest schema test を入れると contract 違反になる。 Allowed Paths に tests/context_mode/test_fetch_strict_policy.py と tests/context_mode/test_fetch_strict_artifact.py を追加する。
    Medium version provenance が #827 で再確認されない。#824/#856 は v1.0.162 前提だが、#880 側 artifact 文脈では 1.0.161 が出ており、継承前提は危険。 context_mode_version, package path hash, fetched_at を #827 artifact に再記録する。

    #827 の契約修正案

    Acceptance Criteria 差し替え

    ## Acceptance Criteria
    
    - [ ] AC1: `.claude/settings.json` / permission artifact を構造化 parse し、committed project policy では `mcp__context-mode__ctx_fetch_and_index` が `deny` のままであることを検証している。`rg` 文字列一致だけでは不可。
    - [ ] AC2: `CTX_FETCH_STRICT=1` が設定上だけでなく effective policy として artifact に記録されている。`ctx_fetch_strict_configured: true` / `ctx_fetch_strict_effective: true` を含む。
    - [ ] AC3: loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants が block されることを URL policy matrix で検証している。実 private network service には接続しない。
    - [ ] AC4: redirect-to-private、DNS-to-private、IPv6-mapped IPv4、numeric IPv4、URL credentials、non-http(s) scheme の adversarial cases を含む。
    - [ ] AC5: loopback trap server を使う場合、block 前に socket 接続されないことを `server_hit_count: 0` として記録している。
    - [ ] AC6: allowed public URL は CI 必須の実 fetch にしない。classifier-only smoke と manual network smoke を分離し、manual smoke の SKIP を PASS 扱いしない。
    - [ ] AC7: `CONTEXT_MODE_DIR` は isolated temp/root を使い、TTL/cache 汚染を防ぐため `ttl: 0` または `force: true` 相当を記録している。
    - [ ] AC8: `.claude/artifacts/context-mode/fetch-strict-negative-test.json` が schema `context_mode_fetch_strict_negative_test_v1` を満たし、raw HTML/body、URL credential、token-like value、unredacted home path、`null`、`pending`、`unknown`、`<...>` placeholder を含まない。
    - [ ] AC9: mutation test で `CTX_FETCH_STRICT` 無効化、deny entry 除去、private range blocklist 緩和のいずれかが検出される。
    - [ ] AC10: `docs/dev/agent-ops/context-mode-fetch-policy.md` に通常利用条件、禁止条件、prompt injection 扱い、cache/purge、#828 への依存関係が記録されている。

    Verification Commands 修正

    # AC1 / AC2 / AC8
    uv run python scripts/test_context_mode_fetch_strict.py \
      --settings .claude/settings.json \
      --registered-tools .claude/artifacts/context-mode/registered-tools.json \
      --permission-policy .claude/artifacts/context-mode/permission-policy.json \
      --artifact .claude/artifacts/context-mode/fetch-strict-negative-test.json \
      --assert-policy
    
    # AC3-AC7 / AC9
    uv run pytest tests/context_mode/test_fetch_strict_policy.py -v
    
    # AC8 schema/redaction/stale guard
    uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v
    
    # AC10
    test -f docs/dev/agent-ops/context-mode-fetch-policy.md
    rg -n "ctx_fetch_and_index|CTX_FETCH_STRICT|prompt injection|purge|cache|禁止|許可|#828" docs/dev/agent-ops/context-mode-fetch-policy.md

    Allowed Paths 修正

    ## Allowed Paths
    
    - `.claude/settings.json`
    - `.claude/hooks/**`
    - `.claude/artifacts/context-mode/**`
    - `docs/dev/agent-ops/**`
    - `scripts/test_context_mode_fetch_strict.py`
    - `tests/context_mode/test_fetch_strict_policy.py`
    - `tests/context_mode/test_fetch_strict_artifact.py`
    - `tests/fixtures/context-mode/**`

    Stop Conditions 追加

    ## Stop Conditions
    
    - committed `.claude/settings.json` 上で `mcp__context-mode__ctx_fetch_and_index` を allow に変更する必要が出た場合
    - private / link-local / metadata endpoint へ実 network request を送らないと検証できない場合
    - `CTX_FETCH_STRICT=1` が設定上は存在するが runtime effective であることを証明できない場合
    - URL classifier / redirect / DNS resolution を hermetic fixture または controlled probe で検証できない場合
    - artifact に raw response body、credential 付き URL、token-like value、unredacted home path、`null`、`pending`、`unknown`、`<...>` placeholder が含まれる場合
    - public URL smoke test が network unavailable で SKIP されたのに PASS として扱われる場合
    - context-mode upstream の fetch policy / cache / storage semantics が変わり、既存 test vector の意味が不明になった場合

    実装設計の推奨

    fetch-strict-negative-test.json は最低限この形にしてください。

    {
      "schema": "context_mode_fetch_strict_negative_test_v1",
      "issue": "#827",
      "status": "pass",
      "generated_at": "ISO-8601",
      "head_sha": "actual commit sha",
      "context_mode_version": "actual installed version",
      "policy": {
        "ctx_fetch_and_index_committed_permission": "deny",
        "ctx_fetch_strict_configured": true,
        "ctx_fetch_strict_effective": true,
        "probe_profile_committed": false,
        "deny_restored": true
      },
      "network_safety": {
        "real_private_network_requests": 0,
        "resolver_mode": "stubbed",
        "redirect_mode": "fixture",
        "loopback_trap_server_hit_count": 0
      },
      "cases": [
        {
          "name": "loopback_ipv4",
          "input_url_redacted": "http://127.0.0.1:<PORT>/canary",
          "expected": "blocked_before_connect",
          "actual": "blocked_before_connect",
          "cache_hit": false
        }
      ],
      "cache_and_purge": {
        "context_mode_dir_isolated": true,
        "ttl_bypass": true,
        "purge_or_tmpdir_cleanup_verified": true,
        "post_cleanup_search_hit_count": 0
      },
      "redaction": {
        "raw_response_body_absent": true,
        "url_credentials_absent": true,
        "token_like_values_absent": true,
        "home_paths_redacted": true,
        "placeholders_absent": true
      },
      "mutation_test": {
        "strict_disabled_detected": true,
        "deny_removed_detected": true,
        "private_blocklist_relaxed_detected": true
      }
    }

    URL matrix は少なくとも次を含めるべきです。

    blocked:
      - http://127.0.0.1:<port>/
      - http://localhost:<port>/
      - http://localhost.:<port>/
      - http://0.0.0.0:<port>/
      - http://[::1]:<port>/
      - http://[::ffff:127.0.0.1]:<port>/
      - http://10.0.0.1/
      - http://172.16.0.1/
      - http://172.31.255.255/
      - http://192.168.0.1/
      - http://[fc00::1]/
      - http://[fe80::1]/
      - http://169.254.169.254/latest/meta-data/
      - http://169.254.170.2/
      - https://public.example/redirect-to-private   # fixture redirect
      - https://dns-private.example/                 # stub resolver -> private IP
      - file:///etc/passwd
      - data:text/plain,hello
    
    allowed-classifier-only:
      - https://example.com/
    

    配布物・ライセンス面の注意

    context-mode は Elastic License 2.0 として提供され、利用・fork・modify・distribute は可能だが、hosted/managed service 化や notice removal は禁止と説明されています。#827 では context-mode の source/binary を repo に vendoring せず、installed package の version/hash/provenance を artifact に残すだけに留めるのが安全です。([GitHub]1)

    GitHub secret scanning は git history だけでなく issue / PR descriptions / comments / discussions / wiki / gists も scan 対象です。fetch strict の canary、URL credential、fake token は本物の provider token 形式に似せず、artifact と PR comment に raw secret-like marker を残さない設計にしてください。([GitHub Docs]3)

    最終提案

    #827 はこのまま実装に進めず、まず Issue 契約を上記の形へ更新してください。特に committed deny 維持、effective strict 証明、private network への実接続ゼロ、cache/purge 証明、artifact schema test、mutation test が入るまで merge-ready な実装 Issue ではありません。

    1: https://github.com/mksglu/context-mode "GitHub - mksglu/context-mode: Context window optimization for AI coding agents. Sandboxes tool output, 98% reduction. 15 platforms · GitHub"
    2: https://docs.anthropic.com/en/docs/claude-code/mcp "Connect Claude Code to tools via MCP - Claude Code Docs"
    3: https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning "Secret scanning - GitHub Docs"ody>

    判定: REQUEST_CHANGES

    #827 の方向性は正しいです。ctx_fetch_and_index は「read-only」に見えても、外部 URL 取得・HTML/Markdown 化・chunk/index・TTL cache を伴うため、SSRF、metadata endpoint 接触、DNS/redirect 経由の private network 到達、外部コンテンツ由来の prompt injection、index 汚染を同時に扱う必要があります。context-mode upstream も ctx_fetch_and_index を URL fetch/index tool として説明し、TTL cache は既定 24h、保存先 content DB、force/ttl 指定を持つと説明しています。(GitHub) (GitHub)

    ただし、現行 #827 は 「CTX_FETCH_STRICT という文字列がある」「artifact ファイルがある」「docs ファイルがある」だけで pass し得る契約です。#827 本体は open / comments 0 で、AC は localhost/private/ULA/metadata endpoint 風 URL block と artifact/docs を要求していますが、runtime effective strict、実接続未発生、redirect/DNS rebinding、cache bypass、artifact schema、mutation test を要求していません。

    主要ブロッカー

    Severity 指摘 修正方針
    High rg -n "CTX_FETCH_STRICT" は AC1 の検証にならない。設定に文字列があっても、context-mode process に有効化されているとは限らない。 ctx_fetch_strict_configured: true と ctx_fetch_strict_effective: true を artifact に記録し、設定 source と runtime/probe source を分ける。
    High #856 で ctx_fetch_and_index は project-shared plugin 上に registered され、mcp__context-mode__ctx_fetch_and_index は deny されています。#827 は「deny したままどう negative test するか」を定義していない。 committed policy は deny 維持。runtime probe が必要なら commit されない local probe profile でのみ一時許可し、probe_profile_committed: false / deny_restored: true を artifact 化する。
    High upstream README 上、loopback / RFC1918 / ULA は既定では local dev/internal fetch 用に許可され、CTX_FETCH_STRICT=1 で追加 block される設計です。つまり strict は「追加安全策」であり、既定安全ではない。 #827 は “strict が設定された” ではなく “strict により block 判定が実効した” ことを証明する Issue にする。(GitHub)
    High private network negative test が薄い。127.0.0.1 / localhost / RFC1918 / ULA だけでは、IPv6-mapped IPv4、numeric IPv4、redirect、DNS rebinding、link-local、cloud metadata variants を逃す。 URL classification matrix を明示し、redirect/DNS は fixture/stub で検証する。実 private service には接続しない。
    High cache が block 結果を偽装し得る。TTL cache hit なら fetch 経路を通らず、strict block の検証にならない。 isolated CONTEXT_MODE_DIR、unique URL、ttl: 0 または force: true、post-test purge/cleanup を必須化する。(GitHub)
    High artifact が存在確認だけ。#825/#826 で既に null / pending / を見落とす問題が出ている。 context_mode_fetch_strict_negative_test_v1 schema を作り、null / pending / unknown / <...> / token-like value / raw body を fail にする。
    Medium allowed public URL smoke test を CI で実 network にすると、flaky かつ外部 content prompt injection surface になる。 CI は classifier/surrogate test に限定。実 public fetch は manual/runtime artifact とし、SKIP は PASS にしない。Claude Code docs も外部 content を取る MCP server の prompt injection risk を警告しています。(Claude API Docs)
    Medium fetch result の persistence / purge 手順 が #828 と重複。#828 はまだ open です。 #827 は fetch strict 固有の cleanup proof に絞り、運用 policy は #828 へ hard-link する。
    Medium Allowed Paths に tests/context_mode/** がない。#824/#825/#826 の convention と違い、まともな pytest schema test を入れると contract 違反になる。 Allowed Paths に tests/context_mode/test_fetch_strict_policy.py と tests/context_mode/test_fetch_strict_artifact.py を追加する。
    Medium version provenance が #827 で再確認されない。#824/#856 は v1.0.162 前提だが、#880 側 artifact 文脈では 1.0.161 が出ており、継承前提は危険。 context_mode_version, package path hash, fetched_at を #827 artifact に再記録する。

    #827 の契約修正案

    Acceptance Criteria 差し替え

    ## Acceptance Criteria
    
    • AC1: .claude/settings.json / permission artifact を構造化 parse し、committed project policy では mcp__context-mode__ctx_fetch_and_index が deny のままであることを検証している。rg 文字列一致だけでは不可。
    • AC2: CTX_FETCH_STRICT=1 が設定上だけでなく effective policy として artifact に記録されている。ctx_fetch_strict_configured: true / ctx_fetch_strict_effective: true を含む。
    • AC3: loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants が block されることを URL policy matrix で検証している。実 private network service には接続しない。
    • AC4: redirect-to-private、DNS-to-private、IPv6-mapped IPv4、numeric IPv4、URL credentials、non-http(s) scheme の adversarial cases を含む。
    • AC5: loopback trap server を使う場合、block 前に socket 接続されないことを server_hit_count: 0 として記録している。
    • AC6: allowed public URL は CI 必須の実 fetch にしない。classifier-only smoke と manual network smoke を分離し、manual smoke の SKIP を PASS 扱いしない。
    • AC7: CONTEXT_MODE_DIR は isolated temp/root を使い、TTL/cache 汚染を防ぐため ttl: 0 または force: true 相当を記録している。
    • AC8: .claude/artifacts/context-mode/fetch-strict-negative-test.json が schema context_mode_fetch_strict_negative_test_v1 を満たし、raw HTML/body、URL credential、token-like value、unredacted home path、null、pending、unknown、&lt;...&gt; placeholder を含まない。
    • AC9: mutation test で CTX_FETCH_STRICT 無効化、deny entry 除去、private range blocklist 緩和のいずれかが検出される。
    • [ ] AC10: docs/dev/agent-ops/context-mode-fetch-policy.md に通常利用条件、禁止条件、prompt injection 扱い、cache/purge、#828 への依存関係が記録されている。

    Verification Commands 修正

    # AC1 / AC2 / AC8
    uv run python scripts/test_context_mode_fetch_strict.py
    --settings .claude/settings.json
    --registered-tools .claude/artifacts/context-mode/registered-tools.json
    --permission-policy .claude/artifacts/context-mode/permission-policy.json
    --artifact .claude/artifacts/context-mode/fetch-strict-negative-test.json
    --assert-policy

    AC3-AC7 / AC9

    uv run pytest tests/context_mode/test_fetch_strict_policy.py -v

    AC8 schema/redaction/stale guard

    uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v

    AC10

    test -f docs/dev/agent-ops/context-mode-fetch-policy.md
    rg -n "ctx_fetch_and_index|CTX_FETCH_STRICT|prompt injection|purge|cache|禁止|許可|#828" docs/dev/agent-ops/context-mode-fetch-policy.md

    Allowed Paths 修正

    ## Allowed Paths

    • .claude/settings.json

    • .claude/hooks/**

    • .claude/artifacts/context-mode/**

    • docs/dev/agent-ops/**

    • scripts/test_context_mode_fetch_strict.py

    • tests/context_mode/test_fetch_strict_policy.py

    • tests/context_mode/test_fetch_strict_artifact.py

    • tests/fixtures/context-mode/**

    Stop Conditions 追加

    ## Stop Conditions

  11. committed .claude/settings.json 上で mcp__context-mode__ctx_fetch_and_index を allow に変更する必要が出た場合

  12. private / link-local / metadata endpoint へ実 network request を送らないと検証できない場合

  13. CTX_FETCH_STRICT=1 が設定上は存在するが runtime effective であることを証明できない場合

  14. URL classifier / redirect / DNS resolution を hermetic fixture または controlled probe で検証できない場合

  15. artifact に raw response body、credential 付き URL、token-like value、unredacted home path、null、pending、unknown、&lt;...&gt; placeholder が含まれる場合

  16. public URL smoke test が network unavailable で SKIP されたのに PASS として扱われる場合

  17. context-mode upstream の fetch policy / cache / storage semantics が変わり、既存 test vector の意味が不明になった場合

  18. 実装設計の推奨

    fetch-strict-negative-test.json は最低限この形にしてください。

    {
    "schema": "context_mode_fetch_strict_negative_test_v1",
    "issue": "#827",
    "status": "pass",
    "generated_at": "ISO-8601",
    "head_sha": "actual commit sha",
    "context_mode_version": "actual installed version",
    "policy": {
    "ctx_fetch_and_index_committed_permission": "deny",
    "ctx_fetch_strict_configured": true,
    "ctx_fetch_strict_effective": true,
    "probe_profile_committed": false,
    "deny_restored": true
    },
    "network_safety": {
    "real_private_network_requests": 0,
    "resolver_mode": "stubbed",
    "redirect_mode": "fixture",
    "loopback_trap_server_hit_count": 0
    },
    "cases": [
    {
    "name": "loopback_ipv4",
    "input_url_redacted": "http://127.0.0.1:<PORT>/canary",
    "expected": "blocked_before_connect",
    "actual": "blocked_before_connect",
    "cache_hit": false
    }
    ],
    "cache_and_purge": {
    "context_mode_dir_isolated": true,
    "ttl_bypass": true,
    "purge_or_tmpdir_cleanup_verified": true,
    "post_cleanup_search_hit_count": 0
    },
    "redaction": {
    "raw_response_body_absent": true,
    "url_credentials_absent": true,
    "token_like_values_absent": true,
    "home_paths_redacted": true,
    "placeholders_absent": true
    },
    "mutation_test": {
    "strict_disabled_detected": true,
    "deny_removed_detected": true,
    "private_blocklist_relaxed_detected": true
    }
    }

    URL matrix は少なくとも次を含めるべきです。

    blocked:

    allowed-classifier-only:

    配布物・ライセンス面の注意

    context-mode は Elastic License 2.0 として提供され、利用・fork・modify・distribute は可能だが、hosted/managed service 化や notice removal は禁止と説明されています。#827 では context-mode の source/binary を repo に vendoring せず、installed package の version/hash/provenance を artifact に残すだけに留めるのが安全です。(GitHub)

    GitHub secret scanning は git history だけでなく issue / PR descriptions / comments / discussions / wiki / gists も scan 対象です。fetch strict の canary、URL credential、fake token は本物の provider token 形式に似せず、artifact と PR comment に raw secret-like marker を残さない設計にしてください。(GitHub Docs)

    最終提案

    #827 はこのまま実装に進めず、まず Issue 契約を上記の形へ更新してください。特に committed deny 維持、effective strict 証明、private network への実接続ゼロ、cache/purge 証明、artifact schema test、mutation test が入るまで merge-ready な実装 Issue ではありません。

    ## 判定: REQUEST_CHANGES

    #827 の方向性は正しいです。ctx_fetch_and_index は「read-only」に見えても、外部 URL 取得・HTML/Markdown 化・chunk/index・TTL cache を伴うため、SSRF、metadata endpoint 接触、DNS/redirect 経由の private network 到達、外部コンテンツ由来の prompt injection、index 汚染を同時に扱う必要があります。context-mode upstream も ctx_fetch_and_index を URL fetch/index tool として説明し、TTL cache は既定 24h、保存先 content DB、force/ttl 指定を持つと説明しています。([GitHub]1) ([GitHub]1)

    ただし、現行 #827 は 「CTX_FETCH_STRICT という文字列がある」「artifact ファイルがある」「docs ファイルがある」だけで pass し得る契約です。#827 本体は open / comments 0 で、AC は localhost/private/ULA/metadata endpoint 風 URL block と artifact/docs を要求していますが、runtime effective strict、実接続未発生、redirect/DNS rebinding、cache bypass、artifact schema、mutation test を要求していません。

    主要ブロッカー

    Severity 指摘 修正方針
    High rg -n "CTX_FETCH_STRICT" は AC1 の検証にならない。設定に文字列があっても、context-mode process に有効化されているとは限らない。 ctx_fetch_strict_configured: true と ctx_fetch_strict_effective: true を artifact に記録し、設定 source と runtime/probe source を分ける。
    High #856 で ctx_fetch_and_index は project-shared plugin 上に registered され、mcp__context-mode__ctx_fetch_and_index は deny されています。#827 は「deny したままどう negative test するか」を定義していない。 committed policy は deny 維持。runtime probe が必要なら commit されない local probe profile でのみ一時許可し、probe_profile_committed: false / deny_restored: true を artifact 化する。
    High upstream README 上、loopback / RFC1918 / ULA は既定では local dev/internal fetch 用に許可され、CTX_FETCH_STRICT=1 で追加 block される設計です。つまり strict は「追加安全策」であり、既定安全ではない。 #827 は “strict が設定された” ではなく “strict により block 判定が実効した” ことを証明する Issue にする。([GitHub]1)
    High private network negative test が薄い。127.0.0.1 / localhost / RFC1918 / ULA だけでは、IPv6-mapped IPv4、numeric IPv4、redirect、DNS rebinding、link-local、cloud metadata variants を逃す。 URL classification matrix を明示し、redirect/DNS は fixture/stub で検証する。実 private service には接続しない。
    High cache が block 結果を偽装し得る。TTL cache hit なら fetch 経路を通らず、strict block の検証にならない。 isolated CONTEXT_MODE_DIR、unique URL、ttl: 0 または force: true、post-test purge/cleanup を必須化する。([GitHub]1)
    High artifact が存在確認だけ。#825/#826 で既に null / pending / <placeholder> を見落とす問題が出ている。 context_mode_fetch_strict_negative_test_v1 schema を作り、null / pending / unknown / <...> / token-like value / raw body を fail にする。
    Medium allowed public URL smoke test を CI で実 network にすると、flaky かつ外部 content prompt injection surface になる。 CI は classifier/surrogate test に限定。実 public fetch は manual/runtime artifact とし、SKIP は PASS にしない。Claude Code docs も外部 content を取る MCP server の prompt injection risk を警告しています。([Claude API Docs]2)
    Medium fetch result の persistence / purge 手順 が #828 と重複。#828 はまだ open です。 #827 は fetch strict 固有の cleanup proof に絞り、運用 policy は #828 へ hard-link する。
    Medium Allowed Paths に tests/context_mode/** がない。#824/#825/#826 の convention と違い、まともな pytest schema test を入れると contract 違反になる。 Allowed Paths に tests/context_mode/test_fetch_strict_policy.py と tests/context_mode/test_fetch_strict_artifact.py を追加する。
    Medium version provenance が #827 で再確認されない。#824/#856 は v1.0.162 前提だが、#880 側 artifact 文脈では 1.0.161 が出ており、継承前提は危険。 context_mode_version, package path hash, fetched_at を #827 artifact に再記録する。

    #827 の契約修正案

    Acceptance Criteria 差し替え

    ## Acceptance Criteria
    
    - [ ] AC1: `.claude/settings.json` / permission artifact を構造化 parse し、committed project policy では `mcp__context-mode__ctx_fetch_and_index` が `deny` のままであることを検証している。`rg` 文字列一致だけでは不可。
    - [ ] AC2: `CTX_FETCH_STRICT=1` が設定上だけでなく effective policy として artifact に記録されている。`ctx_fetch_strict_configured: true` / `ctx_fetch_strict_effective: true` を含む。
    - [ ] AC3: loopback / localhost / RFC1918 / ULA / link-local / metadata endpoint variants が block されることを URL policy matrix で検証している。実 private network service には接続しない。
    - [ ] AC4: redirect-to-private、DNS-to-private、IPv6-mapped IPv4、numeric IPv4、URL credentials、non-http(s) scheme の adversarial cases を含む。
    - [ ] AC5: loopback trap server を使う場合、block 前に socket 接続されないことを `server_hit_count: 0` として記録している。
    - [ ] AC6: allowed public URL は CI 必須の実 fetch にしない。classifier-only smoke と manual network smoke を分離し、manual smoke の SKIP を PASS 扱いしない。
    - [ ] AC7: `CONTEXT_MODE_DIR` は isolated temp/root を使い、TTL/cache 汚染を防ぐため `ttl: 0` または `force: true` 相当を記録している。
    - [ ] AC8: `.claude/artifacts/context-mode/fetch-strict-negative-test.json` が schema `context_mode_fetch_strict_negative_test_v1` を満たし、raw HTML/body、URL credential、token-like value、unredacted home path、`null`、`pending`、`unknown`、`<...>` placeholder を含まない。
    - [ ] AC9: mutation test で `CTX_FETCH_STRICT` 無効化、deny entry 除去、private range blocklist 緩和のいずれかが検出される。
    - [ ] AC10: `docs/dev/agent-ops/context-mode-fetch-policy.md` に通常利用条件、禁止条件、prompt injection 扱い、cache/purge、#828 への依存関係が記録されている。

    Verification Commands 修正

    # AC1 / AC2 / AC8
    uv run python scripts/test_context_mode_fetch_strict.py \
      --settings .claude/settings.json \
      --registered-tools .claude/artifacts/context-mode/registered-tools.json \
      --permission-policy .claude/artifacts/context-mode/permission-policy.json \
      --artifact .claude/artifacts/context-mode/fetch-strict-negative-test.json \
      --assert-policy
    
    # AC3-AC7 / AC9
    uv run pytest tests/context_mode/test_fetch_strict_policy.py -v
    
    # AC8 schema/redaction/stale guard
    uv run pytest tests/context_mode/test_fetch_strict_artifact.py -v
    
    # AC10
    test -f docs/dev/agent-ops/context-mode-fetch-policy.md
    rg -n "ctx_fetch_and_index|CTX_FETCH_STRICT|prompt injection|purge|cache|禁止|許可|#828" docs/dev/agent-ops/context-mode-fetch-policy.md

    Allowed Paths 修正

    ## Allowed Paths
    
    - `.claude/settings.json`
    - `.claude/hooks/**`
    - `.claude/artifacts/context-mode/**`
    - `docs/dev/agent-ops/**`
    - `scripts/test_context_mode_fetch_strict.py`
    - `tests/context_mode/test_fetch_strict_policy.py`
    - `tests/context_mode/test_fetch_strict_artifact.py`
    - `tests/fixtures/context-mode/**`

    Stop Conditions 追加

    ## Stop Conditions
    
    - committed `.claude/settings.json` 上で `mcp__context-mode__ctx_fetch_and_index` を allow に変更する必要が出た場合
    - private / link-local / metadata endpoint へ実 network request を送らないと検証できない場合
    - `CTX_FETCH_STRICT=1` が設定上は存在するが runtime effective であることを証明できない場合
    - URL classifier / redirect / DNS resolution を hermetic fixture または controlled probe で検証できない場合
    - artifact に raw response body、credential 付き URL、token-like value、unredacted home path、`null`、`pending`、`unknown`、`<...>` placeholder が含まれる場合
    - public URL smoke test が network unavailable で SKIP されたのに PASS として扱われる場合
    - context-mode upstream の fetch policy / cache / storage semantics が変わり、既存 test vector の意味が不明になった場合

    実装設計の推奨

    fetch-strict-negative-test.json は最低限この形にしてください。

    {
      "schema": "context_mode_fetch_strict_negative_test_v1",
      "issue": "#827",
      "status": "pass",
      "generated_at": "ISO-8601",
      "head_sha": "actual commit sha",
      "context_mode_version": "actual installed version",
      "policy": {
        "ctx_fetch_and_index_committed_permission": "deny",
        "ctx_fetch_strict_configured": true,
        "ctx_fetch_strict_effective": true,
        "probe_profile_committed": false,
        "deny_restored": true
      },
      "network_safety": {
        "real_private_network_requests": 0,
        "resolver_mode": "stubbed",
        "redirect_mode": "fixture",
        "loopback_trap_server_hit_count": 0
      },
      "cases": [
        {
          "name": "loopback_ipv4",
          "input_url_redacted": "http://127.0.0.1:<PORT>/canary",
          "expected": "blocked_before_connect",
          "actual": "blocked_before_connect",
          "cache_hit": false
        }
      ],
      "cache_and_purge": {
        "context_mode_dir_isolated": true,
        "ttl_bypass": true,
        "purge_or_tmpdir_cleanup_verified": true,
        "post_cleanup_search_hit_count": 0
      },
      "redaction": {
        "raw_response_body_absent": true,
        "url_credentials_absent": true,
        "token_like_values_absent": true,
        "home_paths_redacted": true,
        "placeholders_absent": true
      },
      "mutation_test": {
        "strict_disabled_detected": true,
        "deny_removed_detected": true,
        "private_blocklist_relaxed_detected": true
      }
    }

    URL matrix は少なくとも次を含めるべきです。

    blocked:
      - http://127.0.0.1:<port>/
      - http://localhost:<port>/
      - http://localhost.:<port>/
      - http://0.0.0.0:<port>/
      - http://[::1]:<port>/
      - http://[::ffff:127.0.0.1]:<port>/
      - http://10.0.0.1/
      - http://172.16.0.1/
      - http://172.31.255.255/
      - http://192.168.0.1/
      - http://[fc00::1]/
      - http://[fe80::1]/
      - http://169.254.169.254/latest/meta-data/
      - http://169.254.170.2/
      - https://public.example/redirect-to-private   # fixture redirect
      - https://dns-private.example/                 # stub resolver -> private IP
      - file:///etc/passwd
      - data:text/plain,hello
    
    allowed-classifier-only:
      - https://example.com/
    

    配布物・ライセンス面の注意

    context-mode は Elastic License 2.0 として提供され、利用・fork・modify・distribute は可能だが、hosted/managed service 化や notice removal は禁止と説明されています。#827 では context-mode の source/binary を repo に vendoring せず、installed package の version/hash/provenance を artifact に残すだけに留めるのが安全です。([GitHub]1)

    GitHub secret scanning は git history だけでなく issue / PR descriptions / comments / discussions / wiki / gists も scan 対象です。fetch strict の canary、URL credential、fake token は本物の provider token 形式に似せず、artifact と PR comment に raw secret-like marker を残さない設計にしてください。([GitHub Docs]3)

    最終提案

    #827 はこのまま実装に進めず、まず Issue 契約を上記の形へ更新してください。特に committed deny 維持、effective strict 証明、private network への実接続ゼロ、cache/purge 証明、artifact schema test、mutation test が入るまで merge-ready な実装 Issue ではありません。

  19. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "PLANNER_FAIL_CLOSED: Issue #827 に必須セクション 4 つが欠落 (Parent Goal Ref / Current Validated Scope / Remaining Parent Gaps / Required Skills)"
    
    "anchor comment #issuecomment-4699971924 の REQUEST_CHANGES が未適用のまま"
    
    "LP010 違反: AC2・AC5 に対応する VC コメントが存在しない"
    
  20. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  21. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    CONTRACT_REVIEW_RESULT_V1

    schema: CONTRACT_REVIEW_RESULT_V1
    status: go
    issue_number: 827
    repo: squne121/loop-protocol
    generated_at: "2026-06-14T00:00:00Z"
    body_sha256: "sha256:5a38266999161216c35c23335bdc63ef19408ff35482d5cdd7e666afb70ea956"
    
    worktree_branch:
      worktree: .claude/worktrees/issue-827-ctx-fetch-strict
      branch: worktree-issue-827-ctx-fetch-strict
      collision: false
    
    checks:
      template_compliance: pass
      state_label:
        value: state/queued
        decision: pass
      allowed_paths_present: pass
      vc_present: pass
      stop_conditions_complete: pass
      ac_verifiability: pass
      worktree_branch_collision: pass
      blockers: pass
      product_spec_check:
        applicability: not_applicable
        decision: pass
        reason: "Allowed Paths に docs/product/ が含まれない(workflow / test infrastructure issue)"
      vc_preflight:
        status: pass
        summary:
          expected_fail: 11
          unexpected_pass: 0
          blocked: 0
          human_judgment: 0
          expected_pass: 0
        classifications:
          - ac: AC1
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC2
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC3
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC4
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC5
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC6
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC7
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC8
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC9
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC10 (test -f)
            scope_class: baseline_fail_expected
            decision: go
          - ac: AC10 (pytest fetch_policy_docs)
            scope_class: baseline_fail_expected
            decision: go
      runtime_verification_applicability:
        decision: deferred
        note: "実装ターゲットファイルが未作成のため baseline fail は全て expected"
      next_action: implement-issue
      blocked_reasons: []

    Handoff to implement-issue

    • Issue: 実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827
    • Outcome: committed deny を維持したまま、CTX_FETCH_STRICT=1 が runtime effective policy として artifact 化され、URL policy matrix の block 動作が hermetic fixture / stub で証明される
    • Worktree: .claude/worktrees/issue-827-ctx-fetch-strict
    • Branch: worktree-issue-827-ctx-fetch-strict
    • Allowed Paths:
      • .claude/settings.json
      • .claude/hooks/**
      • .claude/artifacts/context-mode/**
      • docs/dev/agent-ops/**
      • scripts/test_context_mode_fetch_strict.py
      • tests/context_mode/test_fetch_strict_policy.py
      • tests/context_mode/test_fetch_strict_artifact.py
      • tests/fixtures/context-mode/**
  22. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-13T22:58:20Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/827
      body_sha256: "sha256:5a38266999161216c35c23335bdc63ef19408ff35482d5cdd7e666afb70ea956"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  23. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-06-14T00:10:00Z)

    VC 結果サマリ

    AC VC コマンド 結果
    AC1 pytest -k committed_deny 5 passed
    AC2 pytest -k effective_strict 5 passed
    AC3 pytest -k url_policy_matrix 21 passed
    AC4 pytest -k adversarial 15 passed
    AC5 pytest -k trap_server 1 passed
    AC6 pytest -k ci_smoke 3 passed, 1 skipped (manual smoke — SKIP != PASS)
    AC7 pytest -k isolation 4 passed
    AC8 pytest test_fetch_strict_artifact.py -v 31 passed
    AC9 pytest -k mutation 5 passed
    AC10 test -f context-mode-fetch-policy.md + pytest -k fetch_policy_docs 7 passed
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  24. added 2 commits that reference this issue on Jun 13, 2026
  25. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    IMPL_REVIEW_LOOP_RESULT_V1

    schema: IMPL_REVIEW_LOOP_RESULT_V1
    status: draft_pr_ready
    merge_ready: true
    issue_number: 827
    pr_url: https://github.com/squne121/loop-protocol/pull/892
    pr_head_sha: fa9fc07a3ebe8e47f5fa13c1cc795f27dc9a0261
    generated_at: "2026-06-14T00:00:00Z"
    iteration: 0
    termination_reason: approved
    
    loop_verdict:
      verdict: APPROVE
      merge_ready: true
      required_auto_actions: []
      allowed_paths_gate:
        status: ok
      blockers: []
    
    ci_status:
      PR_Body_Japanese_Check: pass
      typecheck: pass
      lint: pass
      test: pass
      build: pass
      python_test: pass
      e2e: pass
      validate_generated_artifact: pass
      actionlint: pass
    
    verification:
      AC1: PASS (5 tests)
      AC2: PASS (5 tests)
      AC3: PASS (21 tests)
      AC4: PASS (15 tests)
      AC5: PASS (1 test)
      AC6: PASS (3 passed, 1 skipped — manual smoke SKIP != PASS)
      AC7: PASS (4 tests)
      AC8: PASS (31 tests)
      AC9: PASS (5 tests)
      AC10: PASS (test -f OK + 7 tests)
    
    next_action: "人間がマージを判断してください: https://github.com/squne121/loop-protocol/pull/892"
  26. added 7 commits that reference this issue on Jun 14, 2026
  27. squne121 commented on Jun 14, 2026

    @squne121
    OwnerAuthor

    IMPL_REVIEW_LOOP_RESULT_V1

    status: draft_pr_ready
    merge_ready: true
    issue_number: 827
    pr_number: 892
    pr_url: https://github.com/squne121/loop-protocol/pull/892
    branch: worktree-issue-827-ctx-fetch-strict
    head_sha: "113a3e5"
    verdict: APPROVE
    merge_state: MERGED
    merged_by: squne121
    merged_at: "2026-06-14T00:40:08Z"
    allowed_paths_gate:
      status: ok
      producer_role: review_subagent
    iterations_used: 2
    termination_reason: approved

    完了サマリ

    Issue #827「context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する」の実装が完了し、PR #892 がマージされました。

    実装内容(AC1〜AC10 全て充足)

    ファイル 役割
    scripts/test_context_mode_fetch_strict.py settings.json deny ルール確認 + artifact 生成
    tests/context_mode/test_fetch_strict_policy.py URL ポリシーマトリクス / adversarial / mutation テスト
    tests/context_mode/test_fetch_strict_artifact.py artifact スキーマ検証テスト(CI=true でhead_sha テストをスキップ)
    .claude/artifacts/context-mode/fetch-strict-negative-test.json 証跡 artifact(schema: context_mode_fetch_strict_negative_test_v1)
    docs/dev/agent-ops/context-mode-fetch-policy.md fetch policy 文書(AC10)

    CI 結果

    全ジョブ pass(python-test / test / build / e2e / typecheck / lint / actionlint / validate-generated-artifact / PR Body Japanese Check)

  28. squne121 commented on Jun 14, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-06-14T00:46:42Z)

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues: []
    
      note_only_observations:
        - dedupe_key: "parent-813-keep-open-until-828"
          source_url: "https://github.com/squne121/loop-protocol/issues/813"
          source_note_id: "parent_issue_status"
          summary: "parent issue #813 は child #828(ctx_fetch_and_index persistence/purge/ELv2 docs)が OPEN のためクローズ不可。#828 完了後に再実行。"
        - dedupe_key: "worktree-issue-827-ctx-fetch-strict-unstaged"
          source_url: "https://github.com/squne121/loop-protocol/pull/892"
          source_note_id: "unresolved_cleanup_items"
          summary: ".claude/worktrees/issue-827-ctx-fetch-strict に unstaged deletions(tests/fixtures/agent-session-manifest/temp-invalid-no-markers.md)あり。自動削除を保留。手動で git worktree remove .claude/worktrees/issue-827-ctx-fetch-strict を確認・実行してください。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions