Prefer Host header over ModSecurity hostname
This commit is contained in:
@@ -776,11 +776,7 @@ function wafAuditLogList(array $params): array
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^host:\s*(.+)$/i', $line, $matches)) {
|
||||
$current['host'] = trim($matches[1]);
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^Host:\s*(.+)$/', $line, $matches)) {
|
||||
if (preg_match('/^\s*host:\s*(.+)$/i', $line, $matches)) {
|
||||
$current['host'] = trim($matches[1]);
|
||||
continue;
|
||||
}
|
||||
@@ -835,7 +831,18 @@ function wafAuditLogList(array $params): array
|
||||
}
|
||||
}
|
||||
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')) {
|
||||
|
||||
Reference in New Issue
Block a user