From ccefcfaf303fe6a02c0e2fde23ab322c5b04cbfa Mon Sep 17 00:00:00 2001 From: Alena Maslova Date: Mon, 17 Jan 2022 14:13:27 +0300 Subject: [PATCH 1/2] use custom UserIDFunc for anonymous provider --- backend/app/cmd/server.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 89b2b91940..574fa8c132 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -836,7 +836,7 @@ func (s *ServerCommand) addAuthProviders(authenticator *auth.Service) error { if s.Auth.Anonymous { log.Print("[INFO] anonymous access enabled") var isValidAnonName = regexp.MustCompile(`^[\p{L}\d_ ]+$`).MatchString - authenticator.AddDirectProvider("anonymous", provider.CredCheckerFunc(func(user, _ string) (ok bool, err error) { + authenticator.AddDirectProviderWithUserIDFunc("anonymous", provider.CredCheckerFunc(func(user, _ string) (ok bool, err error) { // don't allow anon with space prefix or suffix if strings.HasPrefix(user, " ") || strings.HasSuffix(user, " ") { @@ -859,7 +859,10 @@ func (s *ServerCommand) addAuthProviders(authenticator *auth.Service) error { return false, nil } return true, nil - })) + }), + func(user string, r *http.Request) string { + return user + r.RemoteAddr + }) } if providersCount == 0 { From 68ac624bdd2c56a4b3b02f3437c1f20e0924a7fe Mon Sep 17 00:00:00 2001 From: Alena Maslova Date: Tue, 10 May 2022 20:15:38 +0300 Subject: [PATCH 2/2] add comment about custom ID user generation --- backend/app/cmd/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 574fa8c132..521e3124ef 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -860,6 +860,8 @@ func (s *ServerCommand) addAuthProviders(authenticator *auth.Service) error { } return true, nil }), + // Custom user ID generator, used to distinguish anonymous users with the same login + // coming from different IPs func(user string, r *http.Request) string { return user + r.RemoteAddr })