PLT-1764: Sanitize sensitive fields in FormatterTrait object normaliz…#21
Open
ypppa wants to merge 1 commit intopaysera:masterfrom
Open
PLT-1764: Sanitize sensitive fields in FormatterTrait object normaliz…#21ypppa wants to merge 1 commit intopaysera:masterfrom
ypppa wants to merge 1 commit intopaysera:masterfrom
Conversation
Contributor
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>
ashamrov
reviewed
Mar 25, 2026
| continue; | ||
| } | ||
|
|
||
| $normalizedKey = preg_replace('/[^a-z]/', '', strtolower($fixedKey)); |
There was a problem hiding this comment.
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.
ashamrov
reviewed
Mar 25, 2026
| 'secretkey', | ||
| 'credentials', | ||
| ]; | ||
| /** |
ashamrov
reviewed
Mar 25, 2026
| trait FormatterTrait | ||
| { | ||
| /** @var string[] */ | ||
| private static $sensitiveKeys = [ |
There was a problem hiding this comment.
private static array $sensitiveKeys = [...]
ashamrov
reviewed
Mar 25, 2026
|
|
||
| $normalizedKey = preg_replace('/[^a-z]/', '', strtolower($fixedKey)); | ||
| if (in_array($normalizedKey, self::$sensitiveKeys, true)) { | ||
| $result[$fixedKey] = '***'; |
There was a problem hiding this comment.
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
ashamrov
reviewed
Mar 25, 2026
| 'apiSecret' => ['apiSecret'], | ||
| 'secretKey' => ['secretKey'], | ||
| 'credentials' => ['credentials'], | ||
| ]; |
There was a problem hiding this comment.
missing: 'apiSecretKey' => ['apiSecretKey'],
|
off the top of my head, some more common sensitivekeys:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.