fix(security): harden /v1/sse endpoint β auth, tenant scoping, connection limiting#4395
Merged
Merged
Conversation
β¦tion limiting (#4393) Addresses P1 security finding from Themis audit: 1. Move /sse β /v1/sse, add to auth middleware SSE regex so Bearer/SSE token, dashboard cookie, and query-string ?token= all apply 2. Add tenant filtering via isGlobalEventVisibleToRequest() β clients only see events for their tenant 3. Add SSEConnectionLimiter β reuse server's existing limiter instance 4. Wire to real SessionEventBus (not isolated LocalEventBus) with subscribeGlobal() instead of wildcard pattern matching 5. Rewrite sse-bridge.ts to accept RouteContext, matching /v1/events patterns for auth/tenant/limiter 6. Remove dead LocalEventBus import from server.ts 7. Update tests to match new API (8 tests, all passing)
Contributor
There was a problem hiding this comment.
β Approved β P1 security fix, clean implementation.
Gates: All 9 pass β CI green (18/18), no conflicts, proper tests, targets develop.
What's good:
- Route moved to /v1/sse, auth regex expanded β endpoint now fully auth-covered
- Tenant filtering reuses proven isGlobalEventVisibleToRequest()
- Connection limiting reuses SSEConnectionLimiter (same posture as /v1/events)
- Wired to real SessionEventBus.subscribeGlobal() instead of inert LocalEventBus
- Clean cleanup on disconnect (heartbeat + unsubscribe + limiter release)
- 8 tests covering auth rejection, tenant filtering, subscription failure, SSE headers
Nit (non-blocking): SYSTEM_TENANT imported but unused in sse-bridge.ts β remove it in a follow-up.
Merge authorized.
aegis-gh-agent Bot
pushed a commit
that referenced
this pull request
May 28, 2026
Documents the SSE bridge endpoint in: - api-reference.md: full endpoint spec with auth, tenant scoping, connection limits, and error responses - api-quick-ref.md: quick reference entry - real-time-events.md: SSE bridge section alongside global/per-session Endpoint was introduced in #4373 and hardened in #4395 but never documented. Co-authored-by: Hephaestus <hep@aegis.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4393 (P1 Security β Themis audit finding)
The
/sseSSE bridge endpoint was unauthenticated and unscoped:LocalEventBus(inert, but would leak on wiring)Changes
/v1/sseβ now matches auth middleware SSE regex/v1/(events|sse)isGlobalEventVisibleToRequest()fromroutes/events.tsctx.sseLimiter(same as/v1/events)SessionEventBus.subscribeGlobal()instead of isolatedLocalEventBusLocalEventBusimport removed fromserver.tsTesting
Security Impact
Before: On localhost (zero-config), any local process could connect to
/sseand read all events across all tenants. On production, the endpoint was dead code (401 from generic catch-all).After: Full auth coverage, tenant isolation, and connection limits β same posture as
/v1/events.