Skip to content

PLT-1764: Sanitize sensitive fields in FormatterTrait object normaliz…#21

Open
ypppa wants to merge 1 commit intopaysera:masterfrom
ypppa:PLT-1764
Open

PLT-1764: Sanitize sensitive fields in FormatterTrait object normaliz…#21
ypppa wants to merge 1 commit intopaysera:masterfrom
ypppa:PLT-1764

Conversation

@ypppa
Copy link
Copy Markdown
Contributor

@ypppa ypppa commented Mar 25, 2026

  • FormatterTrait::normalizeObject() now redacts known sensitive property names (password, secret, apiKey, apiSecret, apiSecretKey, secretKey, credentials) replacing their values with ***
  • Matching is case-insensitive and ignores non-letter separators, so variants like api_key, API-SECRET, secret.key are all caught
  • Added unit tests covering default sensitive keys, case insensitivity, separator variants, non-sensitive passthrough, and mixed properties

…ation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
continue;
}

$normalizedKey = preg_replace('/[^a-z]/', '', strtolower($fixedKey));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we make sanitization enabled by default, but allow disabling it via a configuration option? There may be cases (e.g., debugging in a controlled environment) where logging the actual values is preferred over redacting them.

'secretkey',
'credentials',
];
/**
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line sparator?

trait FormatterTrait
{
/** @var string[] */
private static $sensitiveKeys = [
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static array $sensitiveKeys = [...]


$normalizedKey = preg_replace('/[^a-z]/', '', strtolower($fixedKey));
if (in_array($normalizedKey, self::$sensitiveKeys, true)) {
$result[$fixedKey] = '***';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the value at a sensitive key is an object or array, the whole thing gets replaced with ***, not sure if this is expected, we might lose some useful non-sensitive data for debugging

'apiSecret' => ['apiSecret'],
'secretKey' => ['secretKey'],
'credentials' => ['credentials'],
];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing: 'apiSecretKey' => ['apiSecretKey'],

@ashamrov
Copy link
Copy Markdown

ashamrov commented Mar 25, 2026

off the top of my head, some more common sensitivekeys:

  • clientsecret / client_secret
  • appsecret / app_secret
  • accesskey / access_key
  • secretaccesskey
  • connectionstring
  • dsn
  • passphrase
  • pin
  • cvv
  • cardnumber
  • otp
  • bearer
  • signature
  • encryptionkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants