Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 2.13.3

### Upgrade notes

- Under `--strict-blocking`, runs without `--scm` now compare against the head
scan even when no manifest changed, and fail on existing blocking alerts. That
covers default-branch pushes in Bitbucket, Azure Pipelines, Jenkins and other
pipelines that don't set `--scm`, and target paths that aren't git
repositories. Those runs used to pass with a full scan. `--ignore-commit-files`
already behaved this way.

### Fixed

- `--strict-blocking` fails on existing blocking alerts when the change touches no
manifest. Without `--ignore-commit-files`, such a change used to get a full scan
with blocking turned off, so code-only pull requests passed. The comparison now
runs over every manifest in the target path, and PR/MR comments list the existing
alerts.

## 2.13.2

### Added
Expand Down
4 changes: 3 additions & 1 deletion docs/ci-cd.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ A full scan has no baseline, so it cannot tell a newly introduced alert from one
that was already there. Rather than block on a number that would mean something
different depending on which output format was enabled, those runs behave as if
`--disable-blocking` was supplied and report through the Dashboard instead. This
matches how the CLI already treats a run with no supported manifest files.
matches how the CLI treats a change with no supported manifest files, except under
`--strict-blocking`: there a pull request or merge request that touches no manifest
still gets the comparison, so existing blocking alerts fail it.

The event type is authoritative once `--scm` is set: `--enable-diff` and
`--ignore-commit-files` do not turn a branch pipeline into a comparison. To diff
Expand Down
8 changes: 5 additions & 3 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ The CLI runs a pinned version of the Coana CLI, the analysis engine; it does **n
| `--disable-blocking` | False | False | Non-blocking CI mode: the CLI exits **0** even when blocking alerts are present (including with `--strict-blocking`). Also exits 0 on infrastructure errors (missing API or SCM token, Socket API failures, uncaught runtime errors) and interrupts, so the job is treated as successful while findings and errors are still logged. Invalid flags still exit **2**. Takes precedence over `--strict-blocking`. |
| `--disable-ignore` | False | False | Disable support for `@SocketSecurity ignore` commands in PR comments. When set, alerts cannot be suppressed via comments and ignore instructions are hidden from comment output. See [Who can ignore an alert](#who-can-ignore-an-alert). |
| `--ignore-authorization` | False | enforce | Who may suppress alerts with `@SocketSecurity ignore`. `enforce` requires write access and honors the command with a warning when the provider cannot report it; `strict` rejects it in that case; `off` honors any commenter. See [Who can ignore an alert](#who-can-ignore-an-alert). |
| `--strict-blocking` | False | False | Fail on ANY security policy violations (blocking severity), not just new ones. Only works in diff mode. See [Strict Blocking Mode](#strict-blocking-mode) for details. |
| `--strict-blocking` | False | False | Fail on ANY security policy violations (blocking severity), not just new ones. Runs a comparison even when no manifest changed. See [Strict Blocking Mode](#strict-blocking-mode) for details. |
| `--enable-diff` | False | False | Enable diff mode even when using `--integration api` (forces diff mode without SCM integration) |
| `--scm` | False | api | Source control management type |
| `--timeout` | False | 1200 | Positive integer timeout in seconds for each API request. This is not a total CLI runtime limit and does not limit local discovery, Git, or reachability analysis. |
Expand Down Expand Up @@ -668,6 +668,8 @@ Security issues detected by Socket Security:
### Important Notes

- **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).
- **No manifest changed**: When the changed files include no supported manifest, the CLI still runs the comparison over every manifest in the target path, as with `--ignore-commit-files`, instead of falling back to a full scan. Code-only pull requests fail on existing blocking alerts and list them in the PR/MR comment. Without `--scm`, this also applies to default-branch pushes and to target paths that aren't git repositories, so those runs fail on existing blocking alerts where they used to pass. This adds the comparison and existing-alert requests to those runs.
- **With `--reach`**: The comparison uses the last default-branch scan made with `--reach` as its baseline. If the default branch is scanned without `--reach`, the baseline is empty and every alert is reported as new. The exit code is the same under `--strict-blocking`, but the PR/MR comment says the change introduced them. Scan the default branch with `--reach` too.
- **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.
- **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.
Expand Down Expand Up @@ -771,14 +773,14 @@ The CLI determines which files to scan based on the following logic:

3. **`--ignore-commit-files` Flag**: When set, the changed-file check is skipped entirely. The CLI runs the comparison regardless of what changed, and scans every manifest file in the target directory.

4. **Automatic Fallback**: If no manifest files are found in git commit changes and no `--files` are specified, the CLI automatically switches to "API mode" and performs a full repository scan.
4. **Automatic Fallback**: If no manifest files are found in git commit changes and no `--files` are specified, the CLI automatically switches to "API mode" and performs a full repository scan. With `--strict-blocking`, it runs the comparison instead, as `--ignore-commit-files` does, so existing blocking alerts are still checked.

> **Important**: The CLI doesn't scan only the specified files - it uses them to determine whether a scan should be performed and what type of scan to run. When triggered, it searches the entire `--target-path` for all supported manifest files.

### Scanning Modes

- **Differential Mode**: When manifest files are detected in changes, performs a diff scan with PR/MR comment integration
- **API Mode**: When no manifest files are in changes, creates a full scan report without PR comments but still scans the entire repository
- **API Mode**: When no manifest files are in changes, creates a full scan report without PR comments but still scans the entire repository. With `--strict-blocking`, the CLI runs a comparison instead (see Automatic Fallback above); SCM branch pipelines still create a full scan
- **Force Mode**: With `--ignore-commit-files`, always runs a comparison regardless of which files changed, over every manifest in the target path
- **Forced Diff Mode**: With `--enable-diff`, forces differential mode even when using `--integration api` (without SCM integration)

Expand Down
2 changes: 1 addition & 1 deletion 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 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__}'
3 changes: 2 additions & 1 deletion socketsecurity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,8 @@ def create_argument_parser() -> argparse.ArgumentParser:
"--strict-blocking",
dest="strict_blocking",
action="store_true",
help="Fail on ANY security policy violations (blocking severity), not just new ones. Only works in diff mode."
help="Fail on ANY security policy violations (blocking severity), not just new ones. Runs a comparison even "
"when no manifest changed. SCM branch (non-PR/MR) pipelines create a full scan and do not block."
)
advanced_group.add_argument(
"--enable-diff",
Expand Down
24 changes: 21 additions & 3 deletions socketsecurity/socketcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,16 @@ def main_code(config: Optional[CliConfig] = None):
log.debug(f"Error finding files in scan paths: {e}")
discovered_scan_files = None
has_supported_files = False


# --strict-blocking fails on existing blocking alerts, and only a comparison
# against the baseline reports them. A change that touches no manifest would
# otherwise get a full scan with blocking turned off and pass every time, so
# run the comparison over the whole target path, as --ignore-commit-files does.
strict_forced_comparison = False
if config.strict_blocking and not has_supported_files and not force_diff_mode:
force_diff_mode = True
strict_forced_comparison = True

# Case 3: If no supported files or files are empty, force API mode (no PR comments)
# BUT: Don't force API mode if we're in force_diff_mode
log.debug(f"files_to_check={files_to_check}, has_supported_files={has_supported_files}, force_diff_mode={force_diff_mode}, config.enable_diff={config.enable_diff}")
Expand Down Expand Up @@ -762,6 +771,14 @@ def _is_unprocessed(c):
return True

scm_event_type = scm.check_event_type() if scm is not None else None
# Logged only once the run is known to compare: skipped SCM events exit inside
# check_event_type, comment events don't scan, and SCM branch pipelines still
# create a full scan.
if strict_forced_comparison and scm_event_type in (None, "diff"):
log.info(
"No supported manifest in the changed files; --strict-blocking compares "
"every manifest in the target path against the baseline to check existing alerts"
)
# Every branch below except the SCM full-scan one produces a comparison, or
# is already covered by force_api_mode. See the blocking guard after the
# scan for why this is tracked.
Expand Down Expand Up @@ -979,8 +996,9 @@ def _is_unprocessed(c):
output_handler.handle_output(diff)

elif (config.enable_diff or force_diff_mode) and force_api_mode:
# User requested diff mode but no manifest files were detected - this should not happen with new logic
# but keeping as a safety net
# --enable-diff without --ignore-commit-files, and the change touched no
# manifest. --strict-blocking never reaches this branch: it sets
# force_diff_mode above so existing alerts are still evaluated.
log.warning("--enable-diff was specified but no supported manifest files were detected in the changed files. Falling back to full scan mode.")
_log_scan_mode_fallback(
"diff",
Expand Down
Loading