Skip to content

Commit 5f15bce

Browse files
committed
Validation.
1 parent 583de65 commit 5f15bce

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/ModelContextProtocol/Auth/AuthorizationConfigExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ public static AuthorizationConfig UseHttpListener(
6060

6161
/// <summary>
6262
/// Default implementation to open a URL in the default browser.
63+
/// Only allows http and https URLs to be opened for security reasons.
6364
/// </summary>
6465
private static Task DefaultOpenBrowser(string url)
6566
{
6667
try
6768
{
69+
// Validate that the URL is using http or https protocol
70+
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) ||
71+
(uri.Scheme != "http" && uri.Scheme != "https"))
72+
{
73+
return Task.FromException(new ArgumentException("Only HTTP or HTTPS URLs can be opened.", nameof(url)));
74+
}
75+
6876
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
6977
{
7078
// On Windows, use the built-in Process.Start for URLs

0 commit comments

Comments
 (0)