Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix: Stopped staff from setting an existing customer's password
Damian Legawiecd22beddf72c2
diff --git a/spree/api/app/controllers/spree/api/v3/admin/customers_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/customers_controller.rbindex 8f7c3b4aa1..9a9ff5e32e 100644--- a/spree/api/app/controllers/spree/api/v3/admin/customers_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/customers_controller.rb@@ -12,9 +12,13 @@ module Spreebody.attribute :first_name, :stringbody.attribute :last_name, :stringbody.attribute :phone, :string- body.attribute :password, :string,+ # On create only: once the account exists its password is the+ # customer's, changed by them or through their own reset email —+ # never set by staff, who would otherwise be able to sign in as+ # any customer.+ body.attribute :password, :string, only: :create,description: 'Optional: a customer created without one claims the account through a password reset.'- body.attribute :password_confirmation, :string,+ body.attribute :password_confirmation, :string, only: :create,description: 'Optional: a customer created without one claims the account through a password reset.'body.attribute :selected_locale, :stringbody.attribute :avatar_signed_id, :string, description: 'A `signed_id` from `files.upload()`.'diff --git a/spree/api/spec/controllers/spree/api/v3/admin/customers_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/customers_controller_spec.rbindex 51dc0f20d1..6e029692b6 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/customers_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/customers_controller_spec.rb@@ -227,6 +227,19 @@ RSpec.describe Spree::Api::V3::Admin::CustomersController, type: :controller doexpect(customer.password_digest).to eq(original_digest)endend++ # Staff never set an existing customer's password: that would let them+ # sign in to the storefront as the customer.+ context 'with a password' do+ it 'ignores it' do+ original_digest = customer.password_digest++ patch :update, params: { id: customer.prefixed_id, password: 'staff-chosen', password_confirmation: 'staff-chosen' }, as: :json++ expect(response).to have_http_status(:ok)+ expect(customer.reload.password_digest).to eq(original_digest)+ end+ endenddescribe 'DELETE #destroy' do