|
4 | 4 | "encoding/json" |
5 | 5 | "errors" |
6 | 6 | "net/http" |
| 7 | + "net/url" |
7 | 8 | "strings" |
8 | 9 | "time" |
9 | 10 |
|
@@ -47,13 +48,11 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) { |
47 | 48 | } |
48 | 49 |
|
49 | 50 | redir := r.FormValue("goto") |
50 | | - if redir != "" && strings.HasPrefix(redir, "/") { |
| 51 | + if redir != "" && strings.HasPrefix(redir, "/") && !strings.HasPrefix(redir, "//") && !strings.HasPrefix(redir, "/\\") { |
51 | 52 | common.RedisPool.Do(radix.Cmd(nil, "SET", "csrf_redir:"+csrfToken, redir, "EX", "500")) |
52 | 53 | } |
53 | 54 |
|
54 | 55 | url := OauthConf.AuthCodeURL(csrfToken, oauth2.AccessTypeOnline) |
55 | | - // disabled prompt to see if the multiple requests are still happening when user expliclity consents to login |
56 | | - // url += "&prompt=none" |
57 | 56 | http.Redirect(w, r, url, http.StatusTemporaryRedirect) |
58 | 57 | } |
59 | 58 |
|
@@ -89,15 +88,20 @@ func HandleConfirmLogin(w http.ResponseWriter, r *http.Request) { |
89 | 88 |
|
90 | 89 | http.SetCookie(w, sessionCookie) |
91 | 90 |
|
92 | | - var redirUrl string |
93 | | - err = common.RedisPool.Do(radix.Cmd(&redirUrl, "GET", "csrf_redir:"+state)) |
| 91 | + var redir string |
| 92 | + err = common.RedisPool.Do(radix.Cmd(&redir, "GET", "csrf_redir:"+state)) |
94 | 93 | if err != nil { |
95 | | - redirUrl = "/manage" |
| 94 | + redir = "/manage" |
96 | 95 | } else { |
97 | 96 | common.RedisPool.Do(radix.Cmd(nil, "DEL", "csrf_redir:"+state)) |
98 | 97 | } |
99 | 98 |
|
100 | | - http.Redirect(w, r, redirUrl, http.StatusTemporaryRedirect) |
| 99 | + redirParsed, err := url.Parse(redir) |
| 100 | + if err != nil || redirParsed.Host != "" || redirParsed.Scheme != "" { |
| 101 | + redirParsed, _ = url.Parse("/manage") |
| 102 | + } |
| 103 | + |
| 104 | + http.Redirect(w, r, redirParsed.String(), http.StatusTemporaryRedirect) |
101 | 105 |
|
102 | 106 | } |
103 | 107 |
|
|
0 commit comments