Fix #4555: Invalidate sessions for deleted users
Fix three exploits that allowed one to keep using their account after it was deleted: * It was possible to use session cookies from another computer to login after you deleted your account. * It was possible to use API keys to make API requests after you deleted your account. * It was possible to request a password reset, delete your account, then use the password reset link to change your password and login to your deleted account.
This commit is contained in:
@@ -137,6 +137,14 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
should "fail for a deleted user" do
|
||||
@user.update!(is_deleted: true)
|
||||
basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@api_key.key}")}"
|
||||
get profile_path, as: :json, headers: { HTTP_AUTHORIZATION: basic_auth_string }
|
||||
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
should "succeed for non-GET requests without a CSRF token" do
|
||||
assert_changes -> { @user.reload.enable_safe_mode }, from: false, to: true do
|
||||
basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@api_key.key}")}"
|
||||
@@ -183,6 +191,13 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
should "fail for a deleted user" do
|
||||
@user.update!(is_deleted: true)
|
||||
get edit_user_path(@user), params: { login: @user.name, api_key: @api_key.key }
|
||||
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
should "succeed for non-GET requests without a CSRF token" do
|
||||
assert_changes -> { @user.reload.enable_safe_mode }, from: false, to: true do
|
||||
put user_path(@user, login: @user.name, api_key: @api_key.key), params: { user: { enable_safe_mode: "true" }}, as: :json
|
||||
@@ -267,14 +282,26 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "on session cookie authentication" do
|
||||
should "succeed" do
|
||||
user = create(:user, password: "password")
|
||||
setup do
|
||||
@user = create(:user, password: "password")
|
||||
post session_path, params: { name: @user.name, password: "password" }
|
||||
end
|
||||
|
||||
post session_path, params: { name: user.name, password: "password" }
|
||||
get edit_user_path(user)
|
||||
should "succeed" do
|
||||
get profile_path
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "fail for a deleted user" do
|
||||
@user.update!(is_deleted: true)
|
||||
|
||||
get profile_path
|
||||
|
||||
assert_redirected_to login_path(url: "/profile")
|
||||
assert_nil(session[:user_id])
|
||||
assert_equal(true, @user.user_events.exists?(category: :logout))
|
||||
end
|
||||
end
|
||||
|
||||
context "accessing an unauthorized page" do
|
||||
|
||||
Reference in New Issue
Block a user