Skip to content

Commit 12e8e6e

Browse files
author
Orlando Barrera II
committed
Testing the sarif file parsing
1 parent 0df0752 commit 12e8e6e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

socketsecurity/core/messages.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
4545
2) Text-based (requirements.txt, package.json, yarn.lock, etc.)
4646
- Uses compiled regex patterns to detect a match line by line
4747
"""
48-
# Extract just the file name to detect manifest type
4948
file_type = Path(manifest_file).name
5049
logging.debug("Processing file: %s", manifest_file)
5150

@@ -65,7 +64,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
6564
or {}
6665
)
6766
logging.debug("Found package keys: %s", list(packages_dict.keys()))
68-
6967
found_key = None
7068
found_info = None
7169
for key, value in packages_dict.items():
@@ -88,7 +86,7 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
8886
else:
8987
return 1, f"{packagename} {packageversion} (not found in {manifest_file})"
9088
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)
9290
return 1, f"Error reading {manifest_file}"
9391

9492
# ----------------------------------------------------
@@ -172,11 +170,11 @@ def create_security_comment_sarif(diff) -> dict:
172170
"""
173171
Create SARIF-compliant output from the diff report, including dynamic URL generation
174172
based on manifest type and improved <br/> formatting for GitHub SARIF display.
175-
173+
176174
This function now:
177175
- Accepts multiple manifest files from alert.introduced_by or alert.manifests.
178176
- 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.
180178
"""
181179
if len(diff.new_alerts) == 0:
182180
for alert in diff.new_alerts:
@@ -209,6 +207,7 @@ def create_security_comment_sarif(diff) -> dict:
209207

210208
# --- Extract manifest files from alert data ---
211209
manifest_files = []
210+
logging.debug("Alert %s - introduced_by: %s, manifests: %s", rule_id, alert.introduced_by, getattr(alert, 'manifests', None))
212211
if alert.introduced_by and isinstance(alert.introduced_by, list):
213212
for entry in alert.introduced_by:
214213
if isinstance(entry, list) and len(entry) >= 2:
@@ -218,12 +217,13 @@ def create_security_comment_sarif(diff) -> dict:
218217
elif hasattr(alert, 'manifests') and alert.manifests:
219218
manifest_files = [mf.strip() for mf in alert.manifests.split(";") if mf.strip()]
220219

221-
logging.debug("Alert %s manifest_files before fallback: %s", rule_id, manifest_files)
222220
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
225224

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.
227227
socket_url = Messages.get_manifest_type_url(manifest_files[0], pkg_name, pkg_version)
228228
short_desc = (f"{alert.props.get('note', '')}<br/><br/>Suggested Action:<br/>{alert.suggestion}"
229229
f"<br/><a href=\"{socket_url}\">{socket_url}</a>")

0 commit comments

Comments
 (0)