Skip to content

fix(login): wait for either 2FA input target in step_two_fa#1

Closed
Srain021 wants to merge 1 commit intoonurserce:masterfrom
Srain021:fix/step-two-fa-race-onurserce
Closed

fix(login): wait for either 2FA input target in step_two_fa#1
Srain021 wants to merge 1 commit intoonurserce:masterfrom
Srain021:fix/step-two-fa-race-onurserce

Conversation

@Srain021
Copy link
Copy Markdown

@Srain021 Srain021 commented Apr 23, 2026

Originally opened against IBeam master as Voyz#283; redirecting here per @Voyz's suggestion so that @onurserce's contributions in Voyz#277 are preserved properly.

Problem

When step_select_two_fa selects a 2FA method from the dropdown, IBKR's login SPA briefly re-renders, which can remove input[placeholder*="Code"] from the DOM for a short window. The current step_two_fa path calls _find_two_fa_input_target() synchronously right after the TOTP code is generated, and that call does a point-in-time DOM snapshot without waiting. If the snapshot lands inside the re-render gap, the lookup falls back to TWO_FA_INPUT (xyz-field-bronze-response), which does not exist in the Mobile Authenticator App flow, and the subsequent wait_and_identify_trigger times out after 60s even though TOTP was generated correctly.

Fix

Replace the eager snapshot + lookup with a direct wait_and_identify_trigger on both TWO_FA_INPUT and TWO_FA_INPUT_GENERIC, so Selenium natively waits for whichever input is active for the flow. This removes the race without changing the selector semantics.

Tested

Tested on aarch64 Linux running this fork's second-factor-selection branch: TOTP auto-entry completed on the Mobile Authenticator App flow and the session persisted across container restarts.

When step_select_two_fa selects a 2FA method from the dropdown, IBKR's
login SPA briefly re-renders, which can remove input[placeholder*="Code"]
from the DOM for a short window. The current step_two_fa path calls
_find_two_fa_input_target() synchronously right after the TOTP code is
generated, and that call does a point-in-time DOM snapshot without waiting.
If the snapshot lands inside the re-render gap, the lookup falls back to
TWO_FA_INPUT (xyz-field-bronze-response), which does not exist in the
Mobile Authenticator App flow, and the subsequent wait_and_identify_trigger
times out after 60s even though TOTP was generated correctly.

Fix: replace the eager snapshot + lookup with a direct
wait_and_identify_trigger on both TWO_FA_INPUT and TWO_FA_INPUT_GENERIC,
so Selenium natively waits for whichever input is active for the flow.
This removes the race without changing the selector semantics.

Tested on aarch64 Linux running this fork's second-factor-selection
branch: TOTP auto-entry completed on the Mobile Authenticator App flow
and the session persisted across container restarts.
@Srain021
Copy link
Copy Markdown
Author

Superseded by #1, per @Voyz's suggestion to keep @onurserce's contribution chain intact. Closing this one — happy to continue the review over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant