fix: strip hash fragment when comparing redirect vs current URL (closes #2143)#2220
Open
FabianGosebrink wants to merge 2 commits into
Open
fix: strip hash fragment when comparing redirect vs current URL (closes #2143)#2220FabianGosebrink wants to merge 2 commits into
FabianGosebrink wants to merge 2 commits into
Conversation
The file was checked in with mixed CRLF/CR/LF line endings, which git's auto-detection treated as binary (-text). Re-encode to LF to match the rest of the repo (core.autocrlf = input). No semantic changes — only line-ending bytes differ. Committed separately so the bug-fix in the next commit shows a clean diff.
Issue #2143: Facebook appends "#_=_" to OAuth redirect URLs. With `checkRedirectUrlWhenCheckingIfIsCallback: true`, the trailing fragment made `currentUrl != redirectUrl` after stripping the query string, so `isCallbackFromSts` returned false. The page got stuck on the callback URL because the library no longer recognised it as an STS response. The same root cause breaks implicit flow: the IdP returns the auth response in the URL fragment by design (`#access_token=...&state=...`), which the comparison treated as making the URLs unequal. Fix: `getUrlWithoutQueryParameters` now also clears the fragment, so the base-URL comparison only considers scheme/host/path. The query- params-must-be-present-in-current-url check below is unchanged and continues to enforce that the redirect URL's own query parameters were preserved. Adds tests for: - the helper: hash is stripped along with query - isCallbackFromSts: Facebook's "#_=_" trailing fragment - isCallbackFromSts: implicit flow's response fragment Full lib test suite passes; lint clean. Fixes #2143
Owner
|
This looks like a previous PR already in the repo. I need to verify, if the causes new bugs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UrlService.getUrlWithoutQueryParametersnow also clearsu.hash. That's the entire production change — 1 line + a comment. Closes #2143 (Facebook#_=_callback stuck) and fixes a related implicit-flow regression two commenters reported on the same issue.Two commits so the diff is reviewable:
chore: normalize line endings on url.service.spec.ts— the spec file was checked in with mixed CRLF/CR/LF (git treated it as-text/binary). Re-encode to LF to match the rest of the repo. No semantic change.fix: strip hash fragment when comparing redirect vs current URL— the actual fix + 3 new tests.The bug
With
checkRedirectUrlWhenCheckingIfIsCallback: true,isCallbackFromStscomparedcurrentUrlandredirectUrlafter stripping the query string. The hash fragment was kept. Two providers were silently broken:"#_=_"to OAuth redirects (known behavior). Result:https://app.com/cb?code=…#_=_was rejected becausehttps://app.com/cb#_=_≠https://app.com/cb.#access_token=…&state=…). Same root cause: the fragment made the URL strings unequal.Both reported in #2143 — original author for Facebook, two follow-up commenters for implicit flow and a regression on the v17→v20 upgrade.
The fix
keys.forEach((key) => { u.searchParams.delete(key); }); +// Also drop the hash fragment. Some identity providers (e.g. Facebook) +// append "#_=_" to their redirect URL, and implicit flow puts the auth +// response in the fragment by design. Either way, the fragment is not +// part of the configured redirect URL and must not factor into the +// base-URL comparison done by isCallbackFromSts. +// https://github.com/damienbod/angular-auth-oidc-client/issues/2143 +u.hash = ''; return u;The companion check (the configured redirect's query parameters must all be present on the current URL) is unchanged — it still defends against partial-match callback URLs.
Does it change behaviour?
Yes — but only in the direction the bug report demands.
isCallbackFromStsmay now returntruein cases where it previously (incorrectly) returnedfalse: specifically, whencurrentUrlcarries a hash fragment that the configuredredirectUrldoesn't have. That covers the Facebook + implicit-flow cases above.trueresult intofalse. Nothing that worked before stops working.The only edge case would be a user who configures
redirectUrlwith a hash fragment (e.g.https://app.com/cb#foo) and expects the fragment to be enforced. That's against the OAuth spec (RFC 6749 §3.1.2: redirect URI MUST NOT include a fragment) and would have been broken in other ways even before this PR.Internal helper note:
getUrlWithoutQueryParametersis now slightly misnamed (it also strips the fragment). The method isn't exported via the lib'sindex.tsso the rename can happen separately if you want. Left as-is here to keep the fix minimal.Test plan
getUrlWithoutQueryParametersalso strips the hashisCallbackFromSts: Facebook#_=_regressionisCallbackFromSts: implicit-flow fragmentnpm run lint-libclean🤖 Generated with Claude Code