Problem/Motivation

In MicroContentAccessHandler.php, ‘own’ content is determined by $microcontent->getRevisionUserId()

case 'update':
        return AccessResult::allowedIfHasPermission($account, sprintf('update any %s microcontent', $microcontent->bundle()))
          ->orIf(AccessResult::allowedIf($account->hasPermission(sprintf('update own %s microcontent', $microcontent->bundle())) && $microcontent->getRevisionUserId() === $account->id())
            ->cachePerPermissions()
            ->cachePerUser());

Use of the revision owner user id here is wrong. Or, if intentional, it’s not how Drupal core and contrib modules generally work - they determine “own” content based on the author/owner value of the entity. Example for core media module in MediaAccessControlHandler.php

$is_owner = ($account->id() && $account->id() === $entity->getOwnerId());

// ... later ...

  case 'update':
    if ($account->hasPermission('edit any ' . $type . ' media')) {
      return AccessResult::allowed()->cachePerPermissions();
    }
    if ($account->hasPermission('edit own ' . $type . ' media') && $is_owner) {
      return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);

Impact:

If a user’s edit and delete permissions are limited to edit-own and delete-own, they lose that access if an admin (etc) edits the item, because then the revision author would become that person.

Proposed resolution

Use $microcontent->getOwnerId() instead of $microcontent->getRevisionUserId()

Remaining tasks

I've built a patch, to be submitted shortly.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Andy Inman created an issue. See original summary.

andy inman’s picture

I have learned: don't right-click the Open MR button hoping to check the URL - that will trigger the button action.

larowlan’s picture

Status: Active » Reviewed & tested by the community

This change looks reasonable to me.
Thanks for the MR.

Will merge if tests pass

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Looks like there's a failing test, likely needs updating to match new logic

andy inman’s picture

Looks like there's a failing test, likely needs updating to match new logic

Confirmed - access tests were checking edit-own and delete-own permission based on revision uid rather than entity uid. I've changed that. I've also added a couple of tests cases to check update and delete when user has the edit/delete-own permission but is not the owner.

andy inman’s picture

Before marking as RTBC, I think it's worth at least considering the possibility that somebody out there may have an access control strategy that would be broken by these changes. That seems very unlikely to me, but I suppose it's not impossible. In the worst case, people could get edit/delete access to micro-content that they're not supposed to be able to change. There's no simple solution - I'm just suggesting a pause for thought - maybe wait for a bit more input from others.

acbramley changed the visibility of the branch 8.x-1.x to hidden.

acbramley’s picture

Status: Needs work » Reviewed & tested by the community

Thanks very much @Andy Inman for the thorough fix and test coverage. I agree this is wrong (and I wrote it originally).

Your points in #7 are valid, but I think as long as we spell it out in the release notes we're good hopefully!

Will merge and release on green.

sime’s picture

Yeah the comparison to Media access checking is a good one - patch works for me.

  • acbramley committed ea4a16e9 on 8.x-1.x authored by Andy Inman
    Issue #3377831 by Andy Inman, larowlan: Incorrect logic for 'edit-own'...
acbramley’s picture

Status: Reviewed & tested by the community » Fixed

Available in 8.x-1.6

Status: Fixed » Closed (fixed)

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