Skip to content

fix(dashboard): apply the owner gate to session history, knowledge reads and task actions - #22704

Closed
iamwhatever wants to merge 1 commit into
kirodotdev:mainfrom
iamwhatever:fix/owner-gate-dashboard
Closed

iamwhatever wants to merge 1 commit into
kirodotdev:mainfrom
iamwhatever:fix/owner-gate-dashboard

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Session history, knowledge-library reads and task actions on the dashboard answer the dashboard owner only.

A linked chat-channel session (Telegram, Teams or Webex allowlist link) reaches the dashboard with the same empty app claim as the owner's own session. The app-isolation checks on GET/DELETE /api/sessions/{key}, DELETE /api/sessions, the GET /api/knowledge/* reads and POST /api/tasks/{task_id} (plus /cancel) admit every such caller, so these routes were not limited to the owner.

Why it matters

Transcripts, the knowledge library and the owner's waiting runs are the owner's data. A non-owner linked session should not read, delete or act on them.

Not a goal

  • No change to app-token callers: they keep their existing app-isolation checks and manifest scope.
  • No change to internal-secret callers.
  • No new routes, settings or UI.

What changed (motivation → approach → change)

  • Non-owner dashboard sessions pass the app checks on these routes → add require_owner_for_dashboard_caller in dashboard/handlers/_shared_access.py, which gates only the dashboard-user class (empty app claim) and passes every other caller to the control that already governs it.
  • Session history: guard_owner_surface_routes (_shared_route_guards.py) gains a dashboard_owner_only flag, and sessions_parts/history_reads.py and sessions_parts/delete_routes.py set it. Every api_session* route in those two modules (list, search, detail, meta, archive list and read, delete, clear, clearable count) now runs the existing private-member check and then the owner check, before the handler. Other modules keep the plain guard.
  • Knowledge and tasks: call the helper before any read in each knowledge read route (knowledge_*.py) and in the two task action routes (tasks.py).
  • _require_knowledge_owner now delegates to it, so the library uses one rule for reads and writes.
  • Facade type-checking manifests list the new name; spec docs (knowledge.md, learn-cron-dashboard.md) describe the gate.

Backwards compatibility

Breaking: a non-owner dashboard session now gets 403 owner_only on these routes. Writer sweep on origin/main: the owner's own dashboard session, app tokens and internal-secret callers are unaffected.

Note: the owner signing in through their own channel link gets a token whose subject is the channel user, not owner_id, so that session is also refused here, as it already is on the existing owner-gated routes.

Reader: src/kiro_crew/dashboard/handlers/sessions_parts/history_reads.py:api_session_detail -- crew page -- owner session passes; test_dashboard_owner_gate_history_kb_tasks.py
Reader: src/kiro_crew/dashboard/handlers/sessions_parts/history_reads.py:api_sessions -- crew page -- owner session passes; test_the_owner_passes_the_gate_on_every_history_read
Reader: src/kiro_crew/dashboard/handlers/sessions_parts/history_reads.py:api_session_archive_read -- crew page -- owner session passes; test_the_owner_passes_the_gate_on_every_history_read
Reader: src/kiro_crew/dashboard/handlers/sessions_parts/delete_routes.py:api_session_delete -- crew page -- owner session passes; test_dashboard_owner_gate_history_kb_tasks.py
Reader: src/kiro_crew/dashboard/handlers/knowledge_library.py:list_namespaces -- crew page -- owner session passes; test_dashboard_owner_gate_history_kb_tasks.py
Reader: src/kiro_crew/dashboard/handlers/tasks.py:api_task_action -- crew page -- owner session passes; app tokens unaffected; test_dashboard_owner_gate_history_kb_tasks.py

Tests

test/test_dashboard_owner_gate_history_kb_tasks.py (new): through the real token middleware and route table, a non-owner dashboard session is refused with 403 owner_only on every session history route, every knowledge read and both task actions; the owner passes; an app token keeps its 404 / own-transcript / manifest-scope answers. dashboard_owner_surface_guard is checked on all four caller classes (owner, non-owner dashboard, app token, internal caller). Existing knowledge, sessions, tasks and facade suites pass.

Manual verification

N/A — unit coverage exercises every gated route with each caller class.

Related Issues

N/A

Pattern harvest

Rule candidate: review-prompt
Pattern: "a dashboard route guarded only by an app-isolation check also needs the owner gate for empty-app-claim callers"

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

Contributed under the project's Apache-2.0 license.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 21, 2026 08:23
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 1e9d53486a552ab65e86bae4b802be08664a3add touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 1e9d53486a552ab65e86bae4b802be08664a3add via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The new gate reuses the owner rule the knowledge writes and vault routes already apply, and it only touches empty-app-claim callers.

