Update sample with URI validation (#824)

This commit is contained in:
Den Delimarsky 2025-10-03 10:00:51 -07:00 • committed by GitHub
commit 445ea42adc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -134,6 +134,13 @@ static async Task<string?> HandleAuthorizationUrlAsync(Uri authorizationUrl, Uri
/// <param name="url">The URL to open.</param> /// <param name="url">The URL to open.</param>
static void OpenBrowser(Uri url) static void OpenBrowser(Uri url)
{ {
// Validate the URI scheme - only allow safe protocols
if (url.Scheme != Uri.UriSchemeHttp && url.Scheme != Uri.UriSchemeHttps)
{
Console.WriteLine($"Error: Only HTTP and HTTPS URLs are allowed.");
return;
}
try try
{ {
var psi = new ProcessStartInfo var psi = new ProcessStartInfo
@ -145,7 +152,7 @@ static void OpenBrowser(Uri url)
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error opening browser. {ex.Message}"); Console.WriteLine($"Error opening browser: {ex.Message}");
Console.WriteLine($"Please manually open this URL: {url}"); Console.WriteLine($"Please manually open this URL: {url}");
} }
} }