Skip to content

Commit

Permalink
Add Cloudflare "CF-Connecting-IP" header
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bisharyan committed Oct 1, 2024
1 parent 8c48bf2 commit 34cc1b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public static string TryParseUserAgent(this HttpContext httpContext)
"X-Forwarded-Host",
"X-Forwarded-Proto",
"X-Forwarded-Server",
"X-Forwarded-Port"
"X-Forwarded-Port",
"CF-Connecting-IP"
};

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

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

foreach (var header in headersToCheck)
{
Expand Down Expand Up @@ -235,4 +237,4 @@ private static bool IsValidIpAddress(string? ipAddress)
return !string.IsNullOrWhiteSpace(ipAddress) && IPAddress.TryParse(ipAddress, out var parsed)
&& !parsed.IsIPv6UniqueLocal && ipAddress != "::1";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ div.topbar {
width: 100%;
top: 0;
border-bottom: 1px solid #ffffff;
z-index: 1000000;
z-index: 1000;
}

.swagger-ui {
Expand Down

0 comments on commit 34cc1b8

Please sign in to comment.