Generated with the help of an LLM.
Problem/Motivation
1. REST writes can link another contact's contact method to a contact you edit (medium-low)
src/Service/rest/ContactMethodItemService.php:354. When a REST payload references an existing method by ID only, the code requires view access to that method. Its own comment says the goal is to stop editors attaching other contacts' emails and phones. But view access allows exactly that: a user who can edit contact A and view contact B can put B's email method into A's emails field.
- The method's owner (crm_contact) doesn't change, so B's data isn't moved. Rendering still checks access, so it doesn't leak to people who can't see B.
- What you get is A and B sharing one method, which is a data-integrity problem. Edits made through A then change B's record.
- Fix: for a method that already has an owner, require it to belong to the contact being written (target_instance), or require update access instead of view.
2. Permission to create a contact method doesn't depend on which contact it's for (low; only if REST or JSON:API is enabled for crm_contact_method)
src/Access/ContactMethodAccessControlHandler.php → checkCreateAccess() allows anyone with create any crm contact or edit mapped crm contact, whatever contact the method points at.
- Reference validation limits the target to contacts the user can view. So a user with view any crm contact plus either of those permissions could attach new methods to contacts they can't edit, through a generic entity POST.
- Updates are fine, because they defer to the contact's update access. But nothing stops a PATCH from changing crm_contact on an existing method to another viewable contact.
- Fix: add field-level edit access on crm_contact (allow it only when it's empty, or when the user can update the target contact), or validate it in a constraint.
3. Claiming orphan contact methods (low)
Orphans are contact methods with no owning contact yet, and the same REST path lets you link one by ID. Contact::postSave() (src/Entity/Contact.php:137) then makes the linking contact its owner, so any user with create access can claim one by guessing its ID. Orphans only exist briefly (for example, during registration), so the risk is small. The REST reference path could require that the current request created the orphan.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork crm-3634880
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