Add Permission Handling to ConfigPages Block Feature

Created on 17 August 2024, 7 months ago

Problem/Motivation

The ConfigPages module is an effective tool for managing configuration entities as pages. However, the current implementation of the ConfigPages Block does not respect user permissions when it comes to viewing these pages. This can result in unauthorized users, such as anonymous users, being able to view the content of the block even if they do not have the appropriate permissions.

Steps to reproduce

Currently, even when the β€œView the @label config page entity” permission is not granted to anonymous users, they are still able to view the Block.

Proposed resolution

The proposed approach involves overriding the access method in the ConfigPagesBlock class. This method would check the user’s access rights for the associated ConfigPage entity before rendering the block. If the user does not have permission to view the content, the block would not be displayed.

Remaining tasks

I have submitted a patch, and I would appreciate it if the maintainer could review and test it.

User interface changes

Not particularly.

API changes

Not particularly.

Data model changes

Not particularly.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡―πŸ‡΅Japan umekikazuya

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @umekikazuya
  • πŸ‡―πŸ‡΅Japan umekikazuya

    I have created a patch.

  • Status changed to Needs review 7 months ago
  • πŸ‡―πŸ‡΅Japan umekikazuya

    I have completed the MR creation and Patch submission, so I am changing the status from β€œActive” to β€œNeeds review.”

  • Issue was unassigned.
  • πŸ‡¨πŸ‡¦Canada lindsay.wils

    I have just noticed this issue too. I have the 'View the XXX config page entity' permission set to just one of my roles, but the anonymous user also sees the block. I have applied the patch, but the issue still persists. Drupal 10.4.0.

  • πŸ‡¨πŸ‡¦Canada lindsay.wils

    Is anyone else able to confirm if the patch is working or not for them? This is not working for me and all user roles are still able to view the configpage block.

    This is a critical permissions bug. Any project developers available to review?

    Thank you in advance.

  • πŸ‡΅πŸ‡±Poland shumer Wroclaw

    Hello @lindsay.wils I've just tried to setup a fresh install of Drupal 10.4 + latest configPages with the patch provided

    the patch does work for me. See the screenshot I've included the permission setup + screen of anonymous + authorized user. Can you please share some infor about your setup (the caching setting or modules enabled)? Maybe that will help us to identify the issue you have right now.

  • πŸ‡¨πŸ‡¦Canada lindsay.wils

    Thank you for confirming shumer. I have managed to work out my issues.

    I was not rendering this block through a region, I was loading it programatically into a variable on my node, and rendering that variable in twig, which seems to be bypassing to permissions if rendered this way

    $variables['custom_blocks'][$key]['block'] = $entityTypeManager
    ->getViewBuilder('block')
    ->view($custom_block);

    Once added to the 'Content' region, this is working correctly now. Not sure if this is a bug in the permissions setup, or if this is the intended way of drupal working. I would have thought that no matter how you render the block into a page, the permissions still are honoured.

    Thank you for taking the time to respond and help here.

  • πŸ‡΅πŸ‡±Poland shumer Wroclaw

    In Drupal, rendering a block programmatically using the view() method on the block entity's view builder bypasses the usual access checks unless explicitly handled. This behavior occurs because rendering an entity directly focuses solely on generating its display output and does not automatically invoke the access checks associated with the block's entity or plugin.

    To ensure the access checks are performed, you need to use the access method of the block entity before rendering it.

  • πŸ‡―πŸ‡΅Japan umekikazuya

    @shumer , @lindsay.wils
    Thank you for confirming, reproducing the issue, and testing the patch.

    As this is a critical permissions-related issue, I believe it would be beneficial to include the fix in the module if there are no objections from the maintainers.
    Of course, I am open to any feedback or further discussions if needed.

    I greatly appreciate your time and consideration on this matter.

  • πŸ‡΅πŸ‡±Poland shumer Wroclaw

    Hey @umekikazuya I'm going to apply the patch and create a new release this weekend

    • 44511d78 committed on 8.x-2.x
      Issue #3468681 by umekikazuya: Add Permission Handling to ConfigPages...
  • πŸ‡΅πŸ‡±Poland shumer Wroclaw
  • πŸ‡―πŸ‡΅Japan umekikazuya

    @shumer
    The latest release has been confirmed. Thank you for your prompt response and support.

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

Production build 0.71.5 2024