93 network: IPv4Network | IPv6Network,
94 request: flask.Request,
96) -> werkzeug.Response |
None:
99 redis_client = redisdb.client()
101 if network.is_link_local
and not cfg[
'botdetection.ip_limit.filter_link_local']:
102 logger.debug(
"network %s is link-local -> not monitored by ip_limit method", network.compressed)
105 if request.args.get(
'format',
'html') !=
'html':
106 c = incr_sliding_window(redis_client,
'ip_limit.API_WINDOW:' + network.compressed, API_WINDOW)
108 return too_many_requests(network,
"too many request in API_WINDOW")
110 if cfg[
'botdetection.ip_limit.link_token']:
112 suspicious = link_token.is_suspicious(network, request,
True)
116 drop_counter(redis_client,
'ip_limit.SUSPICIOUS_IP_WINDOW' + network.compressed)
120 c = incr_sliding_window(
121 redis_client,
'ip_limit.SUSPICIOUS_IP_WINDOW' + network.compressed, SUSPICIOUS_IP_WINDOW
123 if c > SUSPICIOUS_IP_MAX:
124 logger.error(
"BLOCK: too many request from %s in SUSPICIOUS_IP_WINDOW (redirect to /)", network)
125 return flask.redirect(flask.url_for(
'index'), code=302)
127 c = incr_sliding_window(redis_client,
'ip_limit.BURST_WINDOW' + network.compressed, BURST_WINDOW)
128 if c > BURST_MAX_SUSPICIOUS:
129 return too_many_requests(network,
"too many request in BURST_WINDOW (BURST_MAX_SUSPICIOUS)")
131 c = incr_sliding_window(redis_client,
'ip_limit.LONG_WINDOW' + network.compressed, LONG_WINDOW)
132 if c > LONG_MAX_SUSPICIOUS:
133 return too_many_requests(network,
"too many request in LONG_WINDOW (LONG_MAX_SUSPICIOUS)")
138 c = incr_sliding_window(redis_client,
'ip_limit.BURST_WINDOW' + network.compressed, BURST_WINDOW)
140 return too_many_requests(network,
"too many request in BURST_WINDOW (BURST_MAX)")
142 c = incr_sliding_window(redis_client,
'ip_limit.LONG_WINDOW' + network.compressed, LONG_WINDOW)
144 return too_many_requests(network,
"too many request in LONG_WINDOW (LONG_MAX)")