Skip to content

fix: skip 2FA preflight when using OAuth tokens#846

Merged
m-abdelwahab merged 1 commit intomasterfrom
sam/skip-2fa-preflight-oauth
Apr 21, 2026
Merged

fix: skip 2FA preflight when using OAuth tokens#846
m-abdelwahab merged 1 commit intomasterfrom
sam/skip-2fa-preflight-oauth

Conversation

@samaybar
Copy link
Copy Markdown
Contributor

Summary

  • CLI's 2FA preflight (`validate_two_factor_if_enabled`) fires under OAuth authentication even though backboard already exempts OAuth from 2FA (`hasTwoFactorVerification` scope short-circuits when `ctx.sessionId == null`).
  • End-user symptom: for users with 2FA enabled, `railway delete` (and any other command that goes through the preflight) prompts for a 2FA code on fresh OAuth logins, then fails with `Bad Access` regardless of whether the code is correct.
  • Root cause: the `twoFactorInfoValidate` mutation's resolver requires `ctx.sessionId != null` and throws `BadAccessError` otherwise — OAuth requests always have `sessionId: null`, so the validation is unreachable.

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

```

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.
@m-abdelwahab m-abdelwahab added the release/patch Author patch release label Apr 21, 2026
@m-abdelwahab m-abdelwahab merged commit 4db4ff3 into master Apr 21, 2026
6 of 7 checks passed
@m-abdelwahab m-abdelwahab deleted the sam/skip-2fa-preflight-oauth branch April 21, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release/patch Author patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants