Skip to content

Commit

Permalink
Add Cloudflare "CF-Connecting-IP" header + some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bisharyan committed Oct 1, 2024
1 parent 21231c5 commit 7311329
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ public static WebApplication UseCors(this WebApplication app)
return app;
}

private static readonly char[] Separator = [';', ','];

private static string[] SplitOrigins(this string input)
{
if (string.IsNullOrEmpty(input))
{
throw new ArgumentException("Cors Origins cannot be null or empty.");
}

var result = input.Split([';', ','], StringSplitOptions.RemoveEmptyEntries);
var result = input.Split(Separator, StringSplitOptions.RemoveEmptyEntries);

for (var i = 0; i < result.Length; i++)
{
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 @@ -188,7 +189,7 @@ public static decimal TryParseAccuracy(this HttpContext httpContext)

public static string TryParseUserNetworkAddress(this HttpContext httpContext)
{
string[] headersToCheck = ["X-Forwarded-For", "Forwarded", "X-Real-IP"];
string[] headersToCheck = ["CF-Connecting-IP", "X-Forwarded-For", "Forwarded", "X-Real-IP"];

foreach (var header in headersToCheck)
{
Expand Down Expand Up @@ -237,4 +238,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 @@ -10,7 +10,7 @@ public static class HangfireServerExtensions
{
public static WebApplicationBuilder AddHangfireServer(this WebApplicationBuilder builder)
{
var postgresConnectionString = builder.Configuration.GetPostgresUrl;
var postgresConnectionString = builder.Configuration.GetPostgresUrl();
builder.Services.AddHangfire(configuration =>
{
configuration.SetDataCompatibilityLevel(CompatibilityLevel.Version_180);
Expand Down

0 comments on commit 7311329

Please sign in to comment.