Skip to content

Commit 5ec0956

Browse files
committed
[brand] darmarit.org/searx - BLOCK known bots
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
1 parent f6e68b5 commit 5ec0956

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

searx/plugins/limiter.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
+ r')'
4141
)
4242

43+
ip_block_list = ['35.84.41.175', '183.93.70.31', '209.198.8.138', '58.97.160.13']
44+
45+
query_block_list = re.compile(
46+
r'('
47+
+ r"site:zhidao\.baidu\.com .*"
48+
+ r')'
49+
)
4350

4451
def is_accepted_request() -> bool:
4552
# pylint: disable=too-many-return-statements
@@ -50,6 +57,15 @@ def is_accepted_request() -> bool:
5057
if request.path == '/healthz':
5158
return True
5259

60+
if x_forwarded_for in ip_block_list:
61+
logger.debug("BLOCK %s: %s --> IP is on block list: %s" % (x_forwarded_for, request.path, user_agent))
62+
return False
63+
64+
q = request.form.get('q')
65+
if q and query_block_list.match(q):
66+
logger.debug("BLOCK %s: %s --> query is on block list: %s" % (x_forwarded_for, request.path, q))
67+
return False
68+
5369
if block_user_agent.match(user_agent):
5470
logger.debug("BLOCK %s: %s --> detected User-Agent: %s" % (x_forwarded_for, request.path, user_agent))
5571
return False

0 commit comments

Comments
 (0)