Skip to content

Commit 5430d3f

Browse files
committed
Populate gitlab security report with alerts for full scans
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 4020285 commit 5430d3f

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

docs/cli-reference.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,22 @@ All alert types are included in the GitLab report if they're marked as `error` o
702702
703703
### Report Schema
704704
705-
Socket CLI generates reports compliant with [GitLab Dependency Scanning schema version 15.0.0](https://docs.gitlab.com/ee/development/integrations/secure.html). The reports include:
705+
Socket CLI generates reports compliant with [GitLab Dependency Scanning schema version 15.0.0](https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/blob/v15.0.0/dist/dependency-scanning-report-format.json). The reports include:
706706
707-
- **Scan metadata**: Analyzer and scanner information
707+
- **Scan metadata**: Analyzer and scanner information with ISO 8601 timestamps
708708
- **Vulnerabilities**: Detailed vulnerability data with:
709709
- Unique deterministic UUIDs for tracking
710710
- Package location and dependency information
711711
- Severity levels mapped from Socket's analysis
712712
- Socket-specific alert types and CVE identifiers
713713
- Links to Socket.dev for detailed analysis
714+
- **Dependency files**: Manifest files and their dependencies discovered during the scan
715+
716+
**Schema compatibility:** The v15.0.0 schema is supported across all GitLab versions 12.0+ (both self-hosted and cloud). The report includes the `dependency_files` field, which is required by v15.0.0 and accepted as an optional extra by newer schema versions, ensuring maximum compatibility across GitLab instances.
717+
718+
### Performance Notes
719+
720+
When `--enable-gitlab-security` (or `--enable-json` / `--enable-sarif`) is used with a full scan (non-diff mode), the CLI fetches package and alert data from the scan results to populate the report. This adds time proportional to the number of packages in the scan. Without these output flags, no additional data is fetched and scan performance is unchanged.
714721

715722
### Requirements
716723

@@ -726,7 +733,8 @@ Socket CLI generates reports compliant with [GitLab Dependency Scanning schema v
726733
- Ensure the report file follows the correct schema format
727734

728735
**Empty vulnerabilities array:**
729-
- This is normal if no new security issues were detected
736+
- This is normal if no new security issues were detected in diff mode
737+
- For full scans, ensure you are using `--enable-gitlab-security` so alert data is fetched
730738
- Check Socket.dev dashboard for full analysis details
731739

732740
## Development

socketsecurity/core/__init__.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,48 @@ def create_full_scan_with_report_url(
659659
diff.report_url = f"{base_socket}/{self.config.org_slug}/sbom/{new_full_scan.id}"
660660
diff.diff_url = diff.report_url
661661
diff.id = new_full_scan.id
662-
diff.packages = {}
663662

664-
# Return result in the format expected by the user
663+
needs_alerts = (
664+
self.cli_config is not None
665+
and (
666+
self.cli_config.enable_gitlab_security
667+
or self.cli_config.enable_json
668+
or self.cli_config.enable_sarif
669+
)
670+
)
671+
672+
if needs_alerts:
673+
log.info("Output format requires alerts, fetching SBOM data for full scan")
674+
sbom_start = time.time()
675+
sbom_artifacts_dict = self.get_sbom_data(new_full_scan.id)
676+
sbom_artifacts = self.get_sbom_data_list(sbom_artifacts_dict)
677+
packages = self.create_packages_dict(sbom_artifacts)
678+
diff.packages = packages
679+
680+
all_alerts_collection: Dict[str, List[Issue]] = {}
681+
for package_id, package in packages.items():
682+
self.add_package_alerts_to_collection(
683+
package=package,
684+
alerts_collection=all_alerts_collection,
685+
packages=packages
686+
)
687+
688+
consolidated: Set[str] = set()
689+
for alert_key, alerts in all_alerts_collection.items():
690+
for alert in alerts:
691+
alert_str = f"{alert.purl},{alert.type}"
692+
if (alert.error or alert.warn) and alert_str not in consolidated:
693+
diff.new_alerts.append(alert)
694+
consolidated.add(alert_str)
695+
696+
sbom_end = time.time()
697+
log.info(
698+
f"Fetched {len(packages)} packages and {len(diff.new_alerts)} alerts "
699+
f"in {sbom_end - sbom_start:.2f}s"
700+
)
701+
else:
702+
diff.packages = {}
703+
665704
return diff
666705

667706
def get_full_scan(self, full_scan_id: str) -> FullScan:

0 commit comments

Comments
 (0)