Skip to content

Commit 859fa99

Browse files
authored
Merge pull request #1 from willysoft/validate-allowports
fix: add validation for empty AllowPorts in local port filtering
2 parents 2cb1bf7 + 3437311 commit 859fa99

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

src/LocalPortFiltering.AspNetCore/LocalPortFilteringMiddleware.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public Task Invoke(HttpContext context)
5151
if (exceptionHandler == null)
5252
return m_Next(context);
5353

54+
if (exceptionHandler.AllowPorts == null || exceptionHandler.AllowPorts.Count == 0)
55+
return HostValidationFailed(context);
5456
if (!exceptionHandler.AllowPorts.Contains(context.Connection.LocalPort))
5557
return HostValidationFailed(context);
5658

test/LocalPortFiltering.AspNetCore.Tests/LocalPortFilteringMiddlewareTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public async Task LocalPortFiltering_DefaultBehavior()
4343

4444
[Theory]
4545
[InlineData(200, 443, new int[] { 443 })]
46+
[InlineData(403, 443, new int[] { })]
4647
[InlineData(403, 80, new int[] { 443 })]
4748
[InlineData(200, 3000, new int[] { 3000, 3001 })]
4849
[InlineData(403, 4000, new int[] { 3000, 3001 })]

0 commit comments

Comments
 (0)