Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed: only allow safe parameters to be updater via Customer API (#13589)

Damian Legawiec8eb45862718d
diff --git a/backend/engines/api/app/controllers/spree/api/v3/store/customer/account_controller.rb b/backend/engines/api/app/controllers/spree/api/v3/store/customer/account_controller.rb
index 7b51f66be8..dcc6cc92af 100644
--- a/backend/engines/api/app/controllers/spree/api/v3/store/customer/account_controller.rb
+++ b/backend/engines/api/app/controllers/spree/api/v3/store/customer/account_controller.rb
@@ -27,7 +27,8 @@ module Spree
end
def permitted_params
- params.permit(Spree::PermittedAttributes.user_attributes)
+ params.permit(:email, :password, :password_confirmation, :first_name, :last_name,
+ :accepts_email_marketing, :phone)
end
end
end
diff --git a/backend/engines/api/spec/controllers/spree/api/v3/store/customer/account_controller_spec.rb b/backend/engines/api/spec/controllers/spree/api/v3/store/customer/account_controller_spec.rb
index 495d379844..d19395a670 100644
--- a/backend/engines/api/spec/controllers/spree/api/v3/store/customer/account_controller_spec.rb
+++ b/backend/engines/api/spec/controllers/spree/api/v3/store/customer/account_controller_spec.rb
@@ -84,6 +84,16 @@ RSpec.describe Spree::Api::V3::Store::Customer::AccountController, type: :contro
expect(json_response['first_name']).to eq('Updated')
end
+ it 'ignores restricted attributes' do
+ patch :update, params: { first_name: 'John', private_metadata: { secret: 'value' }, internal_note: 'admin only' }
+
+ expect(response).to have_http_status(:ok)
+ user.reload
+ expect(user.first_name).to eq('John')
+ expect(user.private_metadata).not_to include('secret')
+ expect(user.internal_note).to be_nil
+ end
+
context 'validation errors' do
it 'returns errors for blank email' do
patch :update, params: { email: '' }
diff --git a/backend/engines/api/spec/integration/spree/api/v3/store/customers_spec.rb b/backend/engines/api/spec/integration/spree/api/v3/store/customers_spec.rb
index 516cf92d63..bd346dbe87 100644
--- a/backend/engines/api/spec/integration/spree/api/v3/store/customers_spec.rb
+++ b/backend/engines/api/spec/integration/spree/api/v3/store/customers_spec.rb
@@ -63,7 +63,9 @@ RSpec.describe 'Customers API', type: :request, swagger_doc: 'api-reference/stor
last_name: { type: :string, example: 'Doe' },
email: { type: :string, format: 'email', example: '[email protected]' },
password: { type: :string, example: 'newpassword123' },
- password_confirmation: { type: :string, example: 'newpassword123' }
+ password_confirmation: { type: :string, example: 'newpassword123' },
+ accepts_email_marketing: { type: :boolean, example: true },
+ phone: { type: :string, example: '+1 555 123 4567' }
}
}
diff --git a/packages/next/package.json b/packages/next/package.json
index c22616df4a..4e30bb8076 100644
--- a/packages/next/package.json
+++ b/packages/next/package.json
@@ -55,7 +55,7 @@
"url": "https://github.com/spree/spree/issues"
},
"peerDependencies": {
- "@spree/sdk": ">=0.1.6",
+ "@spree/sdk": ">=0.1.8",
"next": ">=15.0.0",
"react": ">=19.0.0"
},
diff --git a/packages/sdk/.changeset/deep-oranges-hug.md b/packages/sdk/.changeset/deep-oranges-hug.md
deleted file mode 100644
index 969142f6db..0000000000
--- a/packages/sdk/.changeset/deep-oranges-hug.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@spree/sdk": patch
----
-
-Add digital_links to StoreLineItem type and zod schema, exposing digital download metadata (filename, content_type, access status) on line items
diff --git a/packages/sdk/.changeset/rename-user-to-customer.md b/packages/sdk/.changeset/rename-user-to-customer.md
deleted file mode 100644
index a2105f520c..0000000000
--- a/packages/sdk/.changeset/rename-user-to-customer.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@spree/sdk": patch
----
-
-Rename StoreUser/AdminUser types to StoreCustomer/AdminCustomer to align with industry naming conventions and avoid future AdminUser model conflict
diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md
index 20def1a02d..847a3d0cba 100644
--- a/packages/sdk/CHANGELOG.md
+++ b/packages/sdk/CHANGELOG.md
@@ -1,13 +1,17 @@
# @spree/sdk
+## 0.1.7
+
+### Patch Changes
+
+- Add password, password_confirmation, accepts_email_marketing, and phone to customer.update() params type
+
## 0.1.6
### Patch Changes
- Add digital_links to StoreLineItem type and zod schema, exposing digital download metadata (filename, content_type, access status) on line items
-- Rename StoreUser/AdminUser types to StoreCustomer/AdminCustomer to align with industry naming conventions and avoid future AdminUser model conflict
-
## 0.1.5
### Patch Changes
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index 88f5749594..31341b5157 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "@spree/sdk",
- "version": "0.1.6",
+ "version": "0.1.7",
"description": "Official TypeScript SDK for Spree Commerce API",
"type": "module",
"main": "./dist/index.cjs",
diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts
index e9e680dd7c..16be90ce2f 100644
--- a/packages/sdk/src/client.ts
+++ b/packages/sdk/src/client.ts
@@ -716,7 +716,15 @@ export class SpreeClient {
* Update current customer profile
*/
update: (
- params: { first_name?: string; last_name?: string; email?: string },
+ params: {
+ first_name?: string
+ last_name?: string
+ email?: string
+ password?: string
+ password_confirmation?: string
+ accepts_email_marketing?: boolean
+ phone?: string
+ },
options?: RequestOptions
): Promise<StoreCustomer> =>
this.request<StoreCustomer>('PATCH', '/customer', {