[master] bbd4e79 Collapse multiple X-Forwarded-For headers

Federico G. Schwindt fgsch at lodoss.net
Wed Jan 14 06:27:22 CET 2015


commit bbd4e79adc2ac44fe3866b5288fed8a3ecb05bb0
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Wed Jan 14 04:32:50 2015 +0000

    Collapse multiple X-Forwarded-For headers
    
    Fixes #1650

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 3e1e9d0..66da39e 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -587,6 +587,7 @@ cnt_recv(struct worker *wrk, struct req *req)
 		 * This really should be done earlier, but we want to capture
 		 * it in the VSL log.
 		 */
+		http_CollectHdr(req->http, H_X_Forwarded_For);
 		if (http_GetHdr(req->http, H_X_Forwarded_For, &xff)) {
 			http_Unset(req->http, H_X_Forwarded_For);
 			http_PrintfHeader(req->http, "X-Forwarded-For: %s, %s",
diff --git a/bin/varnishtest/tests/r01650.vtc b/bin/varnishtest/tests/r01650.vtc
new file mode 100644
index 0000000..e21ceba
--- /dev/null
+++ b/bin/varnishtest/tests/r01650.vtc
@@ -0,0 +1,16 @@
+varnishtest "xff handling discards multiple headers"
+
+server s1 {
+	rxreq
+	expect req.http.X-Forwarded-For == "1.2.3.4, 5.6.7.8, 127.0.0.1"
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+	txreq -hdr "X-Forwarded-For: 1.2.3.4" -hdr "X-Forwarded-For: 5.6.7.8"
+	rxresp
+} -run
+



More information about the varnish-commit mailing list