Skip to content

Commit 2c148db

Browse files
committed
Correct the handling of multiple X-Forwarded-For headers to Synapse.
1 parent 84bfaf8 commit 2c148db

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ defaults
2626

2727
log global
2828

29+
# The Ingress Controller should appropriately set an X-Forwarded-For header
30+
# We leave it alone if it has, but add in the source address in cases where it hasn't
31+
# or the request hasn't come from the ingress controller (i.e. in-cluster)
32+
option forwardfor if-none
33+
34+
# Set the RFC7239 `Forwarded` header
35+
option forwarded
36+
2937
# wait for 5s when connecting to a server
3038
timeout connect 5s
3139

charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ frontend synapse-http-in
3939
http-request capture req.fhdr(x-forwarded-for) len 64
4040
http-request capture req.fhdr(user-agent) len 200
4141

42-
# before we change the 'src', stash it in a session variable
43-
http-request set-var(sess.orig_src) src if !{ var(sess.orig_src) -m found }
44-
45-
# in case this is not the first request on the connection, restore the
46-
# 'src' to the original, in case we fail to parse the x-f-f header.
47-
http-request set-src var(sess.orig_src)
48-
49-
# Traditionally do this only for traffic from some limited IP addreses
50-
# but the incoming router being what it is, means we have no fixed IP here.
51-
http-request set-src hdr(x-forwarded-for)
52-
53-
# We always add a X-Forwarded-For header (clobbering any existing
54-
# headers).
55-
http-request set-header X-Forwarded-For %[src]
56-
5742
# Ingresses by definition run on both 80 & 443 and there's no customising of that
5843
# It is up to the ingress controller and any annotations provided to it whether
5944
# it sets any additional headers or not or whether it redirects http -> https

newsfragments/788.changed.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Correct the handling of multiple X-Forwarded-For headers to Synapse.
2+
3+
This may have exhibit itself as requests being incorrectly rate-limited by Synapse.
4+
5+
The source IP logged by HAProxy is now always the IP connecting to HAProxy rather than
6+
a value extracted from the X-Forwarded-For header (if present). This is usually an IP
7+
for the ingress controller.

0 commit comments

Comments
 (0)