Skip to content

Session auth: a remember-me cookie can skip two-factor authentication #707

In progress

Description

@armanist

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

  1. 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.
  2. 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.
  3. The session ID is not renewed after the OTP. verifyOtp() signs the user in without session()->regenerateId(), which signin() 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.
  4. 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 without session()->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() calls setRememberToken() before twoStepVerification().
  • 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 in user() 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 does signout().
  • 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 in user() 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 later user() call keeps the new ID.

Activity

  1. added this to the 3.2.0 milestone on Nov 24, 2026
  2. added
    bug
    on Nov 24, 2026
  3. self-assigned this
    on Nov 26, 2026
  4. added a commit that references this issue on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugsecurity

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions