-
Notifications
You must be signed in to change notification settings - Fork 403
Open
Description
PHP Version
8.1
Laravel Version
10.0
Package Version
13.7.2
Description
i have added the custom IpAddressResolver to save user real ip
Currently, its saving Cloudflare IP, not the original IP wvwn though modified to save the Cloudflare IP with header CF-Connecting-IP . my solution works fine with local and auditing in queue but in production my solutions saves 127.0.0.1
class irUserIPResolver implements \OwenIt\Auditing\Contracts\Resolver
{
public static function resolve(Auditable $auditable)
{
return request()->header('CF-Connecting-IP')??request()->ip();
Log::build([
'driver' => 'single',
'path' => storage_path('logs/audit_logs.log'),
'level' => 'info',
])->info('Audirt Logs ',[
'CF-Connecting-IP' => request()->header('CF-Connecting-IP'),
'X-Forwarded-For' => trim(explode(',', request()->header('X-Forwarded-For'))[0]),
'fallback' => request()->ip(),
'url' => request()->fullUrl(),
]);
// Cloudflare real IP headers
if (request()->hasHeader('CF-Connecting-IP')) {
return request()->header('CF-Connecting-IP');
}
if (request()->hasHeader('X-Forwarded-For')) {
// May contain multiple IPs → take the first (real client)
return trim(explode(',', request()->header('X-Forwarded-For'))[0]);
}
// Fallback to Laravel default
return request()->ip();
}
}Steps To Reproduce
'queue' => [
'enable' => true,
'connection' => env('QUEUE_CONNECTION', 'database'),
'queue' => 'default',
'delay' => 2,
],cloudflare protected site and server using loadbalancer
'resolvers' => [
'ip_address' => \Modules\IRemitify\Resolvers\irUserIPResolver::class,
'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
],Possible Solutions
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels