mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Drop subscriptions when a user loses permission for them
The permission for a subscription was only checked when subscribing, so a control connection kept receiving events after the user's roles or role permissions changed to no longer allow it. Add SubscriptionController.unsubscribeUnpermitted which rechecks every subscription of a link and removes the ones the user is no longer permitted, and call it for the affected control connections from userPermissionsUpdated and rolesUpdated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce6bfe282f
commit
beec2f523a
4 files changed
+103
No files matched your search
@@ -329,6 +329,31 @@ export class SubscriptionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe a link from all events the user no longer has permission to subscribe to.
|
||||
* Used when the permissions of a user changes.
|
||||
* @param link - Link to check the subscriptions of.
|
||||
* @param user - User the link is authenticated as.
|
||||
*/
|
||||
unsubscribeUnpermitted(link: Link, user: IUser) {
|
||||
for (const [eventName, eventData] of this._events) {
|
||||
for (const [addressIndex, subscriber] of eventData.subscriptions) {
|
||||
if (subscriber.link !== link) {
|
||||
continue;
|
||||
}
|
||||
const request = new SubscriptionRequest(eventName, "subscribe", 0, subscriber.filters);
|
||||
const message = new MessageRequest(
|
||||
0, subscriber.address, new Address(Address.controller, 0), "SubscriptionRequest", request.toJSON(),
|
||||
);
|
||||
try {
|
||||
SubscriptionRequest.permission(user, message);
|
||||
} catch {
|
||||
eventData.subscriptions.delete(addressIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming subscription requests on a link
|
||||
* @param link - Link message was received on
|
||||
|
||||
Reference in new issue
Block a user