@@ -2,7 +2,9 @@ use std::{fs, time::Instant};
22
33use serde_json:: { json, Value } ;
44
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+ } ;
68
79pub struct SecretTool ;
810
@@ -16,6 +18,7 @@ impl SecretTool {
1618 _path : & str ,
1719 _branch : Option < & str > ,
1820 pr_branch : Option < & str > ,
21+ mongo_uri : & str ,
1922 verbose : bool ,
2023 ) {
2124 let start_time = Instant :: now ( ) ;
@@ -61,7 +64,9 @@ impl SecretTool {
6164
6265 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) ;
6366 let output_data = execute_command ( & cmd, true ) . await ;
67+
6468 let mut results: Vec < Value > = Vec :: new ( ) ;
69+
6570 for line in output_data. lines ( ) {
6671 let json_output: serde_json:: Value =
6772 serde_json:: from_str ( & line) . expect ( "Error parsing JSON" ) ;
@@ -100,6 +105,26 @@ impl SecretTool {
100105 continue ;
101106 }
102107 }
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+
103128 new_results. push ( result. clone ( ) ) ;
104129 }
105130 results = new_results;
0 commit comments