@@ -294,7 +294,10 @@ def _get_file_context(self, file_path: Path) -> str:
294294 if file_path .suffix == '.md' :
295295 return 'documentation'
296296 elif file_path .suffix in {'.py' , '.sh' , '.js' , '.ts' , '.bash' , '.zsh' }:
297- if 'example' in str (file_path ).lower () or 'demo' in str (file_path ).lower ():
297+ path_lower = str (file_path ).lower ()
298+ # Check if it's an example/demo/test/template script
299+ example_indicators = ['example' , 'demo' , 'test' , 'template' , 'fixture' , 'mock' ]
300+ if any (indicator in path_lower for indicator in example_indicators ):
298301 return 'example_script'
299302 return 'executable_script'
300303 return 'other'
@@ -402,7 +405,11 @@ def _scan_line(self, file_path: Path, line_num: int, line: str,
402405 """Scan a single line for security issues with context awareness."""
403406
404407 # Skip comments in most cases (but not for secrets)
405- is_comment = line .strip ().startswith ('#' ) or line .strip ().startswith ('//' )
408+ is_comment = line .strip ().startswith ('#' ) or line .strip ().startswith ('//' ) or line .strip ().startswith ('*' )
409+
410+ # Skip string literals containing code patterns (false positives)
411+ # e.g., message="Use of 'eval()' is a security risk"
412+ is_in_string = (line .count ('"' ) >= 2 or line .count ("'" ) >= 2 ) and ('=' in line or ':' in line )
406413
407414 # Check if this line has safety context
408415 has_safety_context = self ._check_safety_context (line_num , lines )
@@ -421,11 +428,14 @@ def _scan_line(self, file_path: Path, line_num: int, line: str,
421428 line_num , issue , line .strip (), recommendation )
422429
423430 # Command injection (scripts only)
424- if is_script :
431+ if is_script and not is_in_string :
425432 for pattern , (severity , issue , recommendation ) in self .injection_patterns .items ():
426433 if re .search (pattern , line ):
427- self ._add_finding (severity , 'Command Injection Risk' , file_path ,
428- line_num , issue , line .strip (), recommendation )
434+ # Apply context-aware severity adjustment
435+ adjusted_severity = self ._adjust_severity (severity , file_context , has_safety_context , is_trusted )
436+ if adjusted_severity : # None means skip
437+ self ._add_finding (adjusted_severity , 'Command Injection Risk' , file_path ,
438+ line_num , issue , line .strip (), recommendation )
429439
430440 # Hardcoded secrets (scan all files, including comments)
431441 for pattern , (severity , issue , recommendation ) in self .secrets_patterns .items ():
@@ -434,14 +444,20 @@ def _scan_line(self, file_path: Path, line_num: int, line: str,
434444 # Additional validation: check if it's clearly a test value
435445 matched_value = match .group (0 )
436446 if not self ._is_test_credential (matched_value , file_path ):
437- self ._add_finding (severity , 'Hardcoded Secret' , file_path ,
438- line_num , issue , line .strip (), recommendation )
447+ # Apply context-aware severity adjustment
448+ adjusted_severity = self ._adjust_severity (severity , file_context , has_safety_context , is_trusted )
449+ if adjusted_severity : # None means skip
450+ self ._add_finding (adjusted_severity , 'Hardcoded Secret' , file_path ,
451+ line_num , issue , line .strip (), recommendation )
439452
440453 # Cloud credentials (scan all files, including comments)
441454 for pattern , (severity , issue , recommendation ) in self .cloud_credentials_patterns .items ():
442455 if re .search (pattern , line ):
443- self ._add_finding (severity , 'Cloud Credentials' , file_path ,
444- line_num , issue , line .strip (), recommendation )
456+ # Apply context-aware severity adjustment
457+ adjusted_severity = self ._adjust_severity (severity , file_context , has_safety_context , is_trusted )
458+ if adjusted_severity : # None means skip
459+ self ._add_finding (adjusted_severity , 'Cloud Credentials' , file_path ,
460+ line_num , issue , line .strip (), recommendation )
445461
446462 # Network security
447463 if not is_comment :
@@ -491,8 +507,11 @@ def _scan_line(self, file_path: Path, line_num: int, line: str,
491507 if is_script :
492508 for pattern , (severity , issue , recommendation ) in self .secure_defaults_patterns .items ():
493509 if re .search (pattern , line ):
494- self ._add_finding (severity , 'Insecure Defaults' , file_path ,
495- line_num , issue , line .strip (), recommendation )
510+ # Apply context-aware severity adjustment
511+ adjusted_severity = self ._adjust_severity (severity , file_context , has_safety_context , is_trusted )
512+ if adjusted_severity : # None means skip
513+ self ._add_finding (adjusted_severity , 'Insecure Defaults' , file_path ,
514+ line_num , issue , line .strip (), recommendation )
496515
497516 # Unsafe deserialization (scripts only)
498517 if is_script and not is_comment :
0 commit comments