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

  1. Create an authenticated user account
  2. Provide "Access the webform user submission page" permission to the authenticated user account
  3. Login as the authenticated user and access submissions tab
  4. Update user ID in URL from current user to another user (such as 1)
  5. 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

CommentFileSizeAuthor
#4 3172318-4.patch1.45 KBjrockowitz

Comments

haydent created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

I can't reproduce this issue using the below steps

  • Create two users (/admin/people)
  • Masquerade as each user
  • Generate a submission via the Contact webfrom (/form/contact)
  • Visit each user submission tab (/user/{uid}/submissions)
  • Confirm that only the {uid} submissions are being displayed.
haydent’s picture

The 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.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.45 KB

@haydent Your explanation from #3 makes perfect sense. Please review the attached patch which is based on your solution.

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community
haydent’s picture

Just 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.

  • jrockowitz authored 5cb8eed on 8.x-5.x
    Issue #3172318 by jrockowitz, haydent: checkUserSubmissionsAccess doesn'...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz authored 5cb8eed on 6.x
    Issue #3172318 by jrockowitz, haydent: checkUserSubmissionsAccess doesn'...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.