Skip to content

Commit

Permalink
fix: redact all private keys from config output
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Dec 8, 2021
1 parent e1da1fa commit a02ede5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ const keyValues = args => {
return kv
}

const publicVar = k => !/^(\/\/[^:]+:)?_/.test(k)
const publicVar = k => {
// _password
if (k.startsWith('_')) {
return false
}
// //localhost:8080/:_password
if (k.startsWith('//') && k.includes(':_')) {
return false
}
return true
}

const BaseCommand = require('../base-command.js')
class Config extends BaseCommand {
Expand Down Expand Up @@ -147,7 +157,7 @@ class Config extends BaseCommand {
const out = []
for (const key of keys) {
if (!publicVar(key)) {
throw `The ${key} option is protected, and cannot be retrieved in this way`
throw new Error(`The ${key} option is protected, and cannot be retrieved in this way`)
}

const pref = keys.length > 1 ? `${key}=` : ''
Expand Down
1 change: 1 addition & 0 deletions lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const exitHandler = err => {
exitCode = err.code
noLogMessage = true
} else if (typeof err === 'string') {
// XXX: we should stop throwing strings
log.error('', err)
noLogMessage = true
} else if (!(err instanceof Error)) {
Expand Down
8 changes: 7 additions & 1 deletion test/lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ t.test('config get private key', async t => {

await t.rejects(
sandbox.run('config', ['get', '_authToken']),
'_authToken is protected',
/_authToken option is protected/,
'rejects with protected string'
)

await t.rejects(
sandbox.run('config', ['get', '//localhost:8080/:_password']),
/_password option is protected/,
'rejects with protected string'
)
})
Expand Down

0 comments on commit a02ede5

Please sign in to comment.