Fix flask_login._get_remote_addr

We can't easily upgrade to 0.3.0 right now due to backwards incompatible
changes in that version (some methods became properties). So for now
we simply backport the fix in question through a monkey patch.

Fixes #2296
This commit is contained in:
Gina Häußge committed 2018-03-12 16:40:19 +01:00
1 parent e0722e6c28
commit a95407c815
2 files changed
+16

No files matched your search

+2
View File
@@ -1439,6 +1439,8 @@ class Server(object):
assets.register("less_app", less_app_bundle)
def _setup_login_manager(self):
util.flask.fix_flask_login_remote_address()
loginManager = LoginManager()
loginManager.session_protection = "strong"
loginManager.user_callback = load_user
+14
View File
@@ -236,6 +236,20 @@ def fix_webassets_filtertool():
FilterTool._wrap_cache = fixed_wrap_cache
def fix_flask_login_remote_address():
def fixed_get_remote_addr():
"""Backported from https://github.com/maxcountryman/flask-login/pull/217"""
from flask import request
address = request.headers.get('X-Forwarded-For', request.remote_addr)
if address is not None:
# An 'X-Forwarded-For' header includes a comma separated list of the
# addresses, the first address being the actual remote address.
address = address.encode('utf-8').split(b',')[0].strip()
return address
flask_login._get_remote_addr = fixed_get_remote_addr
#~~ WSGI environment wrapper for reverse proxying
class ReverseProxiedEnvironment(object):