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:
1 parent
b9f2b0443c
commit
9a56fc5b48
31 files changed
+335
-462
No files matched your search
@@ -1,9 +1,9 @@
|
||||
using Flypaper.Core;
|
||||
using Flypaper.Core.Settings;
|
||||
using Flypaper.Http;
|
||||
using Flypaper.Http.Matching;
|
||||
using Flypaper.Storage;
|
||||
using Flypaper.Storage.Entities;
|
||||
using Flypaper.Storage.Maintenance;
|
||||
using Flypaper.Storage.Settings;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -28,8 +28,8 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
await db.Database.MigrateAsync();
|
||||
db.Settings.AddRange(
|
||||
new SettingEntity { Key = SettingKeys.MaxConnections, Value = "5" },
|
||||
new SettingEntity { Key = SettingKeys.TrapPaths, Value = "/custom\n/other/*" },
|
||||
new SettingEntity { Key = SettingKeys.ExtraKnownHosts, Value = "extra.example" },
|
||||
new SettingEntity { Key = SettingKeys.RetentionDays, Value = "30" },
|
||||
new SettingEntity { Key = "Flypaper:Http:TrustedProxies:0", Value = "203.0.113.0/24" },
|
||||
new SettingEntity { Key = "Flypaper:Admin:Password", Value = "evil" });
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
@@ -38,14 +38,12 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
await host.Services.MigrateFlypaperDatabaseAsync();
|
||||
|
||||
var core = host.Services.GetRequiredService<IOptionsMonitor<FlypaperOptions>>().CurrentValue;
|
||||
var http = host.Services.GetRequiredService<IOptionsMonitor<HttpTrapOptions>>().CurrentValue;
|
||||
var configuration = host.Services.GetRequiredService<IConfiguration>();
|
||||
|
||||
core.MaxConnections.ShouldBe(5);
|
||||
core.MaxConnectionsPerIp.ShouldBe(10);
|
||||
http.TrapPaths.ShouldBe(["/custom", "/other/*"]);
|
||||
http.KnownHosts.ShouldBe(["dashboard.lan", "extra.example"]);
|
||||
http.TrustedProxies.ShouldBe(["172.18.0.0/16"]);
|
||||
host.Services.GetRequiredService<IOptionsMonitor<RetentionOptions>>().CurrentValue.Days.ShouldBe(30);
|
||||
host.Services.GetRequiredService<IOptionsMonitor<HttpTrapOptions>>().CurrentValue.TrustedProxies.ShouldBe(["172.18.0.0/16"]);
|
||||
configuration["Flypaper:Admin:Password"].ShouldBe("secret");
|
||||
}
|
||||
|
||||
@@ -56,61 +54,31 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
await host.Services.MigrateFlypaperDatabaseAsync();
|
||||
|
||||
host.Services.GetRequiredService<IOptionsMonitor<FlypaperOptions>>().CurrentValue.MaxConnections.ShouldBe(100);
|
||||
host.Services.GetRequiredService<IOptionsMonitor<HttpTrapOptions>>().CurrentValue.TrapPaths.ShouldBe(["/.env"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Saving_reloads_trap_matcher_and_reset_restores_startup_values()
|
||||
public async Task Saving_reloads_options_and_reset_restores_startup_values()
|
||||
{
|
||||
var host = BuildHost();
|
||||
await host.Services.MigrateFlypaperDatabaseAsync();
|
||||
var matcher = host.Services.GetRequiredService<TrapMatcher>();
|
||||
var options = host.Services.GetRequiredService<IOptionsMonitor<FlypaperOptions>>();
|
||||
var store = host.Services.GetRequiredService<RuntimeSettingsStore>();
|
||||
|
||||
matcher.Match("dashboard.lan", "/custom").ShouldBe(TrapMatch.None);
|
||||
matcher.Match("dashboard.lan", "/.env").ShouldBe(TrapMatch.TrapPath);
|
||||
matcher.Match("extra.example", "/").ShouldBe(TrapMatch.UnknownHost);
|
||||
await store.SaveAsync(new RuntimeSettings(50, 4, TimeSpan.FromMinutes(10), 90, false));
|
||||
|
||||
await store.SaveAsync(new RuntimeSettings(
|
||||
["/custom"],
|
||||
50,
|
||||
4,
|
||||
TimeSpan.FromMinutes(10),
|
||||
["extra.example"],
|
||||
90,
|
||||
true));
|
||||
|
||||
matcher.Match("dashboard.lan", "/custom").ShouldBe(TrapMatch.TrapPath);
|
||||
matcher.Match("dashboard.lan", "/.env").ShouldBe(TrapMatch.None);
|
||||
matcher.Match("extra.example", "/").ShouldBe(TrapMatch.None);
|
||||
options.CurrentValue.MaxConnections.ShouldBe(50);
|
||||
options.CurrentValue.MaxConnectionsPerIp.ShouldBe(4);
|
||||
options.CurrentValue.MaxHoldDuration.ShouldBe(TimeSpan.FromMinutes(10));
|
||||
options.CurrentValue.IgnorePrivateNetworks.ShouldBeFalse();
|
||||
(await store.HasOverridesAsync()).ShouldBeTrue();
|
||||
|
||||
await store.ResetAsync();
|
||||
|
||||
matcher.Match("dashboard.lan", "/custom").ShouldBe(TrapMatch.None);
|
||||
matcher.Match("dashboard.lan", "/.env").ShouldBe(TrapMatch.TrapPath);
|
||||
options.CurrentValue.MaxConnections.ShouldBe(100);
|
||||
options.CurrentValue.IgnorePrivateNetworks.ShouldBeTrue();
|
||||
(await store.HasOverridesAsync()).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Saved_empty_trap_path_list_disables_path_traps()
|
||||
{
|
||||
var host = BuildHost();
|
||||
await host.Services.MigrateFlypaperDatabaseAsync();
|
||||
var matcher = host.Services.GetRequiredService<TrapMatcher>();
|
||||
|
||||
await host.Services.GetRequiredService<RuntimeSettingsStore>().SaveAsync(new RuntimeSettings(
|
||||
[],
|
||||
50,
|
||||
4,
|
||||
TimeSpan.FromMinutes(10),
|
||||
[],
|
||||
90,
|
||||
true));
|
||||
|
||||
matcher.Match("dashboard.lan", "/.env").ShouldBe(TrapMatch.None);
|
||||
}
|
||||
|
||||
private IHost BuildHost()
|
||||
{
|
||||
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true });
|
||||
@@ -119,8 +87,6 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
["ConnectionStrings:Flypaper"] = $"Data Source={_dbPath}",
|
||||
["Flypaper:MaxConnections"] = "100",
|
||||
["Flypaper:MaxConnectionsPerIp"] = "10",
|
||||
["Flypaper:Http:TrapPaths:0"] = "/.env",
|
||||
["Flypaper:Http:KnownHosts:0"] = "dashboard.lan",
|
||||
["Flypaper:Http:TrustedProxies:0"] = "172.18.0.0/16",
|
||||
["Flypaper:Admin:Password"] = "secret"
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user