Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent redirect to Host (2) #19175

Merged
merged 6 commits into from
Mar 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net/http"
"net/url"
"path"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -174,13 +175,19 @@ func (ctx *Context) HasValue(name string) bool {
return ok
}

var precedingSlashesRE = regexp.MustCompile(`^/[\\/]+`)
zeripath marked this conversation as resolved.
Show resolved Hide resolved

// RedirectToFirst redirects to first not empty URL
func (ctx *Context) RedirectToFirst(location ...string) {
for _, loc := range location {
if len(loc) == 0 {
continue
}

if precedingSlashesRE.MatchString(loc) {
continue
}

u, err := url.Parse(loc)
if err != nil || ((u.Scheme != "" || u.Host != "") && !strings.HasPrefix(strings.ToLower(loc), strings.ToLower(setting.AppURL))) {
continue
Expand Down