Repository navigation
fix: scope the dashboard SSE stream and log stream per app token - #38254
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Each change is aimed at the real gap: the SSE queue had no per-app gate at all. Two notes: a second "unreadable declarations" behaviour that the WebSocket does not have, and a log-scope check now written in two places. Notes
What this change shipsInventory (7 items) — 4 justifiedIntent: stop an app token from reading every slot, chat and log line through the SSE streams without the scope it declared. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 35ab218 Description read[DESCRIPTION-READ] 116abce67db86f5a8e0d35d23daa25f06fe42a8508bebe75ea4bb8c1615ebf3c That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. Both SSE doors now use the WebSocket's own scope helpers instead of a second evaluator, and the only things taken away are the two app-token breaks the description lists and accepts. Notes
[DESIGN-REVIEWED] 35ab218 Description read[DESCRIPTION-READ] dc8f183f39c6144cddc3f6b18996fdff89b512a80f0d21f3732b87c149a916d5 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: |
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: |
5719b9f to
b6fa42d
Compare
b6fa42d to
841803b
Compare
841803b to
d0efd44
Compare
The dashboard SSE stream fanned every note to an app token with no per-app scope: an app granted the route but no `slots:*` scope received every slot row, title and chat message. The log stream admitted an app that had not declared the `log` scope, and a reader carrying neither the dashboard-user mark nor an app claim was served instead of refused. Both doors now take the WebSocket gate's decisions from the shared ws_event_scope helpers: slot rows through filter_slots_for_app, every other note through ws_event_allowed, the owner-only status fields stripped by one shared helper, the log scope re-checked before every replayed and live entry, a disabled app or an unmarked reader refused with the middleware's 403, and an unreadable declaration set failing closed. Every grant and denial is audited.
d0efd44 to
35ab218
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
I reviewed head 35ab218. The SSE stream and log stream now apply the same per-app scope decisions as the WebSocket. Every auth path that can reach either route sets the dashboard-user mark or the app claim, so the new refusal of unmarked readers locks out no real caller. The WebSocket keeps its current handling of unreadable declarations, and slot filtering copies rows, so the shared broadcast note is never modified. The related backend tests pass on this head (351 across the stream, scoping and staged-grant suites). Taking the new slot filter out turns the new scope tests red, so they really test it. Nothing blocks.
Problem / Motivation
Goal: An app token reading the dashboard's SSE stream or log stream receives only what its declared scope allows, the same as on the WebSocket, and a reader with no recognised identity is refused.
Three gaps on the two SSE doors in
src/kiro_crew/dashboard/handlers/updates_streams.py:GET /api/streamfanned every note on its queue to an app token with no per-app filtering. An app granted the route but noslots:*scope received every slot row (titles, previews, last message), every slot title and every chat message, and the periodic status frame with owner-only fields. The WebSocket door filters all of these throughws_event_scope.GET /api/logsadmitted an app that had not declared thelogscope; its docstring and the WebSocket'ssubscribe_logsrequire it.The gap predates #37408. That change (the rule-table redaction engine) only made it visible:
test_chat_send_echo_scope.py::test_user_echo_reaches_only_authorized_ws_clientsuses a syntheticghp_value the old engine masked and the new one, which validates the checksum, does not, so the text an unscoped app was already receiving stopped being masked and the test went red intermittently (only when a slots push reached the stream before its fence frame). A real credential is still masked; what reached the app was the user's chat text and session previews.Why it matters
An app is a third-party extension with a declared scope. The SSE stream let any app holding the route read the person's conversations and session list across all slots, and the log stream let it read every log line, without declaring either. It also kept one backend test red on unrelated PRs.
Not a goal
/api/logsas today. Whether a teammate should see the operator's log ring is a separate decision, left open.What changed (motivation → approach → change)
Both SSE doors now take the WebSocket gate's decisions instead of a second evaluator. A new module,
src/kiro_crew/dashboard/sse_event_scope.py, wires the sharedws_event_scopehelpers into the SSE handlers:request["app"]set and no dashboard-user mark. Dashboard users (including relayed teammates) keep today's stream. A reader with neither mark gets the auth middleware's own 403 before the stream opens, as does a disabled app. (Since fix: let every shared crew teammate act as the owner inside the crew #38209 a Shared Crew teammate acts as the owner, so it is a dashboard user here.)/api/stream: declarations are loaded at connect (off the loop, likeapi_ws) and intersected with the live set for every note (effective_allowed_events, so a revoked scope takes effect mid-stream).slotsrows go throughfilter_slots_for_appand no frame is sent when none is left;slot_title,chat_messageand every other note type go throughws_event_allowed;chat_messagekeepsinclude_metadata=False. The status frame dropsbranch,commitandupdate_policy_filefor an app reader, through one helper (strip_owner_only_status) now shared withws.py./api/logs: an app must be enabled and have declaredlogorlog:all, or it gets 403. The scope is re-checked before every replayed and every live entry, so a revocation ends the stream.app.json, a failed read, or the grants helper returning before it reads all count as unreadable (load_declared_events_checked). The declaration cache keeps that marker in its own field (one writer,_store_declared), and both SSE doors check it before every live decision, so a stream opened while the declarations were readable drops to Tier 0 (refresh,update_progress,models_changed) and a log tail ends once they become unreadable. The WebSocket keeps mapping an unreadable set to an empty one, exactly as before. An exception in a scope check drops the note._audit_allow/_audit_denyhelpers, including live log grants,scope_check_exception,declarations_unreadable, and a dashboard user'sloggrant (asws.pyrecords it).docs/system-specs/modules/app-kit-platform.mddescribes the SSE scoping and the new module.Backwards compatibility
Breaking: an app that lists
/api/logsinpermissions.apibut has not declared thelogevent scope now gets 403 where it used to get the stream; an app reading/api/streamnow receives only its scope instead of every slot. Writer sweep on origin/main @ 521ee4d: no in-tree app or frontend consumer reads either SSE route (the spec lists none); the in-tree callers are test doubles, updated to set the positive mark the middleware sets. An installed third-party app relying on the unscoped stream would need to declare the scope it reads, as it already must on the WebSocket.Reader: src/kiro_crew/dashboard/handlers/updates_streams.py:api_stream -- app -- scoped like the WebSocket; test_sse_stream_app_scope.py::test_app_token_stream_reader_sees_only_its_scope
Reader: src/kiro_crew/dashboard/handlers/updates_streams.py:api_logs -- app -- needs
log; test_sse_stream_app_scope.py::test_log_stream_needs_the_log_scopeReader: src/kiro_crew/dashboard/kiro_relay/admission.py -- crew page -- relayed teammates keep the dashboard-user mark; test_kiro_relay_teammate_app_frames.py
Tests
Proof: not provable -- other: prove.py stops at collection because reverting the production hunks removes the new sse_event_scope module the new tests import; instead the new test file was run against main 09e5482, where its scope, log and unmarked-reader tests fail, and test_chat_send_echo_scope.py is intermittently red on main
test/test_sse_stream_app_scope.py(new, 26 tests) drives both handlers through an aiohttp test server bound to port 0, puts notes directly on the client's queue and reads to a fence frame with bounded waits, so it does not depend on frame arrival order. It covers: an app withoutslots:*scope gets no slot content; an app scoped to its own slots gets only those; the dashboard user gets everything; the status frame's owner-only fields are stripped for an app;/api/logswith and withoutlog; unreadable declarations (a real manifest read error inside the loader) send nothing scoped; a disabled app and a reader with neither mark are refused; a scope revoked after connect, during replay and during the live tail ends delivery, with the denial audited; a corruptapp.json, a grants read that returns before reading, and declarations that become unreadable after connect all fall back to Tier 0 on/api/streamand 403 or an ended tail on/api/logs, while the WebSocket mapping stays unchanged. Unit tests ofsse_event_scopecover every fail-closed branch (a loader or live check that raises, a live scope read that raises, a disabled app on/api/logs, a failing audit write) and bring the module to 100% line coverage, above the Coverage Gate's 80% floor.Planted regressions, each red by name: removing the slot filter, the per-note live re-check, the replay re-check, the live log re-check, the disabled-app refusal, the unidentified-reader refusal, the status-field strip, the unreadable marker, or the live denial audit.
test_chat_send_echo_scope.py, unchanged: 20/20 runs green with-n0(intermittently red on main). Related files (everything touchingupdates_streams,/api/stream,/api/logs,sse_event_scope,ws_event_scope,_push_status, the token-auth middleware and the relay teammate frames, plus the flake ratchet and facade guards): 2909 passed, 4 skipped. flake8, isort, black gate,mypy --platform linuxon the changed modules, comment-history, brand, line-cap, docs-lint, subprocess-encoding, harness-parity gates, andsemgrep --config semgrep/(no new finding): clean. Two local AI reviews (GPT 6.1, Opus 5.5) ran on the same change; their findings are fixed in it.Manual verification
N/A — the handlers are exercised end to end through aiohttp's test server in the new tests; no UI surface changes.
Related Issues
Surfaced by
test_chat_send_echo_scope.pyturning intermittently red after #37408 (the cause predates it).Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Sibling sweep
Swept: git grep -nE "register_sse|async def api_(stream|logs)|filter_slots_for_app|ws_event_allowed" -- src/
Sibling: src/kiro_crew/dashboard/ws.py -- not affected -- the WebSocket door already filters through ws_event_scope
Sibling: src/kiro_crew/dashboard/chat_api/slot_detail.py -- not affected -- GET slot routes already apply filter_slots_for_app and deny_app_slot_access
Sibling: src/kiro_crew/dashboard/sessions_parts/history_reads.py -- not affected -- history routes return only the app's own sessions
Pattern harvest
Rule candidate: review-prompt
Pattern: a new event transport for app readers must route every frame through the shared ws_event_scope decisions, never its own allow logic
Contribution License Agreement
Contributed under the project's Apache-2.0 license.