mirror of
https://github.com/searxng/searxng.git
synced 2025-07-15 01:09:21 +02:00
[fix] limiter: replace real_ip by IPv4/v6 network
Closes: https://github.com/searxng/searxng/issues/2477 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
38431d2e14
commit
281e36f4b7
12 changed files with 208 additions and 106 deletions
|
@ -16,7 +16,12 @@ bot if the Accept-Encoding_ header ..
|
|||
"""
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
from ipaddress import (
|
||||
IPv4Network,
|
||||
IPv6Network,
|
||||
)
|
||||
|
||||
import flask
|
||||
import werkzeug
|
||||
|
||||
|
@ -24,8 +29,13 @@ from searx.tools import config
|
|||
from ._helpers import too_many_requests
|
||||
|
||||
|
||||
def filter_request(request: flask.Request, cfg: config.Config) -> Optional[werkzeug.Response]:
|
||||
def filter_request(
|
||||
network: IPv4Network | IPv6Network,
|
||||
request: flask.Request,
|
||||
cfg: config.Config,
|
||||
) -> werkzeug.Response | None:
|
||||
|
||||
accept_list = [l.strip() for l in request.headers.get('Accept-Encoding', '').split(',')]
|
||||
if not ('gzip' in accept_list or 'deflate' in accept_list):
|
||||
return too_many_requests(request, "HTTP header Accept-Encoding did not contain gzip nor deflate")
|
||||
return too_many_requests(network, "HTTP header Accept-Encoding did not contain gzip nor deflate")
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue