M8: Security-Headers, Rate-Limits und Audit-Log

Erste drei Bausteine der Haertung:

- Security-Headers (X-Content-Type-Options, X-Frame-Options, Referrer-
  Policy, Permissions-Policy, HSTS bei HTTPS) laufen automatisch ueber
  app_send_security_headers() am Ende von app/bootstrap.php fuer jede
  dynamische Seite; landing.php war als einzige Seite ganz ohne PHP und
  bekam einen minimalen Bootstrap-Aufruf. Bewusst kein CSP, da die
  bestehenden Templates durchgaengig auf Inline-style-Attribute setzen.
- DB-gestuetzte Rate-Limits (neue Tabelle rate_limit_attempts) fuer
  Login (10/15min je E-Mail, 20/15min je IP), Registrierung (5/h je IP)
  und Passwort-Reset-Anfrage (5/h je E-Mail, 10/h je IP); bei
  ausgereiztem Reset-Limit erscheint dieselbe generische Meldung wie im
  Erfolgsfall, um kein Konto-Enumeration-Signal zu geben.
- Zentrales Audit-Log (neue Tabelle audit_log) fuer Mitgliederverwaltung,
  Zugangsvergabe/-entzug, Storno, Mandant-Einstellungen, Hinweise,
  CSV-Import, Jahresbonus-Verteilung und Live-Mailversand; sichtbar fuer
  Owner/Admin auf mandant-einstellungen.php.

Live getestet: Rate-Limit greift nach 10 Fehlversuchen, Audit-Log-Eintrag
mit korrekten Metadaten und Nutzernamen ueber einen isolierten Test-
Mandanten geprueft. Alle Regressionstests weiterhin gruen (26/26 Smoke,
104 Golden-Master-Assertions).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-15 18:04:14 +02:00
co-authored by Claude Sonnet 5
parent 7b517bcbf6
commit 54217d2acb
18 changed files with 375 additions and 55 deletions
+25
View File
@@ -27,6 +27,29 @@ function app_is_https(): bool
|| (($_SERVER['SERVER_PORT'] ?? null) === '443');
}
/**
* Sends baseline security headers on every dynamic request. Deliberately
* does not set a Content-Security-Policy: the existing templates rely on
* inline style="" attributes throughout (banners, table cells, etc.), and
* locking that down would need a broader template pass. Runs once per
* request via the auto-invocation at the bottom of this file.
*/
function app_send_security_headers(): void
{
if (PHP_SAPI === 'cli' || headers_sent()) {
return;
}
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: DENY');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: geolocation=(), microphone=(), camera=()');
if (app_is_https()) {
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
}
}
function app_start_session(): void
{
if (PHP_SAPI === 'cli' || session_status() === PHP_SESSION_ACTIVE) {
@@ -102,3 +125,5 @@ function app_require_csrf(): void
die('CSRF validation failed.');
}
}
app_send_security_headers();