Prefer Host header over ModSecurity hostname

This commit is contained in:
root
2026-01-30 23:44:24 +02:00
parent e1188b4175
commit 02f681a60e

View File

@@ -776,11 +776,7 @@ function wafAuditLogList(array $params): array
continue; continue;
} }
if (preg_match('/^host:\s*(.+)$/i', $line, $matches)) { if (preg_match('/^\s*host:\s*(.+)$/i', $line, $matches)) {
$current['host'] = trim($matches[1]);
continue;
}
if (preg_match('/^Host:\s*(.+)$/', $line, $matches)) {
$current['host'] = trim($matches[1]); $current['host'] = trim($matches[1]);
continue; continue;
} }
@@ -835,7 +831,18 @@ function wafAuditLogList(array $params): array
} }
} }
if (preg_match('/\\[hostname "([^"]+)"\\]/', $line, $matches)) { if (preg_match('/\\[hostname "([^"]+)"\\]/', $line, $matches)) {
$entry['host'] = $matches[1]; $loggedHost = $matches[1];
$currentHost = (string) ($entry['host'] ?? '');
$remoteIp = (string) ($entry['remote_ip'] ?? '');
$shouldOverrideHost = $currentHost === ''
|| $currentHost === $remoteIp
|| $currentHost === '127.0.0.1'
|| $currentHost === '::1'
|| $currentHost === 'localhost';
if ($shouldOverrideHost && $loggedHost !== '') {
$entry['host'] = $loggedHost;
}
} }
if (str_contains($line, 'Access denied')) { if (str_contains($line, 'Access denied')) {