Repository navigation
fix(apps): give an in-process app its app token after the secret left its folder - #35533
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check: the diff adds or changes no user-visible control. The only frontend change is the [UX-REVIEWED] 57ef4fa Description read[DESCRIPTION-READ] 51b77fda74d3d6a780fa499ab73e7e2e34d0582fa4826ce4d9160e7acd35a5e1 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. One rider: Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: a FIX. A third-party app whose backend runs as hooks in the gateway process can get an app token again after #34762.
[FIRST-PRINCIPLES-REVIEWED] 57ef4fa Description read[DESCRIPTION-READ] eecb07f1367166d85ae05150cae8c05dda2dc91e5f6906120e21197cc143b13f That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. Hooks that run in the gateway process now get a minted app token instead of the secret. The secret moves on the hook-load path through the same one-time Notes
[DESIGN-REVIEWED] 57ef4fa Description read[DESCRIPTION-READ] 7b7b205ec7813ec0b35aa2d2c3b2175cd2555ab8626a11b0c8fbe3e009b65fe2 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: A person should decideWhy: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 446 lines, more than the 400 it may approve on its own. The fix achieves its goal. AppContext.app_token() issues the same token as the exchange route, through the same generate_token call, after checking the same owner-enable marker. It is audited, and it returns "" once the app is disabled. Code that runs in the gateway process could already create tokens, so this opens no new trust boundary. Both hook-loading paths (gateway startup and app enable) now call replace_legacy_app_secret through _prepare_hook_load. That move is idempotent, runs under a lock with the spawn path, and catches disk errors (RecordsNotMoved is an OSError). The new loopback_gateway_origin helper behaves exactly like the inline code it replaces in backend.py, and backend.py's warning path still reads the bound-host setting. The seam level is 5 in both the Python and TS constants, and the existing test that keeps them equal still passes. No current source reads the new seam names from a context, so the pin tool's new entries change no built-in app. The tests use the real install, update, enable, startup and disable paths. Most CI was pending or failed on infrastructure (rate limits, merge-base reads), not on the code. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
7186993 to
a6ef297
Compare
a6ef297 to
81cfef3
Compare
81cfef3 to
57ef4fa
Compare
|
Thanks for the fix. The review of this head found no blocking issue, but a maintainer needs to approve it, because it adds a new way to mint a credential. What the review checked on this head:
Done well: hooks get a token, not the raw secret. The secret never leaves the gateway record, so a hook has no secret it could pass to a sandboxed child. Security: on main, an app whose backend runs in the gateway process gets no app token. With this change, hook code gets one from Optional:
|
bolichen97
left a comment
There was a problem hiding this comment.
Read the full diff. Fixes #35532.
On scope: issue_in_process_app_token mints with generate_token(app_name, app=app_name), the same call main's POST /api/apps/<name>/token makes (handlers/core.py). So the token carries the same app claim, and _enforce_app_scope confines it to the manifest's permissions.api as before. It is gated on the same owner-enable marker validate_app_secret checks first, so a context kept past a disable gets "", and both outcomes are audited as app_token_exchange / app_context. The grant is no wider than main's, and code already running in the gateway process gets nothing it could not reach before.
The hook load now calls replace_legacy_app_secret, the same move a spawn does. That adds no refusal, because the folder value was already refused. loopback_gateway_origin is the spawn's host logic moved unchanged, and the spawn now calls it, so both paths share one rule. The seam level goes to 5 in both the backend and the website. No regex. LGTM.
Kiro Crew gave App Kit level 5 to ctx.app_token (kirodotdev/KiroCrew#35533), and the agentReadOnlyDirs seam (kirodotdev/KiroCrew#33589) now lands at level 6. Gating on 5 would move the decision record into a data/trust/ that a level-5 host does not fence. Raise READONLY_DIRS_SDK_LEVEL to 6, update the docs and tests that named level 5, and pin that a level-5 host keeps the record where it gates it. Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
Problem / Motivation
Goal: An app whose backend runs in the gateway process can call the gateway REST API with an app token again, and the first load of its hooks moves the folder secret of an older install out of the folder.
An app with
backend.hooksand noentryPointruns in the gateway process, so the gateway never spawns a backend for it. Since #34762 the secret lives inmember-records/app-secrets/, the gateway never accepts the folder.app_secret, and only a backend spawn moves the secret of an older install. An app that runs in the gateway process gets no secret through any channel. An app installed before #34762 gets403 invalid secreton everyPOST /api/apps/<name>/token, and a disable and enable does not change that.Why it matters
Every third-party app that runs its backend in the gateway process and calls the gateway REST API stops working after the update to #34762. On one host, one app got 196 refusals in 97 minutes and no grant.
Not a goal
agentToolsthat the owner approves, so the call goes through the gateway and no sandboxed process holds a credential. The linked issue compares this with a scoped token per agent session.What changed (motivation → approach → change)
Every token exchange from such an app fails because the gateway moves a secret only when it spawns a backend, and code in the gateway process has no channel for the secret. The hooks now get the token itself, and the hook load does the move:
ctx.app_token()AppContextmethod returns the token thatPOST /api/apps/<name>/tokenissues, with no secret, behind the same owner-enable marker. It returns""after a disable. The gateway audits each call asapp_token_exchangewith sourceapp_context.ctx.gateway_origin()AppContextmethod returns the loopback origin a spawned backend gets inKIROCREW_GATEWAY_ORIGIN, read fromKIROCREW_BOUND_PORTandKIROCREW_BOUND_HOST. It returns""when the gateway is bound to one specific interface. Without it a hook has nobase_url, and the Python client falls back toKIROCREW_PORTor port 5476, which can be another gateway. The newapps/gateway_origin.pyholds the one copy of this logic, andapps/backend.pynow calls it for the spawn environment, with the same output for every port and host value.hooks_integration._prepare_hook_load. It callsreplace_legacy_app_secret, the same one-time move the spawn does: store a new secret and remove the folder file.APP_SDK_LEVELis 5 inapps/app_sdk_level.pyandapp-sdk/sdkLevel.ts, and the adoption pin tool (scripts/adoption_pin.py) mapsctx.app_tokenandctx.gateway_originto level 5.ctx.app_token()andctx.gateway_origin(), the Python client setup for hooks (build no client when the origin is"") and the agent MCP server gap. Theapp-kit-platformanddashboard-token-authspecs name the hook load as a place where the secret moves.The starting idea was an App Kit call that returns the secret. Code in the gateway process needs the secret only to exchange it for a token, so the context returns the token. The secret never leaves the gateway record, so a hook cannot pass it to a child process in a sandbox. The context is the proof of identity, because the gateway builds each context for one app.
Backwards compatibility
Compatible: the exchange route, the spawn path and stored secrets do not change, and an app that reads
.app_secretis refused as on main.Reader: packages/kirocrew-client-py/kirocrew_client/client.py:_read_app_secret -- app -- reads the folder file only as a fallback for an older gateway, and the gateway refuses that value on main already
Reader: src/kiro_crew/apps/manager_install.py:update_app -- app -- keeps the folder file only when one exists, and the moved secret is not in the folder (test_enable_moves_the_secret_of_an_app_installed_and_then_updated)
Reader: src/kiro_crew/dashboard/token_auth_tokens.py:replace_legacy_app_secret -- app -- a later spawn or hook load finds the stored secret and returns it unchanged (test_enable_moves_the_secret_of_an_app_installed_and_then_updated)
Tests
test/test_app_in_process_secret.pyinstalls, updates, enables and disables a real app withbackend.hooksand stubs only the hook body. Boot and enable both move the secret of an older install, also after an update that keeps the folder file. The hook context mints a token whose app claim is the app, and a context kept past a disable mints nothing. Six cases check thatctx.gateway_origin()uses the bound port and notKIROCREW_PORT, and returns""for a specific interface or a missing, zero or invalid port.test/test_builtin_adoption_pins.pyadds the cases that the pin tool readsctx.app_tokenandctx.gateway_originas level 5.test/integration/test_builtin_adoption_boot.pyadopts an app whose backend is only in-process hooks. On main, nothing moved that app's folder secret, so the test read the old file after the restart. Now the hook load on that restart moves it, so the test checks that the folder file is gone and that the gateway holds a new secret. If the adoption lost the file, the app would have no secret and the test fails.Repeats: 20 runs at
-n0, and 10 runs at-n 4 --dist loadgroup --max-worker-restart=2withtest/test_app_trust_enabled.pyandtest/test_lifecycle_data_dir_off_loop.pyas co-tenants, all green. Shuffled order: green with seed 21766, 27 ids.Proof: PROVEN test/test_app_in_process_secret.py::test_boot_moves_the_secret_of_an_app_installed_before_it_left_the_folder, test/test_app_in_process_secret.py::test_enable_moves_the_secret_of_an_app_installed_and_then_updated, test/test_builtin_adoption_pins.py::test_the_pin_tool_finds_every_seam_above_level_one[manifest7-files7-uses7], test/test_builtin_adoption_pins.py::test_the_pin_tool_finds_every_seam_above_level_one[manifest8-files8-uses8] (head 57ef4fa)
Gate proof: tree 8e96a5293da5; ran 24; skipped none
Manual verification
N/A: unit coverage is sufficient. The tests drive the real install, update, enable, boot and disable paths and the real token validation, with only the hook body stubbed.
Screenshots / video
Why no screenshot: the only frontend change is the exported seam level constant, which renders nothing.
Related Issues
Fixes #35532
Regression from #34762.
Sibling sweep
Swept: git grep -nE "replace_legacy_app_secret|KIROCREW_PROXY_SECRET|read_app_secret" -- src/
Sibling: src/kiro_crew/apps/backend.py -- not affected -- the spawn path moves the secret and hands it over in KIROCREW_PROXY_SECRET
Sibling: src/kiro_crew/apps/builtins/dev_fleet/http_api.py -- not affected -- a spawned backend that reads KIROCREW_PROXY_SECRET
Sibling: src/kiro_crew/apps/manager_external.py -- not affected -- a self-managed app gets its new secret in its registration response
Pattern harvest
Rule candidate: review-prompt
Pattern: a credential moved to a store no sandbox reads needs a delivery channel for every runtime shape an app can have (spawned backend, self-managed, hooks in the gateway process, agent MCP servers), not only the shape the change was tested with.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)