Skip to content

regression: Update express OAuth route handlers on re-register - #41624

Merged
dionisio-bot[bot] merged 2 commits into
release-8.7.0from
reg/update-express-route-handlers
Jul 29, 2026
Merged

regression: Update express OAuth route handlers on re-register#41624
dionisio-bot[bot] merged 2 commits into
release-8.7.0from
reg/update-express-route-handlers

Conversation

@yash-rajpal

@yash-rajpal yash-rajpal commented Jul 29, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

OAuth services are re-registered at runtime when their settings change. The passport strategy is replaced correctly, but the express routes are only appended, the old handlers are also part of execution stack.

passportOAuthCallback isn't a request handler, but is a factory that gives out request handler function based on settings configs. Due to this the request handler always uses old handler with old settings within its closure.

The fix implemented in this PR removes old request handlers from express router stack before pushing new handlers. In future we can come up with a better fix to not sure factory and closures, where express route handlers can use new settings directly.

Issue(s)

Steps to test or reproduce

  • Go to Workspace → Settings → OAuth
  • Enable Use Modern OAuth Flow.
  • Set Login Style to Redirect and save the changes
  • Wait for the settings to be applied or select Refresh OAuth Services
  • Change Login Style to Popup and save the changes
  • Do not restart the Rocket.Chat server
  • Open the workspace URL in a fresh incognito window
  • Select the Custom OAuth provider
  • Complete authentication successfully

Further comments

CORE-2489

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved OAuth provider reconfiguration by removing existing OAuth routes before registering updated Passport strategies.
    • Prevented duplicate or conflicting OAuth endpoints during OAuth service initialization.
    • Applied the same route cleanup behavior to Apple OAuth and custom OAuth providers.
  • New Features
    • Added a shared utility to remove OAuth routes for a specified provider.

@dionisio-bot

dionisio-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 68bf8f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@yash-rajpal
yash-rajpal marked this pull request as ready for review July 29, 2026 15:04
@yash-rajpal
yash-rajpal requested a review from a team as a code owner July 29, 2026 15:04
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 46bae8e3-fc8c-4418-87cc-ace92b782226

📥 Commits

Reviewing files that changed from the base of the PR and between c89ff97 and 68bf8f6.

📒 Files selected for processing (1)
  • apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
⚠️ CI failures not shown inline (5)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ❌ **Has milestone or project** — This PR is missing the required milestone or project
- ✅ **Valid PR title**
- ✅ **Correct target version**

Walkthrough

OAuth route cleanup is centralized in a new utility and invoked before provider registration or Apple OAuth reconfiguration. Custom OAuth configuration now explicitly requires a client secret.

Changes

OAuth route cleanup

Layer / File(s) Summary
Shared OAuth route removal
apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
Adds removeOAuthRoutes to remove matching /oauth/<service> and /_oauth/<service> route layers from the shared router.
Provider registration cleanup
apps/meteor/server/lib/oauth/configureOAuthServices.ts, apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts
Removes existing provider routes before Passport registration and tightens the custom OAuth configuration type to include clientSecret.
Apple OAuth reconfiguration
apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
Removes Apple OAuth routes after unusing the existing Apple Passport strategy during settings changes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type: bug

Suggested reviewers: kevlehman, ricardogarim, tassoevan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: removing and updating OAuth handlers when services are re-registered.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2489: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts (1)

15-15: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make clientSecret required in the exported type.

Partial<OAuthConfiguration & { clientSecret: string }> marks clientSecret and OAuthConfiguration members optional. Use Partial<OAuthConfiguration> & { clientSecret: string } so the API contract reflects what the runtime guard requires.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts` at line 15, Update
the exported function’s config parameter type to use Partial<OAuthConfiguration>
intersected with a required clientSecret string, rather than wrapping the
clientSecret field in Partial. Preserve the existing runtime guard and all other
optional OAuthConfiguration properties.
🧹 Nitpick comments (2)
apps/meteor/server/lib/oauth/removeOAuthRoutes.ts (2)

13-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove implementation comments from this utility.

The repository guideline says to avoid code comments in TypeScript/JavaScript implementations; move any necessary rationale to external documentation or the PR description.

Also applies to: 27-27

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/lib/oauth/removeOAuthRoutes.ts` around lines 13 - 20,
Remove the implementation comment block associated with the OAuth route removal
utility, including the additional comment at the referenced location, while
leaving the route-removal behavior and surrounding code unchanged.

Source: Coding guidelines


25-28: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the router-stack cleanup.

