Repository navigation
fix(approvals): bind decides to the request the card showed - #18810
Conversation
A tool-approval decide that names only the request id resolves whichever request holds that id at the moment, and request ids can recur. - Both decide routes refuse an id-only decide from a caller that is not the dashboard user's browser session (a loopback internal-secret caller) with 404 approval_target_required. Owner-bound targets are accepted from every caller, and dashboard browser callers keep the id-only form. - The Mochi panel bridge carries each card's owner-bound target (coordinator slot + instance, or the native row mid) and sends it on approve/reject. - A guard test requires every hand-built decide under website/src/apps to carry an owner-bound target, with a marked exception for the slot route's durable trust actions.
UX Review (Opus 5.5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS When a card's request has been replaced, the new 404 shows "Couldn't send — check your connection and try again." That points the user at the wrong cause and the wrong fix. Watch
Suggestions
[UX-REVIEWED] b835731 Description read[DESCRIPTION-READ] 9d1fc712a45e5e397e405b3fb724d39d85cffb48396553d2c8bacd38b1e97604 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) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The server refusal guards zero real callers today, and its security framing overstates it: internal callers can still approve with an owner-bound target. Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: make a Mochi approval click decide only the request its card showed. FIX.
[FIRST-PRINCIPLES-REVIEWED] b835731 Description read[DESCRIPTION-READ] 70a2dfbb01bbd048cc4fe4a4ae1692a0cd75ed62a5231dd0c3f348a99d4f7771 That sha256 names the PR description this verdict read. 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: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the Mochi panel's host sends the dashboard cookie, so the server sets an empty [DESIGN-REVIEWED] b835731 Description read[DESCRIPTION-READ] 0562db22e02aed4e147fd278111ffc2963d694392e3ebd9aa348406464d060e3 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 |
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: |
|
This PR stops a tool-approval decide from landing on a later request that reused the same id. It makes /api/approvals/{id}/{action} and the slot approve route refuse a bare-id decide unless the caller is the owner's browser session (bare_approval_decide_allowed: app claim present and empty, and not internal_auth). Mochi now sends the coordinator or native owner-bound target instead. The fix does target the root cause, the id-only lookup. HOLD reason: it changes approval authorization, which callers may resolve a permission request, and the brief holds permission/auth changes for a human. I tried to get past the check. An internal-secret caller is refused because internal_auth is checked first. App callers return earlier through their own grant path. I could not verify that no in-tree non-browser caller, such as a messaging-channel approval button or a CLI that posts over HTTP with an internal secret, still decides by bare id; any such caller now gets 404 approval_target_required. A maintainer should confirm that sweep. The UX and First Principles lanes are CONCERNS on head b835731 (advisory), GPT and Opus have no findings, and checks are green. — crew-pr-reviewer |
iamwhatever
left a comment
There was a problem hiding this comment.
This PR makes both decide routes refuse a bare-id approval decide unless the caller is the dashboard user's browser session (bare_approval_decide_allowed: present empty app claim and no internal_auth). Mochi now sends the owner-bound target (coordinator slot+instance, or native request_mid), so a stale card can no longer resolve a later request that reused the id. That is the root cause. Last round I asked whether any in-tree non-browser caller still decides by bare id, so I swept main myself. No Python code in src posts either route. Slack, the channels and the task runner resolve in-process. kirocrew-client-py authenticates with the mc_token cookie, so token_auth labels it as the dashboard user or an app. The app SDK paths (ChatEmbed, ops-mission-control) carry an app claim, so _resolve_app_approval handles them before the new check, and Mochi's fetches are same-origin with the dashboard cookie. Then I tried to break the check: an X-Internal-Secret caller gets no empty app claim (the middleware leaves it absent), and internal_auth is checked first anyway, so it is refused on both routes, including the no-request_id single-pending pick. The change can only refuse more, it breaks no caller I could find, the tests fail on main, and checks are green. One small follow-up from the UX lane: a stale card's 404 shows "check your connection"; a staleTarget flag that drops the card would be nicer. — crew-pr-reviewer (deep re-check)
|
Heads-up: on current
Reproduce: |
Problem / Motivation
Goal: A tool-approval decision lands on the request the approval card actually showed, never on a later request that took over the same id.
Both decide routes,
POST /api/approvals/{id}/{action}andPOST /api/chat/slots/{slot}/approve, still accept a decide that names only the request id. A request id is minted by whoever raised the approval and can recur, so an id-only decide resolves whichever request holds the id now. Two places rely on that form today:respondApprovalinwebsite/src/apps/mochi/panel/panelBridge.ts), so a card left up for request A can decide request B once B reuses A's id.X-Internal-Secretcaller (an agent, MCP tool or cron). That caller is not a person looking at a card and has no reason to decide by guess.Why it matters
An approval is a security decision. One that lands on a request the user never saw can grant a tool call they didn't approve. That affects every Mochi panel user, and it leaves an id-only approve open to any internal caller on both routes.
Not a goal
api.resolveApprovalcall sites and threeapproveChatSlotcall sites on main still send the bare id. Binding those is the client half of fix: bind every approval decide to an owner-bound target #16481. Refusing the bare form from cookie callers before fix: bind every approval decide to an owner-bound target #16481 merges would break approve buttons on main, so that strictness follows once fix: bind every approval decide to an owner-bound target #16481 lands.trust,trust_command,trust_base). That route accepts them only by request id and re-verifies the card before granting.What changed (motivation → approach → change)
Symptom → cause → change:
Server: id-only decide from a non-dashboard caller.
bare_approval_decide_allowed()inchat_handlers.pyadmits the id-only form only from the dashboard user's own browser session. That means a present, emptyappclaim, the same positive proofis_owner_dashboard_requestreads, and nointernal_auth. Any other caller must send an owner-bound target or get 404approval_target_required. Two places use it:api_approval_resolve(handlers/sessions.py);originpath inapi_chat_slot_approve, which also covers the no-request_id"single pending" pick.Owner-bound targets are unchanged and still accepted from every caller:
?origin=coordinator&slot=…&instance=…, or{origin: "native", request_mid}.Mochi panel: no binding sent. The bridge now attaches each card's owner-bound target when it builds the card:
approvalframe gives the coordinatorslot+instance;permissionchat frame gives the row'smeta.midas the native target.ChatPanelkeeps the target with the card and passes it torespondApproval. Approve/reject then sends the target: the coordinator route gets the query, and a native request goes to the slot route withorigin: 'native'andrequest_mid. A card for a request that has since been replaced gets 404 instead of deciding the new request. A card with no target, from an older frame, keeps the id-only form, which the dashboard browser session still accepts.Guard.
website/src/test/appsApprovalTargetGuard.test.tsscanswebsite/src/appsand requires every hand-built POST to either decide route to carry anorigin:target. The single exception is markedapproval-target: trust-only.Spec. The approvals entry in
docs/system-specs/modules/learn-cron-dashboard.mdstates the rule.Overlap with #16481: both PRs touch
handlers/sessions.py(api_approval_resolve),chat_handlers.py(api_chat_slot_approve) andpanelBridge.ts, though in different hunks. This PR adds a new branch inside the existing bare-idelse, one guard line afterstrict_native = "origin" in body, and changesrespondApprovaland the frame parsing. #16481 touches the pet event near line 605. Whichever lands second will need a small rebase. Neither change depends on the other.Alternatives considered and rejected:
Backwards compatibility
Breaking: an id-only decide from a non-dashboard caller (loopback
X-Internal-Secret, or a request the auth middleware did not label as the dashboard user) now gets 404approval_target_requiredon both routes. That includes a durable trust action from such a caller. Writer sweep on origin/main @ d3f462f:src: no Python code posts either decide route over HTTP. Slack, the channels and the task runner resolve approvals in-process throughDashboardState.kirocrew-client-pypackage (KiroCrewClient.respond_approval) authenticates with themc_token_<port>cookie (dashboard or app token), so the server labels it as the dashboard user or an app. It is unchanged.website/src: every dashboard call site runs in the browser session and is unchanged. The Mochi panel now sends the binding (see above).Reader:
kiro_crew/dashboard/handlers/sessions.py:api_approval_resolve-- chat -- the dashboard browser session still decides by id (test_dashboard_user_bare_id_coordinator_decide_still_resolves)Reader:
kiro_crew/dashboard/chat_handlers.py:api_chat_slot_approve-- chat -- the dashboard browser session still decides by id (test_dashboard_user_bare_id_slot_approve_still_resolves)Reader:
website/src/apps/mochi/panel/panelBridge.ts:respondApproval-- app -- a card without a target keeps the id-only form (respondApproval routes approve/reject and trust to DIFFERENT endpoints)Tests
test/test_approval_decide_owner_bound.py, all through the real handlers:request_idpick. These three tests fail on main.test/test_dashboard_approval.py: thereject_onceseam test's request double now carries the dashboard user's empty app claim, which is what the auth middleware sets.website/src/apps/mochi/test/mochiPanelBridge.test.ts:approvalandpermissionframes carry the coordinator and native targets;respondApprovalsends the coordinator query and the nativerequest_midbody;website/src/test/MochiChatPanel.coverage.test.tsx: the card decides with its own target.website/src/test/appsApprovalTargetGuard.test.ts: the guard above, with a non-vacuity check. It fails on main.Locally:
test/*approv*,*trust*and*mochi*file (2675 passed);tsc --noEmitand eslint on the changed files;Manual verification
N/A: the behaviour change is entirely in the two route handlers and the panel bridge's request shape, and the handler tests drive both through aiohttp. The Mochi card's look is unchanged.
Screenshots / video
Why no screenshot: The Mochi approval card renders exactly as before; only the request it sends on approve or reject changes.
Related Issues
Follows on from the scope #16481 leaves out: it binds the dashboard surfaces and keeps the id-only form on the server for other callers.
Pattern harvest
Rule candidate: review-prompt
Pattern: a decision or resolve keyed by a caller-minted id that can recur, with no binding to the instance the user saw
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.