mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-01-20 14:22:29 +00:00
fix: ensure safe redirect check only accepts actual domains
This commit is contained in:
@@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -95,7 +96,7 @@ func IsRedirectSafe(redirectURL string, domain string) bool {
|
|||||||
|
|
||||||
hostname := parsed.Hostname()
|
hostname := parsed.Hostname()
|
||||||
|
|
||||||
if strings.HasSuffix(hostname, domain) {
|
if strings.HasSuffix(hostname, fmt.Sprintf(".%s", domain)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,4 +205,9 @@ func TestIsRedirectSafe(t *testing.T) {
|
|||||||
redirectURL = "http://example.org/page"
|
redirectURL = "http://example.org/page"
|
||||||
result = utils.IsRedirectSafe(redirectURL, domain)
|
result = utils.IsRedirectSafe(redirectURL, domain)
|
||||||
assert.Equal(t, false, result)
|
assert.Equal(t, false, result)
|
||||||
|
|
||||||
|
// Case with malicious domain
|
||||||
|
redirectURL = "https://malicious-example.com/yoyo"
|
||||||
|
result = utils.IsRedirectSafe(redirectURL, domain)
|
||||||
|
assert.Equal(t, false, result)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user