fix(audit): remove credentials from URLs before storing audit changes

This commit is contained in:
Andras Bacsai
2026-10-06 12:56:57 +02:00
parent 5d20f54f71
commit ecf969e35d
2 changed files with 70 additions and 0 deletions
+12
View File
@@ -269,6 +269,10 @@ class AuditEvent extends Model
$value = (array) $value;
}
if (is_string($value)) {
return self::stripUrlCredentials($value);
}
if (! is_array($value)) {
return $value;
}
@@ -280,6 +284,14 @@ class AuditEvent extends Model
->all();
}
/**
* Removes the user info of URLs (https://user:token@host), so the audit keeps the URL without credentials.
*/
private static function stripUrlCredentials(string $value): string
{
return preg_replace('#\b([a-z][a-z0-9+.-]*://)[^/?\#\s]+@#i', '$1', $value) ?? $value;
}
private static function isSensitiveKey(string $key): bool
{
if (preg_match('/_(id|uuid|name)$/i', $key)) {