Problem/Motivation

Views uses EntityViewsData and sub-classes to generate views data for entity base fields.
The bulk of these use the 'standard' plugin which extends from HandlerBase.
HandlerBase::access does not respect field level access.
As a result no field level-access is applied for entity base when used in views.
Patch demonstrates that comment's hostname field level access isn't respected.

Proposed resolution

Make the 'standard' plugin defer to the relevant entity access controller.

Remaining tasks

Patch
Review

User interface changes

none

API changes

none

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because if you implement an access plugin to define field level access, you'd expect views to respect it
Issue priority Critical because security

Postponed until

#2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

Status: Active » Needs review
jibran’s picture

Issue tags: +VDC, +Security

Tagging

Status: Needs review » Needs work

The last submitted patch, views-field-access-2382931.fail_.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
Issue tags: +needs profiling
FileSize
11.04 KB

So here's a pass at fixing it, burns me up to add use a function, but I think we need to tackle HandlerBase using function_exists before we have a choice? and that seems like a big bite to chew.

Status: Needs review » Needs work

The last submitted patch, 4: views-base-field-access-2385443.pass_.patch, failed testing.

dawehner’s picture

What a wonder, views did not got an update while the entity world changed.

  1. +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_hostname_access.yml
    @@ -0,0 +1,207 @@
    diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php
    
    diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php
    index 4bb38fe..3bee3ac 100644
    
    index 4bb38fe..3bee3ac 100644
    --- a/core/modules/views/src/EntityViewsData.php
    
    --- a/core/modules/views/src/EntityViewsData.php
    +++ b/core/modules/views/src/EntityViewsData.php
    
    +++ b/core/modules/views/src/EntityViewsData.php
    +++ b/core/modules/views/src/EntityViewsData.php
    @@ -368,6 +368,12 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
    
    @@ -368,6 +368,12 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
         if (method_exists($this, $process_method)) {
           $this->{$process_method}($table, $field_definition, $views_field, $column_name);
    

    Let's expand the unit test coverage of EntityViewsData all the time

  2. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -368,6 +368,12 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
    +    $views_field['field']['access callback'] = 'views_entity_base_field_access';
    

    Does this need to be a function or can it be any kind of callable?

  3. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -368,6 +368,12 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
    +    $views_field['field']['access arguments'] = [
    +      'entity_type_id' => $this->entityType->id(),
    +      'field_name' => $field_definition->getName(),
    +    ];
     
    

    Note: This all is really related to #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency which basically would tackle the problem from the other side

larowlan’s picture

larowlan’s picture

larowlan’s picture

Status: Needs work » Needs review
FileSize
5.17 KB
12.27 KB

Something less icky

larowlan’s picture

missed a bit

jhodgdon’s picture

Why don't we postpone this issue, or mark it as a duplicate? It seems like we need to have the base fields using Field UI anyway on #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency, which is already critical and should fix this problem, so this is just a stop-gap fix. I would be in favor of making the title of that issue "... and entity access is not respected" and combining this into it, since the real fix would be the same and we already need to fix that other issue. Whatever is being done here will just be discarded.

larowlan’s picture

@jhodgdon - I asked the same question on irc and was told to leave this one open, in case the other was demoted to major.

larowlan’s picture

Issue tags: +CriticalADay
chx’s picture

Gábor Hojtsy’s picture

I sure hope there is no chance #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency is demoted to major, it is impossible to make a multilingual view where both base fields and configurable fields exist now, so...

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/EntityViewsData.php
@@ -368,6 +368,8 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co
diff --git a/core/modules/views/src/Plugin/views/field/Standard.php b/core/modules/views/src/Plugin/views/field/Standard.php

diff --git a/core/modules/views/src/Plugin/views/field/Standard.php b/core/modules/views/src/Plugin/views/field/Standard.php
index 11ecc6a..472667b 100644

index 11ecc6a..472667b 100644
--- a/core/modules/views/src/Plugin/views/field/Standard.php

--- a/core/modules/views/src/Plugin/views/field/Standard.php
+++ b/core/modules/views/src/Plugin/views/field/Standard.php

+++ b/core/modules/views/src/Plugin/views/field/Standard.php
+++ b/core/modules/views/src/Plugin/views/field/Standard.php
@@ -6,6 +6,9 @@

@@ -6,6 +6,9 @@
  */

@@ -16,4 +19,49 @@
+  /**
+   * {@inheritdoc}
+   */
+  public function access(AccountInterface $account) {
+    if (isset($this->definition['field access']) && strstr($this->definition['field access'], ':') !== FALSE) {
+      list($entity_type_id, $field_name) = explode(':', $this->definition['field access']);
+      $access_handler = $this->entityManager->getAccessControlHandler($entity_type_id);
+      $field_definition = $this->entityManager->getBaseFieldDefinitions($entity_type_id)[$field_name];
+      return $access_handler->fieldAccess('view', $field_definition, $account);
+    }
+
+    return parent::access($account);
+  }
+

Just to be clear, its entirely wrong that this behaviour is attached to the Standard class for multiple reasons:

a) numeric fields are using a different class already
b) why do we not use the existing 'access callback' mechanism ... as you probably know, we could also expand that one to support what you want. its a callback, you can't get more flexibility.

catch’s picture

Title: Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access » [PP-1] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access
Status: Needs work » Postponed

If this is postponed on [#9416717] then that issue can't/shouldn't be demoted to major.

chx’s picture

What is this postponed on...? catch's link doesn't seem to be valid or even resembling any of the issue mentioned here (I even tried https://www.drupal.org/comment/9416717/view)

jibran’s picture

dawehner’s picture

Yeah its exactly postpoed on that.

jhodgdon’s picture

Shouldn't this actually just be marked as a duplicate of that other issue, rather than postponed on the other issue? Will there be anything left to do here when the other (which is already also critical) is fixed?

dawehner’s picture

@jhodgdon
I'm a huge fan of using issues as bugs, not only for solutions.
... I think we could for example leverage this issue to have dedicated tests for access checking.

jhodgdon’s picture

OK. There is no reason to postpone writing tests, which would also allow us to see if the other issue fixes the problem.

dawehner’s picture

Status: Postponed » Needs work

Agreed

alexpott’s picture

Issue tags: +Triaged D8 critical
alexpott’s picture

Status: Needs work » Postponed

DIscussed with @dawehner on IRC - it would be great if #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency contained the test coverage since its implementation will solve this - but we should check once that issue is in.

xjm’s picture

xjm’s picture

Issue summary: View changes
plach’s picture

Issue tags: +entity storage
webchick’s picture

Issue tags: +D8 upgrade path

Since this is security-related, tagging as D8 upgrade path.

dawehner’s picture

Note: I think we should have a test which uses the entity_test entity instead of just the comment entity type as @larowlan did earlier.

larowlan’s picture

Assigned: Unassigned » larowlan

giddyup

larowlan’s picture

So here's a test with entity_test - but it passes :( - so maybe this is a non-issue?
But comment test above shows it is?

No idea.

Battery flat, that's me for today.

larowlan’s picture

Oh, it passes because field API field != base field, will fix when battery is back

larowlan’s picture

this moving closer, but getting errors with 'missing base fields'
something not right in my field definition in the views config.

larowlan’s picture

Status: Postponed » Needs review
FileSize
1.92 KB
8.52 KB

Ok, so this demonstrates the fail/access bypass.
Not starting on fix - do you prefer the fix at #9 or #4 ?

Status: Needs review » Needs work

The last submitted patch, 36: views-base-field-access-2385443.36-fail.patch, failed testing.

dawehner’s picture

Well #7 honestly, but we need a proper test coverage.

larowlan’s picture

Even better, so should we move this test over there and close this?

dawehner’s picture

Well, not sure, we could do that for sure, or just leave the test for this issue, as they are logically two separated issues, its just an implementation detail that the
other issue fixes this already.

Do what you think is the best thing to do, but yeah adding the comment test coverage should be also included. More test coverage is
not a bad idea.

Gábor Hojtsy’s picture

So #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency solves some of the base fields. IMHO we should figure out what other base fields are critical to resolve and either elevate those issues as well and postpone this one or choose another course of action.

jhodgdon’s picture

dawehner’s picture

Title: [PP-1] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access » [PP-2] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access
Status: Needs work » Postponed

.

dawehner’s picture

Title: [PP-2] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access » [PP-1] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access

$issue_title--

larowlan’s picture

Title: [PP-1] Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access » Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access
Assigned: larowlan » Unassigned
Status: Postponed » Needs review
FileSize
8.52 KB

Blocker is in

larowlan’s picture

larowlan’s picture

With the blocker in, this now passes - as expected - so this test-only patch is ready in my books.

Gábor Hojtsy’s picture

Title: Base entity fields using 'standard' plugin added via EntityViewsData to not respect field level access » Test that base entity fields on views respect field level access
Status: Needs review » Reviewed & tested by the community

Let's get this in then :)

dawehner’s picture

+1

Nice work!

The last submitted patch, 33: views-base-field-access-2385443.33.patch, failed testing.

The last submitted patch, 35: views-base-field-access-2385443.34.patch, failed testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Yay, moar test coverage! :)

Committed and pushed to 8.0.x. Thanks!

  • webchick committed f26b532 on 8.0.x
    Issue #2385443 by larowlan, dawehner: Test that base entity fields on...
Gábor Hojtsy’s picture

Superb thanks all!

YesCT’s picture

Category: Bug report » Task

looks like this evolved into a task along the way.

Status: Fixed » Closed (fixed)

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