Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logging): sanitize logged argv #3658

Merged
merged 1 commit into from Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cli.js
Expand Up @@ -27,7 +27,8 @@ module.exports = async (process) => {
if (process.argv[1][process.argv[1].length - 1] === 'g')
process.argv.splice(1, 1, 'npm', '-g')

log.verbose('cli', process.argv)
const replaceInfo = require('../lib/utils/replace-info.js')
log.verbose('cli', replaceInfo(process.argv))

log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/error-message.js
Expand Up @@ -109,9 +109,7 @@ module.exports = (er, npm) => {
[
'Merge conflict detected in your package.json.',
'',
'Please resolve the package.json conflict and retry the command:',
'',
`$ ${process.argv.join(' ')}`,
'Please resolve the package.json conflict and retry.',
].join('\n'),
])
break
Expand Down
4 changes: 1 addition & 3 deletions tap-snapshots/test/lib/utils/error-message.js.test.cjs
Expand Up @@ -1537,9 +1537,7 @@ Object {
String(
Merge conflict detected in your package.json.

Please resolve the package.json conflict and retry the command:

$ arg v
Please resolve the package.json conflict and retry.
),
],
],
Expand Down
26 changes: 26 additions & 0 deletions test/lib/cli.js
Expand Up @@ -104,6 +104,32 @@ t.test('calling with --versions calls npm version with no args', async t => {
t.strictSame(exitHandlerCalled, [])
})

t.test('logged argv is sanitized', async t => {
const proc = processMock({
argv: ['node', 'npm', 'testcommand', 'https://username:password@npmjs.org/test_url_with_a_password'],
})
const { npm } = mockNpm(t)
const cli = cliMock(npm)

npm.commands.testcommand = (args, cb) => {
cb()
}

await cli(proc)
t.equal(proc.title, 'npm')
t.strictSame(logs, [
'pause',
['verbose', 'cli', [
'node',
'npm',
'testcommand',
'https://username:***@npmjs.org/test_url_with_a_password',
]],
['info', 'using', 'npm@%s', npm.version],
['info', 'using', 'node@%s', process.version],
])
})

t.test('print usage if no params provided', async t => {
const proc = processMock({
argv: ['node', 'npm'],
Expand Down