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:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/functions.php';
|
||||
require_once __DIR__ . '/app/rate-limit.php';
|
||||
|
||||
$pdo = app_db_pdo();
|
||||
$errors = [];
|
||||
@@ -10,26 +11,33 @@ $tenantSlug = trim((string)($_POST['tenant_slug'] ?? ''));
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
app_require_csrf();
|
||||
|
||||
$result = saas_authenticate(
|
||||
$pdo,
|
||||
$email,
|
||||
(string)($_POST['password'] ?? ''),
|
||||
$tenantSlug
|
||||
);
|
||||
$emailBucketOk = app_rate_limit_check($pdo, 'login_email:' . saas_email_norm($email), 10, 900);
|
||||
$ipBucketOk = app_rate_limit_check($pdo, 'login_ip:' . app_client_ip(), 20, 900);
|
||||
|
||||
if ($result['ok'] && !empty($result['needs_tenant_selection'])) {
|
||||
saas_start_pending_tenant_selection((int)$result['user_id']);
|
||||
header('Location: mandant-auswahl.php');
|
||||
exit;
|
||||
if (!$emailBucketOk || !$ipBucketOk) {
|
||||
$errors = ['Zu viele Anmeldeversuche. Bitte versuche es in einigen Minuten erneut.'];
|
||||
} else {
|
||||
$result = saas_authenticate(
|
||||
$pdo,
|
||||
$email,
|
||||
(string)($_POST['password'] ?? ''),
|
||||
$tenantSlug
|
||||
);
|
||||
|
||||
if ($result['ok'] && !empty($result['needs_tenant_selection'])) {
|
||||
saas_start_pending_tenant_selection((int)$result['user_id']);
|
||||
header('Location: mandant-auswahl.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($result['ok']) {
|
||||
saas_session_login($result['identity']);
|
||||
header('Location: konto.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = $result['errors'];
|
||||
}
|
||||
|
||||
if ($result['ok']) {
|
||||
saas_session_login($result['identity']);
|
||||
header('Location: konto.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = $result['errors'];
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user