Problem/Motivation
WebformAccountAccess::checkUserSubmissionsAccess() does not sufficiently check whether the account to run access checks for actually matches the user account in the URL parameter. When the permission "Access the webform user submission page" is provided for authenticated users, it allows them to access their submissions from a URL containing a different user ID.
While it doesn't allow a user to see the other persons submissions, it does change the page title to show this other users display name. This should return access denied.
Steps to reproduce
- Create an authenticated user account
- Provide "Access the webform user submission page" permission to the authenticated user account
- Login as the authenticated user and access submissions tab
- Update user ID in URL from current user to another user (such as 1)
- The current users submissions will show however the page title (depending on configuration/code) will show the display name for the user account matching the ID in the URL.
Proposed resolution
Pass the $user URL parameter to the custom access callback and check the account ID matches the user ID. Removing the check for the current user ID and the account ID. So it should look like this:
public static function checkUserSubmissionsAccess(AccountInterface $account, UserInterface $user) {
$condition = ($account->hasPermission('administer webform') || $account->hasPermission('administer webform submission') || $account->hasPermission('view any webform submission'))
|| ($account->hasPermission('access webform submission user') && $user->id() === $account->id());
return AccessResult::allowedIf($condition)->cachePerPermissions();
}
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3172318-4.patch | 1.45 KB | jrockowitz |
Comments
Comment #2
jrockowitz commentedI can't reproduce this issue using the below steps
Comment #3
haydent commentedThe issue is not with the submissions themselves - this works as expected. The issue is that an access denied error page is not presented when accessing the submission page using a different UID.
So if you sign in as a user with the UID of 2 and visit /user/3/submissions (a different UID) then the page will still load. While you won't be able to view the submissions for the user with the UID 3, you will still see their display name.
My code above checks that the user account in the route parameter matches the account you want to check the access for. Currently it compares the account ID with the current user however these are generally the same thing.
Sorry for the confusion, hopefully that makes a little more sense.
Comment #4
jrockowitz commented@haydent Your explanation from #3 makes perfect sense. Please review the attached patch which is based on your solution.
Comment #5
jrockowitz commentedComment #6
haydent commentedJust checked this on another one of our sites and it is working as expected with an access denied error when attempting to access submissions for another user.
Thanks heaps.
Comment #8
jrockowitz commented