element-hq / element-hq/synapse

synapse blindly trusts X-Forwarded-For if x_forwarded option is enabled

Open
#9,471 0 comments 0 reactions 0 assignees View on GitHub
S-Minor Security T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#9471](https://github.com/matrix-org/synapse/issues/9471).

---

Synapse does not check that the chain in `X-Forwarded-For` is trusted, and so an attacker can spoof their IP address if the reverse proxy does not sanitize `X-Forwarded-For`. Ideally, we should be able to pass a set of trusted IP addresses, and synapse should only trust `X-Forwarded-For` if: 1) the request comes from a trusted IP address, and 2) every IP address in X-Forwarded-For, other than the first one, is trusted.

This can be mitigated by ensuring that the `X-Forwarded-For` header is sanitized before it hits synapse. For example, the public-facing reverse-proxy should remove any `X-Forwarded-For` header that it receives.

The IP address seems to be used for:

- checking that AS requests come from trusted IP addresses
- rate limiting registration requests
- UI auth (maybe?)
- request logging
- last-seen IP address for devices

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.