Skip to main content
Menu
Advisories

@logto/experience open redirect

GHSA-P88Q-P28C-J9JFPublished Updated GitHub

Description

VULN-016 — OAuth/SSO Authorization-Code Exfiltration and Cross-Session Account Takeover via Attacker-Controlled native_callback Parameter in Social/SSO Landing Flow

Status

CONFIRMED — via static trace, with the server-side half of the chain independently re-verified: assignConnectorSessionResult/getConnectorSessionResult (packages/core/src/libraries/verification-helpers/social-verification.ts:105-124) store and re-read the connectorSession (including the client-chosen state) purely against the calling request's own oidc-provider interaction cookie — there is no mechanism anywhere in this path that ties a code redemption to "the same browser that completed the IdP consent," only to "a state value that self-matches whatever the caller previously stored in their own session." This confirms the core claim that state-matching here is a self-consistency check within one attacker-controlled session, not a cross-session binding control. The client-side (React) half of the chain (sessionStorage poisoning via native_callback, forwarding via Callback.tsx) was not exercised in a live browser, and no real third-party IdP consent was performed — full end-to-end reproduction would need a live Google/enterprise-IdP account and is recommended before or alongside vendor remediation, but is not required to establish that the vulnerability is real: the mechanism has no other gate that would stop it.