Notes

  • The PR states the trade-off itself: an owner who signs in through their own Telegram, Teams or Webex link gets a channel-user subject, so the sidebar's history list and transcript reopen now return 403 for them. Before merge, confirm the SPA shows that 403 as "owner only" rather than an empty or broken history pane.

[DESIGN-REVIEWED] 1e9d534

Description read

[DESCRIPTION-READ] 1f51b49cbadd08bacebba140ac0c53e79ad9783880a19165910670e30ba76f6d

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 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 1e9d53486a552ab65e86bae4b802be08664a3add via the fork AI-review pipeline — 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 does not.

First-Principles-Verdict: PASS

This fix restores the owner boundary that linked channel sessions were getting past. It extracts one shared helper but leaves a third identical copy of the gate unconverted.

Notes

  • Item 5 — duplicate of src/kiro_crew/dashboard/handlers/taskrunner.py:152: _require_taskrunner_owner has the same body as the new helper (if request.get("app") != "": return None; return await require_owner_dashboard_request(...)). Grepping request.get("app") != "" finds 2 copies of this exact body on base: knowledge_access.py (this PR converts it) and taskrunner.py (left as is). Subtraction: replace the body of _require_taskrunner_owner with a call to require_owner_for_dashboard_caller, or delete it and call the helper at its call sites.
  • Item 7 — zero consumers: dashboard_owner_surface_guard is added to the _shared.py facade, but the only importer through the facade is the new test. Its single production caller is inside _shared_route_guards.py. Subtraction: drop the facade entry.

What this change ships

Inventory (8 items) — 6 justified

Intent: a dashboard session reached through someone else's Telegram, Teams or Webex link can no longer read, delete or act on the owner's history, knowledge library or waiting runs. This is a FIX.

  1. A non-owner linked session gets 403 owner_only on every session-history read, delete and clear — justified
  2. A non-owner linked session gets 403 on all 19 knowledge-library reads, the export included — justified
  3. A non-owner linked session gets 403 on task answer, cancel_wait and cancel — justified
  4. A new dashboard_owner_only option on guard_owner_surface_routes, used by 2 modules — justified
  5. A new shared helper require_owner_for_dashboard_caller — duplicate of taskrunner.py:_require_taskrunner_owner, which is left unconverted
  6. _require_knowledge_owner now delegates to the shared helper — justified
  7. A new public dashboard_owner_surface_guard exported from _shared — zero consumers outside its module and tests
  8. The spec docs for knowledge and tasks describe the read and action gates — justified

[FIRST-PRINCIPLES-REVIEWED] 1e9d534

Description read

[DESCRIPTION-READ] bd519d553e850031d4165599cf16b69724c640f535b03ec57b0539df0cabdc6b

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 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 1e9d53486a552ab65e86bae4b802be08664a3add via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1e9d534

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 1e9d53486a552ab65e86bae4b802be08664a3add via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 1e9d534

@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 21, 2026

@bolichen97 bolichen97 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.

Not ready: the owner gate closes transcript detail, but the same transcripts stay readable through the archive and search routes in the same file.

Head reviewed: 842de9c. Bots read: Design PASS, First Principles BLOCK, UX skipped, Opus no blocking, GPT no blocking, readiness checking. Backend tests and coverage have not run on this head yet (Coverage Gate failed closed because the backend jobs were skipped).

1 must-fix, 0 should-fix.

What I checked:

  • All 19 GET routes under /api/knowledge now call the gate, and the new test pins that list against setup_knowledge_routes. Good.
  • The task answer and cancel routes gate before the body read, and the tests use a real task store. Good.
  • require_owner_for_dashboard_caller only refuses app == "" callers, so app tokens and internal callers keep their current controls.

The must-fix (inline) agrees with the First Principles blocker: the Goal says session history answers the owner only, but GET /api/session/archive/{name} still returns a full transcript to a non-owner linked session, and GET /api/sessions/search still returns content matches to it. If you decide these routes are out of scope, please amend the Goal and name them as a residual, and I will withdraw this.

Not repeated: the pass-through _require_knowledge_owner (First Principles note) and the owner-on-their-own-channel-link case (Design note).

# conversation, and a non-owner dashboard session (a Telegram, Teams or Webex
# allowlist link) holds the same empty app claim that check lets through.
# Before any transcript read, so a denial costs no read.
owner_denied = await require_owner_for_dashboard_caller(request, "sessions.detail.read")

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.

🔴 Archived transcripts and search hits stay open to the non-owner session this gate refuses

This change refuses a non-owner dashboard session on GET /api/sessions/{key}. In the same module, api_session_archive_read returns the full archived transcript (up to 250 KB of JSONL) to any caller, and api_session_archive_list lists every archive name. api_sessions_search runs search_sessions over all transcripts for any caller with an empty app claim, and api_session_meta returns titles. None of them call the new gate. So a Telegram, Teams or Webex linked session that now gets 403 here can list the archives and read the same conversation from the archive route.

owner_denied = await require_owner_for_dashboard_caller(request, "sessions.detail.read")

Why it matters: the Goal is "Session history ... answer the dashboard owner only". With these routes open, the 403 on detail does not keep the owner's transcripts private, and the PR states a protection that does not hold.

Suggestion: call require_owner_for_dashboard_caller at the top of api_session_archive_list, api_session_archive_read, api_sessions_search and api_session_meta (and api_sessions_clearable_count in delete_routes.py), and add them to the parametrized refusal tests. If some of them must stay open for a linked session, name them in the Goal as a residual instead.
Rule: Description and diff fidelity; the frozen Goal of this PR.

…ads and task actions

GET and DELETE /api/sessions/{key} and DELETE /api/sessions, every
GET /api/knowledge/* read (the whole-library export included), and
POST /api/tasks/{task_id} and its /cancel sibling now answer the
dashboard owner only. A Telegram, Teams or Webex allowlist link holds the
same empty app claim as the owner's own session, and the app-isolation
checks on these routes admit every such caller, so a non-owner dashboard
session could read or delete any transcript, export the library, or feed
an answer into (or end) the owner's waiting run.

The new require_owner_for_dashboard_caller gates the dashboard-user class
only and is layered under the existing app checks: an app token keeps its
uniform 404, its own transcripts and its manifest scope, and an
internal-secret caller keeps its own door. _require_knowledge_owner now
delegates to it, so the library has one rule for reads and writes.
@iamwhatever
iamwhatever force-pushed the fix/owner-gate-dashboard branch from 842de9c to 1e9d534 Compare October 21, 2026 15:40
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Addressed in 1e9d534.

Blocker (session-history point patch): fixed as suggested. The per-handler calls are gone. guard_owner_surface_routes gained a dashboard_owner_only flag, and history_reads.py and delete_routes.py set it, so every api_session* route there (list, search, detail, meta, archive list and read, delete, clear, clearable count) runs the owner check before the handler. New tests cover each of those routes for the non-owner, owner and app-token callers.

Note (_require_knowledge_owner duplicate): kept on purpose. It is not new: main already defines it and calls it from every knowledge write route, and its docstring holds the library's access rule. This PR only makes its body call the shared helper so reads and writes use one rule. Deleting it would touch every knowledge write site and the facade manifests with no change in behavior.

Design note (owner via own channel link): stated in the description under Backwards compatibility.

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

@bolichen97 bolichen97 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.

The earlier must-fix is fixed on this head, so I am withdrawing my change request. This is an authorization change, so it still needs a maintainer to approve it; I am not approving it.

Head reviewed: 1e9d534 (rebased onto main; the PR's own change is one commit). Bots read on this head: Design PASS, First Principles PASS, UX skipped, Opus no blocking, GPT no blocking. Readiness is still checking and Lint Gate is queued.

0 must-fix, 1 should-fix.

What I checked, route by route:

  • history_reads.py and delete_routes.py now call guard_owner_surface_routes(..., dashboard_owner_only=True), so every api_session* handler in those modules runs dashboard_owner_surface_guard before its body. That covers api_sessions, api_sessions_search, api_session_detail, api_session_meta, api_session_archive_list, api_session_archive_read, api_session_delete, api_sessions_clear and api_sessions_clearable_count. A handler added to those modules later is gated by default.
  • The guard refuses only an empty app claim whose user is not the owner. App tokens and internal callers (no app key) pass through to their existing controls; the caller-class test pins all four classes.
  • The new tests go through the real token middleware and register_all. OTHER_HISTORY_READS covers the list, search, meta, archive list, archive read and clearable count, and asserts 403 owner_only with no transcript text in the body for a non-owner session. Detail, delete and clear have their own tests. A wrong route path would come back 404 and fail these tests.
  • The First Principles note on _require_taskrunner_owner (same body as the new helper) and the extra facade export are cleanup only. Not blocking.

Should-fix: POST /api/sessions/summarize (summaries.py) is still open to the same caller. With an empty app claim the handler only checks log.has_log(key) and then returns an LLM one-line summary of that transcript, so a non-owner linked session that knows a key still gets a digest of the owner's conversation. It also spends a model call per key. The list and search routes no longer hand out keys, so this is narrower than before. The fix is one line: pass dashboard_owner_only=True to the guard_owner_surface_routes call at the bottom of summaries.py, and add /api/sessions/summarize (POST) to the refusal tests. If you want that route to stay open, please name it as a residual in the Goal.

The Design note still applies before merge: an owner who opens the dashboard through their own channel link now gets 403 on history, so the sidebar should show that as owner only, not as an empty pane.

@bolichen97
bolichen97 dismissed their stale review October 21, 2026 16:08

The earlier must-fix (archive, search, meta and clearable-count routes open to a non-owner linked session) is fixed on 1e9d534. Withdrawing; this still needs a maintainer approval.

@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 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

superseded by #22838

@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants