fix(PROJ-64): Session-Invalidation bei Passwort-Change + Datei-Permissions gehärtet

Security-Audit deckte zwei Medium-Findings auf: JWTs blieben bis zu 8h nach
Passwort-Change/-Reset oder Admin-TOTP-Reset gültig (kein Session-Invalidation),
und archivierte Mails/Anhänge wurden mit 0644/0755 statt 0600/0700 geschrieben.

- users.tokens_valid_after (neue Spalte) wird bei SetPassword() und
  InvalidateTokensBefore() gesetzt; ValidateToken() lehnt JWTs mit iat davor ab.
- Admin-TOTP-Reset revoked jetzt aktive Sessions des Zielnutzers.
- Mail-/Attachment-Dateien und ihre Verzeichnisse nur noch für den
  archivmail-Service-Account lesbar.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
sysops
2026-07-03 22:23:27 +02:00
co-authored by Claude Sonnet 5
parent 0ccbd5bafb
commit b286352d07
7 changed files with 96 additions and 9 deletions
+15
View File
@@ -375,6 +375,21 @@ func (m *Manager) ValidateToken(tokenStr string) (*Session, error) {
}
}
// PROJ-64: reject tokens issued before a password change / admin TOTP reset,
// closing the session-hijack window that a stateless-only JWT leaves open.
var iat time.Time
switch v := claims["iat"].(type) {
case float64:
iat = time.Unix(int64(v), 0)
case int64:
iat = time.Unix(v, 0)
}
if validAfter, err := m.store.TokensValidAfter(context.Background(), userID); err == nil && validAfter != nil {
if iat.Before(*validAfter) {
return nil, errors.New("auth: token revoked (credentials changed)")
}
}
return &Session{
UserID: userID,
Username: username,