Classification

  • Vulnerability: Open Redirect enabling OAuth/OIDC Authorization Code Interception → Cross-Session Account Takeover
  • CWE: CWE-601 — URL Redirection to Untrusted Site ('Open Redirect') as the root technical flaw; CWE-346 — Origin Validation Error (native callback link is never checked against any allow-listed scheme/origin); impact reaches CWE-287 — Improper Authentication (attacker completes sign-in bound to the victim's linked social/SSO identity from the attacker's own session)
  • Severity: High
  • CVSS (estimate): 8.1 — CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:N (Attack Complexity rated High because the attacker must first self-mint a valid state/authorizationUri pair and lure the victim through a real IdP consent; Confidentiality/Integrity High because the outcome is authentication as the victim's linked identity)

Location

  • File: packages/experience/src/utils/social-connectors.ts:93-105 — buildSocialLandingUri(path, redirectTo): url.searchParams.set(SearchParameters.RedirectTo, redirectTo); ... url.searchParams.set(SearchParameters.NativeCallbackLink, callbackLink);
  • File: packages/experience/src/pages/SocialLanding/use-social-landing-handler.ts:17-32 — reads redirect_to and native_callback straight from window.location.search and (a) navigates to redirect_to unconditionally (see VULN-015), and (b) stores native_callback verbatim via storeCallbackLink(connectorId, nativeCallbackLink) with no validation that it is a legitimate native-app URI scheme (e.g. io.myapp://...) as opposed to an arbitrary https:// URL.
  • File: packages/experience/src/utils/social-connectors.ts:107-109 — storeCallbackLink = (connectorId, callbackLink) => sessionStorage.setItem(\social_callback_data:${connectorId}\, callbackLink) — persists the attacker-controlled value in sessionStorage, keyed only by connectorId.
  • File: packages/experience/src/pages/Callback/use-social-callback-handler.ts:24-31 — on return from the upstream IdP, reads the stored value back via getCallbackLinkFromStorage(connectorId) and, if present, does window.location.replace(new URL(\${callbackLink}${search}\)), forwarding the entire query string — including the OAuth code and state returned by the IdP — to whatever URL was poisoned in the prior step.
  • File: packages/experience/src/types/index.ts:25-28 — SearchParameters.NativeCallbackLink = 'native_callback', SearchParameters.RedirectTo = 'redirect_to' — both are bare, unauthenticated query-parameter keys.
  • Route registration: packages/experience/src/App.tsx:75-76,181 — social/landing/:connectorId (poisoning entry point) and callback/:connectorId (forwarding exit point) are both public, unauthenticated top-level routes.
  • Server-side corroborating routes: packages/core/src/routes/experience/verification-routes/social-verification.ts:31-81 (POST /api/experience/verification/social/:connectorId/authorization-uri — accepts a fully client-chosen state and redirectUri, see socialAuthorizationUrlPayloadGuard in packages/schemas/src/types/interactions.ts:79-83) and :83-169 (POST /api/experience/verification/social/:connectorId/verify — redeems connectorData.code/state against the requester's own interaction session).
  • Same pattern applies to enterprise SSO: packages/experience/src/hooks/use-single-sign-on.ts:32-42 builds the identical buildSocialLandingUri(...) handoff for SSO connectors.

Vulnerable Code

// packages/experience/src/utils/social-connectors.ts:93-105
export const buildSocialLandingUri = (path: string, redirectTo: string) => {
  const { origin } = window.location;
  const url = new URL(`${origin}${path}`);
  url.searchParams.set(SearchParameters.RedirectTo, redirectTo);

  const callbackLink = getLogtoNativeSdk()?.callbackLink;
  if (callbackLink) {
    url.searchParams.set(SearchParameters.NativeCallbackLink, callbackLink); // legitimate native flow sets this from the SDK bridge
  }
  return url;
};
// packages/experience/src/pages/SocialLanding/use-social-landing-handler.ts:15-33
const socialLandingHandler = useCallback(
  (connectorId: string) => {
    const redirectUri = getSearchParameters(search, SearchParameters.RedirectTo);
    if (!redirectUri) { /* ... */ return; }

    const nativeCallbackLink = getSearchParameters(search, SearchParameters.NativeCallbackLink);
    if (nativeCallbackLink) {
      storeCallbackLink(connectorId, nativeCallbackLink);   // <-- ATTACKER can also reach this page directly with an arbitrary native_callback value
    }
    window.location.replace(new URL(redirectUri));
  },
  [search, setToast, t]
);
// packages/experience/src/pages/Callback/use-social-callback-handler.ts:12-31
const socialCallbackHandler = useCallback(
  (connectorId: string) => {
    const searchParams = new URLSearchParams(window.location.search);
    const hashParams = new URLSearchParams(window.location.hash.slice(1));
    const joinedSearchParams = new URLSearchParams([...searchParams, ...hashParams]);
    const search = joinedSearchParams.toString() ? `?${joinedSearchParams.toString()}` : '';

    const callbackLink = getCallbackLinkFromStorage(connectorId);   // <-- reads back whatever was poisoned above
    removeCallbackLinkFromStorage(connectorId);

    if (callbackLink) {
      window.location.replace(new URL(`${callbackLink}${search}`)); // <-- forwards code+state (the real IdP callback query string) to the poisoned URL
      return;
    }
    // ... normal web flow otherwise
  },
  [navigate]
);

Why It's Vulnerable

SocialLanding (comment: "Only used for native app out of the app webview sign-in flow") and Callback are, in practice, plain public routes with no enforcement that they are only reached via the intended native-app deep-link handoff. Any visitor can navigate directly to /social/landing/:connectorId?redirect_to=<url>&native_callback=<url>. The native_callback value is stored in sessionStorage completely unvalidated — it is never checked to be a non-http(s) custom scheme (the actual native-app deep link), a same-origin URL, or anything else. It is later read back by Callback (the real OAuth redirect_uri registered with the upstream IdP for this connector) and used to build the URL that the entire authorization callback query string — including the IdP's code and state — is forwarded to via window.location.replace.

Because the OAuth state value sent to the upstream IdP is also fully client-chosen (socialAuthorizationUrlPayloadGuard in packages/schemas/src/types/interactions.ts:79-83 accepts a bare z.string() for state, populated client-side by generateState() in packages/experience/src/containers/SocialSignInList/use-social.ts:63), and the authorization-uri creation endpoint (POST /api/experience/verification/social/:connectorId/authorization-uri) requires no authentication (only a bootstrapped, anonymous experience interaction — the same precondition already demonstrated live for VULN-014), an attacker can self-mint a completely valid authorizationUri (a real, working link to the upstream IdP's consent screen) using a state of their own choosing, entirely from their own browser/session, before ever involving a victim.

The attacker then combines that legitimately-obtained authorizationUri as the redirect_to value with a malicious native_callback=https://attacker.example/collect in a single crafted link to /social/landing/:connectorId. When the victim clicks it:

  1. The victim's browser stores https://attacker.example/collect in the victim's own sessionStorage (poisoning step, silent, no visible effect).
  2. The victim is immediately redirected (via the VULN-015 open redirect in the same handler) to the real, legitimate upstream IdP consent screen (e.g., Google) using the attacker's pre-generated state.
  3. The victim, seeing a completely genuine IdP consent screen, logs in with their real account and approves.
  4. The IdP redirects back to Logto's real, registered callback URI (https://<tenant>/callback/<connectorId>?code=<real code>&state=<attacker's state>), which is Callback.tsx.
  5. Callback.tsx finds the poisoned native_callback entry in sessionStorage and immediately forwards the entire query string, including the victim's real, unused authorization code, to https://attacker.example/collect?code=...&state=... via window.location.replace.
  6. The attacker's server now has a valid, unredeemed authorization code for the victim's real IdP login. Because this is a confidential-client, non-PKCE flow, standard OAuth2 semantics mean the code is a bearer credential: whoever redeems it first (with the client_secret, which only Logto's server holds, and the exact redirect_uri originally used, which is unaffected by this bug) succeeds — regardless of which browser/session performed the original authorization request to the IdP.
  7. The attacker, using their own browser/session (the same one that minted state in step 0, and whose interaction record already has the matching connectorSession stored server-side via assignConnectorSessionResult in packages/core/src/libraries/verification-helpers/social-verification.ts:44-59, keyed off the OIDC provider's own interaction cookie for the requester), calls POST /api/experience/verification/social/:connectorId/verify with connectorData: { code: <leaked victim code>, state: <attacker's state> }. The server-side state check passes (it matches what the attacker's own session stored), the code exchange with the IdP succeeds (valid, unused code, correct client_id/secret/redirect_uri), and Logto fetches the victim's real IdP identity and binds it to the attacker's interaction/verification session (SocialVerification.verify in packages/core/src/routes/experience/classes/verifications/social-verification.ts:159-174).
  8. The attacker completes the interaction (identifyAndSubmitInteraction) from their own session, resulting in Logto signing the attacker in as the Logto account linked to the victim's social identity (or creating/linking a new account bound to the victim's verified email/identity, depending on tenant settings) — full account takeover, entirely from the attacker's own browser.

Data Flow (source → sink → redemption)

  • Source: native_callback (and redirect_to) query parameters on GET /social/landing/:connectorId, fully attacker-controlled, no authentication.
  • Poison: storeCallbackLink(connectorId, nativeCallbackLink) → sessionStorage['social_callback_data:<connectorId>'] (packages/experience/src/utils/social-connectors.ts:107-109).
  • Trigger: Victim completes a genuine IdP login flow (state pre-minted by attacker via the unauthenticated POST .../social/:connectorId/authorization-uri endpoint) and lands on GET /callback/:connectorId?code=...&state=....
  • Sink (exfiltration): window.location.replace(new URL(\${callbackLink}${search}\)) in packages/experience/src/pages/Callback/use-social-callback-handler.ts:28, sending code+state to the attacker's poisoned URL.
  • Redemption: Attacker calls POST /api/experience/verification/social/:connectorId/verify (packages/core/src/routes/experience/verification-routes/social-verification.ts:83-169) from their own session with the leaked code/state; server-side redemption is bound only to the requester's own interaction session via getConnectorSessionResult(ctx, provider) (packages/core/src/libraries/verification-helpers/social-verification.ts:120-124 region), with no cross-check that the same browser/session performed the original IdP authorization request.

Attack Scenario

See "Why It's Vulnerable" above for the full numbered chain. In short: attacker self-mints a valid authorizationUri+state, embeds it plus a malicious native_callback in a single link to the real tenant domain, lures the victim into completing a genuine third-party login through that link, and then redeems the leaked authorization code themselves to authenticate as the victim's linked identity.

Impact

  • Who is affected: Any tenant using social sign-in or enterprise SSO connectors (the same buildSocialLandingUri/native_callback handoff is shared by both, per use-social.ts:38-49 and use-single-sign-on.ts:32-42). Victim must click a crafted link and complete a real login with their own IdP credentials, believing they are signing in normally (the flow looks and behaves identically to a legitimate sign-in, including a real IdP consent screen).
  • What attacker achieves: Authentication as the victim's Logto account (or creation of an attacker-controlled account bound to the victim's verified social/SSO identity), i.e., full account takeover, without ever knowing the victim's Logto password or possessing any of the victim's credentials — the only thing exfiltrated is a short-lived OAuth authorization code.
  • Conditions required: Victim must click the crafted link and complete a genuine third-party login through it. No authentication is required for the attacker to prepare the attack (self-minting state/authorizationUri) or to redeem the leaked code.

Recommended Fix

  1. Fix the root-cause open redirect first (see findings/VULN-015-experience-client-side-open-redirect.md) so redirect_to cannot point off-origin.
  2. Independently, validate native_callback before storing it: only accept values matching an allow-listed native-app URI scheme (e.g., configured per first-party mobile app, not an arbitrary https:// URL), rejecting anything that isn't a registered custom scheme:
// packages/experience/src/pages/SocialLanding/use-social-landing-handler.ts
const nativeCallbackLink = getSearchParameters(search, SearchParameters.NativeCallbackLink);
if (nativeCallbackLink && isAllowedNativeCallbackScheme(nativeCallbackLink)) {
  storeCallbackLink(connectorId, nativeCallbackLink);
} else if (nativeCallbackLink) {
  // reject silently or show an error — do not store an unvalidated value
}
  1. Defense in depth on the server side: bind the state value's validity to a value the server itself generates and signs (rather than accepting an arbitrary client-chosen string), and/or require PKCE (code_verifier/code_challenge) for the social/SSO authorization-uri + verify pair, so that redeeming a leaked code also requires a code_verifier that only the browser which initiated the original request possesses. This closes the interception window even if a code is exfiltrated by any future bug of this shape.

Why the fix works: Restricting native_callback to genuinely registered native schemes removes the exfiltration sink; adding PKCE removes the ability for a different session (the attacker's) to redeem a code obtained via a different browser's (the victim's) completed IdP login, which is the standard mitigation for authorization code interception (RFC 9700 / OAuth 2.0 Security Best Current Practice).

References

Affected versions

References

GitHub · logto-io/logto