Skip to content

Commit 88ed322

Browse files
dunglasbradfitz
authored andcommitted
net/http/httputil: add docs about X-Forwarded-For in ReverseProxy
ReverseProxy automatically sets the X-Forwarded-For header, if the request already contains a X-Forwarded-For header, the value of the client IP is appended to the existing header value. This behavior isn't documented anywhere, and can lead to IP spoofing security issues is the client is untrusted (the most common situation). This PR documents this behavior. For future versions, I proposed #36678 that implements a more secure default behavior and adds support for other forwarded headers. Change-Id: Ief14f5063caebfccb87714f54cffa927c714e5fd GitHub-Last-Rev: fd0bd29 GitHub-Pull-Request: #36672 Reviewed-on: https://go-review.googlesource.com/c/go/+/215617 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 71239b4 commit 88ed322

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/net/http/httputil/reverseproxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ import (
2424
// ReverseProxy is an HTTP Handler that takes an incoming request and
2525
// sends it to another server, proxying the response back to the
2626
// client.
27+
//
28+
// ReverseProxy automatically sets the client IP as the value of the
29+
// X-Forwarded-For header.
30+
// If an X-Forwarded-For header already exists, the client IP is
31+
// appended to the existing values.
32+
// To prevent IP spoofing, be sure to delete any pre-existing
33+
// X-Forwarded-For header coming from the client or
34+
// an untrusted proxy.
2735
type ReverseProxy struct {
2836
// Director must be a function which modifies
2937
// the request into a new request to be sent

0 commit comments

Comments
 (0)