You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
http://golang.org/cl/28930 caused a regression. The CL in question fixes #4800 by automatically copying the headers when following a redirect. In the situation where the initial request has some cookie set and one of the redirects sets the cookie to a different value, we should change the cookies sent in subsequent requests to use newly set cookies.
This pattern is used by some login logic where credentials are stored in the cookies. Suppose the client has a stale auth cookie and makes a request. The server redirects the client to some other page to obtain a new auth cookie (and gets redirected back to the original page). When the client redirects back to original page, it presents both the stale and new auth cookie, which confuses the server. Since the server still thinks the client is not logged in, it sends it through the redirect loop again.
Minimum reproducing case:
funcmain() {
// Start a trivial server.gofunc() {
http.HandleFunc("/", func(resp http.ResponseWriter, req*http.Request) {
fmt.Println("Got cookie:", req.Header.Get("Cookie"))
// Set the cookie to a new value.http.SetCookie(resp, &http.Cookie{
Name: "YumYumCookie",
Value: "NewValue",
Path: "/",
})
// Keep redirecting to yourself until you see the new cookie value.ck, _:=req.Cookie("YumYumCookie")
ifck.Value!="NewValue" {
http.Redirect(resp, req, "/", http.StatusFound)
}
})
http.ListenAndServe("localhost:8888", nil)
}()
time.Sleep(time.Second)
// Make a request to the server. Initialize the request with an old value for the cookie.jar, _:=cookiejar.New(nil)
client:=&http.Client{Jar: jar}
req, _:=http.NewRequest("GET", "http://localhost:8888/", nil)
req.AddCookie(&http.Cookie{
Name: "YumYumCookie",
Value: "OldValue",
Path: "/",
})
req.Header.Add("HeaderKey", "HeaderValue")
fmt.Println(client.Do(req))
}
http://golang.org/cl/28930 caused a regression. The CL in question fixes #4800 by automatically copying the headers when following a redirect. In the situation where the initial request has some cookie set and one of the redirects sets the cookie to a different value, we should change the cookies sent in subsequent requests to use newly set cookies.
This pattern is used by some login logic where credentials are stored in the cookies. Suppose the client has a stale auth cookie and makes a request. The server redirects the client to some other page to obtain a new auth cookie (and gets redirected back to the original page). When the client redirects back to original page, it presents both the stale and new auth cookie, which confuses the server. Since the server still thinks the client is not logged in, it sends it through the redirect loop again.
Minimum reproducing case:
On go1.7, I see:
On go1.8dev, I see:
/cc @bradfitz
The text was updated successfully, but these errors were encountered: