silverstripe / silverstripe-session-manager

Allow users to manage and revoke access to multiple login sessions across devices.
BSD 3-Clause "New" or "Revised" License
9 stars 7 forks source link

Sessions should only be visible by owning user #57

Closed brynwhyman closed 3 years ago

brynwhyman commented 3 years ago

Overview

A user should be the only one who can view and manage existing sessions.

Currently with this module installed, a user who has access to view other member profiles (like the default Administrator role) has the ability to view and manage their sessions. This shouldn't be the case.

Acceptance Criteria

Pull request

emteknetnz commented 3 years ago

This code in LoginSession::handlePermission() should probably be changed from

        // Members can manage their own sessions
        if ($this->ID == $member->ID) {
            return true;
        }

        // Access to SecurityAdmin implies session management permissions
        return Permission::checkMember($member, 'CMS_ACCESS_SecurityAdmin');

to

        // Members can manage their own sessions
        if ($this->MemberID === $member->ID) {
            return true;
        }

        return false;
emteknetnz commented 3 years ago

Probably worth updating following code in LoginSessionController::removeLoginSession():

            $id = $request->param('ID');
            $loginSession = LoginSession::get()->byID($id);

to

            $id = $request->param('ID');
            $memberID = Security::getCurrentUser()->ID;
            $loginSession = LoginSession::get()->filter(['ID' => $id, 'MemberID' => $memberID])->first();
maxime-rainville commented 3 years ago

The current permission model is poorly implemented. MemberExtension has a bunch of logic to determine if the current user can edit and/or view the current session, but it completely bypasses LoginSession::canView/LoginSession::canEdit methods.

MemberExtension is also a PermissionProvider for SESSION_MANAGER_ADMINISTER_SESSIONS. If we want a permission provider, it should be on LoginSession because that's the object we are managing.

MemberExtension also tries to set the SessionManagerField to read-only if you are only allowed to view the current login session. However, we don't have a read-only view for this field.

LoginSession::handlePermission looks pretty good and already has permission extensibility built-in like @bergice mentioned in backlog grooming.

Here's what I want to do:

emteknetnz commented 3 years ago

Looks good

how you could implement your own permission layer if you wanted to.

How do you see this working?

maxime-rainville commented 3 years ago

You would stick an extension on LoginSession an hook into the canView/canDelete extension points.

Maybe you use a pre-existing permission to decide if the user can delete the login session. Maybe you just check if the current user can edit the member. Maybe you implement your own permission provider. Ultimately, that's a decision the developer has to make for themselves.

We've got a follow up issue to explore this in further detail https://github.com/silverstripe/silverstripe-session-manager/issues/57#issuecomment-819161619

brynwhyman commented 3 years ago

The ability for Developers to alter the behaviour (and allow other users to access member session data) should be documented so the feature is discoverable

I've made a suggestion in https://github.com/silverstripe/silverstripe-session-manager/issues/63 that we should recommend that if the behaviour is altered, the privileged user should get both CanView and CanDelete actions (given there's no read-only view).

emteknetnz commented 3 years ago

Linked PR has been merged

Noted on the pull request there's an issue with non-admin users revoking sessions. We've agreed to split that of as a separate issue. https://github.com/silverstripe/silverstripe-session-manager/issues/67