@@ -9,15 +9,33 @@ const { log, output } = require('proc-log')
9
9
const BaseCommand = require ( '../base-cmd.js' )
10
10
11
11
// These are the configs that we can nerf-dart. Not all of them currently even
12
- // *have* config definitions so we have to explicitly validate them here
12
+ // *have* config definitions so we have to explicitly validate them here.
13
+ // This is used to validate during "npm config set"
13
14
const nerfDarts = [
14
15
'_auth' ,
15
16
'_authToken' ,
16
- 'username' ,
17
17
'_password' ,
18
+ 'certfile' ,
18
19
'email' ,
20
+ 'keyfile' ,
21
+ 'username' ,
22
+ ]
23
+ // These are the config values to swap with "protected". It does not catch
24
+ // every single sensitive thing a user may put in the npmrc file but it gets
25
+ // the common ones. This is distinct from nerfDarts because that is used to
26
+ // validate valid configs during "npm config set", and folks may have old
27
+ // invalid entries lying around in a config file that we still want to protect
28
+ // when running "npm config list"
29
+ // This is a more general list of values to consider protected. You can not
30
+ // "npm config get" them, and they will not display during "npm config list"
31
+ const protected = [
32
+ 'auth' ,
33
+ 'authToken' ,
19
34
'certfile' ,
35
+ 'email' ,
20
36
'keyfile' ,
37
+ 'password' ,
38
+ 'username' ,
21
39
]
22
40
23
41
// take an array of `[key, value, k2=v2, k3, v3, ...]` and turn into
@@ -40,10 +58,21 @@ const publicVar = k => {
40
58
if ( k . startsWith ( '_' ) ) {
41
59
return false
42
60
}
43
- // //localhost:8080/:_password
44
- if ( k . startsWith ( '//' ) && k . includes ( ':_' ) ) {
61
+ if ( protected . includes ( k ) ) {
45
62
return false
46
63
}
64
+ // //localhost:8080/:_password
65
+ if ( k . startsWith ( '//' ) ) {
66
+ if ( k . includes ( ':_' ) ) {
67
+ return false
68
+ }
69
+ // //registry:_authToken or //registry:authToken
70
+ for ( const p of protected ) {
71
+ if ( k . endsWith ( `:${ p } ` ) || k . endsWith ( `:_${ p } ` ) ) {
72
+ return false
73
+ }
74
+ }
75
+ }
47
76
return true
48
77
}
49
78
@@ -320,7 +349,7 @@ ${defData}
320
349
const src = this . npm . config . find ( k )
321
350
const overridden = src !== where
322
351
msg . push ( ( overridden ? '; ' : '' ) +
323
- `${ k } = ${ v } ${ overridden ? `; overridden by ${ src } ` : '' } ` )
352
+ `${ k } = ${ v } ${ overridden ? ` ; overridden by ${ src } ` : '' } ` )
324
353
}
325
354
msg . push ( '' )
326
355
}
0 commit comments