git.iko.soy/typeable/oauth2-proxy
on master help sign in
Updated redirect arg handling to only happen when needed.
11ce460Sean O'Connor
oauthproxy.go+23−7
@@ -236,6 +236,22 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
236 return "", false
236 return "", false
237}
237}
238
238
239+func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
240+ err := req.ParseForm()
241+
242+ if err != nil {
243+ return "", err
244+ }
245+
246+ redirect := req.FormValue("rd")
247+
248+ if redirect == "" {
249+ redirect = "/"
250+ }
251+
252+ return redirect, err
253+}
254+
239func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
255func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
240 // check if this is a redirect back at the end of oauth
256 // check if this is a redirect back at the end of oauth
241 remoteIP := req.Header.Get("X-Real-IP")
257 remoteIP := req.Header.Get("X-Real-IP")
@@ -246,13 +262,14 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
246
262
247 var ok bool
263 var ok bool
248 var user string
264 var user string
249− redirect := req.FormValue("rd")
250−
251− if redirect == "" {
252− redirect = "/"
253− }
254
265
255 if req.URL.Path == signInPath {
266 if req.URL.Path == signInPath {
267+ redirect, err := p.GetRedirect(req)
268+ if err != nil {
269+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
270+ return
271+ }
272+
256 user, ok = p.ManualSignIn(rw, req)
273 user, ok = p.ManualSignIn(rw, req)
257 if ok {
274 if ok {
258 p.SetCookie(rw, req, user)
275 p.SetCookie(rw, req, user)
@@ -263,8 +280,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
263 return
280 return
264 }
281 }
265 if req.URL.Path == oauthStartPath {
282 if req.URL.Path == oauthStartPath {
266− // get the ?rd= value
283+ redirect, err := p.GetRedirect(req)
267− err := req.ParseForm()
268 if err != nil {
284 if err != nil {
269 p.ErrorPage(rw, 500, "Internal Error", err.Error())
285 p.ErrorPage(rw, 500, "Internal Error", err.Error())
270 return
286 return