Separate dashboard port, first-run password setup and default trusted proxies

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 17:21:49 +01:00
1 parent a34ff96490
commit c22d452720
25 files changed
+654 -109

No files matched your search

+6 -1
View File
@@ -14,9 +14,12 @@ namespace Flypaper.Http;
public static class FlypaperHttpExtensions
{
private static readonly string[] DefaultTrustedProxies = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7"];
public static IServiceCollection AddFlypaperHttp(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<HttpTrapOptions>(configuration.GetSection(HttpTrapOptions.SectionName));
services.Configure<PortOptions>(configuration.GetSection(PortOptions.SectionName));
services.PostConfigure<HttpTrapOptions>(options =>
{
if (options.TrapPathsOverride is not null)
@@ -33,7 +36,9 @@ public static class FlypaperHttpExtensions
{
forwarded.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
forwarded.ForwardLimit = 1;
foreach (var proxy in trap.Value.TrustedProxies)
var configured = trap.Value.TrustedProxies.Where(proxy => !string.IsNullOrWhiteSpace(proxy)).ToArray();
var proxies = configured.Length > 0 ? configured : DefaultTrustedProxies;
foreach (var proxy in proxies)
{
forwarded.KnownIPNetworks.Add(System.Net.IPNetwork.Parse(proxy.Contains('/') ? proxy : $"{proxy}/{HostBits(proxy)}"));
}
@@ -7,6 +7,7 @@ using Flypaper.Http.Matching;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
using Microsoft.Extensions.Options;
namespace Flypaper.Http.Middleware;
@@ -14,17 +15,24 @@ internal sealed class FlypaperMiddleware(
RequestDelegate next,
TrapMatcher matcher,
TrapRunner runner,
IOptions<PortOptions> ports,
TimeProvider timeProvider)
{
public async Task InvokeAsync(HttpContext context)
{
var request = context.Request;
if (IsInternalHealthProbe(context) || matcher.Match(request.Host.Host, request.Path.Value) == TrapMatch.None)
if (context.Connection.LocalPort == ports.Value.Dashboard || IsInternalHealthProbe(context))
{
await next(context);
return;
}
var request = context.Request;
if (matcher.Match(request.Host.Host, request.Path.Value) == TrapMatch.None)
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
return;
}
var session = new TrapSession(
Guid.NewGuid(),
TrapProtocol.Http,
+10
View File
@@ -0,0 +1,10 @@
namespace Flypaper.Http;
public sealed class PortOptions
{
public const string SectionName = "Flypaper:Ports";
public int Trap { get; set; } = 8080;
public int Dashboard { get; set; } = 8081;
}