Skip to content

Commit 329da7f

Browse files
committed
browser: open AbsoluteUri to avoid double-escaping
GCM launches the system browser for interactive OAuth by handing the authorization URL to the OS "shell execute" handler. On macOS that is /usr/bin/open, which validates the URL and, on finding any character that is not legal in a fully percent-encoded URL, re-encodes the whole query string. That step double-escapes parameters we had already encoded -- redirect_uri=http%3A%2F%2F... becomes redirect_uri=http%253A%252F%252F... -- and the authorization server rejects the redirect. Windows ShellExecuteEx forwards the string verbatim, so only macOS is affected. The trigger was a raw space in the query. Uri.ToString() is a display form that unescapes %20 back to a literal space (while leaving %2F alone), so building the launch string that way reintroduced spaces, most easily via the space-delimited scope parameter. This surfaced after MSAL began encoding spaces[1] as %20 rather than +; a literal + is left untouched by ToString(), which had masked the problem. Uri.AbsoluteUri keeps the query fully percent-encoded, so %20 stays %20 and macOS open accepts the URL unchanged. [1]: AzureAD/microsoft-authentication-library-for-dotnet#5128 Assisted-by: Claude Opus 4.8 Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 1c0b910 commit 329da7f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎src/Core/ISessionManager.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public void OpenBrowser(Uri uri)
6767
throw new ArgumentException("Can only open HTTP/HTTPS URIs", nameof(uri));
6868
}
6969

70+
// Important! Use AbsoluteUri to ensure that the URL is properly
71+
// escaped (e.g. spaces are converted to %20).
72+
// The 'shell execute' handler on some operating systems (e.g. macOS)
73+
// will try to validate the URL handed to it and if it sees any
74+
// unescaped characters it will decide that the rest of the query
75+
// parameters also need esacaping leading to double escaping!
7076
OpenBrowserInternal(uri.AbsoluteUri);
7177
}
7278

0 commit comments

Comments
 (0)