TenantAtlas/apps/platform/app/Services/TenantConfiguration/CoveragePayloadRedactor.php
ahmido ca0f54614d feat: add generic content-backed coverage capture (#482)
Automated PR provided by Codex via Gitea API.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #482
2026-06-25 19:55:52 +00:00

63 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\TenantConfiguration;
final class CoveragePayloadRedactor
{
/**
* @var list<string>
*/
private const SENSITIVE_KEY_PARTS = [
'access_token',
'authorization',
'assertion',
'bearer',
'certificate',
'client_secret',
'cookie',
'credential',
'id_token',
'password',
'private_key',
'refresh_token',
'secret',
'set-cookie',
'token',
];
public function redact(mixed $value): mixed
{
if (! is_array($value)) {
return $value;
}
if (array_is_list($value)) {
return array_map(fn (mixed $item): mixed => $this->redact($item), $value);
}
$redacted = [];
foreach ($value as $key => $nestedValue) {
$key = (string) $key;
$redacted[$key] = $this->isSensitiveKey($key) ? '[redacted]' : $this->redact($nestedValue);
}
return $redacted;
}
private function isSensitiveKey(string $key): bool
{
$normalized = strtolower($key);
foreach (self::SENSITIVE_KEY_PARTS as $part) {
if (str_contains($normalized, $part)) {
return true;
}
}
return false;
}
}