Skip to content

fix(approvals): bind decides to the request the card showed - #18810

Merged
cruisercohen merged 2 commits into
mainfrom
fix/approval-decide-owner-bound
Oct 10, 2026
Merged

cruisercohen merged 2 commits into
mainfrom
fix/approval-decide-owner-bound

Conversation

@cruisercohen

Copy link
Copy Markdown
Contributor

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} and POST /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:

  • The bundled Mochi panel posts both routes by bare id (respondApproval in website/src/apps/mochi/panel/panelBridge.ts), so a card left up for request A can decide request B once B reuses A's id.
  • The server accepts the bare form from every authenticated caller, including a loopback X-Internal-Secret caller (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

What changed (motivation → approach → change)

Symptom → cause → change:

  1. Server: id-only decide from a non-dashboard caller. bare_approval_decide_allowed() in chat_handlers.py admits the id-only form only from the dashboard user's own browser session. That means a present, empty app claim, the same positive proof is_owner_dashboard_request reads, and no internal_auth. Any other caller must send an owner-bound target or get 404 approval_target_required. Two places use it:

    • the bare-id fallthrough in api_approval_resolve (handlers/sessions.py);
    • the non-origin path in api_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}.

  2. Mochi panel: no binding sent. The bridge now attaches each card's owner-bound target when it builds the card:

    • an approval frame gives the coordinator slot + instance;
    • a permission chat frame gives the row's meta.mid as the native target.

    ChatPanel keeps the target with the card and passes it to respondApproval. Approve/reject then sends the target: the coordinator route gets the query, and a native request goes to the slot route with origin: 'native' and request_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.

  3. Guard. website/src/test/appsApprovalTargetGuard.test.ts scans website/src/apps and requires every hand-built POST to either decide route to carry an origin: target. The single exception is marked approval-target: trust-only.

  4. Spec. The approvals entry in docs/system-specs/modules/learn-cron-dashboard.md states the rule.

