Skip to content

fix(code-review-sage): require the dashboard owner for review writes - #15988

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/owner-gate-round14-code-review-sage
Oct 2, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/owner-gate-round14-code-review-sage

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Only the dashboard owner can change Code Review Sage state or start, post, or delete its reviews.

The Code Review Sage write routes had no owner check. Any signed-in dashboard user who is not the owner could start a review, post its comments, cancel or delete runs, and change settings, namespaces and pinned repos. Reviews run with the owner's gh login, so that work happens as the owner.

Why it matters

A shared gateway can admit users who are not the owner. They should be able to read what the owner allows. They should not act as the owner on GitHub or change the owner's review setup.

Not a goal

  • No change to the GET routes. They answer the same as before.
  • No new auth helper. The fix reuses the shared owner gate.
  • No change to the frontend. It already calls these routes with the owner's session cookie.

What changed (motivation → approach → change)

Symptom: a non-owner reached every write route. Cause: the module never called the owner gate the other builtin apps use. Change: each write route now calls require_owner_dashboard_request first and returns its owner_only 403.

Route Gate
POST /review, /review-repo top of handler
POST /runs/{id}/post, /cancel, /archive top of handler
DELETE /runs/{id} top of handler
PUT /settings after the GET branch
POST, DELETE /namespaces after the GET branch
POST, DELETE /repos after the GET branch
POST /learnings/consolidate top of handler
POST /followup after the app-enabled check

Each refusal also writes the shared gate's SEL denied audit event. App tokens are refused too, this app's own included. No product code calls these routes with an app token. The page sends the session cookie, and the skills and backend helpers never call these routes.

Files:

  • src/kiro_crew/apps/builtins/code_review_sage/backend/routes.py: the gate on all 14 write route and method pairs.
  • src/kiro_crew/apps/builtins/code_review_sage/tests/test_owner_gate.py: new tests.
  • src/kiro_crew/apps/builtins/code_review_sage/tests/fixtures.py: one shared OwnerRequest fake carrying the owner's real identity.
  • src/kiro_crew/apps/builtins/code_review_sage/tests/test_backend_routes.py, test_consolidate.py, test_paste_pr_link.py, test_post_comments.py, test_run_endpoints.py, and test/test_sage_backend_routes_coverage.py: their fake requests build on that shared fake.
  • The gate runs unpatched in every test.

Backwards compatibility

Breaking: a non-owner dashboard user or an app token now gets a 403 owner_only on these 14 write routes. Writer sweep on origin/main @ 5a70ce7: the only caller is the dashboard page (website/src/apps/code-review-sage/api.ts), which sends the owner's session cookie and still passes. No MCP tool, skill, cron, hook or backend helper calls these routes.

Tests

  • test_non_owner_dashboard_subject_refused[...]: every write route answers a non-owner with 403 owner_only and reaches no side-effect seam.
  • test_own_app_token_refused[...]: the same for this app's own token.
  • test_owner_passes_gate[...]: the owner reaches each handler's own validation.
  • test_non_owner_get_routes_unchanged[...]: GET settings, namespaces and repos still answer 200.

With the routes change reverted, the 26 refusal rows fail and the owner and GET rows pass. With it applied, all pass.

Pre-existing: tests/test_store_ancestor_chain.py::TestTheWindowBetweenTheRefusalAndTheWalk::test_a_link_planted_inside_the_window_is_followed_outside_every_root fails on clean main too. This PR does not touch it.

Manual verification

N/A — the tests drive the real handlers through a real aiohttp app with the auth middleware's identity keys.

Related Issues

N/A

Pattern harvest

Rule candidate: review-prompt
Pattern: a builtin app's mutating route that never calls require_owner_dashboard_request. Some builtin apps call the shared gate and some do not; this PR fixes only Code Review Sage.

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

@iamwhatever
iamwhatever requested a review from a team as a code owner October 1, 2026 19:58
@iamwhatever
iamwhatever requested a review from bolichen97 October 1, 2026 19:58
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

A future mutating route added to this module ships ungated silently — _MUTATING is a hand-enumerated list, not derived from registrations.

Suggestions

  • In test_owner_gate.py, assert every non-GET registration in register_app_routes appears in _MUTATING, so the suite catches the next ungated write route instead of re-trusting enumeration — the exact lapse this PR fixes.

[DESIGN-REVIEWED] 991da10

Description read

[DESCRIPTION-READ] 7f2039b85f8126813be55a01ed29f6d6a24e67ff2635eba354be9d6ecc5972c7

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.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 991da104f7d87b4807ccb4d6e7d8b10ffd4150e1 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 991da10

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 991da104f7d87b4807ccb4d6e7d8b10ffd4150e1 — 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: PASS

Verify no out-of-repo caller (an operator's script, a non-owner's curl workflow) drives these write routes; every in-repo caller is the owner's dashboard page — I re-ran the sweep.

The defect's provenance is readable in the diff itself (handlers reaching bodies and seams with no gate), the fix reuses the one existing mechanism (require_owner_dashboard_request, src/kiro_crew/dashboard/handlers/_shared.py:3233, 57 caller files including six other builtin apps), and the boundary it closes — multiple humans on one gateway acting as the owner's gh login — is a named, load-bearing one. The declared deferral is real: I counted 8 builtin apps with mutating backend routes and zero gate calls (mochi alone registers ~15 ungated POSTs), but the description names the level and what is left, so it stands as accepted-and-deferred, not a demand. One prose nit: the description says 14 route/method pairs; the table and test matrix list 13.

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX — only the dashboard owner can start, post, cancel, or delete Code Review Sage reviews or change its settings; non-owners previously acted as the owner.

  1. Non-owner dashboard users now get 403 owner_only on the 13 write route/method pairs — justified
  2. App tokens, this app's own included, are refused on the same routes — justified
  3. Each refusal writes the shared gate's SEL denied audit event — justified
  4. New code_review_sage.* operation names appear in SEL denial rows — justified
  5. Shared OwnerRequest test fixture adopted across the app's suites (test-only) — justified

[FIRST-PRINCIPLES-REVIEWED] 991da10

Description read

[DESCRIPTION-READ] 5e97627633d7d2f14036fcebc4d697f07d8b23da9f5e3f976cb81d3a4ad18b31

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.

@iamwhatever

iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=b475380cf27b Derive the test table from the registered route table

Disposition: rebutted (disproportional; not a defect in this diff).
The maintainers already declined a route-registry census test for the owner gate and closed that approach in favour of per-route refusal tests shipped with each fix.
This PR follows that ruling: test_owner_gate.py pins a 403 owner_only refusal, an own-app-token refusal, and an owner pass for each of the 14 write route/method pairs it gates.
A new ungated route is a new finding for its own fix, with its own refusal test, as the ruling intends.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Nothing blocks — the gate is correctly placed on every mutating sage route; one parallel write path to the same state stays ungated.

FINDING — src/kiro_crew/apps/builtins/code_review_sage/backend/routes.py:1755 — the new code_review_sage.settings_write gate guards only PUT /settings, while the generic PUT /api/apps/{name}/config (src/kiro_crew/apps/routes.py:3092, atomic_write(config_path, json.dumps(body...)), no require_owner_dashboard_request anywhere in handle_app_config) lets a non-owner dashboard subject (app == "", user != state.owner_id — the subject the new test_non_owner_dashboard_subject_refused models) replace the same apps/code-review-sage/data/config.json wholesale, including review.auto_post, which review_driver.py:1336 reads to publish findings to the PR under the owner's gh login and which the gated /settings route deliberately cannot write → Fix: not landable in this diff — gate the PUT branch of handle_app_config in src/kiro_crew/apps/routes.py with require_owner_dashboard_request(request, "app_config_write") (the operation name it already SEL-audits).

[OPUS-REVIEWED] 991da10

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

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

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@iamwhatever

iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=331fc32cf1fd Sibling builtin apps with ungated write routes

Disposition: accepted-and-deferred.
Deferred: the sibling builtin apps are tracked in the private security-audit ledger. Each has its own fixer PR this round, or is queued for the next audit round.
This PR's scope is Code Review Sage. The Pattern harvest line that called the siblings gated is corrected in the body.

@iamwhatever

iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=317705c02c5b Duplicate owner-identity fake across test files

Disposition: fixed in aee458a.
One OwnerRequest now lives in code_review_sage/tests/fixtures.py; the five sage test files import it.
The copy in test/test_sage_backend_routes_coverage.py stays: that file sits outside the sage test package.

@iamwhatever
iamwhatever force-pushed the fix/owner-gate-round14-code-review-sage branch from aee458a to 6f811ba Compare October 1, 2026 23:05
@iamwhatever

iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=ded4101066eb Refusal test parametrizes over a literal route list

Disposition: rebutted (disproportional; not a defect in this diff).
The maintainers declined a route-registry census test for the owner gate and chose per-route refusal tests shipped with each fix.
test_owner_gate.py pins a non-owner refusal, an own-app-token refusal, and an owner pass for each of the 14 write route/method pairs this PR gates.
A future ungated route is a new finding for its own fix, with its own refusal test.

@iamwhatever

iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=babfde5370ee Track the other builtin apps that skip the shared gate

Disposition: accepted-and-deferred.
Deferred: the sibling builtin apps are tracked in the private security-audit ledger. Each has its own fixer PR this round, or is queued for the next audit round.
This PR's scope is Code Review Sage.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=c12c120ba20a Owner-gate grants are not audited

