Skip to content

getHashFragmentParams incorrectly decodes entire hash fragment #1466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
u-mikhalenka opened this issue Mar 12, 2025 · 1 comment
Open

getHashFragmentParams incorrectly decodes entire hash fragment #1466

u-mikhalenka opened this issue Mar 12, 2025 · 1 comment

Comments

@u-mikhalenka
Copy link

Bug: getHashFragmentParams incorrectly decodes entire hash fragment

Description

The UrlHelperService.getHashFragmentParams method is prematurely decoding the entire URL hash fragment with decodeURIComponent before parsing individual parameters. This causes issues when parameter values contain encoded special characters, particularly with Azure AD and implicit flow.

Steps to reproduce

  1. Use implicit flow with Azure AD
  2. Perform a silent refresh operation
  3. When silent refresh fails, Azure AD returns a hash fragment containing parameters including error_uri which contains encoded URL characters

Current behavior

The hash fragment from Azure AD like:

#error=login_required&error_description=AADSTS50058%3a+A+silent+sign-in+request...&error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d50058&state=...

Is decoded prematurely with:

hash = decodeURIComponent(hash);

This decodes error_uri value to include a literal ? character, which then breaks the subsequent parsing because the question mark is interpreted as a parameter delimiter.

Expected behavior

The hash fragment should not be decoded as a whole. Instead, decoding should only be applied to individual parameters after they've been properly parsed into key-value pairs, which is already handled in the parseQueryString method:

key = decodeURIComponent(escapedKey);
value = decodeURIComponent(escapedValue);

Fix suggestion

Remove the line hash = decodeURIComponent(hash); from the getHashFragmentParams method, allowing parseQueryString to handle decoding each parameter individually.

@u-mikhalenka
Copy link
Author

Also, userState part must be decoded in parseState method.

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

No branches or pull requests

1 participant