@@ -41,7 +41,7 @@ export class CommandStartedEvent {
41
41
this . requestId = command . requestId ;
42
42
this . databaseName = databaseName ( command ) ;
43
43
this . commandName = commandName ;
44
- this . command = cmd ;
44
+ this . command = maybeRedact ( commandName , cmd , cmd ) ;
45
45
}
46
46
}
47
47
@@ -82,7 +82,7 @@ export class CommandSucceededEvent {
82
82
this . requestId = command . requestId ;
83
83
this . commandName = commandName ;
84
84
this . duration = calculateDurationInMs ( started ) ;
85
- this . reply = maybeRedact ( commandName , extractReply ( command , reply ) ) ;
85
+ this . reply = maybeRedact ( commandName , cmd , extractReply ( command , reply ) ) ;
86
86
}
87
87
}
88
88
@@ -123,7 +123,7 @@ export class CommandFailedEvent {
123
123
this . requestId = command . requestId ;
124
124
this . commandName = commandName ;
125
125
this . duration = calculateDurationInMs ( started ) ;
126
- this . failure = maybeRedact ( commandName , error ) as Error ;
126
+ this . failure = maybeRedact ( commandName , cmd , error ) as Error ;
127
127
}
128
128
}
129
129
@@ -140,13 +140,18 @@ const SENSITIVE_COMMANDS = new Set([
140
140
'copydb'
141
141
] ) ;
142
142
143
+ const HELLO_COMMANDS = new Set ( [ 'hello' , 'ismaster' , 'isMaster' ] ) ;
144
+
143
145
// helper methods
144
146
const extractCommandName = ( commandDoc : Document ) => Object . keys ( commandDoc ) [ 0 ] ;
145
147
const namespace = ( command : WriteProtocolMessageType ) => command . ns ;
146
148
const databaseName = ( command : WriteProtocolMessageType ) => command . ns . split ( '.' ) [ 0 ] ;
147
149
const collectionName = ( command : WriteProtocolMessageType ) => command . ns . split ( '.' ) [ 1 ] ;
148
- const maybeRedact = ( commandName : string , result ?: Error | Document ) =>
149
- SENSITIVE_COMMANDS . has ( commandName ) ? { } : result ;
150
+ const maybeRedact = ( commandName : string , commandDoc : Document , result : Error | Document ) =>
151
+ SENSITIVE_COMMANDS . has ( commandName ) ||
152
+ ( HELLO_COMMANDS . has ( commandName ) && commandDoc . speculativeAuthenticate )
153
+ ? { }
154
+ : result ;
150
155
151
156
const LEGACY_FIND_QUERY_MAP : { [ key : string ] : string } = {
152
157
$query : 'filter' ,
0 commit comments