Repository navigation
fix(realtime): apply the HTTP session rules to realtime connections - #14803
Conversation
A realtime connection authenticated by a session that still owed an MFA factor, or by a blocked user, was treated as signed in, while HTTP refuses both. The factor rule now lives on the User document so HTTP and realtime share it; such connections are treated as guests, in-band authentication refuses them, and impersonation requires a session and an unblocked target as over HTTP. The per-connection message limiter key also named placeholders it never filled, so it collapsed to the connection id alone, which repeats across containers. It now carries the project, container and connection. Co-Authored-By: Claude <[email protected]>
|
Review complete. No issues found — approved ✅. This PR moves the MFA factor-counting logic that previously lived inline in the HTTP auth path into reusable methods on the Reviewed commit: 33f09d6 |
🟢 Tier S · Ready to mergeThe pull request centralizes minimum MFA-factor and session-factor checks on the User model, then applies them to HTTP and realtime authentication. Realtime connections treat blocked or MFA-pending users as guests, enforce those checks during authentication, impersonation, and permission revalidation, and use a limiter key scoped to project, container, and connection. Unit and E2E tests cover the shared factor rules and realtime authentication behavior. Latest changes: The newest commit adds a realtime impersonation-gate check requiring the impersonator's session to meet the user's minimum MFA factors.
📂 Walkthrough · 9
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
The findings that requested changes are resolved. See the summary comment for what is still open.
Co-Authored-By: Claude <[email protected]>
…port #14803) A session or session-bound JWT that still owes an MFA factor, and a blocked user, no longer authenticate a realtime connection, and in-band authentication refuses them. Impersonation needs an impersonator session with its factors met. The per-connection message limiter is keyed by project, container and connection. 1.9 has no realtime permission revalidation, so the update.mfa revalidation trigger is not ported. Adds User::getMinimumFactors() and User::sessionFactorsMet(). (cherry picked from commit 3f829a1)
…port #14803) A session or session-bound JWT that still owes an MFA factor, and a blocked user, no longer authenticate a realtime connection, and in-band authentication refuses them. A blocked user cannot impersonate either. The per-connection message limiter is keyed by project, container and connection. 1.9 has no realtime permission revalidation, so the update.mfa revalidation trigger is not ported, and HTTP impersonation on 1.9 does not require a session, so the onOpen impersonation session check is not ported. Adds User::getMinimumFactors() and User::sessionFactorsMet(). (cherry picked from commit 3f829a1)
…port #14803) A session or session-bound JWT that still owes an MFA factor, and a blocked user, no longer authenticate a realtime connection, and in-band authentication refuses them. A blocked user cannot impersonate either. The per-connection message limiter is keyed by project, container and connection. 1.9 has no realtime permission revalidation, so the update.mfa revalidation trigger is not ported, and HTTP impersonation on 1.9 does not require a session, so the onOpen impersonation session check is not ported. Adds User::getMinimumFactors() and User::sessionFactorsMet(). (cherry picked from commit 3f829a1)
…checks fix(realtime): apply the HTTP session rules to realtime connections (cherry picked from commit 3f829a1)
Summary
Realtime connections now follow the same session rules as the HTTP API: a session that still owes an MFA factor and a blocked user no longer authenticate a connection, and the per-connection message limiter is keyed per connection instead of per connection id alone.
Changes
User::getMinimumFactors()andUser::sessionFactorsMet()hold the MFA factor rule; the HTTPapihook now usesgetMinimumFactors()instead of computing it inline.userresource: a cookie or header session, or a JWT bound to a session, that lacks its required factors connects as a guest, the same way an invalid session does. A blocked user (status === false) connects as a guest on every path (session, JWT, account key).onOpen: impersonation requires a session and a target that is not blocked, as over HTTP (user_more_factors_required/user_blocked).authenticationmessage refuses a blocked user (user_blocked) and a session missing factors (user_more_factors_required).users.*.update.mfanow triggers it (it was listed as an event without access change), so enabling MFA or verifying an authenticator revalidates open connections. The impersonation gate also checks the impersonator session's factors explicitly.project:{project},container:{container},connection:{connection}; it previously named{url}and{connection}while filling{connection}and{container}, so it reduced to the connection id, which repeats across containers.Tests
UserTest::testGetMinimumFactors,UserTest::testSessionFactorsMet.RealtimeCustomClientTest::testConnectionRequiresAllFactors(a session-less JWT for the user receives the account event, while the MFA-pending session and a JWT bound to it connect as guests, receive nothing, and in-band authentication with that session is refused) andRealtimeCustomClientTest::testBlockedUserConnectsAsGuest.app/realtime.phpand the e2e stack runs a single realtime container, where connection ids do not repeat, so the cross-container collision cannot be reproduced in e2e; the change is limited to the key string and its parameters.A follow-up PR applies the same session rules to MQTT and builds on the
Usermethods added here.Related: appwrite-labs/cloud#6666