Skip to content

Honor explicit scan refs in default-branch detection - #478

Merged
lelia merged 8 commits into
mainfrom
dl/default-branch-explicit-args
Dec 5, 2026
Merged

lelia merged 8 commits into
mainfrom
dl/default-branch-explicit-args

Conversation

@dc-larsen

@dc-larsen David Larsen (dc-larsen) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Automatic default-branch detection now checks the scan ref against both Git and SCM signals. A CI run can scan a release tag or another branch without marking that ref as the repository's default branch. For automatic promotion, an explicitly requested commit must be available in the checkout, even if its SHA matches the CI environment. The selected commit supplies the commit message and Git committer fallback when available. Explicit metadata and CI actor settings retain precedence.

--no-default-branch prevents default-branch and head promotion. It is mutually exclusive with --default-branch in CLI arguments and config files. The CLI reference includes a release-tag example and explains when a commit already in the default branch's history can still qualify.

This PR starts the shared 2.16.0 release. #479 and #477 add their entries to the same changelog section.

Verification

  • Unit and core suite passes with locked dependencies.
  • CLI regression coverage includes GitHub SCM detection, explicit overrides, and both cases where the triggering CI commit is missing from the checkout: scanning the checked-out commit and explicitly requesting the missing SHA.

Public Changelog

Use --no-default-branch to prevent a scan from changing the repository's default branch or updating a branch head.

Automatic default-branch detection checks explicit scan refs. An explicit commit must be available in the checkout for automatic promotion. When available, it supplies the commit message and Git committer fallback.


Refs: CE-530

@dc-larsen
David Larsen (dc-larsen) requested a review from a team as a code owner December 1, 2026 19:34
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes which scans become the repository default branch and head in Socket, which affects CI baselines and dashboard state, though behavior is opt-in or stricter validation rather than broad rewrites.

Overview
Bumps the CLI to 2.16.0 and changes when a full scan is treated as the repository default branch and branch head.

--no-default-branch is new and mutually exclusive with --default-branch (CLI and config). It blocks automatic promotion even when CI or git would mark the run as default.

Automatic promotion now goes through resolve_default_branch. When --branch or --commit-sha names a ref different from CI, promotion only happens if that branch is the default, the commit exists in the checkout, and it is reachable on the default branch; qualified refs like refs/heads/main normalize to short names. An explicit --commit-sha can drive commit message and git committer fallback; CI actor env vars still win.

Docs and README CI guidance were expanded (including release-tag scanning). Regression tests cover SCM/GitHub dispatch, missing CI SHAs, and flag combinations.

Reviewed by Cursor Bugbot for commit a0a5ea8. Configure here.

@lelia

lelia commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@lelia lelia self-assigned this Dec 2, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@lelia lelia left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

David Larsen (@dc-larsen), please fix the SCM path before this ships. Please prioritize this PR and use it to set the version for 2.16.0.

Honor explicit refs across detection paths

  • With --scm github and DEFAULT_BRANCH=true, the SCM assignment can restore default-branch status after Git rejects a mismatched --branch or --commit-sha. I reproduced a scan of main still requesting both default-branch and head promotion. Apply the explicit-ref check to the combined automatic detection result. Keep the explicit --default-branch override and --no-default-branch opt-out authoritative. Add a CLI-path regression test with SCM detection enabled that checks both outgoing flags, plus coverage for the explicit overrides.
  • The selected commit can supply the commit message and the Git fallback for the committer. CI actor values still take precedence. Please preserve that behavior and describe it accurately in the body and CLI reference.

