.oO SearXNG Developer Documentation Oo.
|
Functions | |
config.Config | get_cfg () |
werkzeug.Response|None | filter_request (flask.Request request) |
pre_request () | |
is_installed () | |
initialize (flask.Flask app, settings) | |
Variables | |
logger = logger.getChild('limiter') | |
config | CFG = None |
bool | _INSTALLED = False |
str | LIMITER_CFG_SCHEMA = Path(__file__).parent / "limiter.toml" |
dict | CFG_DEPRECATED |
Bot protection / IP rate limitation. The intention of rate limitation is to limit suspicious requests from an IP. The motivation behind this is the fact that SearXNG passes through requests from bots and is thus classified as a bot itself. As a result, the SearXNG engine then receives a CAPTCHA or is blocked by the search engine (the origin) in some other way. To avoid blocking, the requests from bots to SearXNG must also be blocked, this is the task of the limiter. To perform this task, the limiter uses the methods from the :ref:`botdetection`: - Analysis of the HTTP header in the request / :ref:`botdetection probe headers` can be easily bypassed. - Block and pass lists in which IPs are listed / :ref:`botdetection ip_lists` are hard to maintain, since the IPs of bots are not all known and change over the time. - Detection & dynamically :ref:`botdetection rate limit` of bots based on the behavior of the requests. For dynamically changeable IP lists a Redis database is needed. The prerequisite for IP based methods is the correct determination of the IP of the client. The IP of the client is determined via the X-Forwarded-For_ HTTP header. .. attention:: A correct setup of the HTTP request headers ``X-Forwarded-For`` and ``X-Real-IP`` is essential to be able to assign a request to an IP correctly: - `NGINX RequestHeader`_ - `Apache RequestHeader`_ .. _X-Forwarded-For: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For .. _NGINX RequestHeader: https://docs.searxng.org/admin/installation-nginx.html#nginx-s-searxng-site .. _Apache RequestHeader: https://docs.searxng.org/admin/installation-apache.html#apache-s-searxng-site Enable Limiter ============== To enable the limiter activate: .. code:: yaml server: ... limiter: true # rate limit the number of request on the instance, block some bots and set the redis-url connection. Check the value, it depends on your redis DB (see :ref:`settings redis`), by example: .. code:: yaml redis: url: unix:///usr/local/searxng-redis/run/redis.sock?db=0 Configure Limiter ================= The methods of :ref:`botdetection` the limiter uses are configured in a local file ``/etc/searxng/limiter.toml``. The defaults are shown in limiter.toml_ / Don't copy all values to your local configuration, just enable what you need by overwriting the defaults. For instance to activate the ``link_token`` method in the :ref:`botdetection.ip_limit` you only need to set this option to ``true``: .. code:: toml [botdetection.ip_limit] link_token = true .. _limiter.toml: ``limiter.toml`` ================ In this file the limiter finds the configuration of the :ref:`botdetection`: - :ref:`botdetection ip_lists` - :ref:`botdetection rate limit` - :ref:`botdetection probe headers` .. kernel-include:: $SOURCEDIR/limiter.toml :code: toml Implementation ==============
werkzeug.Response | None searx.limiter.filter_request | ( | flask.Request | request | ) |
Definition at line 147 of file limiter.py.
References searx.limiter.get_cfg().
Referenced by searx.limiter.pre_request().
config.Config searx.limiter.get_cfg | ( | ) |
Definition at line 136 of file limiter.py.
Referenced by searx.limiter.filter_request().
searx.limiter.initialize | ( | flask.Flask | app, |
settings ) |
Install the limiter
Definition at line 218 of file limiter.py.
searx.limiter.is_installed | ( | ) |
Returns ``True`` if limiter is active and a redis DB is available.
Definition at line 213 of file limiter.py.
searx.limiter.pre_request | ( | ) |
See :py:obj:`flask.Flask.before_request`
Definition at line 208 of file limiter.py.
References searx.limiter.filter_request().
|
protected |
Definition at line 126 of file limiter.py.
config searx.limiter.CFG = None |
Definition at line 125 of file limiter.py.
dict searx.limiter.CFG_DEPRECATED |
Definition at line 131 of file limiter.py.
str searx.limiter.LIMITER_CFG_SCHEMA = Path(__file__).parent / "limiter.toml" |
Definition at line 128 of file limiter.py.
searx.limiter.logger = logger.getChild('limiter') |
Definition at line 123 of file limiter.py.