Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Require the current password when password_challenge is sent as null (#4990)

GFR18780f514d39
diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb
index e53eb7a1a7..5cf689f673 100644
--- a/app/controllers/passwords_controller.rb
+++ b/app/controllers/passwords_controller.rb
@@ -42,7 +42,11 @@ class PasswordsController < ApplicationController
redirect_to root_path, alert: t("passwords.disabled")
end
+ # User skips the current-password check when password_challenge is nil,
+ # and a JSON null or a bare form key without "=" both arrive as nil, so
+ # always pass a string here.
def password_params
- params.require(:user).permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
+ permitted = params.require(:user).permit(:password, :password_confirmation, :password_challenge)
+ permitted.merge(password_challenge: permitted[:password_challenge].to_s)
end
end
diff --git a/test/controllers/passwords_controller_test.rb b/test/controllers/passwords_controller_test.rb
index 16b7a05c44..7284b5f283 100644
--- a/test/controllers/passwords_controller_test.rb
+++ b/test/controllers/passwords_controller_test.rb
@@ -37,6 +37,22 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest
end
end
+ test "update rejects a null current password sent as JSON" do
+ assert_password_unchanged do
+ patch password_path,
+ params: { user: { password_challenge: nil, password: "newtestpassword817983172", password_confirmation: "newtestpassword817983172" } }.to_json,
+ headers: { "CONTENT_TYPE" => "application/json" }
+ end
+ end
+
+ test "update rejects a current password key sent without a value" do
+ assert_password_unchanged do
+ patch password_path,
+ params: "user[password_challenge]&user[password]=newtestpassword817983172&user[password_confirmation]=newtestpassword817983172",
+ headers: { "CONTENT_TYPE" => "application/x-www-form-urlencoded" }
+ end
+ end
+
test "update rejects a mismatched confirmation" do
assert_password_unchanged do
patch password_path, params: { user: { password_challenge: user_password_test, password: "newtestpassword817983172", password_confirmation: "differentpassword817983172" } }