Skip to content

fix: add better servicing#5800

Merged
PrestigePvP merged 3 commits intomainfrom
tre/config-service
Mar 25, 2026
Merged

fix: add better servicing#5800
PrestigePvP merged 3 commits intomainfrom
tre/config-service

Conversation

@PrestigePvP
Copy link
Copy Markdown
Contributor

Context

  • Fix an issue with our MFA and user service creating

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Updated CLAUDE.md files (if needed)
  • Read the contributing guide

@maidul98
Copy link
Copy Markdown
Collaborator

maidul98 commented Mar 25, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 25, 2026

Greptile Summary

This PR addresses two related concerns: (1) a cross-org SSO account takeover vulnerability in LDAP, SAML, and OIDC login flows, and (2) missing MFA enforcement during the OAuth2 token exchange step. The security fix is well-motivated and follows established patterns in the codebase.

  • Cross-org account takeover fix (LDAP, SAML, OIDC services): Before binding an SSO identity to an existing Infisical user found by email, the code now verifies that user already holds a membership in the target org. This prevents an attacker from configuring SSO on their org with a victim's email to hijack the victim's Infisical account. Note this is a behavioural breaking change for deployments that relied on SSO auto-provisioning of existing cross-org users — they will now receive a ForbiddenRequestError until explicitly invited.
  • MFA enforcement during token exchange (auth-login-service.ts, sso-router.ts): oauth2TokenExchange now mirrors the selectOrganization MFA gate, issuing an MFA token and sending an email OTP when required. The server-side logic is correct.
  • Frontend MFA handling (PasswordStep.tsx): The MFA success callback is set to handleExchange, which re-calls the stateless oauthTokenExchange endpoint. Because the endpoint unconditionally re-evaluates shouldCheckMfa against user/org settings (no MFA-verified session is observed), every subsequent call returns isMfaEnabled: true, creating an infinite MFA challenge loop for any OAuth user with MFA enabled.
  • Type inconsistency (types.ts): OauthTokenExchangeRes.mfaMethod is typed as string instead of the MfaMethod enum, forcing an unsafe cast in the consumer.

Confidence Score: 2/5

  • Not safe to merge — the infinite MFA loop in the frontend will break OAuth login entirely for any user or org with MFA enforced.
  • The backend security fix (cross-org account takeover) and MFA gate in oauth2TokenExchange are solid. However, the frontend callback pattern in PasswordStep.tsx introduces a critical regression: setting handleExchange as the MFA success callback causes an infinite loop because oauthTokenExchange is fully stateless and always re-triggers MFA for MFA-enabled users. This breaks the primary OAuth login path for any user or organisation with MFA enabled, which is the scenario this PR is specifically trying to fix.
  • frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx — the MFA success callback must be redesigned to avoid re-entering the exchange flow.

Important Files Changed

Filename Overview
backend/src/ee/services/ldap-config/ldap-config-service.ts Adds cross-org account takeover prevention by checking org membership before binding LDAP identity to an existing user. Pattern mirrors SAML and OIDC changes.
backend/src/ee/services/oidc/oidc-config-service.ts Adds org-membership guard before binding OIDC identity to an existing user. The check is placed between two !newUser branches; the invited-user lookup path (lines 264-278) adds complexity that deserves explicit test coverage.
backend/src/ee/services/saml-config/saml-config-service.ts Adds cross-org account takeover prevention by checking org membership before binding SAML identity to an existing user. Consistent with LDAP and OIDC changes.
backend/src/server/routes/v1/sso-router.ts Adds early return for MFA-required path in the token-exchange handler, returning only the MFA token and method to the client. Clean and correct.
backend/src/services/auth/auth-login-service.ts Adds MFA enforcement to oauth2TokenExchange, mirroring the selectOrganization logic. Correctly gates on org-enforced or user-enabled MFA and sends email OTP when needed.
frontend/src/hooks/api/auth/queries.tsx Updates oauthTokenExchange to use the new OauthTokenExchangeRes type that includes MFA fields. Straightforward change.
frontend/src/hooks/api/auth/types.ts Adds OauthTokenExchangeRes type extending Login2Res with optional MFA fields. mfaMethod is typed as string instead of the MfaMethod enum, reducing type safety.
frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx Adds MFA handling branch after OAuth token exchange. The success callback set to handleExchange creates an infinite MFA loop since oauthTokenExchange is stateless and will always re-trigger MFA for MFA-enabled users.

Reviews (1): Last reviewed commit: "fix: add better servicing" | Re-trigger Greptile

@PrestigePvP PrestigePvP merged commit 25af036 into main Mar 25, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants