Problem/Motivation

The comments page at /crm/contact/{crm_contact}/comment uses a custom access callback that converts contact view access to a boolean:

AccessResult::allowedIf($crm_contact->access('view') && $this->currentUser()->hasPermission('access comments'));

AccessResult::allowedIf() does not inherit cache contexts or tags from the entity access result (user, permissions, mapping list tags, grant variation). Dynamic Page Cache can then treat the page as shareable across users.

Contact comments are personal data. A cached “allowed” response for a user who may view the contact could be served to a user who may not.

Code: Drupal\crm\Controller\CommentController::access().

Contrast with CrmController::accessLandingPage() and RelationshipController::buildAccess(), which keep AccessResult objects and call cachePerPermissions() or andIf().

Steps to reproduce

  1. Enable Comment on a contact type. Enable Dynamic Page Cache.
  2. User A can view contact 1 and has access comments. User B cannot view contact 1.
  3. As user A, open /crm/contact/1/comment.
  4. As user B, open the same URL (same cache contexts as currently declared).

Whether B sees A’s page depends on cache bins and vary headers; the access result is still incorrect even if a given environment does not reproduce a leak.

Proposed resolution

Return a real access result, for example:

  • Forbidden when the comment module is missing or the field is missing (with appropriate cache tags for module/field config).
  • $crm_contact->access('view', $account, TRUE)->andIf(AccessResult::allowedIfHasPermission($account, 'access comments'))

Pass the account from the route access checker instead of only currentUser() when the signature allows it.

Remaining tasks

  • Fix CommentController::access().
  • Update unit tests to assert cache contexts/tags, not only allowed/forbidden.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork crm-3622719

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bluegeek9 created an issue. See original summary.

bluegeek9’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • bluegeek9 committed c8c61d29 on 1.0.x
    task: #3622719 Contact comments route access result drops cache metadata
    

Status: Fixed » Closed (fixed)

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