Отвечать 400 и 401 вместо 500 на NUL и невалидный UTF-8 во входных данных
This commit is contained in:
@@ -45,7 +45,14 @@ var dummyHash = sync.OnceValue(func() string {
|
||||
|
||||
// Authenticate returns the user whose password matches, or
|
||||
// ErrInvalidCredentials for an unknown username and a wrong password alike.
|
||||
// The username comes straight from the Basic header, so one that cannot
|
||||
// exist (including NUL or invalid UTF-8, which the database would reject)
|
||||
// is answered without a query, but after the same KDF work.
|
||||
func (s *Service) Authenticate(ctx context.Context, username, plain string) (User, error) {
|
||||
if !usernamePattern.MatchString(username) {
|
||||
_, _ = password.Verify(dummyHash(), plain)
|
||||
return User{}, ErrInvalidCredentials
|
||||
}
|
||||
u, err := s.repo.GetByUsername(ctx, username)
|
||||
if errors.Is(err, ErrNotFound) {
|
||||
_, _ = password.Verify(dummyHash(), plain)
|
||||
|
||||
Reference in New Issue
Block a user