Problem/Motivation

Issues like #2456691: User email field need to use Field-Entity-aware formatters in Views fixes potential security problems.

Let's ensure that we have access test coverage for all of them.

Proposed resolution

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Needs review
FileSize
4.63 KB

Alright, let's start with testing the node title. It turns out, ... everyone can access node titles all the time ... Well, its about people with access
to nodes, which is controlled by the listing already.

Status: Needs review » Needs work

The last submitted patch, 1: 2462589-1.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
11.38 KB

Some work on it.

Tested the base implementation on node, user and entity_test. The helper class will allow it much easier to expand the test coverage on the other issues,
and ensure we don't mix up things again in the future.

jhodgdon’s picture

Can we expand this test to one of the entities from #2393339: [META] Make sure Views base fields are using Field API for formatting, and do not lose functionality that still has a critical follow-up, to verify that the test would catch the problem?

dawehner’s picture

FileSize
6.84 KB
18.22 KB

Started adding some tests for file, aggregator_item, aggregator_feed and comment entity types.
This time, they will fail, as I have no motivated to run them, that late during the night.

Status: Needs review » Needs work

The last submitted patch, 6: 2462589-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
18.39 KB
3.73 KB

Alright, it has been late yesterday night.

Status: Needs review » Needs work

The last submitted patch, 8: 2462589-8.patch, failed testing.

alexpott’s picture

Priority: Major » Critical

Since we're not going to add test coverage on issue like #2456691: User email field need to use Field-Entity-aware formatters in Views this needs to be critical.

dawehner’s picture

Status: Needs work » Needs review
FileSize
18.7 KB
4.21 KB

So we miss quite some of the access checking for file fields.

Status: Needs review » Needs work

The last submitted patch, 11: 2462589-11.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
18.7 KB

Reroll.

jhodgdon’s picture

@dawehner -- I got dreditor, let's see how it went... Anyway this patch looks great! I just had a couple of ideas about API docs. Surprise, surprise. ;)

Also we need to:
a) Make sure all the base fields are in there for all the entities.
b) Make sure that on the "convert this to use a proper handler" issues, we uncomment the test lines, or else have a follow-up @todo with an issue to uncomment them all and make sure the tests still pass.

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BasicStringFormatter.php
    @@ -19,7 +19,8 @@
    + *     "email",
    + *     "uuid",
    

    Should this be part of this patch? Seems like it belongs somewhere else?

  2. +++ b/core/modules/aggregator/src/Tests/Views/AggregatorFeedViewsFieldAccessTest.php
    @@ -0,0 +1,50 @@
    + * Tests aggregator_item views field access.
    

    Maybe these first-line class descriptions should be something more like:

    Tests base field access in Views for the foo entity. ??

  3. +++ b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php
    @@ -0,0 +1,123 @@
    +   * Callers to this method already have to create entities.
    

    Can we change this to something like:

    To use this method, set up an entity of type $entity_type_id, with field $field_name. Create an entity instance that contains content $field_content in that field. This method will check that a user with permission can see the content in a view, and a user without access permission on that field cannot.

jhodgdon’s picture

Oh, and didn't we have test coverage for access on a lot of these fields added when you did that "Convert the standard plugins to use 'field'" issue? Maybe we can remove that in favor of this test, which is clearer and comprehensive?

dawehner’s picture

FileSize
18.76 KB
6.5 KB

Should this be part of this patch? Seems like it belongs somewhere else?

Yeah that belongs more into #2450153: Add a default_formatter to UUIDs fields honestly.

To use this method, set up an entity of type $entity_type_id, with field $field_name. Create an entity instance that contains content $field_content in that field. This method will check that a user with permission can see the content in a view, and a user without access permission on that field cannot.

Oh, and didn't we have test coverage for access on a lot of these fields added when you did that "Convert the standard plugins to use 'field'" issue? Maybe we can remove that in favor of this test, which is clearer and comprehensive?

Not sure whether we really want to remove some other test coverage, but yeah these tests are really helpful to cover a wider range.

jhodgdon’s picture

Looking good!

So I started looking through all the entities, from here:
https://api.drupal.org/api/drupal/8/search/basefielddefinitions
It doesn't look like this patch includes all of the base fields on all of the entities. Should it? For instance, I started at the top. The aggregator Feed entity has:
fid
uuid
title
langcode
url
refresh
checked
...

