fix: redact json output value by value so a url cannot corrupt it - #9874
Open
lazerg wants to merge 1 commit into
Open
fix: redact json output value by value so a url cannot corrupt it#9874lazerg wants to merge 1 commit into
lazerg wants to merge 1 commit into
Conversation
lazerg
force-pushed
the
fix/9873-json-redact-corruption
branch
from
August 14, 2026 11:42
56e4174 to
69fa327
Compare
lazerg
force-pushed
the
fix/9873-json-redact-corruption
branch
from
August 14, 2026 11:50
69fa327 to
4712e06
Compare
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.
What / Why
npm ls --json --longprints nothing and exits 1 when the tree holds a package whosedeprecatedmessage contains a url, for example@esbuild-kit/esm-loader@2.6.5("Merged into tsx: https://tsx.hirok.io"). Tools that shell out to it, like@cyclonedx/cyclonedx-npm, fail with "failed to parse npm-ls response".redactValueinlib/utils/display.jsredacted the whole serialized document:JSON.parse(redactLog(JSON.stringify(obj))). Compact json has no whitespace, so the url matcher in@npmcli/redactreads fromhttps://all the way to the next@(here the_idof a scoped package) and treats everything between asuser:password@. What comes back is no longer json,JSON.parsethrows inside the flush, and the error is swallowed. Pretty printed output never hit this because the newlines stop the matcher, which is why it only appeared once redaction moved to compactJSON.stringifyin 11.15.0.The document is still serialized the same way, so
toJSONand dropped keys behave as before, but redaction now runs over the parsed value one string at a time. Punctuation around a value can never be pulled into a match. Object keys are left alone, which in npm's json output means config names, package names and script names.Testing
New case in
test/lib/utils/display.js: a deprecation message with a url next to a scoped_idstays intact, arrays are walked, aDatestill serializes, and a url password is still redacted. It throws the sameSyntaxErrorwithout the change.References
Fixes #9873