Skip to content

Commit

Permalink
Merge pull request #61 from ploxiln/invalid_redirect_v4
Browse files Browse the repository at this point in the history
more liberal invalid redirect check (more blocking)
  • Loading branch information
ploxiln authored Jul 21, 2020
2 parents 698fa5c + f49c6ae commit 6e28e7f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ func (p *OAuthProxy) GetRedirect(req *http.Request) (redirect string, err error)
return
}

var invalidRedirectRe = regexp.MustCompile(`[/\\](?:[\s\v]*|\.\.?)[/\\]`)

func (p *OAuthProxy) IsValidRedirect(redirect string) bool {
url, err := url.Parse(redirect)
if err != nil {
Expand All @@ -482,7 +484,7 @@ func (p *OAuthProxy) IsValidRedirect(redirect string) bool {
log.Printf("invalid redirect: is auth start or sign_in path: %q", redirect)
return false
}
if match, _ := regexp.MatchString(`^[/\\](?:[\s\v]*|\.\.?)[/\\]`, redirect); match {
if strings.HasPrefix(redirect, "/") && invalidRedirectRe.MatchString(redirect) {
// prevent open-redirect tricks: `//` or `/\` or `/ /` or `/ \` or `/./\\` etc.
log.Printf("invalid redirect: tricky prefix: %q", redirect)
return false
Expand Down

0 comments on commit 6e28e7f

Please sign in to comment.