One minor release

  • Use 2.16.0 for #478, #477, and #479. The new supported --no-default-branch option is backward-compatible CLI functionality, which warrants a minor bump. #479 also changes how existing tracked branch patterns affect Alerts after an upgrade. Set the version here in pyproject.toml, socketsecurity/__init__.py, and uv.lock. Please have the other two PRs share this unpublished version and add their entries under the same changelog heading.
  • Under Added, explain that --no-default-branch prevents the scan from changing the repository’s default branch or updating a branch head. Under Fixed, explain that automatic detection honors explicitly scanned refs, with commit metadata qualified by availability and CI precedence. Mirror that language in the PR’s Public Changelog block.
  • Keep the flag, mutual exclusion, and one release-tag CI example in the CLI reference. Document that an older commit already in the default branch’s history can still qualify for automatic detection, and show when to use --no-default-branch. Keep the README to a short pointer from its existing CI guidance. The current PR title is clear. Keep the before/after table, drop the old patch-release sequencing section, and remove the numbered precedence comment once the decision is centralized.
  • Land this before #479, then run CI and Bugbot on the revised heads. Publish once from the commit whose package version matches the v2.16.0 tag.

@lelia lelia changed the title Check --branch and --commit-sha before marking a scan as the default branch Check --branch and --commit-sha before marking a scan as the default branch Dec 2, 2026
@lelia lelia changed the title Check --branch and --commit-sha before marking a scan as the default branch Check --branch and --commit-sha before marking scan as default branch Dec 2, 2026
…branch

Default-branch detection read only the CI variables. On GitHub Actions it
compared GITHUB_REF to the repository's default branch and checked that the
GITHUB_SHA commit is on it; --branch and --commit-sha were never consulted.
A workflow_run job triggered by develop (the default branch) that checks
out a release tag on main and passes --branch main --commit-sha <tag> was
detected as a default-branch scan. The full scan was created with
make_default_branch=true and set_as_pending_head=true, which moved the
repository's default branch to main, and with develop's commit message.
Without --scm, DEFAULT_BRANCH=false did not help, and nothing could turn
--default-branch detection off.

When --branch or --commit-sha names a different ref than the CI variables,
the scan is no longer treated as the default branch unless that branch is
the default branch and that commit is on it. A commit missing from the
checkout cannot be checked, so it is not treated as the default branch
either. The check can only turn detection off; --default-branch still marks
a scan explicitly. The commit message and the committer fallback now come
from the --commit-sha commit when the checkout has it. Changed-file
detection still reads the CI variables.

Add --no-default-branch, which forces make_default_branch and
set_as_pending_head off whatever git or the CI environment says. It is
mutually exclusive with --default-branch, on the command line and in a
--config file.

Set the version to 2.16.0.
GitHub Actions sets GITHUB_ACTOR, which get_formatted_committer prefers over
the commit's committer, so the --commit-sha committer test failed in CI.
With --scm github, the SCM adapter's is_default_branch was copied into
config.default_branch, so DEFAULT_BRANCH=true restored default-branch status
after git had rejected a mismatched --branch or --commit-sha.

resolve_default_branch() now makes the decision in one place:
--no-default-branch and --default-branch are authoritative, and otherwise the
SCM and git detection results are combined before the explicit-ref check runs.
Git.apply_explicit_ref() only records the named ref and switches the commit
details; explicit_ref_allows_default_branch() does the check.

Adds CLI-path tests with SCM detection enabled covering both outgoing flags,
the explicit overrides, and the commit message and committer fallback. Sets
the release to 2.16.0 and updates the CLI reference, README and CHANGELOG.
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

David Larsen (dc-larsen) added a commit that referenced this pull request Dec 2, 2026
Each security comment row showed one advisory ID, the GHSA when the alert
had one and the CVE otherwise, as plain text. Alerts from the API usually
carry both, so the CVE was dropped from the row, and developers who only
see the PR comment had no link to the advisory.

Rows now list every advisory ID on the alert, GHSA first, each linked to
its public page (github.com/advisories for GHSA, nvd.nist.gov for CVE),
the same two sites the GitLab security report already links. Only IDs in
the canonical GHSA or CVE shape are linked; anything else renders as
escaped text. IDs keep the API's spelling instead of being upper-cased.

Issue.advisory_ids() is new and used only for display. advisory_id() and
consolidation_key() are unchanged, so de-duplication, SARIF rule IDs and
GitLab finding IDs stay the same.

Shares the 2.16.0 version set in #478.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread socketsecurity/core/git_interface.py Resolved
David Larsen (dc-larsen) added a commit that referenced this pull request Dec 2, 2026
Full scans sent set_as_pending_head=is_default_branch, so only a
default-branch scan could become a head. The API also makes a scan the
head of a branch that matches the organization's tracked branch patterns
(Settings > Alerts > Scans), but only when the request sets
set_as_pending_head, and it ignores the flag on branches it doesn't track.
Python CLI scans of a tracked branch were never that branch's head, so
their findings never reached the organization Alerts page.

Branch runs now send set_as_pending_head=true and let the API decide.
make_default_branch is unchanged. A run counts as a pull or merge request
when it has a PR number, when the SCM adapter selected the comparison
flow, or when the CI environment describes a PR or MR event, so a PR run
with --pr-number 0 stays out of the new path. A scan marked as the default
branch, including one with an explicit --default-branch on a PR, still
requests it as before, and --no-default-branch keeps it off.

--pending-head stays a deprecated no-op. Its warning, the CLI reference,
the README and the CHANGELOG describe the new behavior. Shares the 2.16.0
version set in #478.
When the clone lacks the CI commit, Git falls back to HEAD. A --commit-sha
naming that checkout then matched self.commit and was not treated as an
explicit ref, so the reachability check never ran and DEFAULT_BRANCH=true
with --scm github could still mark a scan of another ref as the default
branch. Compare with the CI SHA when there is one.
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

David Larsen (dc-larsen) added a commit that referenced this pull request Dec 2, 2026
Full scans sent set_as_pending_head=is_default_branch, so only a
default-branch scan could become a head. The API also makes a scan the
head of a branch that matches the organization's tracked branch patterns
(Settings > Alerts > Scans), but only when the request sets
set_as_pending_head, and it ignores the flag on branches it doesn't track.
Python CLI scans of a tracked branch were never that branch's head, so
their findings never reached the organization Alerts page.

Branch runs now send set_as_pending_head=true and let the API decide.
make_default_branch is unchanged. A run counts as a pull or merge request
when it has a PR number, when the SCM adapter selected the comparison
flow, or when the CI environment describes a PR or MR event, so a PR run
with --pr-number 0 stays out of the new path. A scan marked as the default
branch, including one with an explicit --default-branch on a PR, still
requests it as before, and --no-default-branch keeps it off.

--pending-head stays a deprecated no-op. Its warning, the CLI reference,
the README and the CHANGELOG describe the new behavior. Shares the 2.16.0
version set in #478.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@lelia

lelia commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@lelia lelia changed the title Check --branch and --commit-sha before marking scan as default branch Honor explicit scan refs in default-branch detection Dec 4, 2026
@lelia
lelia temporarily deployed to socket-firewall December 4, 2026 19:00 — with GitHub Actions Inactive
@lelia

lelia commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread socketsecurity/core/git_interface.py Resolved
@lelia

lelia commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@lelia
lelia temporarily deployed to socket-firewall December 5, 2026 04:15 — with GitHub Actions Inactive

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a0a5ea8. Configure here.

@lelia
lelia deployed to socket-firewall December 5, 2026 04:48 — with GitHub Actions Active
@lelia
lelia merged commit a326ec8 into main Dec 5, 2026
33 checks passed
lelia added a commit that referenced this pull request Dec 5, 2026
* Check --branch and --commit-sha before marking a scan as the default branch

Default-branch detection read only the CI variables. On GitHub Actions it
compared GITHUB_REF to the repository's default branch and checked that the
GITHUB_SHA commit is on it; --branch and --commit-sha were never consulted.
A workflow_run job triggered by develop (the default branch) that checks
out a release tag on main and passes --branch main --commit-sha <tag> was
detected as a default-branch scan. The full scan was created with
make_default_branch=true and set_as_pending_head=true, which moved the
repository's default branch to main, and with develop's commit message.
Without --scm, DEFAULT_BRANCH=false did not help, and nothing could turn
--default-branch detection off.

