Skip to content

Let method streams take part in revocation decisions (scope revocation only checks the endpoint class's requiredScopes) #5987

Open

Description

@t-kietzmann

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 requireLogin or requiredScopes (lines 41-45); otherwise no revocation message closes the stream, not even RevokedAuthenticationUser;
  • for RevokedAuthenticationScope it closes the stream only if one of the revoked scopes is in the endpoint class's requiredScopes (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:

  1. Method-level scopes: an annotation such as @RequiredScopes({Scope('x')}) on endpoint methods, honoured by canUserAccessEndpoint (endpoint_dispatch.dart:189-197) and by the revocation handler for streams of that method.
  2. 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.
  3. Refresh instead of close: on RevokedAuthenticationScope, re-run the authentication handler for the stream session and let the method observe the new AuthenticationInfo (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 RevokedAuthenticationUser on 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 (requiredScopes and requireLogin are 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions