fix: redact cause, stdout and stderr in default error details - #10072
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
The top of errorMessage already redacts the error message, stack and command args, but the default case appended er.cause.message, er.stdout and er.stderr to the detail lines untouched. Child process output and chained causes can carry registry or git urls with embedded credentials and published tokens, and these lines also reach stderr verbatim on the early exit path in the exit handler, which prints through console.error and bypasses the display layer redaction entirely. Run the same redaction over those three fields.
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.
Problem
errorMessagestarts by redacting the error message and stack, and the default case already redacts command args:But three sibling fields were pushed to the detail lines untouched:
These fields commonly carry secrets: child process failures attach captured
stdout/stderr(git and fetch errors echo urls with embedded credentials), and chained causes keep the underlying message. Before this change a cause message offetch failed for https://user:sekrit@registry.example.com/fooreached the output verbatim.The gap is wider than the terminal:
lib/cli/exit-handler.jsprints these same detail lines throughconsole.erroron the early exit paths (before the npm instance is set), which bypasses the display layer and its string level redaction entirely, so nothing downstream catches these fields either.Solution
Apply
replaceInfo(the sameredactLogused for message, stack and args) toer.cause.message,er.stdoutander.stderrbefore appending them.Test Evidence
Added a test in
test/lib/utils/error-message.jsthat builds a default case error whose cause message and captured stdout/stderr contain a url password and a granular token, and asserts neither secret appears in the returned detail while the non secret parts survive. The test fails on the previous code, matching onsekritin the detail, and passes with this change. Existing snapshot tests are unchanged because redaction is the identity for their plain values. Full file green:npx tap test/lib/utils/error-message.js.References
lib/cli/exit-handler.js#logConsoleError.