We need to implement access() methods for all fields on all entities so that we have a consistent access API and in order to not expose sensitive data to unprivileged users. Use case example: REST module needs to determine whether to show or hide a particular field when a consumer requests an entity. Who should be able to see the node status flag (published/unpublished), who should be able to retrieve user email addresses from the user entity? Who is allowed to change the node author?

This issue is major since a missing access implementation can have security implications. Individual issues fixing access() might even be critical because of access bypass vulnerabilities.

Also, entity forms that include custom $elements for some fields instead of using widgets should set #access according to "field access rules", instead of hardcoding it as NodeFormController does currently.

Remaining tasks

  • Collect a list of fields of all core entities.
  • Create issues (one per entity) to implement the access checks for the fields on the entity.
  • Track the issues here.
  1. #2029855: Missing access control for user base fields
  2. #2098355: Missing default access for all node fields
  3. #2064181: Filter format access bypass on POST/PATCH
  4. #2098419: Missing default access for all comment fields
  5. #2099259: Missing default access for all taxonomy term fields
  6. #2381835: Missing access control for base fields of block content entity

Comments

moshe weitzman’s picture

Added #2028027: [META] Missing access control for base fields to issue summary. We need to create similar issues for other entities/fields.

fago’s picture

tagging

fago’s picture

Issue summary: View changes

Updated issue summary.

fago’s picture

So what would be the best way to handle that, do it per field, per entity-type?

Imo per entity-type might be a good granularity.

fago’s picture

Issue summary: View changes

Updated issue summary.

fago’s picture

Issue summary: View changes

Updated issue summary.

smiletrl’s picture

Here's an alternative idea of tackling this issue. This idea depends upon #1994140: Unify entity field access and Field API access.
With that issue in, we may do this:

function user_entity_field_access($operation, $field_definition, $account, $items) {
  if ($field_definition->getFieldName() == 'Name' && $items->getParent()->entityType() == 'user') {
    switch ($operation) {
      case 'view':
        // Do and return something.
        break;
      
      default:
        # code...
        break;
    }
  }
}

Thus, we don't have to create new fieldItemList classes for base fields. Also, it provides a central place to handle all operations access for base fields attached to a spcific Entity, e.g, user.

For a particular base field, e.g., user_name:Name, we can still use $items::access() to check the access.

smiletrl’s picture

Issue summary: View changes

Updated issue summary.

fago’s picture

Discussed how we approach that best with yched - it's a general question on how to best provide custom logic per field instance.

We've not been able to identify what's the best approach right now, but agreed that it would make most sense to move with create per field instance field item list classes for now.

We kind of dislike having the entity type module implementing a hook and obfuscating the default-access logic from the field / field definition as a whole.

Other options discussed have been
- add some method on the entity class that's called by default, but this will lead to ugly switch logic there as well
- provide a way to specify custom access callbacks on the field definition, which then could sit on the entity class but be organized more neatly, i.e. group fields with common access logic to use the same callback
-provide a mechanism to provide separate access logic class and define them on the field definition, analogously to validation constraints.

mustanggb’s picture

Issue summary: View changes
Issue tags: +revisit before beta
yched’s picture

Issue summary: View changes
catch’s picture

fago’s picture

Issue tags: +sprint
xjm’s picture

Title: [META] Implement access() methods for all entity fields » [META] Missing access control for base fields accessed via REST
xjm’s picture

Category: Task » Bug report
Priority: Major » Critical
berdir’s picture

Title: [META] Missing access control for base fields accessed via REST » [META] Missing access control for base fields accessed
berdir’s picture

Title: [META] Missing access control for base fields accessed » [META] Missing access control for base fields

Fixing yoda speak

berdir’s picture

Issue tags: -beta target

The API addition that we need from this is in. While this is still a critical bug that we have to sort out, I believe this and the sub issues are now longer beta targets, it doesn't matter when we fix this as long as we do it before 8.0.0.

larowlan’s picture

Can't see reference to 'Block Content' entity in OP - should we have an issue for that too?

star-szr’s picture

Issue summary: View changes
catch’s picture

Title: [META] Missing access control for base fields » [META-2] Missing access control for base fields
Issue summary: View changes

@larowlan opened that issue, well spotted that it was missing.

catch’s picture

Title: [META-2] Missing access control for base fields » [META-1] Missing access control for base fields

And that issue is apparently not necessary.

xjm’s picture

Issue tags: +Triaged D8 critical
berdir’s picture

Title: [META-1] Missing access control for base fields » [META] Missing access control for base fields
Status: Active » Fixed

All child issues were fixed.

Status: Fixed » Closed (fixed)

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