@@ -2,7 +2,9 @@ use std::{fs, time::Instant};
2
2
3
3
use serde_json:: { json, Value } ;
4
4
5
- use crate :: utils:: common:: { checkout, count_env_variables, execute_command, print_error} ;
5
+ use crate :: utils:: common:: {
6
+ checkout, count_env_variables, execute_command, list_whitelisted_secrets, print_error,
7
+ } ;
6
8
7
9
pub struct SecretTool ;
8
10
@@ -16,6 +18,7 @@ impl SecretTool {
16
18
_path : & str ,
17
19
_branch : Option < & str > ,
18
20
pr_branch : Option < & str > ,
21
+ mongo_uri : & str ,
19
22
verbose : bool ,
20
23
) {
21
24
let start_time = Instant :: now ( ) ;
@@ -61,7 +64,9 @@ impl SecretTool {
61
64
62
65
let cmd = format ! ( "trufflehog filesystem --no-update {} --json --exclude-detectors=FLOAT,SIGNABLE,YANDEX,OANDA,CIRCLE,PARSEUR,URI,SENTRYTOKEN,SIRV,ETSYAPIKEY,UNIFYID,MIRO,FRESHDESK,ALIBABA,YELP,FLATIO,GETRESPONSE,ATERA,GITTER,SONARCLOUD,AZURESEARCHADMINKEY" , _path) ;
63
66
let output_data = execute_command ( & cmd, true ) . await ;
67
+
64
68
let mut results: Vec < Value > = Vec :: new ( ) ;
69
+
65
70
for line in output_data. lines ( ) {
66
71
let json_output: serde_json:: Value =
67
72
serde_json:: from_str ( & line) . expect ( "Error parsing JSON" ) ;
@@ -100,6 +105,26 @@ impl SecretTool {
100
105
continue ;
101
106
}
102
107
}
108
+ // Check if the detected secret is whitelisted
109
+ if !mongo_uri. is_empty ( ) {
110
+ // Fetch whitelisted secrets from MongoDB
111
+ let whitelisted_secrets = match list_whitelisted_secrets ( mongo_uri) . await {
112
+ Ok ( secrets) => secrets,
113
+ Err ( e) => {
114
+ eprintln ! ( "Error fetching whitelisted secrets: {}" , e) ;
115
+ continue ; // You might want to handle the error differently
116
+ }
117
+ } ;
118
+
119
+ // Check if the detected secret is in the whitelisted secrets
120
+ if let Some ( raw_value) = result[ "Raw" ] . as_str ( ) {
121
+ if whitelisted_secrets. contains ( & raw_value. to_string ( ) ) {
122
+ println ! ( "[+] Skipping because {} is whitelisted..." , raw_value) ;
123
+ continue ;
124
+ }
125
+ }
126
+ }
127
+
103
128
new_results. push ( result. clone ( ) ) ;
104
129
}
105
130
results = new_results;
0 commit comments