This relies on Express’s internal router.stack and layer.route.path shapes. Test that both OAuth paths are removed while unrelated routes and router.use middleware remain, so an Express upgrade cannot silently reintroduce stale handlers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/lib/oauth/removeOAuthRoutes.ts` around lines 25 - 28, Add
regression coverage for the router-stack cleanup performed by removeOAuthRoutes,
verifying both OAuth paths are removed while unrelated route layers and
middleware registered through router.use remain. Build the test around the
router stack and layer.route.path behavior used by the implementation,
preserving middleware entries during cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts`:
- Line 15: Update the exported function’s config parameter type to use
Partial<OAuthConfiguration> intersected with a required clientSecret string,
rather than wrapping the clientSecret field in Partial. Preserve the existing
runtime guard and all other optional OAuthConfiguration properties.

---

Nitpick comments:
In `@apps/meteor/server/lib/oauth/removeOAuthRoutes.ts`:
- Around line 13-20: Remove the implementation comment block associated with the
OAuth route removal utility, including the additional comment at the referenced
location, while leaving the route-removal behavior and surrounding code
unchanged.
- Around line 25-28: Add regression coverage for the router-stack cleanup
performed by removeOAuthRoutes, verifying both OAuth paths are removed while
unrelated route layers and middleware registered through router.use remain.
Build the test around the router stack and layer.route.path behavior used by the
implementation, preserving middleware entries during cleanup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a8f21cf7-a897-4595-b165-f2c12b5081a6

📥 Commits

Reviewing files that changed from the base of the PR and between a4f5098 and c89ff97.

📒 Files selected for processing (4)
  • apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
  • apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts
  • apps/meteor/server/lib/oauth/configureOAuthServices.ts
  • apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
🧰 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:

  • apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
  • apps/meteor/server/lib/oauth/configureOAuthServices.ts
  • apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
  • apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts
🧠 Learnings (3)
📚 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/server/lib/oauth/removeOAuthRoutes.ts
  • apps/meteor/server/lib/oauth/configureOAuthServices.ts
  • apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
  • apps/meteor/server/lib/oauth/addPassportCustomOAuth.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/server/lib/oauth/removeOAuthRoutes.ts
  • apps/meteor/server/lib/oauth/configureOAuthServices.ts
  • apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
  • apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts
📚 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:

  • apps/meteor/server/lib/oauth/removeOAuthRoutes.ts
  • apps/meteor/server/lib/oauth/configureOAuthServices.ts
  • apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts
  • apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts
🔇 Additional comments (4)
apps/meteor/server/lib/oauth/removeOAuthRoutes.ts (1)

1-11: LGTM!

Also applies to: 22-24, 29-29

apps/meteor/server/lib/oauth/configureOAuthServices.ts (1)

9-9: LGTM!

Also applies to: 19-19

apps/meteor/server/lib/oauth/addPassportCustomOAuth.ts (1)

7-7: LGTM!

Also applies to: 19-19

apps/meteor/server/lib/auth-providers/apple/applePassportOAuth.ts (1)

17-17: LGTM!

Also applies to: 56-56

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.42%. Comparing base (a4f5098) to head (68bf8f6).
⚠️ Report is 2 commits behind head on release-8.7.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-8.7.0   #41624      +/-   ##
=================================================
+ Coverage          68.38%   68.42%   +0.04%     
=================================================
  Files               4139     4140       +1     
  Lines             158311   158318       +7     
  Branches           28252    28317      +65     
=================================================
+ Hits              108263   108333      +70     
+ Misses             44916    44854      -62     
+ Partials            5132     5131       -1     
Flag Coverage Δ
e2e 58.87% <ø> (-0.01%) ⬇️
e2e-api 45.36% <57.14%> (+<0.01%) ⬆️
unit 70.38% <ø> (+0.08%) ⬆️

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/removeOAuthRoutes.ts Outdated
@yash-rajpal yash-rajpal added the stat: QA assured Means it has been tested and approved by a company insider label Jul 29, 2026
@yash-rajpal yash-rajpal added this to the 8.7.0 milestone Jul 29, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 29, 2026
@yash-rajpal yash-rajpal removed the stat: QA assured Means it has been tested and approved by a company insider label Jul 29, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 29, 2026
@yash-rajpal yash-rajpal 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 Jul 29, 2026
@dionisio-bot
dionisio-bot Bot merged commit 9399296 into release-8.7.0 Jul 29, 2026
99 of 101 checks passed
@dionisio-bot
dionisio-bot Bot deleted the reg/update-express-route-handlers branch July 29, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants