diff options
Diffstat (limited to 'searx/botdetection')
| -rw-r--r-- | searx/botdetection/_helpers.py | 6 | ||||
| -rw-r--r-- | searx/botdetection/http_accept.py | 8 | ||||
| -rw-r--r-- | searx/botdetection/http_accept_encoding.py | 8 | ||||
| -rw-r--r-- | searx/botdetection/http_accept_language.py | 9 | ||||
| -rw-r--r-- | searx/botdetection/http_connection.py | 8 | ||||
| -rw-r--r-- | searx/botdetection/http_user_agent.py | 8 | ||||
| -rw-r--r-- | searx/botdetection/ip_limit.py | 3 | ||||
| -rw-r--r-- | searx/botdetection/link_token.py | 8 |
8 files changed, 31 insertions, 27 deletions
diff --git a/searx/botdetection/_helpers.py b/searx/botdetection/_helpers.py index 5387fe5cc..b15f720f6 100644 --- a/searx/botdetection/_helpers.py +++ b/searx/botdetection/_helpers.py @@ -13,12 +13,14 @@ import flask import werkzeug from searx import logger +from searx.extended_types import SXNG_Request + from . import config logger = logger.getChild('botdetection') -def dump_request(request: flask.Request): +def dump_request(request: SXNG_Request): return ( request.path + " || X-Forwarded-For: %s" % request.headers.get('X-Forwarded-For') @@ -66,7 +68,7 @@ def _log_error_only_once(err_msg): _logged_errors.append(err_msg) -def get_real_ip(request: flask.Request) -> str: +def get_real_ip(request: SXNG_Request) -> str: """Returns real IP of the request. Since not all proxies set all the HTTP headers and incoming headers can be faked it may happen that the IP cannot be determined correctly. diff --git a/searx/botdetection/http_accept.py b/searx/botdetection/http_accept.py index 911309ebe..f64991d50 100644 --- a/searx/botdetection/http_accept.py +++ b/searx/botdetection/http_accept.py @@ -12,7 +12,6 @@ Accept_ header .. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept """ -# pylint: disable=unused-argument from __future__ import annotations from ipaddress import ( @@ -20,17 +19,18 @@ from ipaddress import ( IPv6Network, ) -import flask import werkzeug +from searx.extended_types import SXNG_Request + from . import config from ._helpers import too_many_requests def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, - cfg: config.Config, + request: SXNG_Request, + cfg: config.Config, # pylint: disable=unused-argument ) -> werkzeug.Response | None: if 'text/html' not in request.accept_mimetypes: diff --git a/searx/botdetection/http_accept_encoding.py b/searx/botdetection/http_accept_encoding.py index 4f9e28858..0975cc85e 100644 --- a/searx/botdetection/http_accept_encoding.py +++ b/searx/botdetection/http_accept_encoding.py @@ -13,7 +13,6 @@ bot if the Accept-Encoding_ header .. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding """ -# pylint: disable=unused-argument from __future__ import annotations from ipaddress import ( @@ -21,17 +20,18 @@ from ipaddress import ( IPv6Network, ) -import flask import werkzeug +from searx.extended_types import SXNG_Request + from . import config from ._helpers import too_many_requests def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, - cfg: config.Config, + request: SXNG_Request, + cfg: config.Config, # pylint: disable=unused-argument ) -> werkzeug.Response | None: accept_list = [l.strip() for l in request.headers.get('Accept-Encoding', '').split(',')] diff --git a/searx/botdetection/http_accept_language.py b/searx/botdetection/http_accept_language.py index e351d03cb..1287e5453 100644 --- a/searx/botdetection/http_accept_language.py +++ b/searx/botdetection/http_accept_language.py @@ -10,24 +10,25 @@ if the Accept-Language_ header is unset. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent """ -# pylint: disable=unused-argument + from __future__ import annotations from ipaddress import ( IPv4Network, IPv6Network, ) -import flask import werkzeug +from searx.extended_types import SXNG_Request + from . import config from ._helpers import too_many_requests def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, - cfg: config.Config, + request: SXNG_Request, + cfg: config.Config, # pylint: disable=unused-argument ) -> werkzeug.Response | None: if request.headers.get('Accept-Language', '').strip() == '': return too_many_requests(network, "missing HTTP header Accept-Language") diff --git a/searx/botdetection/http_connection.py b/searx/botdetection/http_connection.py index c720b55e6..eed15f989 100644 --- a/searx/botdetection/http_connection.py +++ b/searx/botdetection/http_connection.py @@ -10,7 +10,6 @@ the Connection_ header is set to ``close``. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection """ -# pylint: disable=unused-argument from __future__ import annotations from ipaddress import ( @@ -18,17 +17,18 @@ from ipaddress import ( IPv6Network, ) -import flask import werkzeug +from searx.extended_types import SXNG_Request + from . import config from ._helpers import too_many_requests def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, - cfg: config.Config, + request: SXNG_Request, + cfg: config.Config, # pylint: disable=unused-argument ) -> werkzeug.Response | None: if request.headers.get('Connection', '').strip() == 'close': diff --git a/searx/botdetection/http_user_agent.py b/searx/botdetection/http_user_agent.py index db6356449..57d5bfee7 100644 --- a/searx/botdetection/http_user_agent.py +++ b/searx/botdetection/http_user_agent.py @@ -11,7 +11,6 @@ the User-Agent_ header is unset or matches the regular expression https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent """ -# pylint: disable=unused-argument from __future__ import annotations import re @@ -20,9 +19,10 @@ from ipaddress import ( IPv6Network, ) -import flask import werkzeug +from searx.extended_types import SXNG_Request + from . import config from ._helpers import too_many_requests @@ -56,8 +56,8 @@ def regexp_user_agent(): def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, - cfg: config.Config, + request: SXNG_Request, + cfg: config.Config, # pylint: disable=unused-argument ) -> werkzeug.Response | None: user_agent = request.headers.get('User-Agent', 'unknown') diff --git a/searx/botdetection/ip_limit.py b/searx/botdetection/ip_limit.py index 6e36b44fc..b4c6825b3 100644 --- a/searx/botdetection/ip_limit.py +++ b/searx/botdetection/ip_limit.py @@ -45,6 +45,7 @@ from ipaddress import ( import flask import werkzeug +from searx.extended_types import SXNG_Request from searx import redisdb from searx.redislib import incr_sliding_window, drop_counter @@ -91,7 +92,7 @@ SUSPICIOUS_IP_MAX = 3 def filter_request( network: IPv4Network | IPv6Network, - request: flask.Request, + request: SXNG_Request, cfg: config.Config, ) -> werkzeug.Response | None: diff --git a/searx/botdetection/link_token.py b/searx/botdetection/link_token.py index 4273e22c5..c255790cb 100644 --- a/searx/botdetection/link_token.py +++ b/searx/botdetection/link_token.py @@ -43,11 +43,11 @@ from ipaddress import ( import string import random -import flask from searx import logger from searx import redisdb from searx.redislib import secret_hash +from searx.extended_types import SXNG_Request from ._helpers import ( get_network, @@ -69,7 +69,7 @@ TOKEN_KEY = 'SearXNG_limiter.token' logger = logger.getChild('botdetection.link_token') -def is_suspicious(network: IPv4Network | IPv6Network, request: flask.Request, renew: bool = False): +def is_suspicious(network: IPv4Network | IPv6Network, request: SXNG_Request, renew: bool = False): """Checks whether a valid ping is exists for this (client) network, if not this request is rated as *suspicious*. If a valid ping exists and argument ``renew`` is ``True`` the expire time of this ping is reset to @@ -92,7 +92,7 @@ def is_suspicious(network: IPv4Network | IPv6Network, request: flask.Request, re return False -def ping(request: flask.Request, token: str): +def ping(request: SXNG_Request, token: str): """This function is called by a request to URL ``/client<token>.css``. If ``token`` is valid a :py:obj:`PING_KEY` for the client is stored in the DB. The expire time of this ping-key is :py:obj:`PING_LIVE_TIME`. @@ -113,7 +113,7 @@ def ping(request: flask.Request, token: str): redis_client.set(ping_key, 1, ex=PING_LIVE_TIME) -def get_ping_key(network: IPv4Network | IPv6Network, request: flask.Request) -> str: +def get_ping_key(network: IPv4Network | IPv6Network, request: SXNG_Request) -> str: """Generates a hashed key that fits (more or less) to a *WEB-browser session* in a network.""" return ( |