Skip to content
Snippets Groups Projects
Commit 6709f4d0 authored by Jano Hendriks's avatar Jano Hendriks
Browse files

Fix getting IP address through cloudflare proxy

parent b225e39a
Branches
Tags v1.284.0
No related merge requests found
...@@ -175,9 +175,9 @@ func GetRequestSourceIP(proxyRequest *events.APIGatewayProxyRequest, websocketRe ...@@ -175,9 +175,9 @@ func GetRequestSourceIP(proxyRequest *events.APIGatewayProxyRequest, websocketRe
VerifyCloudflareSourceIP(requestSourceIP) { VerifyCloudflareSourceIP(requestSourceIP) {
forwardedForHeaderIPs := strings.Split(forwardedForHeader, ",") forwardedForHeaderIPs := strings.Split(forwardedForHeader, ",")
if len(forwardedForHeaderIPs) > 0 { if len(forwardedForHeaderIPs) > 1 {
// Use the first IP as the source IP // Use the second-to-last IP – the last IP will be the Cloudflare proxy's IP
headerSourceIP := strings.TrimSpace(forwardedForHeaderIPs[len(forwardedForHeaderIPs)-1]) headerSourceIP := strings.TrimSpace(forwardedForHeaderIPs[len(forwardedForHeaderIPs)-2])
return headerSourceIP return headerSourceIP
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment