Skip to content

Commit 235b047

Browse files
fix: improve ignore path matching to prevent false positives
Updated IsIgnoredPath in DebugProbeMiddleware to use boundary-aware matching. The logic now strictly checks for an exact match (path.Equals) or a valid child path by appending a trailing slash (path.StartsWith(ignorePath.TrimEnd('/') + "/")).
2 parents bf6f710 + 3eb20b6 commit 235b047

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

DebugProbe.AspNetCore.Tests/Middleware/MiddlewareExecutionFlowTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public async Task Ignored_paths_are_skipped()
4141
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
4242
Assert.Empty(app.Store.GetAll());
4343
}
44+
[Fact]
45+
public async Task Similar_paths_are_not_skipped()
46+
{
47+
await using var app = await DebugProbeTestApp.CreateAsync(
48+
endpoints => endpoints.MapGet("/healthcare", () => Results.Ok()),
49+
options => options.IgnorePaths = ["/health"]);
50+
51+
var response = await app.Client.GetAsync("/healthcare");
52+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
53+
Assert.Single(app.Store.GetAll());
54+
}
4455

4556
[Theory]
4657
[InlineData("/health")]

DebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ private bool IsIgnoredPath(PathString requestPath)
162162
return DefaultIgnorePaths
163163
.Concat(_options.IgnorePaths)
164164
.Distinct(StringComparer.OrdinalIgnoreCase)
165-
.Any(ignorePath => path.StartsWith(ignorePath, StringComparison.OrdinalIgnoreCase));
165+
.Any(ignorePath =>
166+
path.Equals(ignorePath, StringComparison.OrdinalIgnoreCase) ||
167+
path.StartsWith(ignorePath.TrimEnd('/') + "/", StringComparison.OrdinalIgnoreCase));
166168
}
167169

168170
private static async Task<string> CaptureRequestBodyAsync(HttpContext context, int maxBodySize)

0 commit comments

Comments
 (0)