File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 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
4451def 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
You can’t perform that action at this time.
0 commit comments