Updated redirect arg handling to only happen when needed.

This commit is contained in:
Sean O'Connor 2013-10-24 15:31:08 +00:00
parent 9a6e895368
commit 11ce460209

View File

@ -236,6 +236,22 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
return "", false return "", false
} }
func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
err := req.ParseForm()
if err != nil {
return "", err
}
redirect := req.FormValue("rd")
if redirect == "" {
redirect = "/"
}
return redirect, err
}
func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// check if this is a redirect back at the end of oauth // check if this is a redirect back at the end of oauth
remoteIP := req.Header.Get("X-Real-IP") remoteIP := req.Header.Get("X-Real-IP")
@ -246,13 +262,14 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
var ok bool var ok bool
var user string var user string
redirect := req.FormValue("rd")
if redirect == "" {
redirect = "/"
}
if req.URL.Path == signInPath { if req.URL.Path == signInPath {
redirect, err := p.GetRedirect(req)
if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error())
return
}
user, ok = p.ManualSignIn(rw, req) user, ok = p.ManualSignIn(rw, req)
if ok { if ok {
p.SetCookie(rw, req, user) p.SetCookie(rw, req, user)
@ -263,8 +280,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
return return
} }
if req.URL.Path == oauthStartPath { if req.URL.Path == oauthStartPath {
// get the ?rd= value redirect, err := p.GetRedirect(req)
err := req.ParseForm()
if err != nil { if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error()) p.ErrorPage(rw, 500, "Internal Error", err.Error())
return return