Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 2.13.3

### Changed

- Bumped the pinned Socket Python SDK (`socketdev`) from `3.6.3` to `3.6.4`.
The release keeps each advisory as its own alert instead of one per alert
type and severity, which changes what the CLI reports; see Fixed below.

### Fixed

- `--strict-blocking` lists and counts every advisory on an unchanged package.
Existing alerts are read through the SDK, which kept one alert per alert type
and severity, so a package with six Critical CVEs showed one, and the
"EXISTING blocking issues" count was too low. Requires `socketdev` 3.6.4.
- A Block-action CVE on an unchanged package now fails the run even when
another CVE of the same severity on that package is triaged to monitor or
ignore. Before, the triaged CVE could stand in for both and the run passed.
- `--strict-blocking` fails on Block alerts that persist across a dependency
version change and lists them in the Existing alerts table.
- In full-scan mode, the `--enable-json`, `--enable-sarif` and
`--enable-gitlab-security` reports now list every advisory on a package.
Before, they listed one per alert type and severity, so expect more alerts,
and more with a Block action, in these reports. In diff mode the same
applies to existing alerts in the `--enable-gitlab-security` and
`--legal-format fossa` output.
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

## 2.13.2

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ Security issues detected by Socket Security:

- **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).
- **Error-Level Only**: Only fails on `error=True` alerts (blocking severity), not warnings.
- **Existing alerts come from the full scan**: The scan comparison doesn't carry alerts on unchanged packages, so the CLI reads them from the new full scan, at the cost of one more API request per run. If that request fails or omits an unchanged package, the run fails with the infrastructure-error code rather than passing without them.
- **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.
- **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.
- **Priority**: `--disable-blocking` takes precedence - if both flags are set, the build will always pass.
- **First Scan**: On the very first scan of a repository, there are no "existing" violations, so behavior is identical to standard mode.
Expand Down
2 changes: 1 addition & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Flags add:
| `--reach` | `POST orgs/{org}/upload-manifest-files`, `POST tier1-reachability-scan/finalize` | `full-scans:create` |
| `--generate-license` | `POST orgs/{org}/purl` | `packages:list` |
| `--enable-json`, `--enable-sarif`, `--enable-gitlab-security` or `--generate-license` on a full scan | `GET orgs/{org}/full-scans/{id}` (scan contents) | `full-scans:list` |
| `--strict-blocking`, `--enable-gitlab-security` or `--legal-format fossa` on a run that compares scans | `GET orgs/{org}/full-scans/{id}` (alerts on unchanged packages) | `full-scans:list` |
| `--strict-blocking`, `--enable-gitlab-security` or `--legal-format fossa` on a run that compares scans | `GET orgs/{org}/full-scans/{id}` (existing alerts) | `full-scans:list` |

`--reach` also runs the analysis engine with the same token. The engine reports to the
`tier1-reachability-scan/*` endpoints, which check `full-scans:create`.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"

