Repository navigation
Require an emailed magic code before turning on 2FA - #107174
neil-marcellini wants to merge 11 commits into
Conversation
Adds the enable_two_factor_auth validate code reason, sends validateCode on TwoFactorAuth_Validate, and reports a rejected magic code (451) so the caller can ask for a new one.
The verify step first emails a magic code and collects it, then shows the QR code and authenticator code input, and sends both codes together. If the server rejects the magic code, the step emails a new one and asks again.
|
@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦜 Polyglot Parrot! 🦜Squawk! Looks like you added some shiny new English strings. Allow me to parrot them back to you in other tongues: View the translation diffdiff --git a/src/languages/de.ts b/src/languages/de.ts
index 64b36dfe..6a8caa77 100644
--- a/src/languages/de.ts
+++ b/src/languages/de.ts
@@ -2732,8 +2732,8 @@ const translations: TranslationDeepObject<typeof en> = {
errorStepCodes: 'Bitte kopiere oder lade die Codes herunter, bevor du fortfährst',
stepVerify: 'Bestätigen',
enterSecurityCode: (contactMethod: string) =>
- `Bitte geben Sie den Sicherheitscode ein, der an ${contactMethod} gesendet wurde, um die Zwei-Faktor-Authentifizierung einzurichten. Er sollte innerhalb ein bis zwei Minuten ankommen.`,
- securityCodeRejected: 'Dieser Sicherheitscode hat nicht funktioniert, daher haben wir Ihnen einen neuen gesendet.',
+ `Bitte geben Sie den Sicherheitscode ein, der an ${contactMethod} gesendet wurde, um die Zwei-Faktor-Authentifizierung einzurichten. Er sollte innerhalb von ein bis zwei Minuten ankommen.`,
+ securityCodeRejected: 'Dieser Sicherheitscode hat nicht funktioniert, daher haben wir Ihnen einen neuen geschickt.',
scanCode: 'Scanne den QR-Code mit deinem',
authenticatorApp: 'Authentifizierungs-App',
addKey: 'Oder füge diesen geheimen Schlüssel zu deiner Authentifizierungs-App hinzu:',
diff --git a/src/languages/el.ts b/src/languages/el.ts
index 6c5dc613..52a5da6f 100644
--- a/src/languages/el.ts
+++ b/src/languages/el.ts
@@ -2789,8 +2789,8 @@ const translations: TranslationDeepObject<typeof en> = {
errorStepCodes: 'Παρακαλούμε αντιγράψτε ή κατεβάστε τους κωδικούς πριν συνεχίσετε',
stepVerify: 'Επιβεβαίωση',
enterSecurityCode: (contactMethod: string) =>
- `Παρακαλούμε εισαγάγετε τον κωδικό ασφαλείας που στάλθηκε στο ${contactMethod} για να ρυθμίσετε τον έλεγχο ταυτότητας δύο παραγόντων. Θα πρέπει να φτάσει μέσα σε ένα-δύο λεπτά.`,
- securityCodeRejected: 'Αυτός ο κωδικός ασφαλείας δεν λειτούργησε, γι’ αυτό σας στείλαμε έναν νέο.',
+ `Παρακαλούμε εισαγάγετε τον κωδικό ασφαλείας που στάλθηκε στο ${contactMethod} για να ρυθμίσετε τον έλεγχο ταυτότητας δύο παραγόντων. Θα πρέπει να φτάσει μέσα σε ένα-δυο λεπτά.`,
+ securityCodeRejected: 'Αυτός ο κωδικός ασφαλείας δεν λειτούργησε, οπότε σας στείλαμε έναν νέο.',
scanCode: 'Σαρώστε τον κωδικό QR χρησιμοποιώντας το',
authenticatorApp: 'εφαρμογή ελέγχου ταυτότητας',
addKey: 'Ή προσθέστε αυτό το μυστικό κλειδί στην εφαρμογή ελέγχου ταυτότητάς σας:',
diff --git a/src/languages/es.ts b/src/languages/es.ts
index 93ee3508..62626b6a 100644
--- a/src/languages/es.ts
+++ b/src/languages/es.ts
@@ -2713,7 +2713,7 @@ const translations: TranslationDeepObject<typeof en> = {
stepVerify: 'Verificar',
enterSecurityCode: (contactMethod: string) =>
`Introduce el código de seguridad enviado a ${contactMethod} para configurar la autenticación de dos factores. Debería llegar en uno o dos minutos.`,
- securityCodeRejected: 'Ese código de seguridad no funcionó, así que te enviamos uno nuevo.',
+ securityCodeRejected: 'Ese código de seguridad no funcionó, así que te hemos enviado uno nuevo.',
scanCode: 'Escanea el código QR usando tu',
authenticatorApp: 'aplicación de autenticación',
addKey: 'O añade esta clave secreta a tu aplicación de autenticación:',
diff --git a/src/languages/ja.ts b/src/languages/ja.ts
index 4f80f3f2..61c84ebd 100644
--- a/src/languages/ja.ts
+++ b/src/languages/ja.ts
@@ -2703,8 +2703,8 @@ const translations: TranslationDeepObject<typeof en> = {
`),
errorStepCodes: '続行する前にコードをコピーまたはダウンロードしてください',
stepVerify: '確認',
- enterSecurityCode: (contactMethod: string) => `2要素認証を設定するために、${contactMethod} に送信されたセキュリティコードを入力してください。1~2分以内に届きます。`,
- securityCodeRejected: 'そのセキュリティコードは使用できなかったため、新しいコードを送信しました。',
+ enterSecurityCode: (contactMethod: string) => `2 要素認証を設定するために、${contactMethod} に送信されたセキュリティコードを入力してください。1~2 分以内に届きます。`,
+ securityCodeRejected: 'そのセキュリティコードは有効ではなかったため、新しいコードをお送りしました。',
scanCode: '次の端末でQRコードをスキャンしてください:',
authenticatorApp: '認証アプリ',
addKey: 'または、この秘密キーを認証アプリに追加してください:',
diff --git a/src/languages/nl.ts b/src/languages/nl.ts
index e4139755..35ebfe3c 100644
--- a/src/languages/nl.ts
+++ b/src/languages/nl.ts
@@ -2721,7 +2721,7 @@ const translations: TranslationDeepObject<typeof en> = {
errorStepCodes: 'Kopieer of download de codes voordat je verdergaat',
stepVerify: 'Verifiëren',
enterSecurityCode: (contactMethod: string) =>
- `Voer de beveiligingscode in die is verstuurd naar ${contactMethod} om tweeledige verificatie in te stellen. Die zou binnen één à twee minuten moeten aankomen.`,
+ `Vul de beveiligingscode in die naar ${contactMethod} is gestuurd om tweefactorauthenticatie in te stellen. Die zou binnen een of twee minuten moeten aankomen.`,
securityCodeRejected: 'Die beveiligingscode werkte niet, dus we hebben je een nieuwe gestuurd.',
scanCode: 'Scan de QR-code met je',
authenticatorApp: 'authenticator-app',
diff --git a/src/languages/pl.ts b/src/languages/pl.ts
index 30b0aadd..7c787266 100644
--- a/src/languages/pl.ts
+++ b/src/languages/pl.ts
@@ -2769,7 +2769,7 @@ const translations: TranslationDeepObject<typeof en> = {
stepVerify: 'Zweryfikuj',
enterSecurityCode: (contactMethod: string) =>
`Wpisz kod bezpieczeństwa wysłany na ${contactMethod}, aby skonfigurować uwierzytelnianie dwuskładnikowe. Powinien dotrzeć w ciągu minuty lub dwóch.`,
- securityCodeRejected: 'Ten kod bezpieczeństwa nie zadziałał, więc wysłaliśmy Ci nowy.',
+ securityCodeRejected: 'Ten kod zabezpieczający nie zadziałał, więc wysłaliśmy ci nowy.',
scanCode: 'Zeskanuj kod QR za pomocą swojego',
authenticatorApp: 'aplikacja uwierzytelniająca',
addKey: 'Lub dodaj ten tajny klucz do swojej aplikacji uwierzytelniającej:',
diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts
index e810e4da..714a8595 100644
--- a/src/languages/pt-BR.ts
+++ b/src/languages/pt-BR.ts
@@ -2726,7 +2726,7 @@ const translations: TranslationDeepObject<typeof en> = {
errorStepCodes: 'Copie ou faça o download dos códigos antes de continuar',
stepVerify: 'Verificar',
enterSecurityCode: (contactMethod: string) =>
- `Digite o código de segurança enviado para ${contactMethod} para configurar a autenticação de dois fatores. Ele deve chegar em um ou dois minutos.`,
+ `Insira o código de segurança enviado para ${contactMethod} para configurar a autenticação em duas etapas. Ele deve chegar em um ou dois minutos.`,
securityCodeRejected: 'Esse código de segurança não funcionou, então enviamos um novo para você.',
scanCode: 'Escaneie o código QR usando seu',
authenticatorApp: 'aplicativo autenticador',
diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts
index 1b5d017d..53390f93 100644
--- a/src/languages/zh-hans.ts
+++ b/src/languages/zh-hans.ts
@@ -2624,8 +2624,8 @@ const translations: TranslationDeepObject<typeof en> = {
`),
errorStepCodes: '请在继续之前复制或下载这些代码',
stepVerify: '验证',
- enterSecurityCode: (contactMethod: string) => `请输入发送到 ${contactMethod} 的安全码以设置双重身份验证。验证码应会在一两分钟内送达。`,
- securityCodeRejected: '该安全码无效,我们已向您发送了新的安全码。',
+ enterSecurityCode: (contactMethod: string) => `请输入发送到 ${contactMethod} 的安全验证码,以设置双重验证。验证码应在一两分钟内到达。`,
+ securityCodeRejected: '该安全码无效,我们已向你发送了新的安全码。',
scanCode: '使用你的 扫描二维码',
authenticatorApp: '身份验证器应用',
addKey: '或者将此密钥添加到你的验证器应用:',
Note You can apply these changes to your branch by copying the patch to your clipboard, then running |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
joekaufmanexpensify
left a comment
There was a problem hiding this comment.
This change makes sense to me from a product perspective.
|
Is the backend PRs merged? |
|
No not yet, I'll let you know when. |
The first step only stores the code, so it does not prove the user can read their email before the recovery codes are created.
Use the same spot and style as the form's own validation errors, instead of a red description line above the input.
The form clears its input when a code is sent, which also cleared the error explaining why a new code was sent.
When the validate response arrives behind a server update the app hasn't received, the app holds it until it fetches that update. The required setup's Onyx clear erased the held response, so the secret stayed and the verify page never moved to the success screen.
# Conflicts: # src/components/ValidateCodeActionForm/index.tsx # src/components/ValidateCodeActionForm/type.ts # src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx # src/libs/API/parameters/ResendValidateCodeParams.ts # src/types/onyx/VerifyValidateCodeAction.ts # tests/ui/DynamicTwoFactorAuthPageTest.tsx
Explanation of Change
(Neil's AI agent)
Before 2FA turns on, NewDot now asks for a security code emailed to the account. Someone holding only a stolen session token can't finish 2FA setup with their own authenticator app and lock the owner out.
How the setup changes (Settings > Security, and the setup a domain forces on its members). It now has three steps:
ResendValidateCodewith the newenable_two_factor_authreason) and shows the existing security code form. The secret and recovery codes are only created after the user enters it. The server checks it on the verify step, together with the authenticator code. The code is kept in memory only, never in the URL or in stored Onyx data.TwoFactorAuth_Validatesends both codes (twoFactorAuthCode+ newvalidateCode). The security code comes before the authenticator code because authenticator codes expire after about a minute, and checking email can take longer.Errors:
Required setup fix (the bug is also on
main): the setup a domain forces on its members got stuck on the verify step after a correct authenticator code. For a new account, theTwoFactorAuth_Validateresponse follows a server update the app hasn't received yet, so the app holds the response until it fetches that update. The required setup clears Onyx right away, which erased the held response, so the secret key was never removed and the verify page never moved to the success screen. It now removes the secret key and recovery codes before clearing Onyx.enable_two_factor_authisn't in expensify-common yet, so it lives in App'sCONST, the same wayAPPROVE_DIGITAL_WALLET_VALIDATE_CODE_REASONdoes.Deploy order: Auth PR 26820 must deploy first, because Auth rejects unknown reason codes. Web-Expensify PR 58701, which passes
validateCodethrough to Auth and returns 451 for a bad security code, must also be on production. Until Auth requires the code, a missing code is still accepted, so older app versions keep working. Related Expensify Classic PR: https://github.com/Expensify/Mobile-Expensify/pull/14238Fixed Issues
$ https://github.com/Expensify/Expensify/issues/700473
PROPOSAL:
Tests
(Neil's AI agent)
Automated:
npx jest tests/actions/SessionTest.ts tests/ui/BaseTwoFactorAuthFormTest.tsx tests/ui/DynamicTwoFactorAuthPageTest.tsx. The new tests check that both codes are sent, that only a 451 response asks for a new security code, that the setup form passes the security code through, that the first step asks for the security code before the recovery codes are created, and that the required setup removes the secret key even when the validate response is held behind a missing update. They fail without the change.Manual (needs the Auth and Web-Expensify changes on your backend):
See above.
Screenshots
Steps 2-3: Settings > Security > Two-factor authentication opens on "Step 1 of 3: Security code", and the security code is emailed.
Steps 4-5: after entering a wrong security code (111111), "Step 2 of 3: Recovery codes" shows.
Step 6: "Step 3 of 3: Verify" with the QR code and secret key.
Step 7: after a correct authenticator code, the server rejects the wrong security code (451), so the security code form shows "That security code didn't work, so we sent you a new one." under the code input, and a new code is emailed.
Step 8: after entering the new security code, the QR code screen shows again.
Steps 9-10: a wrong authenticator code shows the invalid code error and stays on the QR code screen.
Steps 11-12: a correct authenticator code turns on 2FA and the success screen shows.
Step 13: a new member of a domain that requires 2FA signs in and gets the "Two-factor authentication required" prompt.
Step 13: tapping Enable starts the required setup on "Step 1 of 3: Security code".
Step 13: after the security code and recovery codes, "Step 3 of 3: Verify" shows. The "Please enter your two-factor authentication code" error on arrival also shows on
main.Step 13: after a correct authenticator code, 2FA turns on and the success screen shows. I ran it on two new accounts and both finished. Before the fix it got stuck on Step 3 on all 4 runs.
Step 13 on
main, for comparison: the required setup gets stuck on "Step 2 of 2: Verify" after a successful validate. This PR fixes that.Offline: going offline on the security code step shows the offline blocking view.
Offline tests
(Neil's AI agent)
QA Steps
(Neil's AI agent)
Same as the manual tests above, on staging after the Auth and Web-Expensify changes are on production.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari