Skip to content

Commit 417bc49

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 751990d commit 417bc49

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/Service/HealthCheck/HttpUtilities.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,30 @@ public HttpUtilities(
142142
string? errorMessage = null;
143143
try
144144
{
145-
if (string.IsNullOrEmpty(mcpUriSuffix))
145+
if (string.IsNullOrWhiteSpace(mcpUriSuffix))
146146
{
147-
_logger.LogError("The MCP route is not available, hence HealthEndpoint is not available.");
148-
return errorMessage;
147+
const string msg = "MCP path is not configured.";
148+
_logger.LogError(msg);
149+
return msg;
150+
}
151+
152+
if (_httpClient.BaseAddress is null)
153+
{
154+
const string msg = "Health check HTTP client BaseAddress is not configured.";
155+
_logger.LogError(msg);
156+
return msg;
149157
}
150158

151-
if (!Program.CheckSanityOfUrl($"{_httpClient.BaseAddress}{mcpUriSuffix.TrimStart('/')}"))
159+
// Ensure the configured MCP path cannot override the host (e.g. absolute URIs).
160+
if (!Uri.TryCreate(mcpUriSuffix, UriKind.Relative, out _))
161+
{
162+
_logger.LogError("Blocked outbound request due to invalid or unsafe URI.");
163+
return "Blocked outbound request due to invalid or unsafe URI.";
164+
}
165+
166+
Uri requestUri = new(_httpClient.BaseAddress, mcpUriSuffix);
167+
168+
if (!Program.CheckSanityOfUrl(requestUri.AbsoluteUri))
152169
{
153170
_logger.LogError("Blocked outbound request due to invalid or unsafe URI.");
154171
return "Blocked outbound request due to invalid or unsafe URI.";
@@ -157,10 +174,10 @@ public HttpUtilities(
157174
string jsonPayload = Utilities.CreateHttpMcpQuery();
158175
HttpContent content = new StringContent(jsonPayload, Encoding.UTF8, Utilities.JSON_CONTENT_TYPE);
159176

160-
HttpRequestMessage message = new(method: HttpMethod.Post, requestUri: mcpUriSuffix)
177+
HttpRequestMessage message = new(method: HttpMethod.Post, requestUri: requestUri)
161178
{
162179
Content = content
163-
};
180+
}
164181

165182
// The MCP Streamable HTTP transport requires the client to accept both
166183
// JSON and SSE responses.

0 commit comments

Comments
 (0)