fix: security & privacy (rate limiter fix, csrf session cookie, logout on server, drafts stale token passw, login timing, password over 72b, JWT_SECRET complexity, SMTP TLS, CSV export neutralised, fonts bundled, upload metadata, hourly cleanup job, privacy.md report)

This commit is contained in:
Florian Sylvain committed 2026-10-22 00:49:19 +02:00
1 parent e2812ee0b9
commit ea98c5ec05
118 files changed
+3828 -130

No files matched your search

@@ -5,17 +5,21 @@ import (
"RenewCMS/internal/domain/hash"
"RenewCMS/internal/domain/user"
"context"
"crypto/rand"
"errors"
"sync"
)
type AuthenticateUserUseCase struct {
userRepository user.Repository
hasher hash.Hasher
recorder audit.Recorder
decoyOnce sync.Once
decoyHash string
}
func NewAuthenticateUserUseCase(userRepository user.Repository, hasher hash.Hasher, recorder audit.Recorder) *AuthenticateUserUseCase {
return &AuthenticateUserUseCase{userRepository, hasher, recorder}
return &AuthenticateUserUseCase{userRepository: userRepository, hasher: hasher, recorder: recorder}
}
func (a *AuthenticateUserUseCase) Authenticate(ctx context.Context, username string, password string) (user.User, error) {
@@ -34,6 +38,9 @@ func (a *AuthenticateUserUseCase) Authenticate(ctx context.Context, username str
func (a *AuthenticateUserUseCase) verifyCredentials(username string, password string) (user.User, error) {
dbUser, err := a.userRepository.GetByUsername(username)
if err != nil {
if errors.Is(err, user.ErrUserNotFound) {
a.compareWithDecoy(password)
}
return user.User{}, err
}
@@ -44,6 +51,15 @@ func (a *AuthenticateUserUseCase) verifyCredentials(username string, password st
return dbUser, nil
}
func (a *AuthenticateUserUseCase) compareWithDecoy(password string) {
a.decoyOnce.Do(func() {
a.decoyHash, _ = a.hasher.Hash(rand.Text())
})
if a.decoyHash != "" {
_ = a.hasher.Compare(a.decoyHash, password)
}
}
func (a *AuthenticateUserUseCase) recordRejectedLogin(ctx context.Context, username string, cause error) {
if !errors.Is(cause, user.ErrUserNotFound) && !errors.Is(cause, user.ErrInvalidCredentials) {
return