When --branch or --commit-sha names a different ref than the CI variables,
the scan is no longer treated as the default branch unless that branch is
the default branch and that commit is on it. A commit missing from the
checkout cannot be checked, so it is not treated as the default branch
either. The check can only turn detection off; --default-branch still marks
a scan explicitly. The commit message and the committer fallback now come
from the --commit-sha commit when the checkout has it. Changed-file
detection still reads the CI variables.

Add --no-default-branch, which forces make_default_branch and
set_as_pending_head off whatever git or the CI environment says. It is
mutually exclusive with --default-branch, on the command line and in a
--config file.

Set the version to 2.16.0.

* Clear CI committer usernames in git interface tests

GitHub Actions sets GITHUB_ACTOR, which get_formatted_committer prefers over
the commit's committer, so the --commit-sha committer test failed in CI.

* Apply the explicit-ref check to the combined default-branch detection

With --scm github, the SCM adapter's is_default_branch was copied into
config.default_branch, so DEFAULT_BRANCH=true restored default-branch status
after git had rejected a mismatched --branch or --commit-sha.

resolve_default_branch() now makes the decision in one place:
--no-default-branch and --default-branch are authoritative, and otherwise the
SCM and git detection results are combined before the explicit-ref check runs.
Git.apply_explicit_ref() only records the named ref and switches the commit
details; explicit_ref_allows_default_branch() does the check.

Adds CLI-path tests with SCM detection enabled covering both outgoing flags,
the explicit overrides, and the commit message and committer fallback. Sets
the release to 2.16.0 and updates the CLI reference, README and CHANGELOG.

* Compare --commit-sha with the commit CI names

When the clone lacks the CI commit, Git falls back to HEAD. A --commit-sha
naming that checkout then matched self.commit and was not treated as an
explicit ref, so the reachability check never ran and DEFAULT_BRANCH=true
with --scm github could still mark a scan of another ref as the default
branch. Compare with the CI SHA when there is one.

* Update tracked branch heads from full scans

Full scans sent set_as_pending_head=is_default_branch, so only a
default-branch scan could become a head. The API also makes a scan the
head of a branch that matches the organization's tracked branch patterns
(Settings > Alerts > Scans), but only when the request sets
set_as_pending_head, and it ignores the flag on branches it doesn't track.
Python CLI scans of a tracked branch were never that branch's head, so
their findings never reached the organization Alerts page.

Branch runs now send set_as_pending_head=true and let the API decide.
make_default_branch is unchanged. A run counts as a pull or merge request
when it has a PR number, when the SCM adapter selected the comparison
flow, or when the CI environment describes a PR or MR event, so a PR run
with --pr-number 0 stays out of the new path. A scan marked as the default
branch, including one with an explicit --default-branch on a PR, still
requests it as before, and --no-default-branch keeps it off.

--pending-head stays a deprecated no-op. Its warning, the CLI reference,
the README and the CHANGELOG describe the new behavior. Shares the 2.16.0
version set in #478.

* Keep incomplete branch refs from falling back to the default branch

---------

Co-authored-by: lelia <2418071+lelia@users.noreply.github.com>
lelia added a commit that referenced this pull request Dec 5, 2026
* Check --branch and --commit-sha before marking a scan as the default branch

Default-branch detection read only the CI variables. On GitHub Actions it
compared GITHUB_REF to the repository's default branch and checked that the
GITHUB_SHA commit is on it; --branch and --commit-sha were never consulted.
A workflow_run job triggered by develop (the default branch) that checks
out a release tag on main and passes --branch main --commit-sha <tag> was
detected as a default-branch scan. The full scan was created with
make_default_branch=true and set_as_pending_head=true, which moved the
repository's default branch to main, and with develop's commit message.
Without --scm, DEFAULT_BRANCH=false did not help, and nothing could turn
--default-branch detection off.

When --branch or --commit-sha names a different ref than the CI variables,
the scan is no longer treated as the default branch unless that branch is
the default branch and that commit is on it. A commit missing from the
checkout cannot be checked, so it is not treated as the default branch
either. The check can only turn detection off; --default-branch still marks
a scan explicitly. The commit message and the committer fallback now come
from the --commit-sha commit when the checkout has it. Changed-file
detection still reads the CI variables.

