Skip to content

Commit 2e43e31

Browse files
committed
Honour proxy forwarded headers for Azure App Service
Process X-Forwarded-For/Proto before HTTPS redirection so the app sees the original scheme behind App Service's TLS-terminating load balancer, avoiding a redirect loop in production.
1 parent a2103f1 commit 2e43e31

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/Qwertide.Api/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.AspNetCore.HttpOverrides;
12
using Microsoft.EntityFrameworkCore;
23
using Qwertide.Api.Data;
34

@@ -39,6 +40,17 @@
3940
app.UseSwaggerUI();
4041
}
4142

43+
// Trust the X-Forwarded-* headers Azure App Service's load balancer sets, so
44+
// the app sees the original HTTPS scheme instead of looping on redirect behind
45+
// the TLS-terminating proxy.
46+
var forwardedHeaders = new ForwardedHeadersOptions
47+
{
48+
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
49+
};
50+
forwardedHeaders.KnownNetworks.Clear();
51+
forwardedHeaders.KnownProxies.Clear();
52+
app.UseForwardedHeaders(forwardedHeaders);
53+
4254
app.UseHttpsRedirection();
4355

4456
// Serve the Blazor WASM client this API is bundled with (single-service deploy).

0 commit comments

Comments
 (0)