Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use real user ip behind cloudflare #68

Merged
merged 5 commits into from
Mar 29, 2024
Merged

Conversation

t0nka
Copy link
Contributor

@t0nka t0nka commented Feb 12, 2023

if a website is behind clouflare, $this->request->ip() will provide u only a clouflare ip, not the real user ip address.

with $this->request->server('HTTP_CF_CONNECTING_IP') u are able to get the real user ip address

@lrljoe
Copy link
Collaborator

lrljoe commented Feb 18, 2023

You can just use your webserver to modify the standard header. CloudFlare provide instructions on how to do this for Apache and Nginx.

@t0nka
Copy link
Contributor Author

t0nka commented Feb 27, 2023

True, but sometime u need a vanilla server or even u cant cange the configuration of your server

@lrljoe
Copy link
Collaborator

lrljoe commented Feb 27, 2023

In that case, can I suggest that you add some key options into the config file so that it's a little more configurable, perhaps a real_ip header or something?

That way it can be applied to CloudFlare/cloudfront/frontdoor etc

@lrljoe
Copy link
Collaborator

lrljoe commented Apr 11, 2023

Just testing an alternative approach, using the config file to determine which headers to use etc, as this suggested approach limits it to only CloudFlare.

@swilla
Copy link

swilla commented Apr 27, 2023

I think if you use this package on your application no changes will need to be done within this package: https://github.com/monicahq/laravel-cloudflare

@t0nka
Copy link
Contributor Author

t0nka commented Apr 27, 2023

i added a configurable approach - config based

@lrljoe
Copy link
Collaborator

lrljoe commented Apr 27, 2023

One minor tweak I'd recommend is to use the shorthand to simplify it somewhat, the below should work but you get the idea on how to tweak if not.

$ip = (config('authentication-log.behind_cdn')) ? $this->request->server(config('authentication-log.behind_cdn.http_header_field')) : $this->request->ip();

Otherwise it looks like a great addition!

@denizaygu
Copy link

@rappasoft this would be incredibly useful, I'm using Vercel and have a similar issue. Even if I add the correct user IP to the IPs header, it still uses the secondary AWS IP.

@denizaygu
Copy link

As a workaround I ended up implementing the Login event and listener manually myself.

@lrljoe
Copy link
Collaborator

lrljoe commented Aug 19, 2023

I've got some updates and improvements for this that I'll merge across, including smoother detection for the common WAFs/proxies, I'm just focused on the tables package at the mo.

I'd estimate 3 to 4 weeks before I can properly get everything in a good shape for a new release

@lrljoe
Copy link
Collaborator

lrljoe commented Aug 20, 2023

As a side note, rather than replicating the methods, you could do one of the following

configure your webserver to rewrite the header

configure cloudflare to pass the original IP in the original header

use a middleware to rewrite the headers

The update I've got sat to one side has a couple of nifty features for detecting a WAF and picking the appropriate header.
Plus some improvements to the way the package is listening.
Sadly a few weeks before I can think about that tidying it up and adding it in

@rappasoft rappasoft changed the base branch from main to develop March 29, 2024 00:41
@rappasoft rappasoft merged commit 1c9456d into rappasoft:develop Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants