Skip to content

Commit 55ba4e9

Browse files
committed
fix(redirect): allow root cookie domain host redirects
Previously IsRedirectSafe rejected redirects to the exact cookie domain when AppURL had multiple subdomain levels, because it stripped the first label twice.
1 parent a9c1bf8 commit 55ba4e9

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎internal/utils/app_utils.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ func IsRedirectSafe(redirectURL string, domain string) bool {
100100
return false
101101
}
102102

103-
cookieDomain, err := GetCookieDomain(redirectURL)
104-
105-
if err != nil {
106-
return false
103+
host := parsedURL.Hostname()
104+
if host == domain {
105+
return true
107106
}
108107

109-
if cookieDomain != domain {
108+
cookieDomain, err := GetCookieDomain(redirectURL)
109+
if err != nil {
110110
return false
111111
}
112112

113-
return true
113+
return cookieDomain == domain
114114
}
115115

116116
func GetLogLevel(level string) zerolog.Level {

‎internal/utils/app_utils_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestIsRedirectSafe(t *testing.T) {
164164
// Case with no subdomain
165165
redirectURL := "http://example.com/welcome"
166166
result := utils.IsRedirectSafe(redirectURL, domain)
167-
assert.Equal(t, false, result)
167+
assert.Equal(t, true, result)
168168

169169
// Case with different domain
170170
redirectURL = "http://malicious.com/phishing"

0 commit comments

Comments
 (0)