mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-15 09:12:32 -04:00
Closes #12301 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
699 B
PHP
22 lines
699 B
PHP
<?php
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* The client IP for rate limits, allow-lists, and audit logs. Behind Cloudflare, $request->ip()
|
|
* is the Cloudflare edge, so a valid CF-Connecting-IP is used: on cloud, and on self-hosted
|
|
* instances when the request comes from a Cloudflare IP. A client that connects directly
|
|
* cannot set the client IP with the header.
|
|
*/
|
|
function client_ip(Request $request): string
|
|
{
|
|
$ip = (string) $request->ip();
|
|
$cloudflareIp = $request->header('CF-Connecting-IP');
|
|
|
|
if (is_string($cloudflareIp) && filter_var($cloudflareIp, FILTER_VALIDATE_IP) !== false && (isCloud() || isCloudflareIp($ip))) {
|
|
return $cloudflareIp;
|
|
}
|
|
|
|
return $ip;
|
|
}
|