Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Caddyfile to Add X-Real-IP to fix bot detection #162

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

ChillyKitty
Copy link
Contributor

Bot detection complains about not having X-Real-IP which is required https://docs.searxng.org/src/searx.botdetection.html#id4 this adds the header and fixes the problem for me.

Bot detection complains about not having X-Real-IP which is required https://docs.searxng.org/src/searx.botdetection.html#id4 this adds the header and fixes the problem for me.
Copy link
Member

@return42 return42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChillyKitty thanks a lot for adding X-Real-IP to the caddy config. I am not a docker expert and it would take too long to build my own testbed. So I'll just ask you directly, just to be sure:

a.) In the bot detection, the remote IP of the request is taken from (first match):

Its documented here in the searx.botdetection.get_real_ip function.

b.) From the Caddy docs: .. sets or augments the X-Forwarded-For header field.

Can you confirm that X-Real-IP and X-Forwarded-For hold the same value (IP).

@return42
Copy link
Member

@dalf dalf merged commit 9e42027 into searxng:master Aug 25, 2023
@dalf
Copy link
Member

dalf commented Aug 25, 2023

the remote IP of the request is taken from (first match):

as far I can understand from the code, both X-Forwarded-For and X-Real-IP are required.

@return42
Copy link
Member

as far I can understand from the code, both X-Forwarded-For and X-Real-IP are required.

not really

 request_ip = forwarded_for or real_ip or remote_addr or '0.0.0.0'

but the code write log messages:

  • error: when X-Forwarded-For and/or X-Real-IP is missed
  • warning: when the headers have contradictory values.

Reference: get_real_ip(request: flask.Request)

@dalf
Copy link
Member

dalf commented Aug 25, 2023

This log makes X-Real-IP mandatory de facto:
https://github.com/searxng/searxng/blob/4b42644579581699ad1d4b7974610933277dd021/searx/botdetection/_helpers.py#L104-L105

This other log makes X-Forwarded-For mandatory de facto:
https://github.com/searxng/searxng/blob/4b42644579581699ad1d4b7974610933277dd021/searx/botdetection/_helpers.py#L95-L96

By de facto, I mean the user has to set these two headers to avoid tons of errors.

return42 added a commit to return42/searxng that referenced this pull request Aug 25, 2023
To test start a `make run` instance and query multiple times for `ip` (the
answerer), you should see only once the error message(s):

    ERROR   searx.botdetection            : X-Forwarded-For header is not set!
    ERROR   searx.botdetection            : X-Real-IP header is not set!

[1] searxng/searxng-docker#174
[2] searxng/searxng-docker#162 (comment)

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@return42
Copy link
Member

By de facto, I mean the user has to set these two headers to avoid tons of errors.

Ah, OK .. sorry my slow comprehension .. now I understand what you mean / in my understanding of required I thought about the limiter works or not .. was not thinking about the massive error context 🤦

We can reduce the tons of error logs similar to what you suggested in #174 (reply in thread) .. I send PR

.. does the PR mitigate the problem? / .. lets have further discussions in the PR.

return42 added a commit to searxng/searxng that referenced this pull request Aug 28, 2023
To test start a `make run` instance and query multiple times for `ip` (the
answerer), you should see only once the error message(s):

    ERROR   searx.botdetection            : X-Forwarded-For header is not set!
    ERROR   searx.botdetection            : X-Real-IP header is not set!

[1] searxng/searxng-docker#174
[2] searxng/searxng-docker#162 (comment)

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@searxng searxng deleted a comment from rowie Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants