[SES-002] Invoke/CloseSession not owner-scoped; Invoke(DrainEvents) bypasses StreamEvents owner check #241
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
SES-002:
InvokeandCloseSessionare not owner-scoped;DrainEventsbypasses the stream owner checkGrpc/EventStreamService.cs:58(the only use ofOwnerKeyIdin the server)Grpc/MxAccessGatewayService.cs:79-101(CloseSession),:104-174(Invoke),:326-336(ResolveSession)Security/Authorization/GatewayGrpcScopeResolver.cs:52(DrainEventsneeds onlyevents:read)src/ZB.MOM.WW.MxGateway.Worker/Ipc/WorkerPipeSession.cs:615,:997-1037(DrainEventsdequeues from the same queue the event pump drains)docs/DesignDecisions.md:88-97,docs/Sessions.md:277Description
StreamEventsrejects a caller whose key id differs fromGatewaySession.OwnerKeyId.InvokeandCloseSessionresolve the session by id and never compare the owner. The design decision says anevents:readkey that learns a session id must not receive another key's events.Invoke(DrainEvents)does exactly that: it requiresevents:read, returns the session's queued events in the reply, and removes them from the worker queue.The same gap lets a foreign key with the matching scope:
session:close);invoke:read/invoke:write), with events delivered to the owner's stream;Session ids are random, but they appear on the dashboard Sessions pages (visible to Viewers, and to anonymous localhost by default) and in logs.
Failure scenario
Key A opens
session-…abcand streams. Key B (scopeevents:read, different tenant) callsInvokewithDRAIN_EVENTSon that id in a loop. B receives A's data-change events, including tags outside B's read constraints. A's stream silently misses those events: they never reach the gateway pump, so the replay ring has no record and noReplayGapis raised.Suggested fix
Apply the same ordinal owner comparison in
InvokeandCloseSession(one helper next toResolveSession), returningPermissionDenied. Decide explicitly whether anadmin-scoped key may override. Internal callers (GatewayAlarmMonitor, dashboard) go throughISessionManagerdirectly and are unaffected.Test idea
Open a session as key A. As key B, call
Invoke(DrainEvents),Invoke(Write)andCloseSessionon A's session id. AssertPermissionDeniedfor each and that A's session is stillReady.Source:
code-reviews/2026-12-02-perf-bugs/README.mdandcode-reviews/2026-12-02-perf-bugs/PLAN.md(commitf200bda6on local branchdocs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at54367e74.Decision (2026-12-03, recorded as D2 in
code-reviews/2026-12-02-perf-bugs/PLAN.md): noadminoverride.InvokeandCloseSessionuse the same strict ordinal owner compare asStreamEvents. Operators close or kill any session through the dashboard (directISessionManagerpath). The test must assertPermissionDeniedeven when the foreign key holdsadmin.Merged to
mainat68043411(pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.No admin override (D2). Docs:
docs/Authorization.md,docs/DesignDecisions.md, CLAUDE.md.