Repository navigation
Description
Problem to Solve
When a method stream opens, _RevokedAuthenticationHandler.createIfAuthenticationIsRequired (serverpod/lib/src/server/websocket_request_handlers/helpers/method_stream_manager.dart:35-87) registers a listener for revocation messages:
- only if the endpoint class sets
requireLoginorrequiredScopes(lines 41-45); otherwise no revocation message closes the stream, not evenRevokedAuthenticationUser; - for
RevokedAuthenticationScopeit closes the stream only if one of the revoked scopes is in the endpoint class'srequiredScopes(lines 62-67).
Scopes exist only per endpoint class (endpoint.dart:33-37); the access check at call time also knows only the class values (endpoint_dispatch.dart:189-197). Apps that authorize per method, inside the method, because different methods of one endpoint need different scopes, cannot express that to the revocation path. A scope revocation leaves such streams open and they keep delivering data. The session's AuthenticationInfo is resolved once at open (session.dart:723-730) and never refreshed. The workaround is to send RevokedAuthenticationUser, which closes every stream of the user, also those the user may keep.
Proposal
For discussion, any of:
- Method-level scopes: an annotation such as
@RequiredScopes({Scope('x')})on endpoint methods, honoured bycanUserAccessEndpoint(endpoint_dispatch.dart:189-197) and by the revocation handler for streams of that method. - A hook on the endpoint: e.g.
bool shouldCloseStreamOnRevocation(Session session, String method, SerializableModel revocation), default: today's behaviour. Apps with their own authorization decide per stream. - Refresh instead of close: on
RevokedAuthenticationScope, re-run the authentication handler for the stream session and let the method observe the newAuthenticationInfo(a stream of auth changes on the session).
Also worth deciding: should streams of endpoints without requireLogin but with an authenticated session close on RevokedAuthenticationUser? Today they never do (lines 41-45).
Use Case
In our backend, 79 of 147 endpoints with stream methods have no scope on the class; their handlers check permissions per method. A revocation through RevokedAuthenticationScope would leave these streams open.
Alternatives
- We send
RevokedAuthenticationUseron every permission change. It closes all streams of the user, including those the user may keep, and every client reopens them. - Our planned sync stream (
requireLogin, no class scopes) will process scope revocations itself from its own outbox. That works for one stream we own, not for ordinary endpoint streams.
Additional context
- Checked against
serverpod 4.1.0; unchanged in 4.1.1. - Serverpod 4.1.0 has no method-level scopes (
requiredScopesandrequireLoginare getters of the endpoint class,endpoint.dart:33,:37), so this is not a bug report but a question of how streams that check their own permissions can take part in revocation. - Related: #2739, #2754 (both closed; revocation for method streams and across multiple streams).
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsInbox 📫
Activity