mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-09-19 08:03:31 +08:00
fix: fail acl lookup when input domain doesn't match cookie domain
This commit is contained in:
@@ -918,6 +918,7 @@ func TestProxyController(t *testing.T) {
|
|||||||
aclsService := service.NewAccessControlsService(service.AccessControlServiceInput{
|
aclsService := service.NewAccessControlsService(service.AccessControlServiceInput{
|
||||||
Log: log,
|
Log: log,
|
||||||
Config: &cfg,
|
Config: &cfg,
|
||||||
|
Runtime: &runtime,
|
||||||
LabelProvider: nil,
|
LabelProvider: nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -66,15 +66,15 @@ func (service *AccessControlsService) getACLs(domain string, lookup func(locator
|
|||||||
|
|
||||||
normalizedDomain := service.normalizeDomain(domain)
|
normalizedDomain := service.normalizeDomain(domain)
|
||||||
|
|
||||||
|
if !strings.HasSuffix(normalizedDomain, "."+service.runtime.CookieDomain) && normalizedDomain != service.runtime.CookieDomain {
|
||||||
|
return nil, fmt.Errorf("domain does not match cookie domain, expected %s (or a subdomain), got %s", service.runtime.CookieDomain, domain)
|
||||||
|
}
|
||||||
|
|
||||||
var domainMatch *model.App
|
var domainMatch *model.App
|
||||||
var nameMatch *model.App
|
var nameMatch *model.App
|
||||||
var nameMatchedApps []string
|
var nameMatchedApps []string
|
||||||
|
|
||||||
locatorFunc := func(name string, app *model.App) bool {
|
locatorFunc := func(name string, app *model.App) bool {
|
||||||
if !strings.HasSuffix(normalizedDomain, "."+service.runtime.CookieDomain) && normalizedDomain != service.runtime.CookieDomain {
|
|
||||||
service.log.App.Debug().Str("name", name).Msg("Domain does not match runtime cookie domain, skipping")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if app.Config.Domain != "" {
|
if app.Config.Domain != "" {
|
||||||
if !service.ensureAscii(app.Config.Domain) {
|
if !service.ensureAscii(app.Config.Domain) {
|
||||||
service.log.App.Warn().Str("name", name).Str("domain", app.Config.Domain).Msg("Domain contains non-ascii characters, skipping")
|
service.log.App.Warn().Str("name", name).Str("domain", app.Config.Domain).Msg("Domain contains non-ascii characters, skipping")
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ func TestAccessControlsService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
|
errorFunc: func(t *testing.T, e error) {
|
||||||
|
assert.ErrorContains(t, e, "domain does not match cookie domain")
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "App in domain not matching with the cookie domain should return nothing with domain matching",
|
name: "App in domain not matching with the cookie domain should return nothing with domain matching",
|
||||||
@@ -134,6 +137,9 @@ func TestAccessControlsService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
|
errorFunc: func(t *testing.T, e error) {
|
||||||
|
assert.ErrorContains(t, e, "domain does not match cookie domain")
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user