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.

Kept the SSO nonce a browser already holds across provider loads

Damian Legawiecca875e7c2b25
diff --git a/spree/api/app/controllers/spree/api/v3/admin/auth_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/auth_controller.rb
index 97955b93f5..52b3fd56f2 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/auth_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/auth_controller.rb
@@ -56,7 +56,10 @@ module Spree
# anyone can log in — so it exposes only provider keys, kinds, labels
# and authorization URLs.
def providers
- nonce = SecureRandom.hex(16)
+ # The login page may load again while a sign-in is in flight, so a
+ # nonce the browser already holds is kept rather than replaced —
+ # replacing it would fail the callback of the state minted first.
+ nonce = oauth_nonce_from_cookie || SecureRandom.hex(16)
minted = false
described = Spree.admin_authentication_strategies.describe do |key|
minted = true
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/auth_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/auth_controller_spec.rb
index ac7c853776..44e3ed5bdb 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/auth_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/auth_controller_spec.rb
@@ -372,6 +372,14 @@ RSpec.describe Spree::Api::V3::Admin::AuthController, type: :controller do
expect(response.cookies['spree_admin_oauth_nonce']).to be_present
end
+ it 'keeps the nonce the browser already holds, so a sign-in in flight survives a reload' do
+ cookies.signed[:spree_admin_oauth_nonce] = 'held-nonce'
+
+ get :providers
+
+ expect(cookies.signed[:spree_admin_oauth_nonce]).to eq('held-nonce')
+ end
+
it 'describes it with a label and an authorization URL' do
get :providers