Skip to content

Commit 65a90fa

Browse files
dadachiclaude
andcommitted
Remove html_safe from password reset error messages
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c4f0d40 commit 65a90fa

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

app/controllers/shopkeeper_auth/passwords_controller.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def render_error_not_allowed_redirect_url
1818
end
1919

2020
def render_not_found_error
21-
render json: {code: 404, error_message: I18n.t("devise_token_auth.passwords.user_not_found", email: @email)}, status: :not_found
21+
render json: {success: true, message: I18n.t("devise_token_auth.passwords.sended_paranoid")}, status: :ok
2222
end
2323

2424
def render_create_error(errors)
@@ -48,13 +48,11 @@ def render_update_error_missing_password
4848
end
4949

5050
def render_update_error
51-
error_messages = @resource.errors.full_messages.flatten.join("<br/>").html_safe
52-
5351
redirect_to(
5452
edit_shopkeeper_auth_reset_password_path(
5553
reset_password_token: params[:reset_password_token]
5654
),
57-
alert: error_messages
55+
alert: @resource.errors.full_messages.to_sentence
5856
)
5957
end
6058
end

config/initializers/devise_token_auth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# Uncomment to enforce current_password param to be checked before all
3636
# attribute updates. Set it to :password if you want it to be checked only if
3737
# password is updated.
38-
# config.check_current_password_before_update = :attributes
38+
config.check_current_password_before_update = :password
3939

4040
# By default we will use callbacks for single omniauth.
4141
# It depends on fields like email, provider and uid.

test/controllers/shopkeeper_auth/passwords_controller_test.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,31 @@ def setup
3535
assert_equal 401, JSON.parse(response.body)["code"]
3636
end
3737

38-
test "should return not found for non-existent email" do
38+
test "should redirect with error when password update fails validation" do
39+
token = @shopkeeper.send(:set_reset_password_token)
40+
41+
patch shopkeeper_password_url,
42+
params: {
43+
reset_password_token: token,
44+
password: "short",
45+
password_confirmation: "mismatch"
46+
}
47+
48+
assert_response :redirect
49+
assert_match "edit", response.location
50+
follow_redirect!
51+
assert_select ".bg-yellow-50"
52+
end
53+
54+
test "should return generic success for non-existent email to prevent enumeration" do
3955
post shopkeeper_password_url,
4056
params: {
4157
email: "nonexistent@example.com",
4258
redirect_url: "http://localhost:3000/reset"
4359
},
4460
as: :json
4561

46-
assert_response :not_found
47-
assert_equal 404, JSON.parse(response.body)["code"]
62+
assert_response :ok
63+
assert JSON.parse(response.body)["success"]
4864
end
4965
end

0 commit comments

Comments
 (0)