Overlap with #16481: both PRs touch handlers/sessions.py (api_approval_resolve), chat_handlers.py (api_chat_slot_approve) and panelBridge.ts, though in different hunks. This PR adds a new branch inside the existing bare-id else, one guard line after strict_native = "origin" in body, and changes respondApproval and 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 404 approval_target_required on 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 through DashboardState.
  • the kirocrew-client-py package (KiroCrewClient.respond_approval) authenticates with the mc_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:
    • An internal caller's id-only decide is refused with 404 on both routes, including the slot route's no-request_id pick. These three tests fail on main.
    • The same caller's owner-bound decide resolves on both routes.
    • The dashboard user's id-only decide still resolves on both routes.
    • The predicate is pinned on its own.
  • test/test_dashboard_approval.py: the reject_once seam 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:
    • approval and permission frames carry the coordinator and native targets;
    • respondApproval sends the coordinator query and the native request_mid body;
    • trust keeps the id-only slot form.
  • 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:

  • the 21 backend test files that drive the decide routes (3115 passed), plus every test/*approv*, *trust* and *mochi* file (2675 passed);
  • the Mochi panel and app suites (46 files, 683 passed);
  • tsc --noEmit and eslint on the changed files;
  • black, isort, flake8 and mypy on the changed Python files;
  • the fast-gate scripts.

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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

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.
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 10, 2026
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — 🟡 CONCERNS

UX-level review of b835731f570269e888267ada9c71db0f5e2da1c3 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • The stale-card refusal looks like a network failure. This PR makes respondApproval get 404 approval_target_required when the card's request was replaced under the same id. ChatPanel's res.ok === false branch handles that the same way as any other failure: it posts apps.mochi.chat.send_failed ("Couldn't send — check your connection and try again.") and leaves the card and its Approve/Reject buttons in place. The user then checks their network and clicks Approve again, and every retry gets the same 404. The card stays stuck until something else removes it. Severity: rare, but it hits a security decision, the user gets misleading guidance, and the dead card stays on screen. Smallest fix: when the failure is a target refusal, drop the stale card or mark it "This request was replaced — the new one is shown separately" instead of showing the connection copy.

Suggestions

  • Have respondApproval return a staleTarget flag, like the existing staleOwnerSession, so ChatPanel can choose the copy and stop offering the dead buttons.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of b835731f570269e888267ada9c71db0f5e2da1c3 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • Item 4 — inherited: "it leaves an id-only approve open to any internal caller". The description's own sweep says "no Python code posts either decide route over HTTP", and I counted 0 posters to /api/approvals/ or /api/chat/slots/{slot}/approve in src/. bare_approval_decide_allowed still lets an internal_auth caller decide through ?origin=coordinator… or request_mid, so it shuts no agent self-approval path. It only stops a caller that doesn't exist from mis-targeting. The Mochi defect is already fixed by items 1–2: the panel runs in the dashboard session, which this predicate still lets through.
    Subtraction: drop the internal_auth / non-dashboard refusal from both handlers and ship the Mochi binding alone, or defer it to fix: bind every approval decide to an owner-bound target #16481's server strictness.
    Clears when: an existing internal caller that decides by bare id is named, or the item is removed.

What this change ships

Inventory (6 items) — 5 justified

Intent: make a Mochi approval click decide only the request its card showed. FIX.

  1. Mochi coordinator cards' approve/reject now send slot+instance — justified
  2. Mochi native permission cards' approve/reject move to the slot route with request_mid — justified
  3. A card from an older frame with no target still decides by bare id — justified
  4. A bare-id decide from an internal or non-dashboard caller, including the single-pending pick, now gets 404 approval_target_required — inherited, 0 counted callers
  5. A test scans src/apps and requires every decide POST to carry origin — justified
  6. The spec states the bare-id rule — justified

[FIRST-PRINCIPLES-REVIEWED] b835731

Description read

[DESCRIPTION-READ] 70a2dfbb01bbd048cc4fe4a4ae1692a0cd75ed62a5231dd0c3f348a99d4f7771

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of b835731f570269e888267ada9c71db0f5e2da1c3 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b835731

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b835731f570269e888267ada9c71db0f5e2da1c3: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b835731f570269e888267ada9c71db0f5e2da1c3 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the Mochi panel's host sends the dashboard cookie, so the server sets an empty app claim. If it doesn't, cards without a target will get 404.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@cruisercohen
cruisercohen marked this pull request as ready for review October 10, 2026 10:13
@cruisercohen
cruisercohen requested review from a team and KiroCrewCaptain as code owners October 10, 2026 10:13
@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed b835731f570269e888267ada9c71db0f5e2da1c3 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b835731

Verdict parsed from the review's SHA-scoped output markers for commit b835731f570269e888267ada9c71db0f5e2da1c3.

False positive or not applicable? A repository writer can comment:
/ai-review override fable b835731f570269e888267ada9c71db0f5e2da1c3: <one-sentence reason>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 10, 2026
@cruisercohen
cruisercohen enabled auto-merge (squash) October 10, 2026 10:40
@iamwhatever

Copy link
Copy Markdown
Contributor

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 iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@cruisercohen
cruisercohen merged commit 9086e97 into main Oct 10, 2026
104 checks passed
@cruisercohen
cruisercohen deleted the fix/approval-decide-owner-bound branch October 10, 2026 19:58
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 10, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor

Heads-up: on current main (ec2b337, and already at this PR's merge commit 9086e97) three tests added here fail:

  • test/test_approval_decide_owner_bound.py::test_internal_caller_bare_id_slot_approve_is_refused (403, expected 404)
  • test/test_approval_decide_owner_bound.py::test_internal_caller_slot_approve_with_no_request_id_is_refused (403, expected 404)
  • test/test_approval_decide_owner_bound.py::test_internal_caller_owner_bound_slot_approve_resolves (403, expected 200)

Reproduce: python -m pytest test/test_approval_decide_owner_bound.py -q on main gives 3 failed, 5 passed. The PR's own CI ran on base b835731, so this looks like an interaction with a change that landed on main after that base, where the slot approve route now answers 403 for the internal caller before reaching the new check. It turns Backend Tests (3.12, 4) and Backend Tests (Windows) (4) red on every PR rebased past it (e.g. #18128, #18105).

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.

3 participants