@@ -17,14 +17,20 @@ const SENSITIVE_COMMANDS = new Set([
17
17
'copydb'
18
18
] ) ;
19
19
20
+ const HELLO_COMMANDS = new Set ( [ 'hello' , 'ismaster' , 'isMaster' ] ) ;
21
+
20
22
// helper methods
21
23
const extractCommandName = commandDoc => Object . keys ( commandDoc ) [ 0 ] ;
22
24
const namespace = command => command . ns ;
23
25
const databaseName = command => command . ns . split ( '.' ) [ 0 ] ;
24
26
const collectionName = command => command . ns . split ( '.' ) [ 1 ] ;
25
27
const generateConnectionId = pool =>
26
28
pool . options ? `${ pool . options . host } :${ pool . options . port } ` : pool . address ;
27
- const maybeRedact = ( commandName , result ) => ( SENSITIVE_COMMANDS . has ( commandName ) ? { } : result ) ;
29
+ const maybeRedact = ( commandName , cmd , result ) =>
30
+ SENSITIVE_COMMANDS . has ( commandName ) ||
31
+ ( HELLO_COMMANDS . has ( commandName ) && cmd . speculativeAuthenticate )
32
+ ? { }
33
+ : result ;
28
34
const isLegacyPool = pool => pool . s && pool . queue ;
29
35
30
36
const LEGACY_FIND_QUERY_MAP = {
@@ -181,17 +187,11 @@ class CommandStartedEvent {
181
187
const commandName = extractCommandName ( cmd ) ;
182
188
const connectionDetails = extractConnectionDetails ( pool ) ;
183
189
184
- // NOTE: remove in major revision, this is not spec behavior
185
- if ( SENSITIVE_COMMANDS . has ( commandName ) ) {
186
- this . commandObj = { } ;
187
- this . commandObj [ commandName ] = true ;
188
- }
189
-
190
190
Object . assign ( this , connectionDetails , {
191
191
requestId : command . requestId ,
192
192
databaseName : databaseName ( command ) ,
193
193
commandName,
194
- command : cmd
194
+ command : maybeRedact ( commandName , cmd , cmd )
195
195
} ) ;
196
196
}
197
197
}
@@ -215,7 +215,7 @@ class CommandSucceededEvent {
215
215
requestId : command . requestId ,
216
216
commandName,
217
217
duration : calculateDurationInMs ( started ) ,
218
- reply : maybeRedact ( commandName , extractReply ( command , reply ) )
218
+ reply : maybeRedact ( commandName , cmd , extractReply ( command , reply ) )
219
219
} ) ;
220
220
}
221
221
}
@@ -239,7 +239,7 @@ class CommandFailedEvent {
239
239
requestId : command . requestId ,
240
240
commandName,
241
241
duration : calculateDurationInMs ( started ) ,
242
- failure : maybeRedact ( commandName , error )
242
+ failure : maybeRedact ( commandName , cmd , error )
243
243
} ) ;
244
244
}
245
245
}
0 commit comments