Fixed Elmah accessible outside of development environment

This commit is contained in:
2025-06-15 14:11:04 +02:00
parent 7d566cd921
commit 1da78b8356

View File

@@ -32,7 +32,22 @@ builder.Services.AddElmah<XmlFileErrorLog>(Options =>
});
var app = builder.Build();
app.UseElmah();
app.Map("/elmah", builder => // Add a middleware before Elmah that authorizes only the development environment
{
builder.Use(async (context, next) =>
{
if (!app.Environment.IsDevelopment()) // TODO add configuration option to allow for elmah (i.e. opt-in)
{
context.Response.StatusCode = 403;
await context.Response.WriteAsync("Forbidden");
return;
}
await next();
});
builder.UseElmah();
});
app.MapHealthChecks("/healthz");
// Configure the HTTP request pipeline.