Skip to content

Commit 802e555

Browse files
committed
Merge security fix into main
GHSA-mc6q-7qq6-ghg8
2 parents 3b5c609 + 623fd44 commit 802e555

5 files changed

Lines changed: 82 additions & 6 deletions

File tree

‎lib/controllers/backend/spree/admin/user_passwords_controller.rb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def create
2424

2525
set_flash_message(:notice, :send_instructions) if is_navigational_format?
2626

27-
if resource.errors.empty?
28-
respond_with resource, location: admin_user_path(resource)
27+
if successfully_sent?(resource)
28+
location = (spree_current_user && resource.persisted?) ? admin_user_path(resource) : admin_login_path
29+
respond_with resource, location: location
2930
else
3031
respond_with_navigational(resource) { render :new }
3132
end

‎lib/controllers/frontend/spree/user_passwords_controller.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create
2020

2121
set_flash_message(:notice, :send_instructions) if is_navigational_format?
2222

23-
if resource.errors.empty?
23+
if successfully_sent?(resource)
2424
respond_with resource, location: spree.login_path
2525
else
2626
respond_with_navigational(resource) { render :new }
Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Spree::Admin::UserPasswordsController, type: :controller do
4-
before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] }
4+
before do
5+
@request.env["devise.mapping"] = Devise.mappings[:spree_user]
6+
end
57

68
describe "#create" do
7-
it "responds with success" do
9+
before do
10+
create(:store)
11+
create(:user, email: "admin@example.com")
12+
end
13+
14+
it "redirects to the login page" do
815
post :create, params: {spree_user: {email: "admin@example.com"}}
916

1017
expect(assigns[:spree_user].email).to eq("admin@example.com")
11-
expect(response.code).to eq("200")
18+
expect(response).to have_http_status(302)
19+
end
20+
21+
context "when the user email is not found" do
22+
it "re-renders the form" do
23+
post :create, params: {spree_user: {email: "unknown@example.com"}}
24+
25+
expect(response).to have_http_status(200)
26+
expect(response).to render_template :new
27+
end
28+
29+
context "when Devise is in paranoid mode" do
30+
around do |example|
31+
original_paranoid = Devise.paranoid
32+
Devise.paranoid = true
33+
example.run
34+
Devise.paranoid = original_paranoid
35+
end
36+
37+
it "does not reveal that the email is not found" do
38+
post :create, params: {spree_user: {email: "unknown@example.com"}}
39+
40+
expect(response).to have_http_status(302)
41+
end
42+
end
1243
end
1344
end
1445
end

‎spec/controllers/spree/user_passwords_controller_spec.rb‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,44 @@
4242
end
4343
end
4444
end
45+
46+
describe "POST create" do
47+
before do
48+
create(:store)
49+
create(:user, email: "admin@example.com")
50+
end
51+
52+
context "when the user email is not found" do
53+
it "re-renders the form" do
54+
post :create, params: {spree_user: {email: "unknown@example.com"}}
55+
56+
expect(response).to have_http_status(200)
57+
expect(response).to render_template :new
58+
end
59+
60+
context "when Devise is in paranoid mode" do
61+
around do |example|
62+
original_paranoid = Devise.paranoid
63+
Devise.paranoid = true
64+
example.run
65+
Devise.paranoid = original_paranoid
66+
end
67+
68+
it "does not reveal that the email is not found" do
69+
post :create, params: {spree_user: {email: "unknown@example.com"}}
70+
71+
expect(response).to have_http_status(302)
72+
end
73+
end
74+
end
75+
76+
context "when the user email is found" do
77+
it "redirects back to the login page" do
78+
post :create, params: {spree_user: {email: "admin@example.com"}}
79+
80+
expect(response).to redirect_to spree.login_path
81+
expect(response).to have_http_status(302)
82+
end
83+
end
84+
end
4585
end

‎spec/spec_helper.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@
3636
if Spree.solidus_gem_version < Gem::Version.new("2.11")
3737
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
3838
end
39+
40+
config.before(:each, type: :controller) do
41+
ActionMailer::Base.default_url_options[:host] = "example.com"
42+
end
3943
end

0 commit comments

Comments
 (0)