Problem/Motivation
We have implemented commerce_api and have our frontend submit info via the commerce_api. For instance the checkout call, where we submit billing/shipping profile information.
We noticed that you can add uid information, which results in being able to create profiles for a different user than yourself. We fixed this by adding an entity_update hook and setting the profile uid to always match the current_user (except for people having special permissions, so you can still use the cms to edit profiles/orders.
Steps to reproduce
curl 'http://[HOSTNAME]/jsonapi/checkout/9cec9580-9049-415d-ad2f-5e3ff92e37ea' -X PATCH -H 'Accept: application/vnd.api+json' -H 'Content-Type: application/vnd.api+json' -H 'Commerce-Cart-Token: [TOKEN]' -H 'Cookie: [SESSION]' --data-raw '{"data":{"type":"order--default","id":"9cec9580-9049-415d-ad2f-5e3ff92e37ea","attributes":{"email":"test@example.com","field_invoice_email":"test@example.com","field_customer_reference":"backoffice","billing_information":{"address":{"country_code":"NL","locality":"backoffice","postal_code":"backoffice","address_line1":"backoffice","address_line2":"backoffice","given_name":"test","family_name":"test","organization":"organization"},"field_first_name":"test","field_last_name":"test","field_telephone":"1234567890","uid":1 },"shipping_method":"1--default","shipping_information":{"address":{"country_code":"NL","locality":"locality","postal_code":"postal_code","address_line1":"address","address_line2":"address2","given_name":"test","family_name":"test","organization":"organization"},"field_first_name":"test","field_last_name":"test","field_telephone":"1234567890", "uid":1}}}}'
Note: there are some custom fields in this call, so either add those field to the profile, or remove them from the request. We also use the a order type 'default'
Proposed resolution
Do proper access check based on persmissons, although we can't seem to find a "add/edit own profile" permission
Expected results
We find it normal that we don't need to send the uid, and that it automatically will be set on the current user.