zulip/zproject
Alex Vandiver 07779ea879 middleware: Do not trust X-Forwarded-For; use X-Real-Ip, set from nginx.
The `X-Forwarded-For` header is a list of proxies' IP addresses; each
proxy appends the remote address of the host it received its request
from to the list, as it passes the request down.  A naïve parsing, as
SetRemoteAddrFromForwardedFor did, would thus interpret the first
address in the list as the client's IP.

However, clients can pass in arbitrary `X-Forwarded-For` headers,
which would allow them to spoof their IP address.  `nginx`'s behavior
is to treat the addresses as untrusted unless they match an allowlist
of known proxies.  By setting `real_ip_recursive on`, it also allows
this behavior to be applied repeatedly, moving from right to left down
the `X-Forwarded-For` list, stopping at the right-most that is
untrusted.

Rather than re-implement this logic in Django, pass the first
untrusted value that `nginx` computer down into Django via `X-Real-Ip`
header.  This allows consistent IP addresses in logs between `nginx`
and Django.

Proxied calls into Tornado (which don't use UWSGI) already passed this
header, as Tornado logging respects it.
2021-03-31 14:19:38 -07:00
..
jinja2 static: Make debug_mode for default_page_params follow the setting. 2021-03-26 09:41:12 -07:00
__init__.py
backends.py refactor: Make acting_user a mandatory kwarg for do_deactivate_user. 2021-03-29 15:51:45 -07:00
computed_settings.py middleware: Do not trust X-Forwarded-For; use X-Real-Ip, set from nginx. 2021-03-31 14:19:38 -07:00
config.py python: Normalize quotes with Black. 2021-02-12 13:11:19 -08:00
configured_settings.py python: Sort imports with isort. 2020-06-11 16:45:32 -07:00
default_settings.py hotspots: Add TUTORIAL_ENABLED setting to toggle INTRO_HOTSPOTS. 2021-03-30 14:46:42 -07:00
dev_settings.py python: Normalize quotes with Black. 2021-02-12 13:11:19 -08:00
dev_urls.py urls: Add /flush_caches URL to remove all the server-side cache. 2021-03-25 12:58:36 -07:00
email_backends.py email: Set an envelope-from which may be different from the From: field. 2021-02-24 17:32:28 -08:00
legacy_urls.py python: Normalize quotes with Black. 2021-02-12 13:11:19 -08:00
prod_settings_template.py hotspots: Add TUTORIAL_ENABLED setting to toggle INTRO_HOTSPOTS. 2021-03-30 14:46:42 -07:00
sentry.py python: Normalize quotes with Black. 2021-02-12 13:11:19 -08:00
settings.py python: Add noqa comments for the specific star imports we allow. 2020-06-11 15:36:43 -07:00
terms.md.template docs: Capitalize Markdown consistently. 2020-08-11 10:23:06 -07:00
test_extra_settings.py computed_settings: Remove unused TUTORIAL_ENABLED setting. 2021-03-30 14:44:09 -07:00
test_settings.py test_settings: Use TEST_EXTERNAL_HOST to override ‘testserver’ default. 2020-12-17 13:07:59 -08:00
urls.py api: Support user_id in get_user_presence_endpoint. 2021-03-11 20:14:04 -08:00
wsgi.py python: Normalize quotes with Black. 2021-02-12 13:11:19 -08:00