Add --no-default-branch, which forces make_default_branch and
set_as_pending_head off whatever git or the CI environment says. It is
mutually exclusive with --default-branch, on the command line and in a
--config file.

Set the version to 2.16.0.

* Clear CI committer usernames in git interface tests

GitHub Actions sets GITHUB_ACTOR, which get_formatted_committer prefers over
the commit's committer, so the --commit-sha committer test failed in CI.

* Apply the explicit-ref check to the combined default-branch detection

With --scm github, the SCM adapter's is_default_branch was copied into
config.default_branch, so DEFAULT_BRANCH=true restored default-branch status
after git had rejected a mismatched --branch or --commit-sha.

resolve_default_branch() now makes the decision in one place:
--no-default-branch and --default-branch are authoritative, and otherwise the
SCM and git detection results are combined before the explicit-ref check runs.
Git.apply_explicit_ref() only records the named ref and switches the commit
details; explicit_ref_allows_default_branch() does the check.

Adds CLI-path tests with SCM detection enabled covering both outgoing flags,
the explicit overrides, and the commit message and committer fallback. Sets
the release to 2.16.0 and updates the CLI reference, README and CHANGELOG.

* Link the GHSA and CVE ID on each PR/MR comment alert

Each security comment row showed one advisory ID, the GHSA when the alert
had one and the CVE otherwise, as plain text. Alerts from the API usually
carry both, so the CVE was dropped from the row, and developers who only
see the PR comment had no link to the advisory.

Rows now list every advisory ID on the alert, GHSA first, each linked to
its public page (github.com/advisories for GHSA, nvd.nist.gov for CVE),
the same two sites the GitLab security report already links. Only IDs in
the canonical GHSA or CVE shape are linked; anything else renders as
escaped text. IDs keep the API's spelling instead of being upper-cased.

Issue.advisory_ids() is new and used only for display. advisory_id() and
consolidation_key() are unchanged, so de-duplication, SARIF rule IDs and
GitLab finding IDs stay the same.

Shares the 2.16.0 version set in #478.

* Link advisory IDs that already appear in the alert title

An ID the title already named was dropped from the linked list and stayed
plain text, and the substring check also hid a different CVE whose ID is a
prefix of one in the title (CVE-2021-2333 inside CVE-2021-23337).

IDs now match only in full. An ID the title names is linked in place, keeping
the title's spelling and linking the API's ID, and the remaining IDs are
appended once. The plain-text title uses the same full-ID match.

* Compare --commit-sha with the commit CI names

When the clone lacks the CI commit, Git falls back to HEAD. A --commit-sha
naming that checkout then matched self.commit and was not treated as an
explicit ref, so the reachability check never ran and DEFAULT_BRANCH=true
with --scm github could still mark a scan of another ref as the default
branch. Compare with the CI SHA when there is one.

* Update tracked branch heads from full scans

Full scans sent set_as_pending_head=is_default_branch, so only a
default-branch scan could become a head. The API also makes a scan the
head of a branch that matches the organization's tracked branch patterns
(Settings > Alerts > Scans), but only when the request sets
set_as_pending_head, and it ignores the flag on branches it doesn't track.
Python CLI scans of a tracked branch were never that branch's head, so
their findings never reached the organization Alerts page.

Branch runs now send set_as_pending_head=true and let the API decide.
make_default_branch is unchanged. A run counts as a pull or merge request
when it has a PR number, when the SCM adapter selected the comparison
flow, or when the CI environment describes a PR or MR event, so a PR run
with --pr-number 0 stays out of the new path. A scan marked as the default
branch, including one with an explicit --default-branch on a PR, still
requests it as before, and --no-default-branch keeps it off.

--pending-head stays a deprecated no-op. Its warning, the CLI reference,
the README and the CHANGELOG describe the new behavior. Shares the 2.16.0
version set in #478.

* Keep incomplete branch refs from falling back to the default branch

---------

Co-authored-by: lelia <2418071+lelia@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
socket-firewall — dd3c5f33 Deployed Dec 5, 2026 by lelia via python-sfw-smoke-enterprise #758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants