Skip to content

Commit 34cc1b8

Browse files
author
Ruben Bisharyan
committed
Add Cloudflare "CF-Connecting-IP" header
1 parent 8c48bf2 commit 34cc1b8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Pandatech.VerticalSlices/SharedKernel/Helpers/HttpContextParser.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public static string TryParseUserAgent(this HttpContext httpContext)
109109
"X-Forwarded-Host",
110110
"X-Forwarded-Proto",
111111
"X-Forwarded-Server",
112-
"X-Forwarded-Port"
112+
"X-Forwarded-Port",
113+
"CF-Connecting-IP"
113114
};
114115

115116
var stringBuilder = new StringBuilder();
@@ -186,7 +187,8 @@ public static decimal TryParseAccuracy(this HttpContext httpContext)
186187

187188
public static string TryParseUserNetworkAddress(this HttpContext httpContext)
188189
{
189-
string[] headersToCheck = ["X-Forwarded-For", "Forwarded", "X-Real-IP"];
190+
// Check at first Cloudflare "CF-Connecting-IP" header, which contains client real IP address
191+
string[] headersToCheck = ["CF-Connecting-IP", "X-Forwarded-For", "Forwarded", "X-Real-IP"];
190192

191193
foreach (var header in headersToCheck)
192194
{
@@ -235,4 +237,4 @@ private static bool IsValidIpAddress(string? ipAddress)
235237
return !string.IsNullOrWhiteSpace(ipAddress) && IPAddress.TryParse(ipAddress, out var parsed)
236238
&& !parsed.IsIPv6UniqueLocal && ipAddress != "::1";
237239
}
238-
}
240+
}

src/Pandatech.VerticalSlices/wwwroot/assets/css/panda-style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ div.topbar {
8585
width: 100%;
8686
top: 0;
8787
border-bottom: 1px solid #ffffff;
88-
z-index: 1000000;
88+
z-index: 1000;
8989
}
9090

9191
.swagger-ui {

0 commit comments

Comments
 (0)