diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2023-06-03 13:43:34 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarit.de> | 2023-06-05 14:07:19 +0200 |
| commit | f3763d73ad8cf93ea32d7e12713662f7963d950f (patch) | |
| tree | d64964ad9d6c49e0c2c7b1d6da14ccca9d4a7c55 /searx/botdetection/_helpers.py | |
| parent | de2f396e5020228db2a88babdd818fa20d7c44e3 (diff) | |
[mod] limiter: blocklist and passlist (ip_lists)
A blocklist and a passlist can be configured in /etc/searxng/limiter.toml::
[botdetection.ip_lists]
pass_ip = [
'51.15.252.168', # IPv4 of check.searx.space
]
block_ip = [
'93.184.216.34', # IPv4 of example.org
]
Closes: https://github.com/searxng/searxng/issues/2127
Closes: https://github.com/searxng/searxng/pull/2129
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/botdetection/_helpers.py')
| -rw-r--r-- | searx/botdetection/_helpers.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/searx/botdetection/_helpers.py b/searx/botdetection/_helpers.py index 8e0156d6e..19905fd15 100644 --- a/searx/botdetection/_helpers.py +++ b/searx/botdetection/_helpers.py @@ -6,8 +6,8 @@ from __future__ import annotations from ipaddress import ( IPv4Network, IPv6Network, + IPv4Address, IPv6Address, - ip_address, ip_network, ) import flask @@ -46,11 +46,10 @@ def too_many_requests(network: IPv4Network | IPv6Network, log_msg: str) -> werkz return flask.make_response(('Too Many Requests', 429)) -def get_network(real_ip: str, cfg: config.Config) -> IPv4Network | IPv6Network: +def get_network(real_ip: IPv4Address | IPv6Address, cfg: config.Config) -> IPv4Network | IPv6Network: """Returns the (client) network of whether the real_ip is part of.""" - ip = ip_address(real_ip) - if isinstance(ip, IPv6Address): + if real_ip.version == 6: prefix = cfg['real_ip.ipv6_prefix'] else: prefix = cfg['real_ip.ipv4_prefix'] @@ -99,7 +98,7 @@ def get_real_ip(request: flask.Request) -> str: from .limiter import get_cfg # pylint: disable=import-outside-toplevel, cyclic-import forwarded_for = [x.strip() for x in forwarded_for.split(',')] - x_for: int = get_cfg()['real_ip.x_for'] + x_for: int = get_cfg()['real_ip.x_for'] # type: ignore forwarded_for = forwarded_for[-min(len(forwarded_for), x_for)] if not real_ip: |