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

HTTP_X_FORWARDED_FOR can contain multiple IPs #20

Closed
stuaxo opened this issue Jul 12, 2018 · 1 comment
Closed

HTTP_X_FORWARDED_FOR can contain multiple IPs #20

stuaxo opened this issue Jul 12, 2018 · 1 comment

Comments

@stuaxo
Copy link

stuaxo commented Jul 12, 2018

HTTP_X_FORWARDED_FOR can contain a comma seperated list of IPs, and you only want to check one of them (which one may vary depending on if you use a CDN or not).

You can prepend your own IP using curl, e.g.

curl --header X-Forwarded-For '1.1.1.1,2.2.2.2,3.3.3.3 ..'

You get a resulting x-forwarded of: (edited)
1.1.1.1, 2.2.2.2, 3.3.3.3, {the client's real ip}, {cloudfront's ip}

So you need need a way of telling django-admin-restrictor the index of the IP you want from the end, I guess the sane default for this would be -1, but for the sites using cloudfront they will want -2.

Invest PIR has a solution to grab the second to last IP, which is hardcoded, along with unit tests in this PR
uktrade/invest-pir-api@5454251

I'm not sure how the setting would be spelt X_FORWARDED_INDEX ?

@stuaxo
Copy link
Author

stuaxo commented Jul 12, 2018

I'll submit a PR in the next few days, found out you are on holiday so shouldn't be checking this :)

@sdonk sdonk closed this as completed Oct 25, 2018
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

No branches or pull requests

2 participants