mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-29 00:44:05 +09:00
Refuse a session for a password that changed after it was checked
A password change ends every session, but a sign-in or sign-in link checked
against the old password just before the change could still save its session
just after, and that session outlived the change.
The session now checks, as it's saved, that the user's password is still the
one the request loaded. The save's transaction holds SQLite's write lock from
the start, so a change commits either before the check, which fails it, or
after the insert, and ends this session with the others. Sessions start
through the user's association so the check sees the user that was
authenticated, and a refused sign-in is answered like a wrong password.
(cherry picked from commit 19319a1cff)
This commit is contained in:
1 parent
2021bc3296
commit
48da2b4e4e
8 files changed
+66
-5
No files matched your search
@@ -30,4 +30,19 @@ class Sessions::TransfersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :bad_request
|
||||
assert_nil parsed_cookies.signed[:session_token]
|
||||
end
|
||||
|
||||
test "update is refused when the password changes after the link was checked" do
|
||||
user = users(:david)
|
||||
transfer_id = user.transfer_id
|
||||
stale = User.find(user.id)
|
||||
User.find(user.id).update!(password: "a new secret123456")
|
||||
User.stubs(:find_by_transfer_id).with(transfer_id).returns(stale)
|
||||
|
||||
assert_no_difference -> { Session.count } do
|
||||
put session_transfer_url(transfer_id)
|
||||
end
|
||||
|
||||
assert_response :bad_request
|
||||
assert_nil parsed_cookies.signed[:session_token]
|
||||
end
|
||||
end
|
||||
@@ -36,6 +36,19 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert parsed_cookies.signed[:session_token]
|
||||
end
|
||||
|
||||
test "create is refused when the password changes after it was checked" do
|
||||
user = User.find(users(:david).id)
|
||||
User.find(user.id).update!(password: "a new secret123456")
|
||||
User.stubs(:authenticate_by).returns(user)
|
||||
|
||||
assert_no_difference -> { Session.count } do
|
||||
post session_url, params: { email_address: "david@37signals.com", password: "secret123456" }
|
||||
end
|
||||
|
||||
assert_response :unauthorized
|
||||
assert_nil parsed_cookies.signed[:session_token]
|
||||
end
|
||||
|
||||
test "create with invalid credentials" do
|
||||
post session_url, params: { email_address: "david@37signals.com", password: "wrong" }
|
||||
|
||||
|
||||
Reference in new issue
Block a user