Conversation
RedactingFormatter sweeps the wrapped formatter's output for the secret values it collected, and collectSecrets builds one escaped copy of each secret for that sweep: the json spelling. HtmlFormatter escapes with htmlspecialchars instead, so a secret containing &, < or > reaches the output in a spelling the sweep does not carry and survives redaction. This is the same shape as Seldaek#2067, where the sweep had nothing to match a value with. Add the html spelling next to the json one, using the flags HtmlFormatter itself passes so the needle matches what it emits. addcookie on the response side and the other formatters are unaffected; only the sweep's needle list changes.
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.
RedactingFormattersweeps the wrapped formatter's output for the secret values it collected, andcollectSecretsbuilds one escaped copy of each secret for that sweep (RedactingFormatter.php:176-184):That is the json spelling.
HtmlFormatterescapes withhtmlspecialcharsinstead (HtmlFormatter.php:61,:63,:76), so a secret containing&,<or>arrives in the output as&,<,>- a spelling the needle list does not carry - and the sweep leaves it in place.Measured with the same record and secret through both formatters:
This is the same shape as #2067, where the sweep also had nothing to match a value with. The fix adds the html spelling next to the json one, with the flags
HtmlFormatteritself passes so the needle is byte-identical to what it emits. The existing!== ''guard still covershtmlspecialcharsreturning''for invalid UTF-8, matchingHtmlFormatter, which does not passENT_SUBSTITUTEeither.Verification
vendor/bin/phpunit --filter RedactingFormatterTest --no-coverageonphp:8.3-cli.md5sum src/Monolog/Formatter/RedactingFormatter.phpon every row.9620c057Assertions: 77, 0 failures6ab54e2638b9440ed09c6c26testRedactsSecretsNeedingJsonEscapingENT_NOQUOTEStoENT_QUOTES467207f3Dropping either needle fails a different test, so both spellings are independently required. The flag row matters because a first draft used a secret with no quote in it and
ENT_QUOTESpassed; the committed test carries one, so the two flag choices produce different needles.Full suite with
--exclude-group Elasticsearch,Elastica,e2e,MongoDB: 2 failures against 3 on pristine, and the 14 errors are identical on both (missingext-mongodbandext-amqp,GitProcessorTest,SignalHandlerTest).phpstan analysereports[OK] No errors.php -lclean on both files.Not run: the suite on PHP 8.1, the
composer.jsonfloor, because the vendored PHPUnit needs 8.2.Disclosure: this change was written with AI assistance (Claude). The measurements above were reproduced and checked by me before opening this PR.