Repository navigation
In progress
Description
Summary
With two-factor authentication on, SessionAuthAdapter::signin() issues the remember-me token and its cookie before the OTP step. A remember cookie therefore exists before two-factor authentication is finished, and it can sign the browser in without the OTP. This has been the case since 3.0.0.
How it shows
- An OTP that is never entered. A sign-in with "remember me" stores a remember token and sets the cookie, then waits for the OTP.
checkRememberToken()refuses the cookie only while the user has a pending OTP. When the user later completes an OTP sign-in in another browser without "remember me",verifyOtp()clears the pending OTP, and the first browser's remember cookie signs in without its OTP ever being entered. - OTP setup fails. If
twoStepVerification()throws before it stores the OTP, for example on a database error, the remember token is already stored and no OTP is pending, so the cookie works at once. Reported in the review of PR [#672] Pass a read-only ConfigSection to adapters instead of config arrays #706. - The session ID is not renewed after the OTP.
verifyOtp()signs the user in withoutsession()->regenerateId(), whichsignin()calls without two-factor authentication. A session ID planted in the browser before a two-factor sign-in stays valid for the signed-in user. - The session ID is not renewed on a remember-cookie sign-in. When the remember cookie signs a user in,
user()writes the user into the session withoutsession()->regenerateId()either, so a session ID planted in the browser of a remembered user stays valid once the cookie signs them in.
Cause
SessionAuthAdapter::signin()callssetRememberToken()beforetwoStepVerification().checkRememberToken()ties the cookie's validity to "no OTP pending for this user", not to whether this sign-in passed two-factor authentication.verifyOtp()clears the pending OTP for the user, and with it the only check on every remember token issued during an unverified sign-in.verifyOtp()and the remember-cookie sign-in inuser()do not regenerate the session ID.
The JWT adapter has no remember-me and is not affected.
Proposed fix
- With two-factor on,
signin()does not issue a remember token. It only records in the session of the browser that signed in that "remember me" was asked for; a sign-in without "remember me" removes that record, and so doessignout(). verifyOtp()issues the remember token and cookie after the OTP is accepted, when the record matches the verified user, and removes the record.verifyOtp()and the remember-cookie sign-in inuser()regenerate the session ID before they sign the user in.- With two-factor off, nothing changes.
- A failure in OTP setup then leaves no usable remember token.
- Remember tokens issued before the upgrade are not revoked; the changelog tells applications to clear them.
Tests
- Case 1: a remember cookie from a sign-in whose OTP was never entered does not sign in, also after the owner completes an OTP sign-in elsewhere.
- Case 2: when OTP setup throws, no remember token is stored and no cookie is set.
- A sign-in with "remember me" whose OTP is verified gets a working remember cookie.
- With two-factor off, remember-me works as before.
- After
resendOtp(), a verified OTP still gets the remember cookie. - A later sign-in without "remember me", also one whose OTP mail fails, and
signout()before the OTP leave no remember cookie. verifyOtp()and a remember-cookie sign-in change the session ID and keep the session data; a lateruser()call keeps the new ID.
Activity
[quantum-php#707] Remove the test session key after the session ID tests