fix: return early from the multi-factor timebox when no provider is registered - #20348
Draft
shaheenfawzy wants to merge 1 commit into
Draft
fix: return early from the multi-factor timebox when no provider is registered#20348shaheenfawzy wants to merge 1 commit into
shaheenfawzy wants to merge 1 commit into
Conversation
…nged The second `Timebox` in `authenticate()` conceals whether a multi-factor challenge is pending, by padding every sign-in to `auth.timebox_duration`. It never calls `returnEarly()`, so a panel that registers no multi-factor authentication providers pays that padding on every successful sign-in for a challenge that can never be presented. With the default 200ms duration, that is 200ms added to every login on the majority of panels. `Filament::getMultiFactorAuthenticationProviders()` is read from the panel's own configuration, so the check costs nothing and stops being true the moment a provider is registered. Panels that do register one are unaffected.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Login::authenticate()runs its multi-factor lookup inside aTimeboxso an attacker cannot tell from response time whether an account has a challenge pending:Nothing in that closure ever calls
$timebox->returnEarly(), soTimebox::call()sleeps out the remainder ofauth.timebox_durationon every path, including the one where the panel has no multi-factor authentication providers registered at all. On that panel no challenge can ever be presented, so there is nothing to conceal, and the default 200ms is added to every successful sign-in for nothing.This returns early only in that case:
The providers come from the panel's own configuration rather than from the user being authenticated, so the branch reveals nothing about the account, and it stops applying the moment a provider is registered. Panels that use multi-factor authentication keep the full padding on every path.
Measured on a production application: 200ms off every sign-in. Reproduction: https://github.com/shaheenfawzy/filament-login-double-hash
Visual changes
None.
Functional changes
composer cscommand.tests/src/Panels/Auth/LoginTest.phpgains two tests, both using theSleep::fake()pattern the file already uses: a sign-in on theadminpanel records no padding, and a sign-in on theapp-authenticationpanel still does. The first fails on5.xwithout this change, recording[199.989]instead of[]; the second passes either way and is there to prove the fix does not disable the timebox where it matters.