From c89bf6fbf85a7eb2ecf5ac0f1c9232c74f9712b0 Mon Sep 17 00:00:00 2001 From: Sina Ebrahimi Date: Wed, 25 Aug 2021 23:58:38 +0430 Subject: [PATCH] Fix: get the left-most ip when there is multiple (#673) X-Forwarded-For: , , get the part when there is multiple proxies or load balancers --- aiogram/dispatcher/webhook.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiogram/dispatcher/webhook.py b/aiogram/dispatcher/webhook.py index c76ffae2..4254c72c 100644 --- a/aiogram/dispatcher/webhook.py +++ b/aiogram/dispatcher/webhook.py @@ -241,6 +241,8 @@ class WebhookRequestHandler(web.View): # For reverse proxy (nginx) forwarded_for = self.request.headers.get('X-Forwarded-For', None) if forwarded_for: + # get the left-most ip when there is multiple ips (request got through multiple proxy/load balancers) + forwarded_for = forwarded_for.split(",")[0] return forwarded_for, _check_ip(forwarded_for) # For default method