summaryrefslogtreecommitdiff
path: root/searx/botdetection/http_accept_encoding.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2023-06-01 15:41:48 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-06-01 15:51:14 +0200
commit281e36f4b7848374535d5e953050ae73423191ca (patch)
treef7bda906459c8e796ec688a0007191f3c3609d63 /searx/botdetection/http_accept_encoding.py
parent38431d2e142b7da6a9b48aad203f02a2eff7e6fd (diff)
downloadsearxng-281e36f4b7848374535d5e953050ae73423191ca.tar.gz
searxng-281e36f4b7848374535d5e953050ae73423191ca.zip
[fix] limiter: replace real_ip by IPv4/v6 network
Closes: https://github.com/searxng/searxng/issues/2477 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/botdetection/http_accept_encoding.py')
-rw-r--r--searx/botdetection/http_accept_encoding.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/searx/botdetection/http_accept_encoding.py b/searx/botdetection/http_accept_encoding.py
index 5301c5d9d..60718a4ca 100644
--- a/searx/botdetection/http_accept_encoding.py
+++ b/searx/botdetection/http_accept_encoding.py
@@ -16,7 +16,12 @@ bot if the Accept-Encoding_ header ..
"""
# pylint: disable=unused-argument
-from typing import Optional
+from __future__ import annotations
+from ipaddress import (
+ IPv4Network,
+ IPv6Network,
+)
+
import flask
import werkzeug
@@ -24,8 +29,13 @@ from searx.tools import config
from ._helpers import too_many_requests
-def filter_request(request: flask.Request, cfg: config.Config) -> Optional[werkzeug.Response]:
+def filter_request(
+ network: IPv4Network | IPv6Network,
+ request: flask.Request,
+ cfg: config.Config,
+) -> werkzeug.Response | None:
+
accept_list = [l.strip() for l in request.headers.get('Accept-Encoding', '').split(',')]
if not ('gzip' in accept_list or 'deflate' in accept_list):
- return too_many_requests(request, "HTTP header Accept-Encoding did not contain gzip nor deflate")
+ return too_many_requests(network, "HTTP header Accept-Encoding did not contain gzip nor deflate")
return None