dmpayton / django-admin-honeypot

:honey_pot: A fake Django admin login screen page.
http://django-admin-honeypot.readthedocs.io/
MIT License
1.03k stars 188 forks source link

Fix IP identification when behind load balancer or proxy #81

Closed benjo456 closed 2 years ago

benjo456 commented 3 years ago

Currently the user IP address cannot be collected properly if the site is behind a load balancer or proxy. This code adds a fallback in those situations so that the user IP can be collected properly.

Without this, it is impossible to correctly identify a user IP and so there is no way to ban any malicious users.

9mido commented 3 years ago

@benjo456

Read this entire thing even the comments:

https://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django

Your code looks very similar to the answers here that go over why what you have here can be very dangerous https://esd.io/blog/flask-apps-heroku-real-ip-spoofing.html. Probably better off using ipware compared to the method you used here.

There is already another open PR related to ipware. It is good to have both PRs, but I think ipware would be better.

blag commented 3 years ago

Hi, I have forked this project, included a few PRs (including one that solves this same problem), and released a package to PyPI. You might have better luck with my fork.

dmpayton commented 2 years ago

I've merged an integration with django-ipware, which looks like it should resolve the issue nicely, into develop.