Disposition: rebutted (not a defect introduced by this diff; shared-gate behaviour).
The shared require_owner_dashboard_request (dashboard/handlers/_shared.py) audits refusals only; its owner arm returns None with no SEL event, for every caller.
Every sibling gate call has this same shape: issue_radar, auto_improvement, dev_fleet, and the merged #15966, #15973 and #16002.
An allow-audit belongs in the shared gate, so all callers emit it together; that change is tracked separately.
Adding it per app here would make Code Review Sage the one caller that audits differently from the rest.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision 991da104f7d87b4807ccb4d6e7d8b10ffd4150e1 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=622ae7db53f0 Temporary directory cleanup can silently leak

Disposition: fixed in 36404c3.
The autouse fixture now sets KIROCREW_HOME to pytest's tmp_path, so pytest owns and reports the directory's cleanup; the mkdtemp / rmtree(ignore_errors=True) pair is gone.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=9b724d466996 Derive the route list from the registered routes

Disposition: rebutted (disproportional; not a defect in this diff).
The maintainers declined a route-registry census test for the owner gate and chose per-route refusal tests shipped with each fix.
test_owner_gate.py pins a non-owner refusal, an own-app-token refusal, and an owner pass for each of the 14 write route/method pairs this PR gates.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=2be61f78dcb9 Point patch of a counted pattern across builtin apps

Disposition: accepted-and-deferred.
Deferred: the sibling builtin apps are tracked in the private security-audit ledger. Each has its own fixer PR this round, or is queued for the next audit round.
This PR's scope is Code Review Sage.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=dc4e739089d3 SEL denial audits ride along undescribed

Disposition: fixed in the PR description.
"What changed" now states that each refusal writes the shared gate's SEL denied audit event.

@iamwhatever
iamwhatever force-pushed the fix/owner-gate-round14-code-review-sage branch from 36404c3 to 7bfb9eb Compare October 2, 2026 06:51
@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=6091ac12e844 Pin that the route list covers every registered write route

Disposition: rebutted (disproportional; not a defect in this diff).
The maintainers declined a route-registry census test for the owner gate and chose per-route refusal tests shipped with each fix.
test_owner_gate.py pins a non-owner refusal, an own-app-token refusal, and an owner pass for each of the 14 write route/method pairs this PR gates.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=ec382bcb513f Point patch of a counted pattern across builtin apps

Disposition: accepted-and-deferred.
Deferred: the sibling builtin apps are tracked in the private security-audit ledger. Each has its own fixer PR this round, or is queued for the next audit round.
This PR's scope is Code Review Sage.

@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=8052776fd5f6 Settings reachable through another route

Disposition: accepted-and-deferred.
Deferred: tracked privately as a separate surface for the security audit.
The route named is generic and shared by every app, so it is outside this PR's Code Review Sage scope.

Every mutating code-review-sage route now calls the shared
require_owner_dashboard_request before its first branch, so a non-owner
dashboard subject or any app token gets the standard owner_only 403.
GET routes are unchanged. The sage suites' fake requests carry the
owner's real identity through one shared fixture, so the gate runs
unpatched.
@iamwhatever
iamwhatever force-pushed the fix/owner-gate-round14-code-review-sage branch from 7bfb9eb to 991da10 Compare October 2, 2026 07:51
@iamwhatever

iamwhatever commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=c484c8f5bc38 Pin that the route list covers every registered write route

Disposition: rebutted (disproportional; not a defect in this diff).
The maintainers declined a route-registry census test for the owner gate and chose per-route refusal tests shipped with each fix.
test_owner_gate.py pins a non-owner refusal, an own-app-token refusal, and an owner pass for each of the 14 write route/method pairs this PR gates.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=8052776fd5f6 Settings reachable through another route

Disposition: accepted-and-deferred.
Deferred: tracked privately as a separate surface for the security audit.
The route named is generic and shared by every app, so it is outside this PR's Code Review Sage scope.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 2, 2026
@chenmingwei23
chenmingwei23 merged commit 37564ad into main Oct 2, 2026
99 of 105 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/owner-gate-round14-code-review-sage branch October 2, 2026 15:57
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 2, 2026
@Premshay

Premshay commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Reported an advertised MCP contract regression after this owner gate: #16775 . code_review_sage_api still exposes POST /review, but internal MCP authentication does not satisfy is_owner_dashboard_request, so initiation returns owner_only even from an operator dashboard session. The issue includes source evidence and a proposed narrowly scoped owner-authorized delegation path, with explicit protection against implicit publication through review.auto_post. The owner gate should remain intact; the agent initiation contract needs reconciliation.

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