The vulnerability is an Insecure Direct Object Reference (IDOR) in Spree Commerce's guest checkout flow, allowing unauthenticated users to access personally identifiable information (PII) of other guest users. The root cause lies in faulty authorization logic within the bill_address_id= and ship_address_id= setter methods, which are part of the Spree::Order::AddressBook module included in the Spree::Order model.
When a guest user proceeds through checkout, their order does not have an associated user_id (it is nil). If an attacker, also as a guest, manipulates the checkout update request to include the ID of an address belonging to another guest user (bill_address_id or ship_address_id), the application attempts to validate ownership. The vulnerable code checks if address.user_id == user_id. For guest users, this comparison becomes nil == nil, which evaluates to true. This flaw allows the attacker to successfully associate the victim's address with their own order, thereby exposing the victim's PII.
The patch rectifies this by introducing an additional check, user_id.present?. This ensures that the ownership validation is only attempted for authenticated users who have a non-nil user_id. For guest users, this condition fails, preventing them from assigning any existing address by its ID and mitigating the IDOR vulnerability. The identified vulnerable functions, Spree::Order.bill_address_id= and Spree::Order.ship_address_id=, are the precise locations of this flawed logic and would be observed in a runtime profile during an exploit.