mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-24 04:10:14 +00:00
fix: remove port from cookie domain
This commit is contained in:
@@ -335,6 +335,11 @@ func (controller *OAuthController) isRedirectSafe(redirectURI string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if u.Port() != au.Port() {
|
||||||
|
controller.log.App.Warn().Str("redirectUri", redirectURI).Str("appUrl", controller.runtime.AppURL).Msg("Redirect URI port does not match app URL port")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if strings.EqualFold(u.Host, au.Host) {
|
if strings.EqualFold(u.Host, au.Host) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -343,7 +348,7 @@ func (controller *OAuthController) isRedirectSafe(redirectURI string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(strings.ToLower(u.Host), "."+strings.ToLower(controller.runtime.CookieDomain)) {
|
if strings.HasSuffix(strings.ToLower(u.Hostname()), "."+strings.ToLower(controller.runtime.CookieDomain)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func GetCookieDomain(appUrl string, subdomainsEnabled bool) (string, error) {
|
|||||||
return "", fmt.Errorf("domain in public suffix list, cannot set cookies: %w", err)
|
return "", fmt.Errorf("domain in public suffix list, cannot set cookies: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.ToLower(u.Host), nil
|
return hostname, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := strings.Join(parts[1:], ".")
|
domain := strings.Join(parts[1:], ".")
|
||||||
@@ -47,11 +47,7 @@ func GetCookieDomain(appUrl string, subdomainsEnabled bool) (string, error) {
|
|||||||
return "", fmt.Errorf("domain in public suffix list, cannot set cookies: %w", err)
|
return "", fmt.Errorf("domain in public suffix list, cannot set cookies: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now that we validated the domain, return with the port
|
return domain, nil
|
||||||
parts = strings.Split(strings.ToLower(u.Host), ".")
|
|
||||||
host := strings.Join(parts[1:], ".")
|
|
||||||
|
|
||||||
return host, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseFileToLine(content string) string {
|
func ParseFileToLine(content string) string {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestGetRootDomain(t *testing.T) {
|
|||||||
|
|
||||||
// URL with port
|
// URL with port
|
||||||
domain = "http://sub.tinyauth.app:8080"
|
domain = "http://sub.tinyauth.app:8080"
|
||||||
expected = "tinyauth.app:8080"
|
expected = "tinyauth.app"
|
||||||
result, err = utils.GetCookieDomain(domain, true)
|
result, err = utils.GetCookieDomain(domain, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user