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
+3 -3
View File
@@ -69,7 +69,7 @@ type MailWithUID struct {
// and connects to PostgreSQL.
func New(cfg Config) (*Store, error) {
for _, sub := range []string{"store", "attachments", "meta"} {
if err := os.MkdirAll(filepath.Join(cfg.Dir, sub), 0o755); err != nil {
if err := os.MkdirAll(filepath.Join(cfg.Dir, sub), 0o700); err != nil {
return nil, fmt.Errorf("storage: mkdir %s: %w", sub, err)
}
}
@@ -410,7 +410,7 @@ func (s *Store) Save(ctx context.Context, raw []byte, _ time.Time, tenantID *int
id := fmt.Sprintf("%x", sum[:]) // 64 hex chars
path := s.filePath(id)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return "", fmt.Errorf("storage: mkdir shard: %w", err)
}
@@ -443,7 +443,7 @@ func (s *Store) Save(ctx context.Context, raw []byte, _ time.Time, tenantID *int
toWrite = toStore
}
if err := os.WriteFile(path, toWrite, 0o644); err != nil {
if err := os.WriteFile(path, toWrite, 0o600); err != nil {
return "", fmt.Errorf("storage: write: %w", err)
}