forked from Icycoide/searxng
[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
|
@ -12,8 +12,12 @@ if the Accept-Language_ header is unset.
|
|||
|
||||
"""
|
||||
# pylint: disable=unused-argument
|
||||
from __future__ import annotations
|
||||
from ipaddress import (
|
||||
IPv4Network,
|
||||
IPv6Network,
|
||||
)
|
||||
|
||||
from typing import Optional
|
||||
import flask
|
||||
import werkzeug
|
||||
|
||||
|
@ -21,7 +25,11 @@ 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:
|
||||
if request.headers.get('Accept-Language', '').strip() == '':
|
||||
return too_many_requests(request, "missing HTTP header Accept-Language")
|
||||
return too_many_requests(network, "missing HTTP header Accept-Language")
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue