Repository navigation
Make email revoking URL harder to guess. - #491
Conversation
63d6f3f to
5ec7f4e
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The unauthenticated revocation endpoint allows a secret=0 bypass and unlimited six-digit code guesses, enabling attackers to revoke email MFA and terminate users’ sessions.
3 open issues
What changed in this PR
This PR aims to make email-factor revocation links harder to guess by requiring the verification secret alongside the factor record ID.
Changes:
- Adds the secret to revocation links and checks it before revoking email factors.
- Adds a renderer test confirming that revocation links include the secret.
- Increments the main plugin and email-factor versions.
| File | Description |
|---|---|
version.php |
Increments the plugin version and release number. |
factor/email/version.php |
Increments the email-factor version. |
factor/email/tests/factor_test.php |
Adds coverage for the secret in rendered revocation links. |
factor/email/renderer.php |
Includes the verification secret in revocation URLs. |
factor/email/email.php |
Requires and checks the secret; removes an unused assignment. |
Review effort: Balanced
| redirect(new moodle_url('/')); | ||
| } else if ($fromform = $form->get_data()) { | ||
| if (empty($instance)) { | ||
| if (empty($instance) || ($instance->secret != $secret)) { |
| if (empty($instance) || ($instance->secret != $secret)) { | ||
| $message = get_string('error:badcode', 'factor_email'); |
|
How long should the revocation link remain valid? If it’s meant to expire with the sign-in code, could we enforce that in the revocation handler too? The new test checks that the email contains the link. Could we also test the handler itself: a valid link should revoke email MFA, while an invalid or expired link should leave both the user’s email MFA and their sessions unchanged? |
Previously the "this wasn't me" revoke link only needed the tool_mfa instance ID. IDs are sequential, so anyone could revoke a user's email factor and end all of their sessions without authenticating. Revoke link (factor/email/email.php, renderer.php): - Include the emailed code in the revoke link and require it (secret is now a required param). - Limit guesses on the unauthenticated revoke form. - Reject expired codes before an attempt is counted. - Check the user exists and isn't deleted before revoking. - Suspend accounts with user_suspend_user() instead of a raw set_field, so user_updated/user_suspended events fire Email-link sign-in (pass=1): - Only accept pending, unrevoked email codes. - Reject expired codes. - Load the lock state from the DB before checking for the locked state, so a fresh session can't get around the lockout. Both: - Compare codes with hash_equals() on strings (constant time, no type juggling). Other: - Add a test that the revoke link in the email includes the code. - Version bumps.
5ec7f4e to
dbf03b7
Compare


Make the factor revoke email a little harder to guess by adding the secret to it.
Previously the "this wasn't me" revoke link only needed the
tool_mfa instance ID. IDs are sequential, so anyone could revoke a
user's email factor and end all of their sessions without
authenticating.
Revoke link (factor/email/email.php, renderer.php):
(secret is now a required param).
set_field, so user_updated/user_suspended events fire
Email-link sign-in (pass=1):
state, so a fresh session can't get around the lockout.
Both:
type juggling).
Other: