Remove trap paths and known hosts: catch everything on the trap port

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-15 18:56:35 +01:00
1 parent b9f2b0443c
commit 9a56fc5b48
31 files changed
+335 -462

No files matched your search

+30 -22
View File
@@ -1,6 +1,7 @@
using System.Net;
using Flypaper.Core;
using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
using Flypaper.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
@@ -31,42 +32,49 @@ public sealed class PortSeparationTests
[Theory]
[InlineData("unknown.example", "/")]
[InlineData("203.0.113.7", "/settings")]
[InlineData("example.com", "/")]
[InlineData("example.com", "/.env")]
[InlineData("example.com", "/login")]
[InlineData("", "/wp-login.php")]
[InlineData("unknown.example", "/mcp")]
[InlineData("203.0.113.7", "/mcp")]
public async Task Trap_port_traps_unknown_hosts_and_trap_paths(string host, string path)
{
var (reachedApp, status) = await SendAsync(TrapPort, host, path);
reachedApp.ShouldBeFalse();
status.ShouldBe(StatusCodes.Status404NotFound);
}
[Theory]
[InlineData("/")]
[InlineData("/settings")]
[InlineData("/login")]
[InlineData("/mcp")]
public async Task Trap_port_answers_other_paths_of_known_hosts_with_plain_404(string path)
[InlineData("203.0.113.7", "/health")]
public async Task Trap_port_catches_every_host_and_path(string host, string path)
{
var sink = Substitute.For<ITrapEventSink>();
var (reachedApp, status) = await SendAsync(TrapPort, "example.com", path, sink);
var (reachedApp, status) = await SendAsync(TrapPort, host, path, sink);
reachedApp.ShouldBeFalse();
status.ShouldBe(StatusCodes.Status404NotFound);
sink.DidNotReceiveWithAnyArgs().Publish(default!);
sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Outcome == TrapOutcome.Rejected));
}
private static async Task<(bool ReachedApp, int Status)> SendAsync(int localPort, string host, string path, ITrapEventSink? sink = null)
[Fact]
public async Task Removed_settings_change_nothing()
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
var (reachedApp, _) = await SendAsync(
TrapPort,
"example.com",
"/",
extraSettings: new Dictionary<string, string?>
{
["Flypaper:MaxConnections"] = "0",
["Flypaper:Http:KnownHosts:0"] = "example.com",
["Flypaper:Http:TrapPaths:0"] = "/.env"
})
});
reachedApp.ShouldBeFalse();
}
private static async Task<(bool ReachedApp, int Status)> SendAsync(
int localPort,
string host,
string path,
ITrapEventSink? sink = null,
Dictionary<string, string?>? extraSettings = null)
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?> { ["Flypaper:MaxConnections"] = "0" })
.AddInMemoryCollection(extraSettings ?? [])
.Build();
var services = new ServiceCollection()