diff options
| author | Alex Sergeyev <abc@alexsergeyev.com> | 2015-02-16 09:29:37 -0500 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-02-18 19:56:50 +0000 |
| commit | eaf8e8cbe576a8553214ffc8e2ce09e9fbc6e87e (patch) | |
| tree | 8d8061bc4807533fff421e18471b9fafb26eeb00 /src/net/http/cgi/host.go | |
| parent | b2c2bc48564a322a0d68ae429ec6a19836dfd6c1 (diff) | |
| download | go-eaf8e8cbe576a8553214ffc8e2ce09e9fbc6e87e.tar.xz | |
net/http/cgi: fix REMOTE_ADDR, REMOTE_HOST, add REMOTE_PORT
Env vars were incorrectly copying whole value of http.RemoteAddr
to REMOTE_ADDR and REMOTE_HOST. They contained IP:port pair which
instead should only have IP (RFC 3875, other sources).
Module also was not setting REMOTE_PORT variable which become de-facto
standard for passing TCP client port to CGI scripts (Apache mod_cgi,
IIS, and probably others)
Fixes #9861
Change-Id: Ia73e664c48539e3c7db4997d09d957884e98d8a5
Reviewed-on: https://go-review.googlesource.com/4933
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/cgi/host.go')
| -rw-r--r-- | src/net/http/cgi/host.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/net/http/cgi/host.go b/src/net/http/cgi/host.go index ec95a972c1..4efbe7abee 100644 --- a/src/net/http/cgi/host.go +++ b/src/net/http/cgi/host.go @@ -19,6 +19,7 @@ import ( "fmt" "io" "log" + "net" "net/http" "os" "os/exec" @@ -128,11 +129,16 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { "PATH_INFO=" + pathInfo, "SCRIPT_NAME=" + root, "SCRIPT_FILENAME=" + h.Path, - "REMOTE_ADDR=" + req.RemoteAddr, - "REMOTE_HOST=" + req.RemoteAddr, "SERVER_PORT=" + port, } + if remoteIP, remotePort, err := net.SplitHostPort(req.RemoteAddr); err == nil { + env = append(env, "REMOTE_ADDR="+remoteIP, "REMOTE_HOST="+remoteIP, "REMOTE_PORT="+remotePort) + } else { + // could not parse ip:port, let's use whole RemoteAddr and leave REMOTE_PORT undefined + env = append(env, "REMOTE_ADDR="+req.RemoteAddr, "REMOTE_HOST="+req.RemoteAddr) + } + if req.TLS != nil { env = append(env, "HTTPS=on") } |
