From 01d7f4b69df78f19362072237a5a0d800817a7f4 Mon Sep 17 00:00:00 2001 From: Gar Date: Mon, 25 Aug 2025 11:44:44 -0700 Subject: [PATCH] fix: add redaction to log format egress --- lib/utils/format.js | 5 ++++- test/lib/utils/display.js | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/utils/format.js b/lib/utils/format.js index aaecfe1ba0e7a..9216c7918678a 100644 --- a/lib/utils/format.js +++ b/lib/utils/format.js @@ -1,4 +1,7 @@ +// All logging goes through here, both to console and log files + const { formatWithOptions: baseFormatWithOptions } = require('node:util') +const { redactLog } = require('@npmcli/redact') // These are most assuredly not a mistake // https://eslint.org/docs/latest/rules/no-control-regex @@ -40,7 +43,7 @@ function STRIP_C01 (str) { const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', ...options }, ...args) => { const prefix = prefixes.filter(p => p != null).join(' ') - const formatted = STRIP_C01(baseFormatWithOptions(options, ...args)) + const formatted = redactLog(STRIP_C01(baseFormatWithOptions(options, ...args))) // Splitting could be changed to only `\n` once we are sure we only emit unix newlines. // The eol param to this function will put the correct newlines in place for the returned string. const lines = formatted.split(/\r?\n/) diff --git a/test/lib/utils/display.js b/test/lib/utils/display.js index 78bffa0221d03..26f52b17a8528 100644 --- a/test/lib/utils/display.js +++ b/test/lib/utils/display.js @@ -37,7 +37,9 @@ t.test('can log cleanly', async (t) => { const { log, logs } = await mockDisplay(t) log.error('', 'test\x00message') + log.info('', 'fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_000000000000000000000000000000000000 477ms') t.match(logs.error, ['test^@message']) + t.match(logs.info, ['fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_*** 477ms']) }) t.test('can handle special eresolves', async (t) => {