mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
add log info
This commit is contained in:
parent
0eeb22bf82
commit
9f395dc57d
1 changed files with 15 additions and 1 deletions
|
@ -25,6 +25,10 @@ default_on = False
|
||||||
preference_section = 'service'
|
preference_section = 'service'
|
||||||
|
|
||||||
|
|
||||||
|
c_burst_limit = 15
|
||||||
|
c_10min_limit = 150
|
||||||
|
|
||||||
|
|
||||||
re_bot = re.compile(
|
re_bot = re.compile(
|
||||||
r'('
|
r'('
|
||||||
+ r'[Cc][Uu][Rr][Ll]|[wW]get|Scrapy|splash|JavaFX|FeedFetcher|python-requests|Go-http-client|Java|Jakarta|okhttp'
|
+ r'[Cc][Uu][Rr][Ll]|[wW]get|Scrapy|splash|JavaFX|FeedFetcher|python-requests|Go-http-client|Java|Jakarta|okhttp'
|
||||||
|
@ -36,6 +40,11 @@ re_bot = re.compile(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if "logger" not in locals():
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger("searx.plugins.limiter")
|
||||||
|
|
||||||
|
|
||||||
def cdn_reported_ip(headers: dict) -> str:
|
def cdn_reported_ip(headers: dict) -> str:
|
||||||
# some commonly used CDNs:
|
# some commonly used CDNs:
|
||||||
cdn_keys = [
|
cdn_keys = [
|
||||||
|
@ -62,6 +71,7 @@ def is_accepted_request(inc_get_counter) -> bool:
|
||||||
|
|
||||||
if request.path == '/image_proxy':
|
if request.path == '/image_proxy':
|
||||||
if re_bot.match(user_agent):
|
if re_bot.match(user_agent):
|
||||||
|
logger.info(f"reject [{client_ip}]: client may be a bot described by UA=\"{user_agent}\"")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -69,13 +79,16 @@ def is_accepted_request(inc_get_counter) -> bool:
|
||||||
c_burst = inc_get_counter(interval=20, keys=[b'IP limit, burst', client_ip])
|
c_burst = inc_get_counter(interval=20, keys=[b'IP limit, burst', client_ip])
|
||||||
c_10min = inc_get_counter(interval=600, keys=[b'IP limit, 10 minutes', client_ip])
|
c_10min = inc_get_counter(interval=600, keys=[b'IP limit, 10 minutes', client_ip])
|
||||||
|
|
||||||
if c_burst > 15 or c_10min > 150:
|
if c_burst > c_burst_limit or c_10min > c_10min_limit:
|
||||||
|
logger.info(f"reject [{client_ip}]: c_burst({c_burst})>{c_burst_limit} or c_10min({c_10min})>{c_10min_limit}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if re_bot.match(user_agent):
|
if re_bot.match(user_agent):
|
||||||
|
logger.info(f"reject [{client_ip}]: client may be a bot described by UA=\"{user_agent}\"")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if request.headers.get('Accept-Language', '').strip():
|
if request.headers.get('Accept-Language', '').strip():
|
||||||
|
logger.info(f"reject [{client_ip}]: empty Accept-Language")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If SearXNG is behind Cloudflare, all requests will get 429 because
|
# If SearXNG is behind Cloudflare, all requests will get 429 because
|
||||||
|
@ -89,6 +102,7 @@ def is_accepted_request(inc_get_counter) -> bool:
|
||||||
# return False
|
# return False
|
||||||
|
|
||||||
if 'text/html' not in request.accept_mimetypes:
|
if 'text/html' not in request.accept_mimetypes:
|
||||||
|
logger.info(f"reject [{client_ip}]: non-html request to /search")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# IDK but maybe api limit should based on path not format?
|
# IDK but maybe api limit should based on path not format?
|
||||||
|
|
Loading…
Add table
Reference in a new issue