Skip to content

Commit ddebb87

Browse files
authored
Update messages.py
1 parent df22cdf commit ddebb87

File tree

1 file changed

+0
-76
lines changed

1 file changed

+0
-76
lines changed

socketsecurity/core/messages.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
8282
needle_key = f'"{found_key}":' # e.g. "node_modules/axios":
8383
needle_version = f'"version": "{packageversion}"'
8484
lines = raw_text.splitlines()
85-
<<<<<<< HEAD
8685
best_line = 1
87-
=======
88-
best_line = -1
89-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
9086
snippet = None
9187

9288
for i, line in enumerate(lines, start=1):
@@ -101,17 +97,10 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
10197
else:
10298
return 1, f'"{found_key}": {found_info}'
10399
else:
104-
<<<<<<< HEAD
105100
return 1, f"{packagename} {packageversion} (not found in {manifest_file})"
106101

107102
except (FileNotFoundError, json.JSONDecodeError):
108103
return 1, f"Error reading {manifest_file}"
109-
=======
110-
return -1, f"{packagename} {packageversion} (not found in {manifest_file})"
111-
112-
except (FileNotFoundError, json.JSONDecodeError):
113-
return -1, f"Error reading {manifest_file}"
114-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
115104

116105
# ----------------------------------------------------
117106
# 2) Text-based / line-based manifests
@@ -153,7 +142,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
153142
for line_number, line_content in enumerate(lines, start=1):
154143
# For Python conditional dependencies, ignore everything after first ';'
155144
line_main = line_content.split(";", 1)[0].strip()
156-
<<<<<<< HEAD
157145

158146
# Use a case-insensitive regex search
159147
if re.search(searchstring, line_main, re.IGNORECASE):
@@ -203,36 +191,6 @@ def create_security_comment_sarif(diff) -> dict:
203191
Create SARIF-compliant output from the diff report, including dynamic URL generation
204192
based on manifest type and improved <br/> formatting for GitHub SARIF display.
205193
"""
206-
=======
207-
208-
# Use a case-insensitive regex search
209-
if re.search(searchstring, line_main, re.IGNORECASE):
210-
return line_number, line_content.strip()
211-
212-
except FileNotFoundError:
213-
return -1, f"{manifest_file} not found"
214-
except Exception as e:
215-
return -1, f"Error reading {manifest_file}: {e}"
216-
217-
return -1, f"{packagename} {packageversion} (not found)"
218-
219-
@staticmethod
220-
def create_security_comment_sarif(diff: Diff) -> dict:
221-
"""
222-
Create SARIF-compliant output from the diff report, including line references
223-
and a link to the Socket docs in the fullDescription. Also converts any \r\n
224-
into <br/> so they render properly in GitHub's SARIF display.
225-
"""
226-
# Check if there's a blocking error in new alerts
227-
scan_failed = False
228-
if len(diff.new_alerts) == 0:
229-
for alert in diff.new_alerts:
230-
if alert.error:
231-
scan_failed = True
232-
break
233-
234-
# Basic SARIF skeleton
235-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
236194
sarif_data = {
237195
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
238196
"version": "2.1.0",
@@ -259,27 +217,11 @@ def create_security_comment_sarif(diff: Diff) -> dict:
259217
rule_id = f"{pkg_name}=={pkg_version}"
260218
severity = alert.severity
261219

262-
<<<<<<< HEAD
263220
# Generate the correct URL for the alert based on manifest type
264-
=======
265-
# Convert any \r\n in short desc to <br/> so they display properly
266-
short_desc_raw = f"{alert.props.get('note', '')}\r\n\r\nSuggested Action:\r\n{alert.suggestion}"
267-
short_desc = short_desc_raw.replace("\r\n", "<br/>")
268-
269-
# Build link to Socket docs, e.g. "https://socket.dev/npm/package/foo/alerts/1.2.3"
270-
socket_url = f"https://socket.dev/npm/package/{pkg_name}/alerts/{pkg_version}"
271-
272-
# Also convert \r\n in the main description to <br/>, then append the Socket docs link
273-
base_desc = alert.description.replace("\r\n", "<br/>")
274-
full_desc_raw = f"{alert.title} - {base_desc}<br/>{socket_url}"
275-
276-
# Identify the manifest file and line
277-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
278221
introduced_list = alert.introduced_by
279222
manifest_file = introduced_list[0][1] if introduced_list and isinstance(introduced_list[0], list) else alert.manifests or "requirements.txt"
280223
socket_url = Messages.get_manifest_type_url(manifest_file, pkg_name, pkg_version)
281224

282-
<<<<<<< HEAD
283225
# Prepare descriptions with <br/> replacements
284226
short_desc = f"{alert.props.get('note', '')}<br/><br/>Suggested Action:<br/>{alert.suggestion}"
285227
full_desc = f"{alert.title} - {alert.description.replace('\r\n', '<br/>')}\r\n<a href=\"{socket_url}\">{socket_url}</a>"
@@ -290,33 +232,19 @@ def create_security_comment_sarif(diff: Diff) -> dict:
290232
line_number = 1 # Ensure SARIF compliance
291233

292234
# Create the rule if not already defined
293-
=======
294-
line_number, line_content = Messages.find_line_in_file(pkg_name, pkg_version, manifest_file)
295-
296-
# If not already defined, create a rule for this package
297-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
298235
if rule_id not in rules_map:
299236
rules_map[rule_id] = {
300237
"id": rule_id,
301238
"name": f"{pkg_name}=={pkg_version}",
302239
"shortDescription": {"text": f"Alert generated for {rule_id} by Socket Security"},
303-
<<<<<<< HEAD
304240
"fullDescription": {"text": full_desc},
305241
"helpUri": socket_url,
306-
=======
307-
"fullDescription": {"text": full_desc_raw},
308-
"helpUri": alert.url,
309-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
310242
"defaultConfiguration": {
311243
"level": Messages.map_severity_to_sarif(severity)
312244
},
313245
}
314246

315-
<<<<<<< HEAD
316247
# Add the SARIF result
317-
=======
318-
# Create a SARIF "result" referencing the line where we found the match
319-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
320248
result_obj = {
321249
"ruleId": rule_id,
322250
"message": {"text": short_desc},
@@ -334,11 +262,7 @@ def create_security_comment_sarif(diff: Diff) -> dict:
334262
}
335263
results_list.append(result_obj)
336264

337-
<<<<<<< HEAD
338265
# Attach rules and results
339-
=======
340-
# Attach our rules and results to the SARIF data
341-
>>>>>>> 7ddb4537518fa762da7ebebff2044ce71e720f3c
342266
sarif_data["runs"][0]["tool"]["driver"]["rules"] = list(rules_map.values())
343267
sarif_data["runs"][0]["results"] = results_list
344268

0 commit comments

Comments
 (0)