Skip to content

Commit 0bf1e33

Browse files
committed
Preserve blocking actions and advisory details in scan reports
1 parent 21fa663 commit 0bf1e33

5 files changed

Lines changed: 175 additions & 110 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,17 @@
44

55
### Changed
66

7-
- Bumped the pinned Socket Python SDK (`socketdev`) from `3.6.3` to `3.6.4`.
8-
The release keeps each advisory as its own alert instead of one per alert
9-
type and severity, which changes what the CLI reports; see Fixed below.
7+
- Updated the Socket Python SDK (`socketdev`) to 3.6.4. This can increase
8+
advisory counts in full-scan JSON, SARIF, and GitLab security reports, and
9+
in the existing findings shown in GitLab security and FOSSA diff reports.
1010

1111
### Fixed
1212

13-
- `--strict-blocking` lists and counts every advisory on an unchanged package.
14-
Existing alerts are read through the SDK, which kept one alert per alert type
15-
and severity, so a package with six Critical CVEs showed one, and the
16-
"EXISTING blocking issues" count was too low. Requires `socketdev` 3.6.4.
17-
- A Block-action CVE on an unchanged package now fails the run even when
18-
another CVE of the same severity on that package is triaged to monitor or
19-
ignore. Before, the triaged CVE could stand in for both and the run passed.
20-
- `--strict-blocking` fails on Block alerts that persist across a dependency
21-
version change and lists them in the Existing alerts table.
22-
- In full-scan mode, the `--enable-json`, `--enable-sarif` and
23-
`--enable-gitlab-security` reports now list every advisory on a package.
24-
Before, they listed one per alert type and severity, so expect more alerts,
25-
and more with a Block action, in these reports. In diff mode the same
26-
applies to existing alerts in the `--enable-gitlab-security` and
27-
`--legal-format fossa` output.
13+
- `--strict-blocking` counts distinct advisories on unchanged dependencies and
14+
lists findings that persist after a version change in the Existing alerts
15+
table. When a finding has both Warn and Block actions, Block takes precedence.
16+
- SARIF reports use advisory IDs to distinguish findings on the same package
17+
and manifest.
2818

2919
## 2.13.2
3020

