fix: prevent autofilled TOTP codes from being wiped on login#904
Open
faisalahammad wants to merge 1 commit into
Open
fix: prevent autofilled TOTP codes from being wiped on login#904faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
- Removed autocomplete=off from the 2FA login form so browser autofill can reach the per-input one-time-code hints - Added autocomplete=one-time-code to the backup-codes input (TOTP and Email already had it) - Removed two-factor-login.js registration and enqueues: this script blanked the authcode value 200ms after load, destroying any code autofilled by Apple Passwords or Google Password Manager - Rewrote authcode space-insertion logic to be stateless: deriving midpoint from the current value (not a flag) so autofilled codes arriving in a single input event are handled correctly Fixes WordPress#880
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Summary
Apple Passwords and other platform password managers autofill TOTP codes into the 2FA verification field, but three things cause the code to disappear and the form to submit empty: the form has autocomplete="off" (blocking autofill), a 200ms JS timeout blanks the field, and the space-insertion flag doesn't reset when a full code arrives at once.
Fixes #880
Changes
Login form autocomplete
Removed
autocomplete="off"from the validate_2fa_form in class-two-factor-core.php:1130.Why: The form-level override disabled the per-input
autocomplete="one-time-code"hints that TOTP and Email providers already set. Removing it lets password managers deliver codes into the field.Backup codes input
Added
autocomplete="one-time-code"to the backup-codes input (providers/class-two-factor-backup-codes.php:394). TOTP and Email inputs already had this attribute.Dead blanker script removed
Removed
two-factor-login.js(the file) and itswp_register_script/wp_enqueue_scriptcalls across class-two-factor-core.php, the TOTP provider, and the Email provider.Why: This script ran
d.value = ''200ms after page load. It existed to clear+focus the field on render — already empty on load — but it destroyed codes autofilled between page load and the 200ms timer. The backup-codes provider never enqueued it.Authcode JS rewritten
Replaced the stateful
spaceInsertedboolean with value-derived logic.Why: The old flag only reset when the field was cleared. Autofilled codes arriving in one event never triggered the reset path. Now a space is inserted at the midpoint if: the length matches half of expected, digit count matches, and no space already exists. Same effect for manual typing, works for autofill and paste too.
Testing
Test 1: Autofill with TOTP
Test 2: Manual typing still works
Test 3: All providers accept autofilled codes
Build
two-factor-fix-880.zipavailable for manual testing.Verification