[project]
name = "socketsecurity"
version = "2.13.2"
version = "2.13.3"
requires-python = ">= 3.11"
license = {"file" = "LICENSE"}
dependencies = [
Expand All @@ -16,7 +16,7 @@ dependencies = [
"gitpython==3.2.1",
"packaging==26.3",
"python-dotenv==1.2.4",
"socketdev==3.6.3",
"socketdev==3.6.4",
"beautifulsoup4==4.15.0",
"markdown==3.11.3",
"brotli==1.2.1; platform_python_implementation == 'CPython'",
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__author__ = 'socket.dev'
__version__ = '2.13.2'
__version__ = '2.13.3'
USER_AGENT_NAME = 'socket-python-cli'
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'
85 changes: 63 additions & 22 deletions socketsecurity/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,7 @@ def create_new_diff(
# Resolve the baseline scan: --base-scan-id / --base-commit-sha override
# the repository's head scan (None only when the repo has no head scan yet).
head_full_scan_id = self.resolve_base_full_scan_id(params)
has_baseline = head_full_scan_id is not None

# If no head scan exists, create an empty baseline scan
if head_full_scan_id is None:
Expand Down Expand Up @@ -2499,10 +2500,25 @@ def create_new_diff(
)

unchanged_packages = Core.get_unchanged_packages(packages, added_packages, removed_packages)
if unchanged_packages and self._requires_unchanged_alerts():
self.add_existing_alerts_from_full_scan(unchanged_packages, new_full_scan.id)
existing_changed_packages = {}
if has_baseline and getattr(self.cli_config, "strict_blocking", False):
# Keep the comparison's alerts intact for new-finding classification.
existing_changed_packages = {
package_id: copy.copy(package) for package_id, package in added_packages.items()
}
if self._requires_unchanged_alerts():
self.add_existing_alerts_from_full_scan(
unchanged_packages,
new_full_scan.id,
changed_packages=existing_changed_packages,
)

diff = self.create_diff_report(added_packages, removed_packages, unchanged_packages)
diff = self.create_diff_report(
added_packages,
removed_packages,
unchanged_packages,
existing_changed_packages=existing_changed_packages,
)
diff.packages = packages

base_socket = "https://socket.dev/dashboard/org"
Expand Down Expand Up @@ -2542,25 +2558,32 @@ def _requires_unchanged_alerts(self) -> bool:
)

def add_existing_alerts_from_full_scan(
self, unchanged_packages: Dict[str, Package], full_scan_id: str
self,
unchanged_packages: Dict[str, Package],
full_scan_id: str,
*,
changed_packages: Optional[Dict[str, Package]] = None,
) -> None:
"""Fill in the alerts on unchanged packages from the new full scan.
"""Load alerts for unchanged and optionally changed packages from the new full scan.

The cached diff-scans endpoint returns unchanged artifacts with an empty
``alerts`` list, because it keeps only the alerts it counts as new. The full
scan of the same commit carries every package's alerts with their policy
actions, so they are read from there. Packages are matched by artifact ID,
then by ecosystem, namespace, name and version.
The cached comparison keeps only new alerts, so it omits alerts that
persist across a version change as well as alerts on unchanged packages.
The full scan carries current alerts with their policy actions. Match
packages by artifact ID, then by ecosystem, namespace, name and version.

Skipped when any unchanged package already has alerts: the comparison then
came from an endpoint that includes them, such as the streaming fallback.
A failed fetch or an unmatched package raises, because reporting existing
alerts as absent would let ``--strict-blocking`` pass a run it should fail.
The streaming fallback can supply unchanged alerts itself. Changed
packages, when requested, always need the full scan. A failed fetch or
unmatched package raises so strict blocking can evaluate all existing alerts.
"""
packages_to_load = dict(changed_packages or {})
if any(package.alerts for package in unchanged_packages.values()):
log.debug("The comparison already includes alerts on unchanged packages")
else:
packages_to_load.update(unchanged_packages)
if not packages_to_load:
return

package_kind = "current" if changed_packages else "unchanged"
start = time.time()
by_id: Dict[str, List[dict]] = {}
by_identity: Dict[Tuple[str, str, str, str], List[dict]] = {}
Expand All @@ -2574,7 +2597,7 @@ def add_existing_alerts_from_full_scan(

matched = 0
alert_count = 0
for package in unchanged_packages.values():
for package in packages_to_load.values():
alerts = by_id.get(package.id)
if alerts is None:
alerts = by_identity.get(Core._package_identity(
Expand All @@ -2587,12 +2610,12 @@ def add_existing_alerts_from_full_scan(
alert_count += len(alerts)

log.info(
f"Loaded {alert_count} alerts for {matched} of {len(unchanged_packages)} "
f"unchanged packages from full scan {full_scan_id} in {time.time() - start:.2f}s"
f"Loaded {alert_count} alerts for {matched} of {len(packages_to_load)} "
f"{package_kind} packages from full scan {full_scan_id} in {time.time() - start:.2f}s"
)
if matched < len(unchanged_packages):
if matched < len(packages_to_load):
raise InfrastructureError(
f"{len(unchanged_packages) - matched} of {len(unchanged_packages)} unchanged packages "
f"{len(packages_to_load) - matched} of {len(packages_to_load)} {package_kind} packages "
f"were not found in full scan {full_scan_id}; unable to evaluate all existing alerts."
)

Expand Down Expand Up @@ -2628,7 +2651,9 @@ def create_diff_report(
added_packages: Dict[str, Package],
removed_packages: Dict[str, Package],
unchanged_packages: Optional[Dict[str, Package]] = None,
direct_only: bool = True
direct_only: bool = True,
*,
existing_changed_packages: Optional[Dict[str, Package]] = None,
) -> Diff:
"""
Creates a diff report comparing two sets of packages.
Expand All @@ -2637,14 +2662,15 @@ def create_diff_report(
1. Records new/removed packages (direct only by default)
2. Collects alerts from both sets of packages
3. Determines new capabilities introduced
4. Optionally collects alerts from unchanged packages for --strict-blocking
4. Optionally collects existing alerts for --strict-blocking

Args:
added_packages: Dict of packages added in new scan
removed_packages: Dict of packages removed in new scan
unchanged_packages: Dict of packages that didn't change (for --strict-blocking)
direct_only: If True, only direct dependencies are included in new/removed lists
(but alerts are still processed for all packages)
existing_changed_packages: Added/updated packages with alerts from the new full scan

Returns:
Diff object containing the comparison results
Expand Down Expand Up @@ -2712,10 +2738,25 @@ def create_diff_report(
alerts_in_removed_packages
)

# Get unchanged alerts (for --strict-blocking mode)
# Existing findings can also persist on a changed version.
diff.unchanged_alerts = Core.get_unchanged_alerts(
alerts_in_unchanged_packages
)
if existing_changed_packages:
current_changed_alerts: Dict[str, List[Issue]] = {}
for package in existing_changed_packages.values():
self.add_package_alerts_to_collection(
package=package,
alerts_collection=current_changed_alerts,
packages=added_packages,
)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
reported_findings = {
alert.consolidation_key() for alert in (*diff.new_alerts, *diff.unchanged_alerts)
}
diff.unchanged_alerts.extend(
alert for alert in Core.get_unchanged_alerts(current_changed_alerts)
if alert.consolidation_key() not in reported_findings
)

# Get removed alerts (for completeness)
diff.removed_alerts = Core.get_removed_alerts(
Expand Down
6 changes: 3 additions & 3 deletions socketsecurity/core/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ def security_comment_template(diff: Diff, config=None) -> str:

@staticmethod
def existing_comment_alerts(diff: Diff, config) -> list:
"""Alerts on unchanged packages to show in the PR comment.
"""Existing alerts to show in the PR comment.

Only under --strict-blocking, where they fail the run: without it they
don't affect the result, and listing them would bury the new ones.
Expand All @@ -1200,7 +1200,7 @@ def existing_comment_alerts(diff: Diff, config) -> list:
def existing_alerts_section(
alerts: list, diff: Diff, config, show_ignore: bool, view_report_url: str, size_so_far: int
) -> str:
"""Table of alerts on packages this change didn't touch, blocking ones first.
"""Table of existing alerts, with blocking alerts first.

License policy violations are grouped per package, as in the table of new
alerts.
Expand All @@ -1221,7 +1221,7 @@ def existing_alerts_section(
blocking = sum(1 for alert in alerts if alert.error)
section = f"""
<!-- start-socket-existing-alerts -->
**Existing alerts ({len(alerts)}).** These are on dependencies this change didn't add or update. `--strict-blocking` fails the run on the {blocking} with a **Block** action.
**Existing alerts ({len(alerts)}).** The baseline also contains these findings. `--strict-blocking` fails the run on the {blocking} with a **Block** action.

<table>
<thead>
Expand Down
Loading
Loading