|
.oO SearXNG Developer Documentation Oo.
|
Functions | |
| is_suspicious (IPv4Network|IPv6Network network, flask.Request request, bool renew=False) | |
| ping (flask.Request request, str token) | |
| str | get_ping_key (IPv4Network|IPv6Network network, flask.Request request) |
| bool | token_is_valid (token) |
| str | get_token () |
Variables | |
| int | TOKEN_LIVE_TIME = 600 |
| int | PING_LIVE_TIME = 3600 |
| str | PING_KEY = 'SearXNG_limiter.ping' |
| str | TOKEN_KEY = 'SearXNG_limiter.token' |
| logger = logger.getChild('botdetection.link_token') | |
Method ``link_token``
---------------------
The ``link_token`` method evaluates a request as :py:obj:`suspicious
<is_suspicious>` if the URL ``/client<token>.css`` is not requested by the
client. By adding a random component (the token) in the URL, a bot can not send
a ping by request a static URL.
.. note::
This method requires a valkey DB and needs a HTTP X-Forwarded-For_ header.
To get in use of this method a flask URL route needs to be added:
.. code:: python
@app.route('/client<token>.css', methods=['GET', 'POST'])
def client_token(token=None):
link_token.ping(request, token)
return Response('', mimetype='text/css')
And in the HTML template from flask a stylesheet link is needed (the value of
``link_token`` comes from :py:obj:`get_token`):
.. code:: html
<link rel="stylesheet"
href="{{ url_for('client_token', token=link_token) }}"
type="text/css" >
.. _X-Forwarded-For:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
| str searx.botdetection.link_token.get_ping_key | ( | IPv4Network | IPv6Network | network, |
| flask.Request | request ) |
Generates a hashed key that fits (more or less) to a *WEB-browser session* in a network.
Definition at line 115 of file link_token.py.
Referenced by is_suspicious(), and ping().
| str searx.botdetection.link_token.get_token | ( | ) |
Returns current token. If there is no currently active token a new token is generated randomly and stored in the Valkey DB. Without without a database connection, string "12345678" is returned. - :py:obj:`TOKEN_LIVE_TIME` - :py:obj:`TOKEN_KEY`
Definition at line 134 of file link_token.py.
Referenced by token_is_valid().
| searx.botdetection.link_token.is_suspicious | ( | IPv4Network | IPv6Network | network, |
| flask.Request | request, | ||
| bool | renew = False ) |
Checks whether a valid ping is exists for this (client) network, if not this request is rated as *suspicious*. If a valid ping exists and argument ``renew`` is ``True`` the expire time of this ping is reset to :py:obj:`PING_LIVE_TIME`.
Definition at line 73 of file link_token.py.
References get_ping_key().
| searx.botdetection.link_token.ping | ( | flask.Request | request, |
| str | token ) |
This function is called by a request to URL ``/client<token>.css``. If ``token`` is valid a :py:obj:`PING_KEY` for the client is stored in the DB. The expire time of this ping-key is :py:obj:`PING_LIVE_TIME`.
Definition at line 93 of file link_token.py.
References get_ping_key(), and token_is_valid().
| bool searx.botdetection.link_token.token_is_valid | ( | token | ) |
Definition at line 128 of file link_token.py.
References get_token().
Referenced by ping().
| searx.botdetection.link_token.logger = logger.getChild('botdetection.link_token') |
Definition at line 70 of file link_token.py.
| str searx.botdetection.link_token.PING_KEY = 'SearXNG_limiter.ping' |
Definition at line 64 of file link_token.py.
| int searx.botdetection.link_token.PING_LIVE_TIME = 3600 |
Definition at line 61 of file link_token.py.
| str searx.botdetection.link_token.TOKEN_KEY = 'SearXNG_limiter.token' |
Definition at line 67 of file link_token.py.
| int searx.botdetection.link_token.TOKEN_LIVE_TIME = 600 |
Definition at line 58 of file link_token.py.