mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
commit
66849ec770
1 changed files with 5 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import functools
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import itertools
|
import itertools
|
||||||
import typing
|
import typing
|
||||||
|
import logging
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
@ -35,6 +36,8 @@ TELEGRAM_SUBNET_2 = ipaddress.IPv4Network('91.108.4.0/22')
|
||||||
|
|
||||||
allowed_ips = set()
|
allowed_ips = set()
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _check_ip(ip: str) -> bool:
|
def _check_ip(ip: str) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
@ -258,7 +261,9 @@ class WebhookRequestHandler(web.View):
|
||||||
if self.request.app.get('_check_ip', False):
|
if self.request.app.get('_check_ip', False):
|
||||||
ip_address, accept = self.check_ip()
|
ip_address, accept = self.check_ip()
|
||||||
if not accept:
|
if not accept:
|
||||||
|
log.warning(f"Blocking request from an unauthorized IP: {ip_address}")
|
||||||
raise web.HTTPUnauthorized()
|
raise web.HTTPUnauthorized()
|
||||||
|
|
||||||
# context.set_value('TELEGRAM_IP', ip_address)
|
# context.set_value('TELEGRAM_IP', ip_address)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue