@@ -45,7 +45,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
45
45
2) Text-based (requirements.txt, package.json, yarn.lock, etc.)
46
46
- Uses compiled regex patterns to detect a match line by line
47
47
"""
48
- # Extract just the file name to detect manifest type
49
48
file_type = Path (manifest_file ).name
50
49
logging .debug ("Processing file: %s" , manifest_file )
51
50
@@ -65,7 +64,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
65
64
or {}
66
65
)
67
66
logging .debug ("Found package keys: %s" , list (packages_dict .keys ()))
68
-
69
67
found_key = None
70
68
found_info = None
71
69
for key , value in packages_dict .items ():
@@ -88,7 +86,7 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
88
86
else :
89
87
return 1 , f"{ packagename } { packageversion } (not found in { manifest_file } )"
90
88
except (FileNotFoundError , json .JSONDecodeError ) as e :
91
- logging .error ("Error reading JSON from %s: %s" , manifest_file , e )
89
+ logging .error ("Error reading %s: %s" , manifest_file , e )
92
90
return 1 , f"Error reading { manifest_file } "
93
91
94
92
# ----------------------------------------------------
@@ -172,11 +170,11 @@ def create_security_comment_sarif(diff) -> dict:
172
170
"""
173
171
Create SARIF-compliant output from the diff report, including dynamic URL generation
174
172
based on manifest type and improved <br/> formatting for GitHub SARIF display.
175
-
173
+
176
174
This function now:
177
175
- Accepts multiple manifest files from alert.introduced_by or alert.manifests.
178
176
- Generates one SARIF location per manifest file.
179
- - Falls back to a default (" requirements.txt") if none is found .
177
+ - Does NOT fall back to ' requirements.txt' if no manifest file is provided .
180
178
"""
181
179
if len (diff .new_alerts ) == 0 :
182
180
for alert in diff .new_alerts :
@@ -209,6 +207,7 @@ def create_security_comment_sarif(diff) -> dict:
209
207
210
208
# --- Extract manifest files from alert data ---
211
209
manifest_files = []
210
+ logging .debug ("Alert %s - introduced_by: %s, manifests: %s" , rule_id , alert .introduced_by , getattr (alert , 'manifests' , None ))
212
211
if alert .introduced_by and isinstance (alert .introduced_by , list ):
213
212
for entry in alert .introduced_by :
214
213
if isinstance (entry , list ) and len (entry ) >= 2 :
@@ -218,12 +217,13 @@ def create_security_comment_sarif(diff) -> dict:
218
217
elif hasattr (alert , 'manifests' ) and alert .manifests :
219
218
manifest_files = [mf .strip () for mf in alert .manifests .split (";" ) if mf .strip ()]
220
219
221
- logging .debug ("Alert %s manifest_files before fallback: %s" , rule_id , manifest_files )
222
220
if not manifest_files :
223
- manifest_files = ["requirements.txt" ]
224
- logging .debug ("Alert %s falling back to: %s" , rule_id , manifest_files )
221
+ # Do not fall back to requirements.txt; log an error instead.
222
+ logging .error ("Alert %s: No manifest file found; cannot determine file location." , rule_id )
223
+ continue # Skip this alert
225
224
226
- logging .debug ("Alert %s using manifest_file for URL: %s" , rule_id , manifest_files [0 ])
225
+ logging .debug ("Alert %s using manifest_files: %s" , rule_id , manifest_files )
226
+ # Use the first manifest for URL generation.
227
227
socket_url = Messages .get_manifest_type_url (manifest_files [0 ], pkg_name , pkg_version )
228
228
short_desc = (f"{ alert .props .get ('note' , '' )} <br/><br/>Suggested Action:<br/>{ alert .suggestion } "
229
229
f"<br/><a href=\" { socket_url } \" >{ socket_url } </a>" )
0 commit comments