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: Revoked every customer session when the customer changes their password
Damian Legawiec8cf4c53b3299
diff --git a/spree/api/app/controllers/spree/api/v3/store/customers_controller.rb b/spree/api/app/controllers/spree/api/v3/store/customers_controller.rbindex 25ca15e7cc..3cfac0fc2d 100644--- a/spree/api/app/controllers/spree/api/v3/store/customers_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/store/customers_controller.rb@@ -31,7 +31,8 @@ module Spreerequest_params 'UpdateCustomerParams', action: :update do |body|body.attribute :email, :string, format: :email, example: '[email protected]'- body.attribute :password, :string+ body.attribute :password, :string,+ description: 'Changing it signs the customer out everywhere: every refresh token is revoked, so sign in again once the access token expires.'body.attribute :password_confirmation, :stringbody.attribute :current_password, :string,description: 'Required when changing the email or the password.'@@ -86,6 +87,10 @@ module Spreecurrent_user.consent_source = Spree::ConsentRecord::ACCOUNTif current_user.update(update_params)+ # A password change is how a customer takes a stolen session+ # back, so no refresh token issued before it may outlive it —+ # the reset flow does the same.+ Spree::RefreshToken.revoke_all_for(current_user) if update_params[:password].present?render json: serialize_resource(current_user)elserender_errors(current_user.errors)diff --git a/spree/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rbindex d6af748537..6be53aef4a 100644--- a/spree/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb@@ -402,6 +402,23 @@ RSpec.describe Spree::Api::V3::Store::CustomersController, type: :controller doexpect(response).to have_http_status(:ok)end++ it 'revokes every refresh token, so a stolen session does not outlive the change' do+ refresh_token = Spree::RefreshToken.create_for(user, audience: 'store_api')++ patch :update, params: { password: 'newpassword123', password_confirmation: 'newpassword123', current_password: 'secret123' }++ expect(response).to have_http_status(:ok)+ expect(Spree::RefreshToken.exists?(refresh_token.id)).to be(false)+ end++ it 'keeps sessions when only the profile changes' do+ refresh_token = Spree::RefreshToken.create_for(user, audience: 'store_api')++ patch :update, params: { first_name: 'Updated' }++ expect(Spree::RefreshToken.exists?(refresh_token.id)).to be(true)+ endendcontext 'validation errors' do