Repair cross-platform lockfile and verify secure production login behind Nginx
This commit is contained in:
@@ -8,8 +8,11 @@ using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using System.Net;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var bootstrap = args.Contains("--bootstrap");
|
||||
var builder = WebApplication.CreateBuilder(args.Where(arg => arg != "--bootstrap").ToArray());
|
||||
builder.Logging.ClearProviders(); builder.Logging.AddConsole();
|
||||
builder.Logging.AddFilter("Microsoft.AspNetCore.Hosting.Diagnostics", LogLevel.Warning);
|
||||
builder.Logging.AddFilter("System.Net.Http.HttpClient", LogLevel.Warning);
|
||||
@@ -38,6 +41,15 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc
|
||||
};
|
||||
});
|
||||
builder.Services.AddAuthorization(o => o.AddPolicy("Owner", p => p.RequireRole("Owner")));
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(o =>
|
||||
{
|
||||
// Trust only HTTPS information from the configured host reverse proxy.
|
||||
// Client IP forwarding remains disabled until per-client limits are introduced.
|
||||
o.ForwardedHeaders = ForwardedHeaders.XForwardedProto;
|
||||
o.ForwardLimit = 1;
|
||||
if (builder.Configuration["Proxy:KnownAddress"] is { Length: > 0 } address)
|
||||
o.KnownProxies.Add(IPAddress.Parse(address));
|
||||
});
|
||||
builder.Services.AddAntiforgery(o => { o.HeaderName = "X-CSRF-TOKEN"; o.Cookie.Name = "guestops.csrf"; o.Cookie.HttpOnly = true; o.Cookie.SameSite = SameSiteMode.Strict; o.Cookie.SecurePolicy = preview ? CookieSecurePolicy.SameAsRequest : CookieSecurePolicy.Always; });
|
||||
builder.Services.AddRateLimiter(o =>
|
||||
{
|
||||
@@ -45,9 +57,10 @@ builder.Services.AddRateLimiter(o =>
|
||||
o.AddPolicy("login", context => RateLimitPartition.GetFixedWindowLimiter(context.Connection.RemoteIpAddress?.ToString() ?? "unknown", _ => new() { PermitLimit = 10, Window = TimeSpan.FromMinutes(1), QueueLimit = 0 }));
|
||||
});
|
||||
var app = builder.Build();
|
||||
app.UseForwardedHeaders();
|
||||
var store = app.Services.GetRequiredService<IStore>();
|
||||
await store.Initialize();
|
||||
if (args.Contains("--bootstrap"))
|
||||
if (bootstrap)
|
||||
{
|
||||
var email = Environment.GetEnvironmentVariable("BOOTSTRAP_EMAIL")?.Trim().ToLowerInvariant() ?? "";
|
||||
var password = Environment.GetEnvironmentVariable("BOOTSTRAP_PASSWORD") ?? "";
|
||||
|
||||
Reference in New Issue
Block a user