You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `X-Forwarded-For` header contains multiple IPs representing the proxy chain. By default, ASP.NET Core's `ForwardLimit` is `1`, so only the last proxy IP is used.
480
+
The `X-Forwarded-For` header contains multiple IPs representing the proxy chain. When `TrustAllProxies` is `true`, `ForwardLimit` is set to `null` (no limit), so the middleware processes all IPs and returns the original client IP (`203.0.113.50`).
481
+
482
+
### Scenario 9: Proxy Chain with Known Proxies (ForwardLimit = 1)
483
+
484
+
Test how ServiceControl handles multiple proxies when `TrustAllProxies` is `false`. In this case, `ForwardLimit` remains at its default of `1`, so only the last proxy IP is processed.
485
+
486
+
**Cleanup and start ServiceControl:**
487
+
488
+
```cmd
489
+
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=true
490
+
set SERVICECONTROL_FORWARDEDHEADERS_TRUSTALLPROXIES=
491
+
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES=127.0.0.1,::1
492
+
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS=
### Scenario 9: Combined Known Proxies and Networks
503
+
**Expected output:**
504
+
505
+
```json
506
+
{
507
+
"processed": {
508
+
"scheme": "https",
509
+
"host": "example.com",
510
+
"remoteIpAddress": "192.168.1.1"
511
+
},
512
+
"rawHeaders": {
513
+
"xForwardedFor": "203.0.113.50, 10.0.0.1",
514
+
"xForwardedProto": "",
515
+
"xForwardedHost": ""
516
+
},
517
+
"configuration": {
518
+
"enabled": true,
519
+
"trustAllProxies": false,
520
+
"knownProxies": ["127.0.0.1", "::1"],
521
+
"knownNetworks": []
522
+
}
523
+
}
524
+
```
525
+
526
+
When `TrustAllProxies` is `false`, `ForwardLimit` remains at its default of `1`. The middleware only processes the rightmost IP from the chain (`192.168.1.1`). The remaining IPs (`203.0.113.50, 10.0.0.1`) stay in the `X-Forwarded-For` header. Compare this to Scenario 8 where `TrustAllProxies = true` returns the original client IP.
527
+
528
+
### Scenario 10: Combined Known Proxies and Networks
481
529
482
530
Test using both `KnownProxies` and `KnownNetworks` together.
Headers are applied because the request comes from localhost (`::1`), which falls within the `::1/128` network even though it's not in the `knownProxies` list.
525
573
526
-
### Scenario 10: Partial Headers (Proto Only)
574
+
### Scenario 11: Partial Headers (Proto Only)
527
575
528
576
Test that each forwarded header is processed independently. Only sending `X-Forwarded-Proto` should update the scheme while leaving host and remoteIpAddress unchanged.
Only the `scheme` changed to `https`. The `host` remains `localhost:33333` and `remoteIpAddress` remains `::1` because those headers weren't sent. Each header is processed independently.
571
619
572
-
### Scenario 11: IPv4/IPv6 Mismatch
620
+
### Scenario 12: IPv4/IPv6 Mismatch
573
621
574
622
Demonstrates a common misconfiguration where only IPv4 localhost is configured but curl uses IPv6. This scenario shows why you should include both `127.0.0.1` and `::1` in your configuration.
0 commit comments