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
- Enable Comment on a contact type. Enable Dynamic Page Cache.
- User A can view contact 1 and has
access comments. User B cannot view contact 1. - As user A, open
/crm/contact/1/comment. - 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
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
Comment #3
bluegeek9 commented