@@ -13,8 +13,7 @@ use tokio::fs;
1313use tokio:: io:: AsyncBufReadExt ;
1414
1515use super :: {
16- AgentError , Finding , RuleInfo , Severity , ValidationAgent , ValidationContext ,
17- ValidationResult ,
16+ AgentError , Finding , RuleInfo , Severity , ValidationAgent , ValidationContext , ValidationResult ,
1817} ;
1918
2019// ============================================================================
@@ -49,11 +48,7 @@ const SECRET_PATTERNS: &[(&str, &str)] = &[
4948/// Patterns for base64-encoded or hex-encoded potential secrets.
5049const ENCODED_SECRET_PATTERNS : & [ & str ] = & [
5150 // Common API key prefixes
52- "sk_live_" ,
53- "sk_test_" ,
54- "pk_live_" ,
55- "pk_test_" ,
56- "xox" , // Slack tokens
51+ "sk_live_" , "sk_test_" , "pk_live_" , "pk_test_" , "xox" , // Slack tokens
5752 "ghp_" , // GitHub personal access token
5853 "gho_" , // GitHub OAuth token
5954 "ghu_" , // GitHub user-to-server token
@@ -64,7 +59,11 @@ const ENCODED_SECRET_PATTERNS: &[&str] = &[
6459/// Known vulnerable crate patterns (simplified - in production would use advisory database).
6560const VULNERABLE_CRATES : & [ ( & str , & str , & str ) ] = & [
6661 ( "chrono" , "<0.4.20" , "RUSTSEC-2020-0159: Potential segfault" ) ,
67- ( "smallvec" , "<0.6.14" , "RUSTSEC-2019-0009: Double-free vulnerability" ) ,
62+ (
63+ "smallvec" ,
64+ "<0.6.14" ,
65+ "RUSTSEC-2019-0009: Double-free vulnerability" ,
66+ ) ,
6867 ( "regex" , "<1.5.5" , "RUSTSEC-2022-0013: Denial of service" ) ,
6968] ;
7069
@@ -145,7 +144,8 @@ impl SecurityAgent {
145144
146145 // Skip comments that are likely documentation
147146 let trimmed = line. trim ( ) ;
148- if trimmed. starts_with ( "//" ) || trimmed. starts_with ( "///" ) || trimmed. starts_with ( "//!" ) {
147+ if trimmed. starts_with ( "//" ) || trimmed. starts_with ( "///" ) || trimmed. starts_with ( "//!" )
148+ {
149149 // Still check for actual secret values in comments
150150 if !contains_suspicious_value ( & line) {
151151 continue ;
@@ -226,10 +226,7 @@ impl SecurityAgent {
226226 Finding :: new (
227227 rule_id,
228228 severity,
229- format ! (
230- "Vulnerable dependency: {} {} ({})" ,
231- name, version, advisory
232- ) ,
229+ format ! ( "Vulnerable dependency: {} {} ({})" , name, version, advisory) ,
233230 )
234231 . at_file ( & cargo_lock)
235232 . with_suggestion ( format ! ( "Update {} to a patched version" , name) ) ,
@@ -392,11 +389,15 @@ impl SecurityAgent {
392389 && line. contains ( "format!" )
393390 {
394391 findings. push (
395- Finding :: new ( rule_id, Severity :: Error , "Potential SQL injection vulnerability" )
396- . at_file ( file_path)
397- . at_line ( line_num)
398- . with_snippet ( truncate_line ( & line, 80 ) )
399- . with_suggestion ( "Use parameterized queries instead of string formatting" ) ,
392+ Finding :: new (
393+ rule_id,
394+ Severity :: Error ,
395+ "Potential SQL injection vulnerability" ,
396+ )
397+ . at_file ( file_path)
398+ . at_line ( line_num)
399+ . with_snippet ( truncate_line ( & line, 80 ) )
400+ . with_suggestion ( "Use parameterized queries instead of string formatting" ) ,
400401 ) ;
401402 }
402403 }
@@ -571,7 +572,10 @@ fn looks_like_hardcoded_secret(line: &str) -> bool {
571572 if let Some ( end_quote) = line[ start_quote + 1 ..] . find ( '"' ) {
572573 let value = & line[ start_quote + 1 ..start_quote + 1 + end_quote] ;
573574 // Long alphanumeric strings are suspicious
574- if value. len ( ) > 20 && value. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' || c == '-' )
575+ if value. len ( ) > 20
576+ && value
577+ . chars ( )
578+ . all ( |c| c. is_alphanumeric ( ) || c == '_' || c == '-' )
575579 {
576580 return true ;
577581 }
@@ -649,9 +653,13 @@ mod tests {
649653
650654 #[ test]
651655 fn test_looks_like_hardcoded_secret ( ) {
652- assert ! ( !looks_like_hardcoded_secret( "let api_key = env!(\" API_KEY\" );" ) ) ;
656+ assert ! ( !looks_like_hardcoded_secret(
657+ "let api_key = env!(\" API_KEY\" );"
658+ ) ) ;
653659 assert ! ( !looks_like_hardcoded_secret( "api_key: \" ${API_KEY}\" " ) ) ;
654- assert ! ( !looks_like_hardcoded_secret( "password: \" your_password_here\" " ) ) ;
660+ assert ! ( !looks_like_hardcoded_secret(
661+ "password: \" your_password_here\" "
662+ ) ) ;
655663 }
656664
657665 #[ test]
0 commit comments