Skip to content

Commit 445ea42

Browse files
authored
Update sample with URI validation (#824)
1 parent 47b9582 commit 445ea42

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

samples/ProtectedMcpClient/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@
134134
/// <param name="url">The URL to open.</param>
135135
static void OpenBrowser(Uri url)
136136
{
137+
// Validate the URI scheme - only allow safe protocols
138+
if (url.Scheme != Uri.UriSchemeHttp && url.Scheme != Uri.UriSchemeHttps)
139+
{
140+
Console.WriteLine($"Error: Only HTTP and HTTPS URLs are allowed.");
141+
return;
142+
}
143+
137144
try
138145
{
139146
var psi = new ProcessStartInfo
@@ -145,7 +152,7 @@ static void OpenBrowser(Uri url)
145152
}
146153
catch (Exception ex)
147154
{
148-
Console.WriteLine($"Error opening browser. {ex.Message}");
155+
Console.WriteLine($"Error opening browser: {ex.Message}");
149156
Console.WriteLine($"Please manually open this URL: {url}");
150157
}
151158
}

0 commit comments

Comments
 (0)