Skip to content

Commit 9e44d39

Browse files
committed
prevent redirect to non yag urls, and change error message for soundboard
1 parent 0194410 commit 9e44d39

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

soundboard/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func HandleNew(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
166166
var resp *http.Response
167167
resp, err = http.Get(r.FormValue("SoundURL"))
168168
if err != nil {
169-
tmpl.AddAlerts(web.ErrorAlert("Failed downloading sound: " + err.Error()))
169+
logger.WithError(err).Error("Failed downloading soundboard sound")
170+
tmpl.AddAlerts(web.ErrorAlert("Failed downloading sound from: " + r.FormValue("SoundURL") + " Make sure the link is correct"))
170171
destFile.Close()
171172
} else {
172173
defer resp.Body.Close()

web/handlers_auth.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"net/http"
7+
"net/url"
78
"strings"
89
"time"
910

@@ -47,13 +48,11 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
4748
}
4849

4950
redir := r.FormValue("goto")
50-
if redir != "" && strings.HasPrefix(redir, "/") {
51+
if redir != "" && strings.HasPrefix(redir, "/") && !strings.HasPrefix(redir, "//") && !strings.HasPrefix(redir, "/\\") {
5152
common.RedisPool.Do(radix.Cmd(nil, "SET", "csrf_redir:"+csrfToken, redir, "EX", "500"))
5253
}
5354

5455
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"
5756
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
5857
}
5958

@@ -89,15 +88,20 @@ func HandleConfirmLogin(w http.ResponseWriter, r *http.Request) {
8988

9089
http.SetCookie(w, sessionCookie)
9190

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))
9493
if err != nil {
95-
redirUrl = "/manage"
94+
redir = "/manage"
9695
} else {
9796
common.RedisPool.Do(radix.Cmd(nil, "DEL", "csrf_redir:"+state))
9897
}
9998

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)
101105

102106
}
103107

0 commit comments

Comments
 (0)