Remove duplicated logic
This commit is contained in:
parent
fd875fc663
commit
bc4d5941fc
@ -580,20 +580,13 @@ func (p *OAuthProxy) IsValidRedirect(redirect string) bool {
|
|||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(redirect, "/") && !strings.HasPrefix(redirect, "//"):
|
case strings.HasPrefix(redirect, "/") && !strings.HasPrefix(redirect, "//"):
|
||||||
return true
|
return true
|
||||||
case strings.HasPrefix(redirect, "http://"):
|
case strings.HasPrefix(redirect, "http://") || strings.HasPrefix(redirect, "https://"):
|
||||||
redirect = strings.TrimPrefix(redirect, "http://")
|
redirectURL, err := url.Parse(redirect)
|
||||||
redirect = strings.Split(redirect, "/")[0]
|
if err != nil {
|
||||||
for _, domain := range p.whitelistDomains {
|
|
||||||
if strings.HasSuffix(redirect, domain) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
case strings.HasPrefix(redirect, "https://"):
|
}
|
||||||
redirect = strings.TrimPrefix(redirect, "https://")
|
|
||||||
redirect = strings.Split(redirect, "/")[0]
|
|
||||||
for _, domain := range p.whitelistDomains {
|
for _, domain := range p.whitelistDomains {
|
||||||
if strings.HasSuffix(redirect, domain) {
|
if (redirectURL.Host == domain) || (strings.HasPrefix(domain, ".") && strings.HasSuffix(redirectURL.Host, domain)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user