Skip to content
PHP Ecosystem
Explore

SensitiveDataRedactor

API reference › Debug Core › Helper › SensitiveDataRedactor

final classPHPForge\Debug\Helper\SensitiveDataRedactor
Sourcesrc/Helper/SensitiveDataRedactor.php

Replaces values whose array keys match configured exact names, prefixes, or PCRE patterns.

MethodDescriptionDefined by
isSensitiveKey() staticReturns whether a key matches a configured exact name, literal prefix, or PCRE pattern.SensitiveDataRedactor
patterns() staticResolves the pattern list a redaction rule set applies, preserving exact-list override behavior.SensitiveDataRedactor
redact() staticRedacts configured keys case-insensitively throughout a bounded nested array.SensitiveDataRedactor
ConstantValueDescriptionDefined by
DEFAULT_KEYS['access_token', 'accessToken', 'api_key', 'apiKey', 'authorization', 'auth_key', 'authKey', 'aws_secret_access_key', 'client_secret', 'clientSecret', 'cookie', 'csrf_token', 'csrfToken', 'database_url', 'db_password', 'http_authorization', 'http_cookie', 'password', 'password_hash', 'password_reset_token', 'passwd', 'php_auth_pw', 'proxy-authorization', 'redirect_http_authorization', 'refresh_token', 'refreshToken', 'secret', 'session_id', 'set-cookie', 'token', 'verification_token', 'x-api-key', 'x-auth-token', 'x-csrf-token']Common credential and session fields that must never be persisted by default.SensitiveDataRedactor
DEFAULT_PATTERNS['~(?:^|[_\-.])(?:password|passwd|secret|token|api[_-]?key|private[_-]?key|credential)(?:$|[_\-.])~i']Segment-aware defaults for environment-style credential keys.SensitiveDataRedactor
PLACEHOLDER'[redacted]'Replacement written in place of a sensitive value.SensitiveDataRedactor
TRUNCATED'[truncated]'Replacement written where the depth or node budget stops traversal.SensitiveDataRedactor
public static function isSensitiveKey(string $key, list<string> $sensitiveKeys = \self::DEFAULT_KEYS, list<string> $sensitiveKeyPrefixes = [], list<string>|null $sensitiveKeyPatterns = null): bool

Returns whether a key matches a configured exact name, literal prefix, or PCRE pattern.

Parameters

ParameterTypeDescription
$keystringOriginal key to inspect. Exact names and literal prefixes ignore case; PCRE patterns retain their own case-sensitivity modifiers.
$sensitiveKeyslist<string>Exact key names to inspect.
$sensitiveKeyPrefixeslist<string>Literal key prefixes to inspect case-insensitively.
$sensitiveKeyPatternslist<string>|nullPCRE patterns applied to the complete original key. null uses defaults only with the default exact-key list; [] explicitly disables patterns.

Returns

bool: true when the key matches any configured rule; false otherwise.

public static function patterns(list<string> $keys, list<string>|null $patterns): list<string>

Resolves the pattern list a redaction rule set applies, preserving exact-list override behavior.

An explicit list wins. Otherwise DEFAULT_PATTERNS applies only alongside the unmodified DEFAULT_KEYS list, so a custom exact-key list never inherits the segment-aware defaults.

Parameters

ParameterTypeDescription
$keyslist<string>Configured exact key names.
$patternslist<string>|nullConfigured PCRE patterns, or null to resolve the defaults.

Returns

list<string>: Patterns applied to complete original keys.

public static function redact(array<PHPForge\Debug\Helper\TKey, mixed> $value, list<string> $sensitiveKeys = \self::DEFAULT_KEYS, list<string> $sensitiveKeyPrefixes = [], list<string>|null $sensitiveKeyPatterns = null): array<PHPForge\Debug\Helper\TKey, mixed>

Redacts configured keys case-insensitively throughout a bounded nested array.

Parameters

ParameterTypeDescription
$valuearray<PHPForge\Debug\Helper\TKey, mixed>Value tree to sanitize.
$sensitiveKeyslist<string>Exact key names to redact.
$sensitiveKeyPrefixeslist<string>Literal key prefixes to redact case-insensitively.
$sensitiveKeyPatternslist<string>|nullPCRE patterns applied to complete original keys. null uses defaults only with the default exact-key list; [] explicitly disables patterns.

Returns

array<PHPForge\Debug\Helper\TKey, mixed>: Sanitized tree with keys and non-sensitive values preserved.