Problem/Motivation

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
FileSize
16.04 KB

This is a first start.

Wim Leers’s picture

Issue tags: +D8 cacheability

dawehner++

Status: Needs review » Needs work

The last submitted patch, 2: 2551037-2.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
23.13 KB
8.37 KB

Some work on it.¬

Status: Needs review » Needs work

The last submitted patch, 5: 2551037-5.patch, failed testing.

Wim Leers’s picture

This looks great already.

  1. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2234,11 +2235,13 @@ public function access(AccountInterface $account = NULL) {
    +      assert('$result instanceof \Drupal\Core\Access\AccessResultInterface');
    

    Nice :)

  2. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1617,17 +1618,38 @@ public function attachDisplays() {
    +   * @param bool $return_as_object
    +   * @param bool $return_as_object
    

    :)

  3. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1635,15 +1657,18 @@ public function access($displays = NULL, $account = NULL) {
    +          // @fixme This is certainly not the right thing to do. We want to not
    +          // combine all of them but rather just match one of them.
    +          $access = $access->orIf($display->access($account));
    

    This can use other complex cases (such as entity/field access) as examples to follow.

  4. +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php
    @@ -33,7 +34,7 @@ protected function defineOptions() {
    -    return !empty($this->options['access']);
    +    return !empty($this->options['access']) ? AccessResult::allowed() : AccessResult::forbidden();
    

    Hrm, isn't this technically then dependent on the View's configuration, and shouldn't it therefore add the View as a cacheable dependency?

    Similar remark for all other places that use $this->options.

Wim Leers’s picture

Title: Take cacheability metadata into account for views access. » Take cacheability metadata into account for views access
Priority: Major » Critical
Issue tags: +Security

I think this issue needs to be critical. Without this, HEAD may for example end up render caching a view across all users, even if access was only granted to a specific user (because the cacheability metadata of the used Views access plugins does not bubble up, hence the necessary cache contexts are missing).

dawehner’s picture

Priority: Critical » Major
Status: Needs work » Needs review
FileSize
24.42 KB
4.15 KB

Hrm, isn't this technically then dependent on the View's configuration, and shouldn't it therefore add the View as a cacheable dependency?

Similar remark for all other places that use $this->options.

Well, do we need to take that into account for $access or isn't all the other cache tags which are exposed with a view already good enough?

Wim Leers’s picture

Well, do we need to take that into account for $access or isn't all the other cache tags which are exposed with a view already good enough?

Yeah, that's why I said technically. In practice, it won't make a big difference because of what you said.

Except… for ViewsBlock should — just like any other block — actually do this access checking in BlockPluginInterface::access(). That's the correct semantical thing to do. If/when we do that, this will actually matter, because access to the block does depend on the underlying view's configuration.

Status: Needs review » Needs work

The last submitted patch, 9: 2551037-9.patch, failed testing.

dawehner’s picture

Except… for ViewsBlock should — just like any other block — actually do this access checking in BlockPluginInterface::access(). That's the correct semantical thing to do. If/when we do that, this will actually matter, because access to the block does depend on the underlying view's configuration.

Do we cache the result of the access() call?

Berdir’s picture

We don't cache an access call directly, but we might be caching a whole page that contains blocks and therefore need to be aware of their access cacheability.

For example with smartcache or eventually also with page_manager.

Wim Leers’s picture

#2464427-203: Replace CacheablePluginInterface with CacheableDependencyInterface found good reasons to still do this:

+    // @todo Fix this in https://www.drupal.org/node/2551037,
+    // DisplayPluginBase::applyDisplayCachablityMetadata() is not invoked when
+    // using buildBasicRenderable() and a Views access plugin returns FALSE.
Berdir’s picture

So this API change won't be possible anymore.

But I think we can at least get the cacheability metadata of the used access plugin, something like this above the actual access check:

    if (!isset($view->current_display)) {
      $view->initDisplay();
    }

    if (($display = $view->displayHandlers->get($element['#display_id'])) && $display->getPlugin('access')) {
      $cacheablity_metadata = CacheableMetadata::createFromRenderArray($element);
      $cacheablity_metadata = $cacheablity_metadata->merge(CacheableMetadata::createFromObject($display->getPlugin('access')));
      $cacheablity_metadata->applyTo($element);
    }

Also, views access checks actually are render-cached, atleast for rest displays.

dawehner’s picture

Damnit, because well, it feels like this should be better made as a runtime level operation.

xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Issue tags: +@todo clean-up

core/modules/user/src/Tests/Views/AccessRoleTest.php contains a @todo about this issue, which doesn't seem to be addressed in #9.

effulgentsia’s picture

Title: Take cacheability metadata into account for views access » Allow DisplayPluginInterface::access() to return an AccessResultInterface object with cacheability metadata
Version: 8.1.x-dev » 8.2.x-dev
Priority: Major » Normal
Issue tags: -Security +Security improvements

I think this issue needs to be critical. Without this, HEAD may for example end up render caching a view across all users, even if access was only granted to a specific user

I don't see a pathway to that, at least not any more (maybe there was when #8 was written). Each access plugin can/should implement CacheableDependencyInterface, and if it does so, then that makes it into the cacheability information of the display and its renderings. Therefore, removing the "security" tag from this issue.

However, this issue might still make sense as a security improvement / extra protection for cases where a contrib/custom access plugin fails to implement its own CacheableDependencyInterface correctly. Tentatively tagging with "Security improvements" accordingly, but I'm demoting this to Normal priority until a case can be made (via an issue summary update) for why such an improvement should be higher priority than that.

dawehner’s picture

As long we have this statement

-    if ($view && $view->access($element['#display_id'])) {

the metadata is not there, after checking access ... Plugins can implement that plugin, but well, whatever, we ignore it.

xjm’s picture

Priority: Normal » Major

So I think this is still major, just it is not a critical security issue.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

larowlan’s picture

Issue tags: +@deprecated

So now we've got to do this with a BC shim

I guess we can introduce a new interface CacheabilityMetadataAwareAccessPlugin with a new method accessWithCacheability or something

And then in the display we can juggle based on instanceof, triggering an error if something didn't return cacheability and we had to call the old access method.

And in all the existing access methods, trigger error.

And then similar changes in the displays.

Its a long road, but I think we can do it with deprecations and BC

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.