Skip to content

feat: Phising resistant MFA - #39760

Merged
dionisio-bot[bot] merged 54 commits into
developfrom
feat/phishing-resistant-mfa
May 20, 2026
Merged

feat: Phising resistant MFA#39760
dionisio-bot[bot] merged 54 commits into
developfrom
feat/phishing-resistant-mfa

Conversation

@yash-rajpal

@yash-rajpal yash-rajpal commented Mar 20, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Phishing-Resistant Multi-Factor Authentication

Introduces a more secure and reliable server-side OAuth authentication flow.

  • Improved OAuth login security
    OAuth authentication now happens fully on the server, reducing the risk of token theft, phishing attacks, and client-side credential interception.

  • Built-in CSRF, state validation, and PKCE protection
    OAuth logins now include stronger protection against CSRF attacks, request tampering, and authorization code interception through secure state validation and PKCE support.

  • Improved two-step verification with OAuth logins
    Users with email or TOTP two-factor authentication enabled will now be asked to complete 2FA even when signing in with providers like Google, GitHub, GitLab, and others.

  • Improved mobile & desktop app login
    Mobile and desktop apps now support a smoother and more secure deep-link OAuth login flow.

Issue(s)

Steps to test or reproduce

Further comments

PRM-46

Summary by CodeRabbit

  • New Features

    • OAuth sign-in can require two-factor verification (email or TOTP) with a dedicated /2fa flow, resend-email support, and server-managed challenge lifecycle.
    • Deep-linking to share/resume sessions across desktop and mobile and a “login on web” option for desktop clients.
    • Many Passport-based OAuth providers integrated with unified sign-in endpoints.
  • Improvements

    • Hardened OAuth/session handling: session secrets, remembered logins, rate-limited 2FA endpoints, PKCE/state and other protections.

Review Change Stack

@dionisio-bot

dionisio-bot Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2dbdaa2-489b-4f3a-9005-6473a1121458

📥 Commits

Reviewing files that changed from the base of the PR and between d360cd2 and 2700a46.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
  • apps/meteor/package.json
  • packages/web-ui-registration/src/LoginServices.tsx
💤 Files with no reviewable changes (1)
  • apps/meteor/package.json
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/web-ui-registration/src/LoginServices.tsx
  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
🧠 Learnings (6)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • packages/web-ui-registration/src/LoginServices.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/web-ui-registration/src/LoginServices.tsx
  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.

Applied to files:

  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.

Applied to files:

  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/api/server/v1/twoFactorChallenges.ts
🔇 Additional comments (2)
packages/web-ui-registration/src/LoginServices.tsx (1)

38-41: LGTM!

apps/meteor/app/api/server/v1/twoFactorChallenges.ts (1)

32-34: LGTM!


Walkthrough

Adds server-side Passport-based OAuth registration, persistent two-factor challenge storage and APIs, OAuth-specific 2FA checkers (email/TOTP) integrated into OAuth login flow, provider migrations to Passport, client deeplink/session-sharing for mobile/desktop resume, and supporting typings and settings.

Changes

OAuth 2FA and Passport OAuth Framework