The patch has only title (commented out, as that field hasn't been converted yet), url, langcode.

Would it make sense in this test to use some sort of discovery method on the entity type to find out what the base fields are, and test all of them systematically? It seems like we want to aim for 100% test coverage...

dawehner’s picture

FileSize
19.77 KB
3.65 KB

Would it make sense in this test to use some sort of discovery method on the entity type to find out what the base fields are, and test all of them systematically? It seems like we want to aim for 100% test coverage...

Well, I think a generic approach would be hard, given that they first need to setup proper data in the entity, which is hard,
and then you have to know how those values are gonna be rendered.

Just added a few more fields for user and node.

Status: Needs review » Needs work

The last submitted patch, 18: 2462589-18.patch, failed testing.

dawehner queued 18: 2462589-18.patch for re-testing.

The last submitted patch, 18: 2462589-18.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
21.62 KB
8.81 KB

Just a little bit more test coverage.

dawehner’s picture

FileSize
21.94 KB
9.25 KB

A couple of more.

jhodgdon’s picture

OK, this is looking good, aside from not covering all the fields, which we cannot do now since not all of them are fixed yet.

So, should we:

a) Wait until all the other critical children on the parent are done, and make this patch cover everything then?

b) Commit it now with a follow-up to have this cover everything when the other issues are done? [add lots of @todo statements to this patch, one per test class, and a new issue they can all point to]

c) Something else?

dawehner’s picture

I'd prefer to get this issue in first and then maybe, if needed expand the test coverage, because for the conversions it would be great to know whether things are actually fixed, so option b).

jhodgdon’s picture

Status: Needs review » Needs work

I agree. So I filed a followup; patch just needs @todo added to refer to it. [so, needs work]
#2464635: Follow-up: Enable additional tests for base entity field access checking in Views

dawehner’s picture

Status: Needs work » Needs review
FileSize
22.42 KB
6.04 KB

Thanks for filing the follow up.

jhodgdon’s picture

Status: Needs review » Needs work

Oops.

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
    @@ -31,6 +31,7 @@
    + *   default_formatter = "entity_reference_label",
    

    Is this from a different issue? I guess it's OK to have here if it's needed.

  2. +++ b/core/modules/aggregator/src/Tests/Views/AggregatorFeedViewsFieldAccessTest.php
    @@ -0,0 +1,52 @@
    +   * Check access for aggregator_feed fields.
    

    Nitpick: checks not check

  3. +++ b/core/modules/aggregator/src/Tests/Views/AggregatorItemViewsFieldAccessTest.php
    @@ -0,0 +1,60 @@
    +   * Check access for aggregator_item fields.
    

    Same here. Etc.

  4. +++ b/core/modules/comment/src/Tests/Views/CommentViewsFieldAccessTest.php
    @@ -0,0 +1,81 @@
    +    // @todo Expand the test coverage in https://www.drupal.org/node/2462589
    

    I think these are the wrong link? should be https://www.drupal.org/node/2464635 ?

dawehner’s picture

Status: Needs work » Needs review
FileSize
22.42 KB
5.5 KB

Is this from a different issue? I guess it's OK to have here if it's needed.

#2429191: Deprecate entity_reference.module and move its functionality to core does the same, but yeah its required to show the node type label.

YesCT’s picture

+++ b/core/modules/node/src/Tests/Views/NodeViewsFieldAccessTest.php
@@ -0,0 +1,77 @@
+    // @todo Don't we want to display Published / Unpublished by default?
+    $this->assertFieldAccess('node', 'status', 'On');
+    $this->assertFieldAccess('node', 'promote', 'On');
+    $this->assertFieldAccess('node', 'sticky', 'Off');

is this still intended to be done in this issue, or do we need a follow-up to reference?

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php
@@ -0,0 +1,141 @@
+  protected function assertFieldAccess($entity_type_id, $field_name, $field_content) {

This method is slick, love it

So given the goal is to get this in and then uncomment lines in the follow up after the conversions are done, I think this is ready.

Boldly setting to RTBC.

dawehner’s picture

+ // @todo Don't we want to display Published / Unpublished by default?

Well, this was just a line of turning on my brain, it doesn't belong into this issue, its just a general valid comment 100% unreated with the issue.

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

+1 for RTBC. And +1 for a follow-up (not at all related to this patch) that sets the default for Status field to Published/Unpublished. Actually though we should probably file that issue and either put the issue link in the @todo or take it out since that's not where the code will go. And...

+    // @todo Don't we want to display Published / Unpublished by default?
+    $this->assertFieldAccess('node', 'status', 'On');
+    $this->assertFieldAccess('node', 'promote', 'On');
+    $this->assertFieldAccess('node', 'sticky', 'Off');

Presumably Status should say "Published"/"Unpublished", promote should say "Promoted"/"Not promoted", and sticky should say "Sticky"/Not sticky. We should be able to do all of them in one issue.

Needs work to fix/remove that @todo and file the new issue.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community
Related issues: +#2465623: Adapt default titles for node boolean flags
FileSize
22.47 KB
943 bytes
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Excellent. This looks like a really great start.

Committed and pushed to 8.0.x. Thanks!

  • webchick committed 24738eb on 8.0.x
    Issue #2462589 by dawehner, jhodgdon: Provide test coverage for access...

Status: Fixed » Closed (fixed)

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