@@ -17,14 +17,20 @@ const SENSITIVE_COMMANDS = new Set([
1717 'copydb'
1818] ) ;
1919
20+ const HELLO_COMMANDS = new Set ( [ 'hello' , 'ismaster' , 'isMaster' ] ) ;
21+
2022// helper methods
2123const extractCommandName = commandDoc => Object . keys ( commandDoc ) [ 0 ] ;
2224const namespace = command => command . ns ;
2325const databaseName = command => command . ns . split ( '.' ) [ 0 ] ;
2426const collectionName = command => command . ns . split ( '.' ) [ 1 ] ;
2527const generateConnectionId = pool =>
2628 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 ;
2834const isLegacyPool = pool => pool . s && pool . queue ;
2935
3036const LEGACY_FIND_QUERY_MAP = {
@@ -181,17 +187,11 @@ class CommandStartedEvent {
181187 const commandName = extractCommandName ( cmd ) ;
182188 const connectionDetails = extractConnectionDetails ( pool ) ;
183189
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-
190190 Object . assign ( this , connectionDetails , {
191191 requestId : command . requestId ,
192192 databaseName : databaseName ( command ) ,
193193 commandName,
194- command : cmd
194+ command : maybeRedact ( commandName , cmd , cmd )
195195 } ) ;
196196 }
197197}
@@ -215,7 +215,7 @@ class CommandSucceededEvent {
215215 requestId : command . requestId ,
216216 commandName,
217217 duration : calculateDurationInMs ( started ) ,
218- reply : maybeRedact ( commandName , extractReply ( command , reply ) )
218+ reply : maybeRedact ( commandName , cmd , extractReply ( command , reply ) )
219219 } ) ;
220220 }
221221}
@@ -239,7 +239,7 @@ class CommandFailedEvent {
239239 requestId : command . requestId ,
240240 commandName,
241241 duration : calculateDurationInMs ( started ) ,
242- failure : maybeRedact ( commandName , error )
242+ failure : maybeRedact ( commandName , cmd , error )
243243 } ) ;
244244 }
245245}
0 commit comments