Skip to content

Commit 0ea5ae5

Browse files
authored
Document .NET 8 breaking change: Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies (#47985)
1 parent bca4b25 commit 0ea5ae5

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

docs/core/compatibility/8.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ If you're migrating an app to .NET 8, the breaking changes listed here might aff
1717
| ---------------------------------------------------------------------------------------------------- | ------------------- |
1818
| [ConcurrencyLimiterMiddleware is obsolete](aspnet-core/8.0/concurrencylimitermiddleware-obsolete.md) | Source incompatible |
1919
| [Custom converters for serialization removed](aspnet-core/8.0/problemdetails-custom-converters.md) | Behavioral change |
20+
| [Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies](aspnet-core/8.0/forwarded-headers-unknown-proxies.md) | Behavioral change |
2021
| [ISystemClock is obsolete](aspnet-core/8.0/isystemclock-obsolete.md) | Source incompatible |
2122
| [Minimal APIs: IFormFile parameters require anti-forgery checks](aspnet-core/8.0/antiforgery-checks.md) | Behavioral change |
2223
| [Rate-limiting middleware requires AddRateLimiter](aspnet-core/8.0/addratelimiter-requirement.md) | Behavioral change |

docs/core/compatibility/9.0.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ If you're migrating an app to .NET 9, the breaking changes listed here might aff
1313

1414
## ASP.NET Core
1515

16-
| Title | Type of change | Introduced version |
17-
|----------------------------------------------------------------------------------------------------------------------------|---------------------|--------------------|
18-
| [DefaultKeyResolution.ShouldGenerateNewKey has altered meaning](aspnet-core/9.0/key-resolution.md) | Behavioral change | Preview 3 |
19-
| [Dev cert export no longer creates folder](aspnet-core/9.0/certificate-export.md) | Behavioral change | RC 1 |
20-
| [HostBuilder enables ValidateOnBuild/ValidateScopes in development environment](aspnet-core/9.0/hostbuilder-validation.md) | Behavioral change | Preview 7 |
21-
| [Legacy Mono and Emscripten APIs not exported to global namespace](aspnet-core/9.0/legacy-apis.md) | Source incompatible | GA |
22-
| [Middleware types with multiple constructors](aspnet-core/9.0/middleware-constructors.md) | Behavioral change | RC 1 |
16+
| Title | Type of change |
17+
|------------------------------------------------------------------------------------------------|-------------------|
18+
| [DefaultKeyResolution.ShouldGenerateNewKey altered meaning](aspnet-core/9.0/key-resolution.md) | Behavioral change |
19+
| [Dev cert export no longer creates folder](aspnet-core/9.0/certificate-export.md) | Behavioral change |
20+
| [Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies](aspnet-core/8.0/forwarded-headers-unknown-proxies.md) | Behavioral change |
21+
| [HostBuilder enables ValidateOnBuild/ValidateScopes in development environment](aspnet-core/9.0/hostbuilder-validation.md) | Behavioral change |
22+
| [Legacy Mono and Emscripten APIs not exported to global namespace](aspnet-core/9.0/legacy-apis.md) | Source incompatible |
23+
| [Middleware types with multiple constructors](aspnet-core/9.0/middleware-constructors.md) | Behavioral change |
2324

2425
## Containers
2526

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Breaking change: Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies"
3+
description: Learn about the breaking change in ASP.NET Core where Forwarded Headers Middleware now ignores headers from proxies that aren't explicitly configured as trusted.
4+
ms.date: 08/15/2025
5+
---
6+
# Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies
7+
8+
Starting in ASP.NET Core 8.0.17 and 9.0.6, the Forwarded Headers Middleware ignores all `X-Forwarded-*` headers from proxies that aren't explicitly configured as trusted. This change was made for security hardening, as the proxy and IP lists weren't being applied in all cases.
9+
10+
## Version introduced
11+
12+
ASP.NET Core 8.0.17
13+
ASP.NET Core 9.0.6
14+
15+
## Previous behavior
16+
17+
Previously, the middleware, when not configured to use `X-Forwarded-For`, processed `X-Forwarded-Prefix`, `X-Forwarded-Proto`, and `X-Forwarded-Host` headers from any source. That behavior potentially allowed malicious or misconfigured proxies/clients to spoof these headers and affect an application's understanding of client information.
18+
19+
## New behavior
20+
21+
Starting in .NET 8 and .NET 9 servicing releases, only headers sent by known, trusted proxies (as configured via <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions.KnownProxies?displayProperty=nameWithType> and <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions.KnownNetworks?displayProperty=nameWithType>) are processed. Headers from unknown sources are ignored.
22+
23+
> [!NOTE]
24+
> If your deployment relied on forwarded headers from proxies not configured in your application's trusted proxy list, those headers are no longer honored.
25+
26+
This change can cause behavior like infinite redirects if you're using the HTTPS redirection middleware and using TLS termination in your proxy. It can also cause authentication to fail if you're using TLS termination and expecting an HTTPS request.
27+
28+
## Type of breaking change
29+
30+
This change is a [behavioral change](../../categories.md#behavioral-change).
31+
32+
## Reason for change
33+
34+
The change was made for security hardening, as the proxy and IP lists weren't being applied in all cases.
35+
36+
## Recommended action
37+
38+
Review your deployment topology. Ensure that all legitimate proxy servers in front of your app are properly added to <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions.KnownProxies> or <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions.KnownNetworks> in your <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions> configuration.
39+
40+
```csharp
41+
app.UseForwardedHeaders(new ForwardedHeadersOptions
42+
{
43+
KnownProxies = { IPAddress.Parse("YOUR_PROXY_IP") }
44+
});
45+
```
46+
47+
Or, for a network:
48+
49+
```csharp
50+
app.UseForwardedHeaders(new ForwardedHeadersOptions
51+
{
52+
KnownNetworks = { new IPNetwork(IPAddress.Parse("YOUR_NETWORK_IP"), PREFIX_LENGTH) }
53+
});
54+
```
55+
56+
If you wish to enable the previous behavior, which isn't recommended due to security risks, you can do so by clearing the `KnownNetworks` and `KnownProxies` lists in <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersOptions> to allow any proxy or network to forward these headers.
57+
58+
You can also set the `ASPNETCORE_FORWARDEDHEADERS_ENABLED` environment variable to `true`, which clears the lists and enables `ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto`.
59+
60+
For applications that target .NET 9 or earlier, you can set the `Microsoft.AspNetCore.HttpOverrides.IgnoreUnknownProxiesWithoutFor` [AppContext](/dotnet/fundamentals/runtime-libraries/system-appcontext) switch to `"true"` or `1` to get back to the previous behavior. Alternatively, set the `MICROSOFT_ASPNETCORE_HTTPOVERRIDES_IGNORE_UNKNOWN_PROXIES_WITHOUT_FOR` environment variable.
61+
62+
> [!NOTE]
63+
> In cloud environments, the proxy IPs can change over the lifetime of the app, and `ASPNETCORE_FORWARDEDHEADERS_ENABLED` is sometimes used to make forwarded headers work.
64+
65+
## Affected APIs
66+
67+
- <xref:Microsoft.AspNetCore.Builder.ForwardedHeadersExtensions.UseForwardedHeaders*?displayProperty=fullName>
68+
69+
## See also
70+
71+
- [Configure ASP.NET Core to work with proxy servers and load balancers](/aspnet/core/host-and-deploy/proxy-load-balancer)

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ items:
164164
href: aspnet-core/9.0/key-resolution.md
165165
- name: Dev cert export no longer creates folder
166166
href: aspnet-core/9.0/certificate-export.md
167+
- name: Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies
168+
href: aspnet-core/8.0/forwarded-headers-unknown-proxies.md
167169
- name: HostBuilder enables ValidateOnBuild/ValidateScopes in development environment
168170
href: aspnet-core/9.0/hostbuilder-validation.md
169171
- name: Legacy Mono and Emscripten APIs not exported to global namespace
@@ -320,6 +322,8 @@ items:
320322
href: aspnet-core/8.0/concurrencylimitermiddleware-obsolete.md
321323
- name: Custom converters for serialization removed
322324
href: aspnet-core/8.0/problemdetails-custom-converters.md
325+
- name: Forwarded Headers Middleware ignores X-Forwarded-* headers from unknown proxies
326+
href: aspnet-core/8.0/forwarded-headers-unknown-proxies.md
323327
- name: ISystemClock is obsolete
324328
href: aspnet-core/8.0/isystemclock-obsolete.md
325329
- name: "Minimal APIs: IFormFile parameters require anti-forgery checks"

0 commit comments

Comments
 (0)