Skip to content

Commit

Permalink
fix(configuration): default redirection url check fails (#6867)
Browse files Browse the repository at this point in the history
This fixes an  error for the legacy mapping of the default redirection url.
  • Loading branch information
james-d-elliott committed Mar 15, 2024
1 parent 5ba9e9b commit 65a7fc2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion internal/configuration/validator/session.go
Expand Up @@ -163,6 +163,8 @@ func validateSessionUniqueCookieDomain(i int, config *schema.Session, domains []
}

// validateSessionCookiesURLs validates the AutheliaURL and DefaultRedirectionURL.
//
//nolint:gocyclo
func validateSessionCookiesURLs(i int, config *schema.Session, validator *schema.StructValidator) {
var d = config.Cookies[i]

Expand Down Expand Up @@ -190,7 +192,12 @@ func validateSessionCookiesURLs(i int, config *schema.Session, validator *schema
}

if d.Domain != "" && !utils.HasURIDomainSuffix(d.DefaultRedirectionURL, d.Domain) {
validator.Push(fmt.Errorf(errFmtSessionDomainURLNotInCookieScope, sessionDomainDescriptor(i, d), attrDefaultRedirectionURL, d.Domain, d.DefaultRedirectionURL))
if d.Legacy {
validator.PushWarning(fmt.Errorf(errFmtSessionDomainURLNotInCookieScope, sessionDomainDescriptor(i, d), attrDefaultRedirectionURL, d.Domain, d.DefaultRedirectionURL))
d.DefaultRedirectionURL = nil
} else {
validator.Push(fmt.Errorf(errFmtSessionDomainURLNotInCookieScope, sessionDomainDescriptor(i, d), attrDefaultRedirectionURL, d.Domain, d.DefaultRedirectionURL))
}
}

if d.AutheliaURL != nil && utils.EqualURLs(d.AutheliaURL, d.DefaultRedirectionURL) {
Expand Down
17 changes: 15 additions & 2 deletions internal/configuration/validator/session_test.go
Expand Up @@ -757,13 +757,26 @@ func TestShouldRaiseErrorWhenHaveNonAbsDefaultRedirectionURL(t *testing.T) {
AutheliaURL: MustParseURL("https://login.example.com"),
DefaultRedirectionURL: MustParseURL("home.example.com"),
},
{
Domain: "example2.com",
AutheliaURL: MustParseURL("https://login.example2.com"),
DefaultRedirectionURL: MustParseURL("https://google.com"),
},
{
Legacy: true,
Domain: "example3.com",
AutheliaURL: MustParseURL("https://login.example3.com"),
DefaultRedirectionURL: MustParseURL("https://google.com"),
},
}

ValidateSession(&config, validator)
assert.False(t, validator.HasWarnings())
require.Len(t, validator.Errors(), 2)
require.Len(t, validator.Warnings(), 1)
require.Len(t, validator.Errors(), 3)
assert.EqualError(t, validator.Errors()[0], "session: domain config #1 (domain 'example.com'): option 'default_redirection_url' is not absolute with a value of 'home.example.com'")
assert.EqualError(t, validator.Errors()[1], "session: domain config #1 (domain 'example.com'): option 'default_redirection_url' does not share a cookie scope with domain 'example.com' with a value of 'home.example.com'")
assert.EqualError(t, validator.Errors()[2], "session: domain config #2 (domain 'example2.com'): option 'default_redirection_url' does not share a cookie scope with domain 'example2.com' with a value of 'https://google.com'")
assert.EqualError(t, validator.Warnings()[0], "session: domain config #3 (domain 'example3.com'): option 'default_redirection_url' does not share a cookie scope with domain 'example3.com' with a value of 'https://google.com'")
}

func TestShouldRaiseErrorWhenHaveNonSecureDefaultRedirectionURL(t *testing.T) {
Expand Down

0 comments on commit 65a7fc2

Please sign in to comment.