Skip to content

Commit 216761e

Browse files
committed
Merge main into fix/issue-comment-keyerror
# Conflicts: # CHANGELOG.md
2 parents bbe5397 + a38c880 commit 216761e

18 files changed

Lines changed: 1094 additions & 113 deletions

‎CHANGELOG.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22

33
## 2.14.0
44

5+
### Upgrade notes
6+
7+
- Without a GitHub or GitLab SCM adapter, `--strict-blocking` now compares scans
8+
even when no manifest changed. This includes default-branch pushes and scans of
9+
non-git paths. These runs can now fail on Block findings or comparison errors
10+
and need the [API token scopes for comparison runs](docs/troubleshooting.md#api-token-permissions).
11+
- If you use the GitHub Actions example, replace the combined workflow with the
12+
[PR workflow](workflows/github-actions.yml) and require its `socket-security`
13+
check. Install the [push workflow](workflows/github-actions-push.yml) in the
14+
same change: the PR workflow doesn't run on pushes, so without it the
15+
default-branch baseline stops updating and PR comparisons run against an old
16+
scan. Install the
17+
[ignore-command workflow](workflows/github-actions-comments.yml) if you use PR
18+
ignore commands.
19+
520
### Changed
621

722
- Updated the Socket Python SDK (`socketdev`) to 3.6.4. This can increase
823
advisory counts in full-scan JSON, SARIF, and GitLab security reports, and
924
in the existing findings shown in GitLab security and FOSSA diff reports.
25+
- Skipped GitHub events and GitLab pipeline sources now warn that no scan ran.
1026

1127
### Fixed
1228

@@ -15,9 +31,22 @@
1531
table. When a finding has both Warn and Block actions, Block takes precedence.
1632
- SARIF reports use advisory IDs to distinguish findings on the same package
1733
and manifest.
34+
- Comparisons with missing or invalid package lists fail with exit `3` by
35+
default. `--exit-code-on-api-error` can remap the code, and
36+
`--disable-blocking` takes precedence.
37+
- `--strict-blocking` checks existing Block findings on code-only changes.
38+
GitHub and GitLab pull request comments show those findings under Existing
39+
alerts.
40+
- With `--scm github`, reopened pull requests and pull requests marked ready for
41+
review run the PR scan.
1842
- GitHub pull request comment runs exit `0` and leave the Socket security
1943
comment unchanged when there are no Socket ignore commands to process.
2044

45+
### Documentation
46+
47+
- The [CI guide](docs/ci-cd.md#required-github-checks) describes GitHub required
48+
checks and the GitHub Actions workflow migration.
49+
2150
## 2.13.2
2251

2352
### Added

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ JSON:
205205

206206
Prebuilt workflow examples:
207207

208-
- [GitHub Actions](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/github-actions.yml)
208+
- GitHub Actions for [pull requests](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/github-actions.yml), [pushes](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/github-actions-push.yml), and [ignore commands](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/github-actions-comments.yml)
209209
- [Buildkite](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/buildkite.yml)
210210
- [GitLab CI](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/gitlab-ci.yml)
211211
- [Bitbucket Pipelines](https://github.com/SocketDev/socket-python-cli/blob/main/workflows/bitbucket-pipelines.yml)

‎docs/ci-cd.md‎

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ they also hide findings and usage errors. Even with exit `0`, a setup/API failur
8484
does not mean a clean scan; check the logs for a completed report.
8585

8686
Findings block only when a [diff comparison runs](#scan-type-by-pipeline).
87-
SCM event filters can also skip unsupported events with exit `0`; confirm a report
88-
was created when validating a new workflow.
89-
`--strict-blocking` also checks existing blocking alerts; an incomplete comparison
90-
or incomplete existing-alert data is an infrastructure failure. See the
87+
SCM event filters can also skip unsupported events with exit `0` and a warning
88+
(see [Skipped events](#skipped-events)); confirm a report was created when
89+
validating a new workflow.
90+
The CLI treats comparisons marked incomplete or returned with missing or
91+
invalid package lists as infrastructure failures. With `--strict-blocking`,
92+
incomplete existing-alert data is also an infrastructure failure. See the
9193
[2.13.0 migration table](../README.md#upgrading-to-2130) when updating existing CI rules.
9294

9395
## Config file usage in CI
@@ -504,27 +506,75 @@ pipelines:
504506

505507
## Scan type by pipeline
506508

507-
With `--scm github` or `--scm gitlab`, the detected event decides the scan type:
509+
With `--scm github` or `--scm gitlab`, the adapter uses the event and PR/MR
510+
context to select the scan type. A push given a PR/MR number can use the
511+
comparison path.
508512

509513
| Event | Scan | Blocks the build |
510514
|:------|:-----|:-----------------|
511-
| Pull request / merge request | Diff scan against the repository's baseline | Yes, on new blocking alerts; also existing blockers with `--strict-blocking` |
512-
| Any other pipeline, including default-branch pushes | Full scan | No |
515+
| Supported pull request / merge request events | Diff scan against the repository's baseline when a comparison runs | Yes, on new blocking alerts and on existing blockers with `--strict-blocking` |
516+
| Push without a PR/MR number, including default-branch pushes | Full scan | No blocking on findings |
513517

514-
A full scan has no baseline, so it cannot tell a newly introduced alert from one
515-
that was already there. Rather than block on a number that would mean something
516-
different depending on which output format was enabled, those runs behave as if
517-
`--disable-blocking` was supplied and report through the Dashboard instead. This
518-
matches how the CLI already treats a run with no supported manifest files.
518+
With changed-file detection, a PR/MR with no supported manifest change runs a
519+
full scan by default. Use `--strict-blocking` or `--ignore-commit-files` to
520+
compare it. Full scans report through the Dashboard. A branch pipeline without
521+
PR/MR context stays in full-scan mode even with `--enable-diff`,
522+
`--ignore-commit-files`, or `--strict-blocking`.
519523

520-
The event type is authoritative once `--scm` is set: `--enable-diff` and
521-
`--ignore-commit-files` do not turn a branch pipeline into a comparison. To diff
522-
a branch build, drop `--scm` and use `--enable-diff` with `--integration`, which
523-
runs the comparison without the PR comment adapter.
524+
Without a GitHub or GitLab SCM adapter, `--strict-blocking` runs a comparison
525+
even when no supported manifest changed. This includes default-branch pushes and
526+
scans of non-git paths. A Block finding exits `1`. A comparison infrastructure
527+
error exits `3` by default. Check the [API token scopes for comparison runs](troubleshooting.md#api-token-permissions)
528+
when upgrading a pipeline that previously ran only full scans.
524529

525530
`--generate-license` and `--legal-format fossa` work on both paths; a full scan
526531
fetches the package list for them.
527532

533+
### Skipped events
534+
535+
With `--scm github`, `pull_request` runs scan on the `opened`, `synchronize`,
536+
`reopened` and `ready_for_review` actions. Other actions (`closed`, `labeled`,
537+
`edited`, and others) and unsupported events log a warning and exit `0` without
538+
scanning. `issue_comment` handles ignore commands. With `--scm gitlab`, the
539+
recognized scan sources are `web`, `merge_request_event`, `push`, `api`, and
540+
`pipeline`. Other sources, apart from the comment flow, also warn and exit `0`
541+
without scanning.
542+
543+
- A GitHub merge queue evaluates required checks on the `merge_group` commit.
544+
The CLI skips that event. Use a check that scans the merge group for
545+
[merge queue enforcement](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks#status-checks-with-github-actions-and-a-merge-queue).
546+
- GitHub runs `pull_request_target` in the base repository context, and the CLI
547+
skips it. Under GitHub's default fork settings, `pull_request` runs cannot
548+
access the Socket API secret. The CLI exits with its infrastructure error code
549+
if the token is missing. See GitHub's guidance for
550+
[securing workflows that handle fork PRs](https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target).
551+
552+
### Required GitHub checks
553+
554+
Use the [PR workflow](../workflows/github-actions.yml) for the required
555+
`socket-security` check. If your workflow skips drafts, include
556+
`ready_for_review` in its `pull_request.types` so marking a PR ready starts the scan.
557+
Use the [push workflow](../workflows/github-actions-push.yml) to update the
558+
default-branch baseline and scan branch pushes. Use the
559+
[ignore-command workflow](../workflows/github-actions-comments.yml) if your
560+
repository handles ignore commands in PR comments.
561+
562+
GitHub normally checks the PR's test merge commit when it has a status and
563+
otherwise checks the head commit. The default PR checkout uses the test merge
564+
commit, while a push run uses the pushed commit. Keep the required job name
565+
exclusive to the PR workflow in either setup. A job skipped by a job-level
566+
`if` in a shared workflow can still report a successful check. See GitHub's
567+
[required status check rules](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks).
568+
569+
When replacing the combined example, copy the PR workflow to the existing
570+
workflow path and remove any other jobs named `socket-security`. Confirm the
571+
PR job reports the check named in branch protection. Add the push workflow in
572+
the same change: the PR workflow doesn't run on pushes, so without it the
573+
default-branch baseline stops updating and later PR comparisons run against an
574+
old scan. If you use
575+
`--strict-blocking` as a merge gate, verify a reopened PR with an existing
576+
Block alert fails and a completed clean comparison passes.
577+
528578
## Pull request and Dashboard association
529579

530580
The CLI sends the resolved pull request number with each full scan and attaches
@@ -647,7 +697,7 @@ listed thinly or not at all.
647697

648698
Prebuilt examples in this repo:
649699

650-
- [`../workflows/github-actions.yml`](../workflows/github-actions.yml)
700+
- GitHub Actions for [pull requests](../workflows/github-actions.yml), [pushes](../workflows/github-actions-push.yml), and [ignore commands](../workflows/github-actions-comments.yml)
651701
- [`../workflows/buildkite.yml`](../workflows/buildkite.yml)
652702
- [`../workflows/gitlab-ci.yml`](../workflows/gitlab-ci.yml)
653703
- [`../workflows/bitbucket-pipelines.yml`](../workflows/bitbucket-pipelines.yml)

‎docs/cli-reference.md‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,12 @@ The CLI runs a pinned version of the Coana CLI, the analysis engine; it does **n
461461
#### Advanced Configuration
462462
| Parameter | Required | Default | Description |
463463
|:-------------------------|:---------|:--------|:----------------------------------------------------------------------|
464-
| `--ignore-commit-files` | False | False | Compare regardless of which files changed, scanning every manifest |
464+
| `--ignore-commit-files` | False | False | Skip the changed-file check for comparisons eligible under the SCM event rules. |
465465
| `--exit-code-on-api-error` | False | 3 | Remap infrastructure failures, including missing tokens, setup failures, incomplete scan data and unexpected runtime errors. Findings (`1`), usage errors (`2`) and Ctrl+C (`130`) are unaffected. `--disable-blocking` takes precedence. |
466466
| `--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`. |
467467
| `--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). |
468468
| `--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). |
469-
| `--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. |
469+
| `--strict-blocking` | False | False | Fail on new and existing Block findings, including on changes that touch no manifest. See [Strict Blocking Mode](#strict-blocking-mode). |
470470
| `--enable-diff` | False | False | Enable diff mode even when using `--integration api` (forces diff mode without SCM integration) |
471471
| `--scm` | False | api | Source control management type |
472472
| `--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. |
@@ -660,7 +660,8 @@ Security issues detected by Socket Security:
660660
661661
### Important Notes
662662
663-
- **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).
663+
- **Scan scope**. Strict mode compares the configured scan scope even when no supported manifest changed. Scan options such as `--sub-path` and `--reach-use-only-pregenerated-sboms` still control what the CLI submits. With `--scm`, GitHub and GitLab branch pipelines without PR/MR context perform non-blocking full scans. See [Scan type by pipeline](ci-cd.md#scan-type-by-pipeline).
664+
- **With `--reach`**. With no explicit baseline, the CLI looks for a default-branch head scan with reachability enabled. If none exists, the CLI compares against an empty baseline and classifies all findings as new. Scan the default branch with `--reach` too.
664665
- **Policy actions**. Warn findings are reported. If the same finding has both Warn and Block actions, Block takes precedence.
665666
- **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.
666667
- **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.
@@ -762,25 +763,26 @@ The CLI determines which files to scan based on the following logic:
762763
763764
2. **`--files` Parameter Override**: When specified, this parameter takes precedence over git commit detection. It accepts a JSON array of file paths to check for manifest files.
764765
765-
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.
766+
3. **`--ignore-commit-files` Flag**: Skip the changed-file check for comparisons, subject to the SCM event type.
766767
767-
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.
768+
4. **Automatic Fallback**: When the changed-file check finds no supported manifest, the CLI normally runs a full scan. Strict mode compares scans so it can evaluate existing findings. See [Scan type by pipeline](ci-cd.md#scan-type-by-pipeline) for SCM event rules.
768769
769-
> **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.
770+
The changed-file list and `--files` select the scan type. Manifest discovery
771+
uses the configured scan scope, including any `--sub-path` restrictions.
770772
771773
### Scanning Modes
772774
773775
- **Differential Mode**: When manifest files are detected in changes, performs a diff scan with PR/MR comment integration
774-
- **API Mode**: When no manifest files are in changes, creates a full scan report without PR comments but still scans the entire repository
775-
- **Force Mode**: With `--ignore-commit-files`, always runs a comparison regardless of which files changed, over every manifest in the target path
776+
- **Full Scan**: Reports findings to the Dashboard. SCM branch pipelines without PR/MR context use this mode.
777+
- **Force Mode**: With `--ignore-commit-files`, compares regardless of which files changed on pipelines eligible for comparison.
776778
- **Forced Diff Mode**: With `--enable-diff`, forces differential mode even when using `--integration api` (without SCM integration)
777779
778780
### Examples
779781
780782
- **Commit with manifest file**: If your commit includes changes to `package.json`, a differential scan will be triggered automatically with PR comment integration.
781-
- **Commit without manifest files**: If your commit only changes non-manifest files (like `.github/workflows/socket.yaml`), the CLI automatically switches to API mode and performs a full repository scan.
783+
- **Code-only commit**: The CLI runs a full scan by default. `--strict-blocking` selects a comparison on pipelines eligible for comparison.
782784
- **Using `--files`**: If you specify `--files '["package.json"]'`, the CLI will check if this file exists and is a manifest file before determining scan type.
783-
- **Using `--ignore-commit-files`**: This runs the comparison regardless of what's in your commit, over all manifest files in the target path. Use it when the changed-file check would otherwise skip a comparison you need.
785+
- **Using `--ignore-commit-files`**: Compare the configured scan scope regardless of which files changed when the pipeline supports comparison.
784786
- **Using `--enable-diff`**: Forces diff mode without SCM integration - useful when you want differential scanning but are using `--integration api`. For example: `socketcli --integration api --enable-diff --target-path /path/to/repo`
785787
- **Auto-detection**: Most CI/CD scenarios now work with just `socketcli --target-path /path/to/repo --scm github --pr-number $PR_NUM`
786788

‎socketsecurity/config.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,8 @@ def create_argument_parser() -> argparse.ArgumentParser:
10581058
"--strict-blocking",
10591059
dest="strict_blocking",
10601060
action="store_true",
1061-
help="Fail on ANY security policy violations (blocking severity), not just new ones. Only works in diff mode."
1061+
help="Fail on new and existing Block findings. Compare even when no manifest changed. "
1062+
"With --scm, branch pipelines without PR/MR context run non-blocking full scans."
10621063
)
10631064
advanced_group.add_argument(
10641065
"--enable-diff",

0 commit comments

Comments
 (0)