From 8fa363de6fff88f6d80a4bd6dbc2fc141e5a6ed8 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 8 Oct 2018 13:43:21 +0300 Subject: Support multiple IPs in header --- app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app.py') diff --git a/app.py b/app.py index 805ca8a..caa23eb 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,10 @@ app = Flask(__name__) def get_ip(request): if 'PROD' in environ: - return request.headers.get('X-Forwarded-For') + # Heroku routing layers masks the original IP, fetch it from the custom header + # And make sure we just take the first IP in case other proxies were in the way + ips = request.headers.get('X-Forwarded-For') + return ips.split(',')[0] else: return request.remote_addr -- cgit v1.3.1