Problem/Motivation

The implementation of decoration of access_check.latest_revision service has a small mistake that causes the Access Unpublished check src/Access/LatestRevisionCheck::access() to be called twice in row.

  • Once with all other services decorating the access_check.latest_revision. It might be called together with:
  • Second separately as access_unpublished.access_check.latest_revision service alone.

As a result, you might experience the following Access Denied Warning:
Path: /node/1/latest. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: The following permissions are required: 'view latest version' AND 'view any unpublished content'. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 115 of /app/web/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

The definition of the Service access_unpublished.access_check.latest_revision adds the following Tag to the definition:
->addTag('access_check', ['applies_to' => ‘_content_moderation_latest_version']);
which is WRONG as it already decorated the Service access_check.latest_revision and thus it does NOT need to be called as a separate “Content moderation latest version Access Check” AGAIN.

The Tag is added in src/AccessUnpublishedServiceProvider.php:

$container->register('access_unpublished.access_check.latest_revision', LatestRevisionCheck::class)
  ->setDecoratedService('access_check.latest_revision')
  ->addArgument(new Reference('access_unpublished.access_check.latest_revision.inner'))
  ->addTag('access_check', ['applies_to' => '_content_moderation_latest_version']);

The Service access_check.latest_revision defined in the core/modules/content_moderation/content_moderation.services.yml contains tag definition with values: { name: access_check, applies_to: _content_moderation_latest_version } so when decorating there's no reason to define the same values for the service that decorates it.

 access_check.latest_revision:
    class: Drupal\content_moderation\Access\LatestRevisionCheck
    arguments: ['@content_moderation.moderation_information']
    tags:
      - { name: access_check, applies_to: _content_moderation_latest_version }

Steps to reproduce

The check is being called twice all the time.

  • If you debug core/lib/Drupal/Core/Access/AccessManager::checkRequest() which calls core/lib/Drupal/Core/Access/AccessManager::check()
  • And you review the result of the line $checks = $route->getOption('_access_checks') ?: [];
  • You should see both checks in:
    access_check.latest_revision and
    access_unpublished.access_check.latest_revision

Or more complicated situation: Use the following contribs together

Proposed resolution

Remove the service Tag mentioned above.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3421278-4-removed-service-tag.patch1.21 KBdabbor
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

dabbor created an issue. See original summary.

dabbor’s picture

Issue summary: View changes

dabbor’s picture

Issue summary: View changes
StatusFileSize
new1.21 KB

Adding in a simple file patch for https://git.drupalcode.org/project/access_unpublished/-/merge_requests/1...

To make referencing in composer safer.

I tested the patch to make sure the Access check in question is not running twice in row + The Access Unpublished Tokens are working OK.

dabbor’s picture

Title: Access Unpublished check called twice - Problem with Decoration of 'access_check.latest_revision' » Access Unpublished check being called twice
Assigned: dabbor » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
generalredneck’s picture

After reading through your explanation in the issue, it seems to make sense to me. and I can follow your steps to reproduce. I'm not sure there is an easy way to write a test for this.

generalredneck’s picture

Status: Needs review » Fixed

This will be in 1.x-dev release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • generalredneck committed 59b5dc93 on 8.x-1.x
    Issue #3421278 by dabbor: Access Unpublished check being called twice
    

Status: Fixed » Closed (fixed)

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