Layer / File(s) Summary
Two-factor model and types
packages/core-typings/src/ITwoFactorChallenge.ts, packages/models/src/models/TwoFactorChallenges.ts, packages/model-typings/src/models/ITwoFactorChallengesModel.ts, packages/models/src/index.ts
New ITwoFactorChallenge interface, TwoFactorChallengesRaw Mongo model with TTL index and CRUD operations, model typings and proxied export.
OAuth 2FA checkers & endpoints
apps/meteor/app/2fa/server/code/EmailCheckForOAuth.ts, apps/meteor/app/2fa/server/code/TOTPCheckForOAuth.ts, apps/meteor/app/api/server/v1/twoFactorChallenges.ts, apps/meteor/app/2fa/server/code/index.ts
Email/TOTP OAuth checkers create/verify pending challenges; new v1 routes to send email codes and verify challenges, issuing login tokens and persisting 2FA authorizations on success.
CustomOAuthStrategy base
apps/meteor/app/custom-oauth/server/customOAuth.ts
New CustomOAuthStrategy with identity normalization, template-based extractors, merge/update hooks, and an override to run hook chains during Accounts.updateOrCreateUserFromExternalService.
Passport OAuth framework
apps/meteor/server/lib/oauth/*.ts, apps/meteor/server/configuration/configurePassport.ts
Add OAuthConfigs, createOAuthServiceConfig, getOAuthServices, addPassportCustomOAuth, configureOAuthServices, verifyFunction, passportOAuthCallback, and Express/Passport mounting with Mongo-backed sessions and rate limiting.
Provider refactors to Passport
apps/meteor/app/*/server/* (Apple, Dolphin, Drupal, GitLab, LinkedIn, Meteor Developer, Nextcloud, WordPress)
Refactor multiple provider integrations from CustomOAuth to Passport-based registration using addPassportCustomOAuth and settings-driven reconfiguration.
OAuth 2FA helpers
apps/meteor/server/lib/oauth/twoFactorAuth.ts
Expose getTwoFAMethodForOAuth and doesUserRequire2FA to decide 2FA requirement and method.
Server infra and settings
apps/meteor/server/configuration/configurePassport.ts, apps/meteor/server/configuration/index.ts, apps/meteor/server/settings/oauth.ts, apps/meteor/server/models.ts
Mount Express OAuth router with Mongo-backed sessions, add Accounts_OAuth_Session_Secret setting, register TwoFactorChallenges model, and wire configurePassport into server startup.

Client-side OAuth 2FA and Mobile/Desktop Login

Layer / File(s) Summary
Two-factor modal UI
apps/meteor/client/components/TwoFactorModal/*, apps/meteor/client/lib/2fa/process2faReturn.ts
TwoFactorEmailModal now accepts injected resendEmail callback; process2faReturn supplies SDK-based resend for email flow and updates modal prop typings.
OAuth 2FA router & route
apps/meteor/client/views/OAuthTwoFactorAuthentication/*, apps/meteor/client/startup/routes.tsx
Adds OAuthTwoFactorAuthenticationRouter to show 2FA modal from /2fa/:method/:challengeId, verify challenges, handle errors, and resume/login via token or deeplink.
Deeplink & session sharing hooks
apps/meteor/client/lib/buildAuthDeeplinkURL.ts, apps/meteor/client/views/root/hooks/*
Adds buildDeepLinkURL helper, useLoginOtherClients and useShareSessionWithOtherClients hooks to generate/open deep links for desktop/mobile clients, and updates useLoginViaQuery to respect loginClient.
Client integration & registration UI
apps/meteor/client/views/root/AppLayout.tsx, packages/web-ui-registration/src/*
Register new /2fa/:method/:challengeId route, add hooks to AppLayout, show desktop-only login options and "login on web" button, and redirect OAuth button clicks to /oauth/{service} preserving loginClient.

Supporting Changes

Layer / File(s) Summary
2FA code tweaks & token handling
apps/meteor/app/2fa/server/code/*, apps/meteor/app/lib/server/methods/createToken.ts
Add explicit name typings, export getRememberDate/getSecondFactorMethod, add rememberAuthorizationByToken, simplify maxFaildedAttemtpsReached, and await Accounts._insertLoginToken.
REST typings & e2e fixture
packages/rest-typings/src/v1/twoFactorChallenges.ts, apps/meteor/tests/e2e/fixtures/addCustomOAuth.ts
Add AJV validators and endpoint typings for two-factor challenge routes; update e2e fixture to populate custom OAuth settings.
API exports & typings
apps/meteor/app/api/server/ApiClass.ts, apps/meteor/definition/externals/*.d.ts, apps/meteor/package.json
Export generateConnection, augment Express/session/Window typings, adjust Accounts typings, add Passport/session dependencies and @types, and add i18n keys for 2FA messages.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested labels

type: feature

Suggested reviewers

  • KevLehman
  • ricardogarim
  • tassoevan

@changeset-bot

changeset-bot Bot commented Mar 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2700a46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@rocket.chat/web-ui-registration Major
@rocket.chat/model-typings Minor
@rocket.chat/core-typings Minor
@rocket.chat/rest-typings Minor
@rocket.chat/desktop-api Minor
@rocket.chat/models Minor
@rocket.chat/i18n Minor
@rocket.chat/meteor Minor
@rocket.chat/ui-client Major
@rocket.chat/mock-providers Patch
@rocket.chat/ui-contexts Major
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/ui-composer Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.13688% with 189 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.64%. Comparing base (ad7d424) to head (2700a46).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #39760      +/-   ##
===========================================
- Coverage    69.74%   69.64%   -0.11%     
===========================================
  Files         3325     3338      +13     
  Lines       122973   123226     +253     
  Branches     21980    22015      +35     
===========================================
+ Hits         85768    85821      +53     
- Misses       33852    34042     +190     
- Partials      3353     3363      +10     
Flag Coverage Δ
e2e 59.16% <22.93%> (-0.19%) ⬇️
e2e-api 46.73% <31.81%> (+0.57%) ⬆️
unit 70.45% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread apps/meteor/server/lib/oauth/configureOAuthServices.ts Fixed
Comment thread apps/meteor/server/lib/oauth/configureOAuthServices.ts Fixed
@yash-rajpal
yash-rajpal force-pushed the feat/phishing-resistant-mfa branch from d1667e4 to c558ae5 Compare April 15, 2026 17:03
Comment thread apps/meteor/server/lib/oauth/configureOAuthServices.ts Fixed
Comment thread apps/meteor/server/lib/oauth/configureOAuthServices.ts Fixed
Comment thread apps/meteor/server/lib/oauth/configureOAuthServices.ts Fixed
@KevLehman
KevLehman requested a review from tassoevan May 20, 2026 17:25
@coderabbitai coderabbitai Bot added type: feature Pull requests that introduces new feature and removed area: authentication labels May 20, 2026
@yash-rajpal yash-rajpal added the stat: QA assured Means it has been tested and approved by a company insider label May 20, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label May 20, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue May 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 20, 2026
@scuciatto scuciatto removed the stat: QA assured Means it has been tested and approved by a company insider label May 20, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label May 20, 2026
@scuciatto scuciatto added stat: ready to merge PR tested and approved waiting for merge stat: QA assured Means it has been tested and approved by a company insider labels May 20, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue May 20, 2026
Merged via the queue into develop with commit ae9f740 May 20, 2026
82 of 84 checks passed
@dionisio-bot
dionisio-bot Bot deleted the feat/phishing-resistant-mfa branch May 20, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: authentication stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants