Skip to content

feat(a8n-attached): host script 内で project identity を再検証する guard を追加 (#385) - #389

Merged
rebuildup merged 1 commit into
release-0-6-0from
385
Nov 20, 2026
Merged

rebuildup merged 1 commit into
release-0-6-0from
385

Conversation

@rebuildup

Copy link
Copy Markdown
Contributor

概要

Issue #385。PR #379 CodeRabbit Major finding の follow-up。

a8n-attached lane の targetGuard(revalidateTarget)は consent 承認直後・dispatch 直前に target identity を再証明するが、guard 通過から generated ExtendScript が host で評価されるまでの間に user が AE で project を切り替える TOCTOU 窓が残っていた。本 PR で consent-bound source の内側 に host-readable な project identity 検証を注入し、同一評価内で write 前に refuse する。

設計

  • host-readable identity: app.project.file.fsName。ae-a8n の project.info が返す file はまさにこの文字列(host/a8n-host.js の String(project.file.fsName))なので、session が attest した値をそのまま期待値に使える。未保存 project(file null)・identity 読み取り不能時は guard 値を持たない。
  • scripting-adapters/execute.mjs:
    • withHostProjectGuard(programSource, expectedFsName) — consent-bound program を (function(){ guard; return <op program> })() でラップ。guard は op body の前に app.project.file.fsName を期待値と比較し、不一致なら adapter failure shape({ok:false, error:{code:"PROJECT_IDENTITY_MISMATCH"}})を JSON 文字列で返す → outcome FAILED + adapterError.code で構造化され、write は一切実行されない。ES3 のみ(var/typeof/三項)。
    • hostProjectGuardRequired === true かつ mutating op かつ guard 値なし → consent 前に PROJECT_GUARD_UNAVAILABLE で refuse(read op は影響なし)。
    • 注入は toProgramSource 直後・consent scope 計算より前 — guard literal は consent が approve する source の一部であり、実行される文字列と一致する。
  • a8n-transport/attached-session.mjs: attest 済み project.file(非空 string の時のみ)を hostProjectGuard として公開、hostProjectGuardRequired: true。
  • dev-loop/session-open.mjs: 3 session kind 全てで hostProjectGuard/hostProjectGuardRequired をマップ(fake/a8n は null/false)。
  • dev-loop/devloop.mjs verify(): 新フィールドを forwarding。
  • devtools-cli/cli.mjs / mcp-server/tools.mjs: session の guard 値を runOperation/verify に転送。projectIdentity も hostProjectGuard ?? 従来の静的 label に変更 — consent scope が実 project を名指すようになる(attached lane のみ実値、他 lane は不変)。

適用範囲(正直な記載)

  • canonical path(registry op → runOperation)を通る CLI / MCP / VSCode(controller→tools.mjs 経由)の a8n-attached session が対象。agent-loop は runner 直叩きの別 path で registry op を dispatch しないため対象外。
  • owned(a8n)/fake session は hostProjectGuard: null — guard は注入されず従来動作(owned は使い捨て自前 AE で実害小、issue の検討事項どおり)。

テスト(fake/mock レベル)

execute.test.mjs +4 tests:

  • guard 一致 → COMPLETED、consent provider が受け取る source に guard literal を含む
  • project 不一致(TOCTOU 模擬)→ FAILED PROJECT_IDENTITY_MISMATCH、items.length === 0 で write 未実行を確認
  • hostProjectGuardRequired + guard なし → mutating op は consent/dispatch 前に PROJECT_GUARD_UNAVAILABLE refuse、read op は COMPLETED
  • required + guard あり → COMPLETED

check-syntax 140 files、scripting-adapters 3/3、dev-loop 4/4、mcp-server、devtools-cli 53 tests、a8n-transport attached-session 25/25 — 全 green。

検証レベル

  • automated test(fake host vm eval)のみ。real AE での attach lane 実測は未実施 — app.project.file.fsName の形式は ae-a8n host script と同一ソース(String(project.file.fsName))だが、実機での pin 動作確認は今後の real-host run で要検証。

@rebuildup
rebuildup marked this pull request as ready for review November 20, 2026 20:59
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b1afce8-7ee1-4988-bd85-c3defe594173

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@rebuildup
rebuildup merged commit 2aef8cb into release-0-6-0 Nov 20, 2026
10 checks passed
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.

1 participant