Skip to content

Commit 2838704

Browse files
committed
ensure only CDX/SPDX manifests and the .socket.facts.json are included in the final scan
1 parent c1fa510 commit 2838704

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

socketsecurity/core/__init__.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ def create_full_scan_with_report_url(
598598
no_change: bool = False,
599599
save_files_list_path: Optional[str] = None,
600600
save_manifest_tar_path: Optional[str] = None,
601-
base_paths: Optional[List[str]] = None
601+
base_paths: Optional[List[str]] = None,
602+
explicit_files: Optional[List[str]] = None
602603
) -> Diff:
603604
"""Create a new full scan and return with html_report_url.
604605
@@ -609,6 +610,7 @@ def create_full_scan_with_report_url(
609610
save_files_list_path: Optional path to save submitted files list for debugging
610611
save_manifest_tar_path: Optional path to save manifest files tar.gz archive
611612
base_paths: List of base paths for the scan (optional)
613+
explicit_files: Optional list of explicit files to use instead of discovering files
612614
613615
Returns:
614616
Dict with full scan data including html_report_url
@@ -622,11 +624,15 @@ def create_full_scan_with_report_url(
622624
if no_change:
623625
return diff
624626

625-
# Find manifest files from all paths
626-
all_files = []
627-
for path in paths:
628-
files = self.find_files(path)
629-
all_files.extend(files)
627+
# Use explicit files if provided, otherwise find manifest files from all paths
628+
if explicit_files is not None:
629+
all_files = explicit_files
630+
log.debug(f"Using {len(all_files)} explicit files instead of discovering files")
631+
else:
632+
all_files = []
633+
for path in paths:
634+
files = self.find_files(path)
635+
all_files.extend(files)
630636

631637
# Save submitted files list if requested
632638
if save_files_list_path and all_files:
@@ -994,7 +1000,8 @@ def create_new_diff(
9941000
no_change: bool = False,
9951001
save_files_list_path: Optional[str] = None,
9961002
save_manifest_tar_path: Optional[str] = None,
997-
base_paths: Optional[List[str]] = None
1003+
base_paths: Optional[List[str]] = None,
1004+
explicit_files: Optional[List[str]] = None
9981005
) -> Diff:
9991006
"""Create a new diff using the Socket SDK.
10001007
@@ -1005,16 +1012,21 @@ def create_new_diff(
10051012
save_files_list_path: Optional path to save submitted files list for debugging
10061013
save_manifest_tar_path: Optional path to save manifest files tar.gz archive
10071014
base_paths: List of base paths for the scan (optional)
1015+
explicit_files: Optional list of explicit files to use instead of discovering files
10081016
"""
10091017
log.debug(f"starting create_new_diff with no_change: {no_change}")
10101018
if no_change:
10111019
return Diff(id="NO_DIFF_RAN", diff_url="", report_url="")
10121020

1013-
# Find manifest files from all paths
1014-
all_files = []
1015-
for path in paths:
1016-
files = self.find_files(path)
1017-
all_files.extend(files)
1021+
# Use explicit files if provided, otherwise find manifest files from all paths
1022+
if explicit_files is not None:
1023+
all_files = explicit_files
1024+
log.debug(f"Using {len(all_files)} explicit files instead of discovering files")
1025+
else:
1026+
all_files = []
1027+
for path in paths:
1028+
files = self.find_files(path)
1029+
all_files.extend(files)
10181030

10191031
# Save submitted files list if requested
10201032
if save_files_list_path and all_files:

socketsecurity/socketcli.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def main_code():
313313
sbom_files_to_submit = []
314314
for scan_path in scan_paths:
315315
sbom_files_to_submit.extend(core.find_sbom_files(scan_path))
316-
facts_path = os.path.abspath(output_path)
317-
if os.path.exists(facts_path):
318-
sbom_files_to_submit.append(facts_path)
316+
# Use relative path for facts file
317+
if os.path.exists(output_path):
318+
sbom_files_to_submit.append(output_path)
319319
log.info(f"Pre-generated SBOMs mode: will submit {len(sbom_files_to_submit)} files (CDX, SPDX, and facts file)")
320320

321321
except Exception as e:
@@ -474,7 +474,7 @@ def main_code():
474474
log.info("Push initiated flow")
475475
if scm.check_event_type() == "diff":
476476
log.info("Starting comment logic for PR/MR event")
477-
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths)
477+
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths, explicit_files=sbom_files_to_submit)
478478
comments = scm.get_comments_for_pr()
479479
log.debug("Removing comment alerts")
480480

@@ -527,14 +527,14 @@ def main_code():
527527
)
528528
else:
529529
log.info("Starting non-PR/MR flow")
530-
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths)
530+
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths, explicit_files=sbom_files_to_submit)
531531

532532
output_handler.handle_output(diff)
533-
533+
534534
elif config.enable_diff and not force_api_mode:
535535
# New logic: --enable-diff forces diff mode even with --integration api (no SCM)
536536
log.info("Diff mode enabled without SCM integration")
537-
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths)
537+
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths, explicit_files=sbom_files_to_submit)
538538
output_handler.handle_output(diff)
539539

540540
elif config.enable_diff and force_api_mode:
@@ -552,12 +552,13 @@ def main_code():
552552
no_change=should_skip_scan,
553553
save_files_list_path=config.save_submitted_files_list,
554554
save_manifest_tar_path=config.save_manifest_tar,
555-
base_paths=base_paths
555+
base_paths=base_paths,
556+
explicit_files=sbom_files_to_submit
556557
)
557558
log.info(f"Full scan created with ID: {diff.id}")
558559
log.info(f"Full scan report URL: {diff.report_url}")
559560
output_handler.handle_output(diff)
560-
561+
561562
else:
562563
if force_api_mode:
563564
log.info("No Manifest files changed, creating Socket Report")
@@ -572,7 +573,8 @@ def main_code():
572573
no_change=should_skip_scan,
573574
save_files_list_path=config.save_submitted_files_list,
574575
save_manifest_tar_path=config.save_manifest_tar,
575-
base_paths=base_paths
576+
base_paths=base_paths,
577+
explicit_files=sbom_files_to_submit
576578
)
577579
log.info(f"Full scan created with ID: {diff.id}")
578580
log.info(f"Full scan report URL: {diff.report_url}")
@@ -583,7 +585,8 @@ def main_code():
583585
no_change=should_skip_scan,
584586
save_files_list_path=config.save_submitted_files_list,
585587
save_manifest_tar_path=config.save_manifest_tar,
586-
base_paths=base_paths
588+
base_paths=base_paths,
589+
explicit_files=sbom_files_to_submit
587590
)
588591
output_handler.handle_output(diff)
589592

0 commit comments

Comments
 (0)