fix: skip 2FA preflight when using OAuth tokens#846
Merged
m-abdelwahab merged 1 commit intomasterfrom Apr 21, 2026
Merged
Conversation
The CLI's 2FA preflight (validate_two_factor_if_enabled) was running for OAuth-authenticated requests even though backboard's hasTwoFactorVerification authScope exempts OAuth from 2FA enforcement. For users with 2FA enabled, the twoFactorInfo query would report isVerified: true, prompting for a 2FA code. The CLI then calls the twoFactorInfoValidate mutation, whose resolver explicitly requires ctx.sessionId != null and throws BadAccessError otherwise. OAuth requests always have sessionId: null, so the validation is unreachable. The end-user symptom is: `railway delete` (and any other command going through the preflight) prompts for a 2FA code on fresh OAuth logins, then fails with `Bad Access` regardless of whether the code is correct. Extend the existing short-circuit to also cover OAuth tokens, mirroring the behavior for token-based auth and matching the backend's 2FA exemption.
jaredLunde
approved these changes
Apr 16, 2026
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
Fix
Extend the existing `is_using_token_auth()` short-circuit in `src/util/two_factor.rs::validate_two_factor_if_enabled` to also cover OAuth tokens:
```rust
if Configs::is_using_token_auth() || configs.has_oauth_token() {
return Ok(());
}
```
This mirrors the backend's behavior: token-based auth and OAuth are both 2FA-exempt, so the preflight is redundant for both and actively harmful for OAuth (since the validate mutation can't succeed).
Context
Paired with backboard fix https://github.com/railwayapp/mono/pull/27553 (allowed OAuth tokens to query `twoFactorInfo` in the first place). That fix unblocked reading the 2FA status; this fix skips the prompt entirely under OAuth since the backend doesn't require it. Related escalation: https://discord.com/channels/713503345364697088/1487308685331136666
Reproduction
Requires a Railway account with 2FA enabled.
```bash
rm -f ~/.railway/config.json
railway login # browser OAuth
unset RAILWAY_TOKEN RAILWAY_API_TOKEN
railway init -n cli-2fa-oauth-repro
railway delete -p cli-2fa-oauth-repro
Before: prompts for 2FA → "Bad Access"
After: deletes cleanly, no 2FA prompt
```