‎docs/cli-reference.md‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -604,19 +604,12 @@ Bot mode (`bot_configs` array items):
604604
605605
## Strict Blocking Mode
606606
607-
The `--strict-blocking` flag enforces a zero-tolerance security policy by failing builds when **ANY** security violations with blocking severity exist, not just new ones introduced in the current changes.
607+
In a scan comparison, `--strict-blocking` fails the build on new and existing findings with a **Block** action.
608608
609609
### Standard vs Strict Blocking Behavior
610610
611-
**Standard Behavior (Default)**:
612-
- ✅ Passes if no NEW violations are introduced
613-
- ❌ Fails only on NEW violations from your changes
614-
- 🟡 Existing violations are ignored
615-
616-
**Strict Blocking Behavior (`--strict-blocking`)**:
617-
- ✅ Passes only if NO violations exist (new or existing)
618-
- ❌ Fails on ANY violation (new OR existing)
619-
- 🔴 Enforces zero-tolerance policy
611+
- **Default** fails on findings introduced by the change that have a **Block** action.
612+
- **Strict blocking** also checks unchanged dependencies and findings that persist after a version change. For example, if an upgrade leaves a blocking advisory unresolved, the run still fails and the advisory appears under **Existing alerts** at the new version.
620613
621614
### Usage Examples
622615
@@ -668,8 +661,8 @@ Security issues detected by Socket Security:
668661
### Important Notes
669662
670663
- **Diff Mode Only**: The flag applies when a scan comparison runs, with or without SCM integration. A full scan logs a warning and does not evaluate existing violations; see [Scan type by pipeline](ci-cd.md#scan-type-by-pipeline).
671-
- **Error-Level Only**: Only fails on `error=True` alerts (blocking severity), not warnings.
672-
- **Existing alerts come from the full scan**. The CLI reads alerts on unchanged packages and findings that persist across dependency version changes from the new full scan. This takes up to one additional full-scan fetch. A failed fetch or a missing package in that response triggers the infrastructure-error exit code.
664+
- **Policy actions**. Warn findings are reported. If the same finding has both Warn and Block actions, Block takes precedence.
665+
- **Existing alerts come from the full scan**. The CLI fetches the current full scan when the comparison leaves out alerts on unchanged packages or when a dependency version changes. A failed fetch or a missing package in that response triggers the infrastructure-error exit code.
673666
- **PR/MR comments**: Existing alerts are listed in their own table after the new ones, blocking first, with license violations grouped per package. `@SocketSecurity ignore` applies to them too. Very large sets are cut off before the comment reaches GitHub's size limit, with a link to the full report. Ignoring every displayed alert preserves the warning about omitted findings; `ignore-all` also clears omitted findings.
674667
- **Priority**: `--disable-blocking` takes precedence - if both flags are set, the build will always pass.
675668
- **First Scan**: On the very first scan of a repository, there are no "existing" violations, so behavior is identical to standard mode.
@@ -899,13 +892,11 @@ The GitLab Security Dashboard report and the JSON/SARIF diff outputs use differe
899892
900893
| Output Format | Default Alerts | With `--strict-blocking` |
901894
|:---|:---|:---|
902-
| `--enable-gitlab-security` | **All** alerts (new + existing) | All alerts (same) |
895+
| `--enable-gitlab-security` | New alerts and existing alerts on unchanged dependencies | Also includes findings that persist after a version change |
903896
| `--enable-json` | New alerts only | New + existing alerts |
904897
| `--enable-sarif` (diff scope) | New alerts only | New + existing alerts |
905898
906-
**Why the difference?** GitLab's Security Dashboard is designed to present the full security posture of a project. An empty dashboard on a scan with no dependency changes would be misleading -- the vulnerabilities still exist, they just didn't change. By contrast, JSON and SARIF in diff scope are designed to answer "what changed?" and only include existing alerts when `--strict-blocking` explicitly requests it.
907-
908-
> **Tip:** If you use `--enable-json` alongside `--enable-gitlab-security`, the GitLab report may contain more vulnerabilities than the JSON output. This is expected. To make JSON output match, add `--strict-blocking`.
899+
Enable `--strict-blocking` to include existing findings in JSON and diff-scope SARIF. Scan-based SARIF includes the advisory ID in the rule ID when available, so separate advisories on the same package and manifest remain distinguishable.
909900
910901
### Alert Ignoring via PR/MR Comments
911902

‎socketsecurity/core/__init__.py‎

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
import time
1414
from dataclasses import asdict
1515
from pathlib import PurePath
16-
from typing import TYPE_CHECKING, Dict, Iterator, List, NamedTuple, Optional, Set, Tuple
16+
from typing import (
17+
TYPE_CHECKING,
18+
Dict,
19+
Iterable,
20+
Iterator,
21+
List,
22+
NamedTuple,
23+
Optional,
24+
Set,
25+
Tuple,
26+
)
1727

1828
if TYPE_CHECKING:
1929
from socketsecurity.config import CliConfig
@@ -1357,13 +1367,10 @@ def create_full_scan_with_report_url(
13571367
packages=packages
13581368
)
13591369

1360-
consolidated: Set[Tuple[str, str, str, str]] = set()
1361-
for alert_key, alerts in all_alerts_collection.items():
1362-
for alert in alerts:
1363-
finding_key = alert.consolidation_key()
1364-
if (alert.error or alert.warn) and finding_key not in consolidated:
1365-
diff.new_alerts.append(alert)
1366-
consolidated.add(finding_key)
1370+
findings = Core._consolidate_reportable_alerts(
1371+
alert for alerts in all_alerts_collection.values() for alert in alerts
1372+
)
1373+
diff.new_alerts = list(findings.values())
13671374
diff.alerts_fetched = True
13681375

13691376
sbom_end = time.time()
@@ -2502,9 +2509,15 @@ def create_new_diff(
25022509
unchanged_packages = Core.get_unchanged_packages(packages, added_packages, removed_packages)
25032510
existing_changed_packages = {}
25042511
if has_baseline and getattr(self.cli_config, "strict_blocking", False):
2505-
# Keep the comparison's alerts intact for new-finding classification.
2512+
baseline_names = {
2513+
Core._package_identity(package.type, package.namespace, package.name, "")[:3]
2514+
for bucket in (removed_packages, unchanged_packages)
2515+
for package in bucket.values()
2516+
}
25062517
existing_changed_packages = {
25072518
package_id: copy.copy(package) for package_id, package in added_packages.items()
2519+
if package.diffType == "updated"
2520+
or Core._package_identity(package.type, package.namespace, package.name, "")[:3] in baseline_names
25082521
}
25092522
if self._requires_unchanged_alerts():
25102523
self.add_existing_alerts_from_full_scan(
@@ -2680,6 +2693,7 @@ def create_diff_report(
26802693
alerts_in_added_packages: Dict[str, List[Issue]] = {}
26812694
alerts_in_removed_packages: Dict[str, List[Issue]] = {}
26822695
alerts_in_unchanged_packages: Dict[str, List[Issue]] = {}
2696+
current_packages = {**(unchanged_packages or {}), **added_packages}
26832697

26842698
seen_packages = {
26852699
"added": set(),
@@ -2738,7 +2752,6 @@ def create_diff_report(
27382752
alerts_in_removed_packages
27392753
)
27402754

2741-
# Existing findings can also persist on a changed version.
27422755
diff.unchanged_alerts = Core.get_unchanged_alerts(
27432756
alerts_in_unchanged_packages
27442757
)
@@ -2748,15 +2761,16 @@ def create_diff_report(
27482761
self.add_package_alerts_to_collection(
27492762
package=package,
27502763
alerts_collection=current_changed_alerts,
2751-
packages=added_packages,
2764+
packages=current_packages,
27522765
)
2753-
reported_findings = {
2754-
alert.consolidation_key() for alert in (*diff.new_alerts, *diff.unchanged_alerts)
2755-
}
2756-
diff.unchanged_alerts.extend(
2757-
alert for alert in Core.get_unchanged_alerts(current_changed_alerts)
2758-
if alert.consolidation_key() not in reported_findings
2766+
current_findings = Core._consolidate_reportable_alerts(
2767+
alert
2768+
for group in (diff.new_alerts, diff.unchanged_alerts, *current_changed_alerts.values())
2769+
for alert in group
27592770
)
2771+
# Keep the comparison's classification when a finding also appears in the full scan.
2772+
diff.new_alerts = [current_findings.pop(alert.consolidation_key()) for alert in diff.new_alerts]
2773+
diff.unchanged_alerts = list(current_findings.values())
27602774

27612775
# Get removed alerts (for completeness)
27622776
diff.removed_alerts = Core.get_removed_alerts(
@@ -3006,36 +3020,13 @@ def get_new_alerts(
30063020
Returns:
30073021
List of newly found alerts
30083022
"""
3009-
alerts: List[Issue] = []
3010-
consolidated_alerts = set()
3011-
3012-
for alert_key in added_package_alerts:
3013-
if alert_key not in removed_package_alerts:
3014-
new_alerts = added_package_alerts[alert_key]
3015-
for alert in new_alerts:
3016-
finding_key = alert.consolidation_key()
3017-
3018-
if alert.error or alert.warn:
3019-
if finding_key not in consolidated_alerts:
3020-
alerts.append(alert)
3021-
consolidated_alerts.add(finding_key)
3022-
else:
3023-
new_alerts = added_package_alerts[alert_key]
3024-
removed_alerts = removed_package_alerts[alert_key]
3025-
3026-
for alert in new_alerts:
3027-
finding_key = alert.consolidation_key()
3028-
3029-
# Only add if:
3030-
# 1. Alert isn't in removed packages (or we're not ignoring readded alerts)
3031-
# 2. We haven't already recorded this alert
3032-
# 3. It's an error or warning
3033-
if (not ignore_readded or alert not in removed_alerts) and finding_key not in consolidated_alerts:
3034-
if alert.error or alert.warn:
3035-
alerts.append(alert)
3036-
consolidated_alerts.add(finding_key)
3037-
3038-
return alerts
3023+
findings = Core._consolidate_reportable_alerts(
3024+
alert
3025+
for key, alerts in added_package_alerts.items()
3026+
for alert in alerts
3027+
if not ignore_readded or alert not in removed_package_alerts.get(key, ())
3028+
)
3029+
return list(findings.values())
30393030

30403031
@staticmethod
30413032
def get_unchanged_alerts(
@@ -3053,19 +3044,22 @@ def get_unchanged_alerts(
30533044
Returns:
30543045
List of all error/warning alerts from unchanged packages
30553046
"""
3056-
alerts: List[Issue] = []
3057-
consolidated_alerts = set()
3058-
3059-
for alert_key in unchanged_package_alerts:
3060-
for alert in unchanged_package_alerts[alert_key]:
3061-
finding_key = alert.consolidation_key()
3062-
3063-
# Only include error or warning alerts
3064-
if (alert.error or alert.warn) and finding_key not in consolidated_alerts:
3065-
alerts.append(alert)
3066-
consolidated_alerts.add(finding_key)
3047+
findings = Core._consolidate_reportable_alerts(
3048+
alert for alerts in unchanged_package_alerts.values() for alert in alerts
3049+
)
3050+
return list(findings.values())
30673051

3068-
return alerts
3052+
@staticmethod
3053+
def _consolidate_reportable_alerts(alerts: Iterable[Issue]) -> Dict[Tuple[str, str, str, str], Issue]:
3054+
"""Keep the strongest reportable action for each finding across manifests and scan results."""
3055+
findings: Dict[Tuple[str, str, str, str], Issue] = {}
3056+
for alert in alerts:
3057+
if alert.error or alert.warn:
3058+
key = alert.consolidation_key()
3059+
previous = findings.get(key)
3060+
if previous is None or (alert.error and not previous.error):
3061+
findings[key] = alert
3062+
return findings
30693063

30703064
@staticmethod
30713065
def get_removed_alerts(

‎socketsecurity/core/messages.py‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,7 @@ def get_manifest_type_url(manifest_file: str, pkg_name: str, pkg_version: str) -
232232
@staticmethod
233233
def create_security_comment_sarif(diff) -> dict:
234234
"""
235-
Create SARIF-compliant output from the diff report, including dynamic URL generation
236-
based on manifest type and improved <br/> formatting for GitHub SARIF display.
237-
238-
This function now:
239-
- Processes every alert in diff.new_alerts.
240-
- For alerts with multiple manifest files, generates an individual SARIF result for each file.
241-
- Appends the manifest file name to the rule ID and name to make each result unique.
242-
- Does NOT fall back to 'requirements.txt' if no manifest file is provided.
243-
- Adds detailed log to validate our assumptions.
244-
235+
Render each alert at its known manifest locations and identify advisory rules by advisory ID.
245236
"""
246237
if len(diff.new_alerts) == 0:
247238
for alert in diff.new_alerts:
@@ -270,6 +261,9 @@ def create_security_comment_sarif(diff) -> dict:
270261
pkg_name = alert.pkg_name
271262
pkg_version = alert.pkg_version
272263
base_rule_id = f"{pkg_name}=={pkg_version}"
264+
advisory_id = alert.advisory_id()
265+
if advisory_id:
266+
base_rule_id = f"{base_rule_id} {advisory_id}"
273267
severity = alert.severity
274268

275269
log.debug("Alert %s - introduced_by: %s, manifests: %s", base_rule_id, alert.introduced_by, getattr(alert, 'manifests', None))
@@ -283,6 +277,11 @@ def create_security_comment_sarif(diff) -> dict:
283277
manifest_files.extend([m.strip() for m in entry.split(";") if m.strip()])
284278
elif hasattr(alert, 'manifests') and alert.manifests:
285279
manifest_files = [mf.strip() for mf in alert.manifests.split(";") if mf.strip()]
280+
if not manifest_files:
281+
manifest_files = [
282+
entry["file"] for entry in getattr(alert, "manifest_files", [])
283+
if isinstance(entry, dict) and entry.get("file")
284+
]
286285

287286
log.debug("Alert %s - extracted manifest_files: %s", base_rule_id, manifest_files)
288287
if not manifest_files:
@@ -317,6 +316,8 @@ def create_security_comment_sarif(diff) -> dict:
317316
description = alert.description
318317
short_desc = (f"{props.get('note', '')}<br/><br/>Suggested Action:<br/>{suggestion}"
319318
f"<br/><a href=\"{socket_url}\">{socket_url}</a>")
319+
if advisory_id:
320+
short_desc = f"{advisory_id}<br/>{short_desc}"
320321
full_desc = "{} - {}".format(alert_title, description.replace('\r\n', '<br/>'))
321322

322323
if unique_rule_id not in rules_map:

0 commit comments

Comments
 (0)