@@ -110,7 +110,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
110
110
event -> command_owned = false;
111
111
}
112
112
113
- if (mongoc_apm_is_sensitive_command (command_name , command )) {
113
+ if (mongoc_apm_is_sensitive_command_message (command_name , command )) {
114
114
if (!event -> command_owned ) {
115
115
event -> command = bson_copy (event -> command );
116
116
event -> command_owned = true;
@@ -209,7 +209,8 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
209
209
{
210
210
BSON_ASSERT (reply );
211
211
212
- if (force_redaction || mongoc_apm_is_sensitive_reply (command_name , reply )) {
212
+ if (force_redaction ||
213
+ mongoc_apm_is_sensitive_command_message (command_name , reply )) {
213
214
event -> reply = bson_copy (reply );
214
215
event -> reply_owned = true;
215
216
@@ -269,7 +270,8 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
269
270
{
270
271
BSON_ASSERT (reply );
271
272
272
- if (force_redaction || mongoc_apm_is_sensitive_reply (command_name , reply )) {
273
+ if (force_redaction ||
274
+ mongoc_apm_is_sensitive_command_message (command_name , reply )) {
273
275
event -> reply = bson_copy (reply );
274
276
event -> reply_owned = true;
275
277
@@ -940,22 +942,38 @@ _mongoc_apm_is_sensitive_command_name (const char *command_name)
940
942
0 == strcasecmp (command_name , "copydb" );
941
943
}
942
944
943
- bool
944
- mongoc_apm_is_sensitive_command (const char * command_name ,
945
- const bson_t * command )
945
+ static bool
946
+ _mongoc_apm_is_sensitive_hello_message (const char * command_name ,
947
+ const bson_t * body )
946
948
{
947
- BSON_ASSERT (command );
949
+ const bool is_hello =
950
+ (0 == strcasecmp (command_name , "hello" ) ||
951
+ 0 == strcasecmp (command_name , HANDSHAKE_CMD_LEGACY_HELLO ));
948
952
949
- if (_mongoc_apm_is_sensitive_command_name ( command_name ) ) {
950
- return true ;
953
+ if (! is_hello ) {
954
+ return false ;
951
955
}
952
-
953
- if (0 != strcasecmp (command_name , "hello" ) &&
954
- 0 != strcasecmp (command_name , HANDSHAKE_CMD_LEGACY_HELLO )) {
956
+ if (bson_empty (body )) {
957
+ /* An empty message body means that it has been redacted */
958
+ return true;
959
+ } else if (bson_has_field (body , "speculativeAuthenticate" )) {
960
+ /* "hello" messages are only sensitive if they contain
961
+ * 'speculativeAuthenticate' */
962
+ return true;
963
+ } else {
964
+ /* Other "hello" messages are okay */
955
965
return false;
956
966
}
967
+ }
968
+
969
+ bool
970
+ mongoc_apm_is_sensitive_command_message (const char * command_name ,
971
+ const bson_t * body )
972
+ {
973
+ BSON_ASSERT (body );
957
974
958
- return bson_has_field (command , "speculativeAuthenticate" );
975
+ return _mongoc_apm_is_sensitive_command_name (command_name ) ||
976
+ _mongoc_apm_is_sensitive_hello_message (command_name , body );
959
977
}
960
978
961
979
void
@@ -967,22 +985,6 @@ mongoc_apm_redact_command (bson_t *command)
967
985
bson_reinit (command );
968
986
}
969
987
970
- bool
971
- mongoc_apm_is_sensitive_reply (const char * command_name , const bson_t * reply )
972
- {
973
- BSON_ASSERT (reply );
974
-
975
- if (_mongoc_apm_is_sensitive_command_name (command_name )) {
976
- return true;
977
- }
978
-
979
- if (0 != strcasecmp (command_name , "hello" ) &&
980
- 0 != strcasecmp (command_name , HANDSHAKE_CMD_LEGACY_HELLO )) {
981
- return false;
982
- }
983
-
984
- return bson_has_field (reply , "speculativeAuthenticate" );
985
- }
986
988
987
989
void
988
990
mongoc_apm_redact_reply (bson_t * reply )
0 commit comments