Skip to content

Link advisory IDs in PR and MR security comments - #477

Merged
lelia merged 17 commits into
mainfrom
david/ask-634-pr-comment-cve-links
Dec 5, 2026
Merged

lelia merged 17 commits into
mainfrom
david/ask-634-pr-comment-cve-links

Conversation

@dc-larsen

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

Copy link
Copy Markdown
Contributor

PR and MR security comments link available GHSA and CVE IDs to GitHub Advisories and NVD. When the title already contains a complete ID, the ID links in place. The row appends the remaining IDs once. Finding identity, SARIF rule IDs, and GitLab finding IDs are preserved.

Stacked on #479 so the advisory links share the 2.16.0 version and changelog section.

Verification

  • Unit and core suite passes with locked dependencies, including tests for whole-ID matching, in-place links, duplicates, and escaped malformed values.
  • Verified the generated comment through GitHub's Markdown API. GitLab MR rendering verification is pending.

Public Changelog

PR and MR security comments link available GHSA and CVE IDs to their public advisory pages.


Refs: CE-532

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

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
User-facing HTML comment formatting only, with strict ID shape checks before linking; finding identity and blocking logic are untouched.

Overview
PR and MR security comment rows now turn canonical GHSA and CVE IDs into links (GitHub Advisories and NVD), while plain-text paths still list every distinct ID with GHSA first via new Issue.advisory_ids().

HTML titles use alert_title_html: IDs already spelled out in the alert title are linked in place (no duplicate suffix); any remaining IDs are appended once in parentheses. Non-canonical or malicious ID shapes are escaped and never become arbitrary URLs. Row summaries switched from escaped plain text to this HTML helper; advisory_id() and consolidation keys are unchanged.

Changelog updated for 2.16.0; existing and new tests cover linking, deduplication, whole-ID matching, and HTML escaping.

Reviewed by Cursor Bugbot for commit 97ceb80. Configure here.

@lelia

lelia commented Dec 2, 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 self-assigned this Dec 2, 2026

@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 one rendering edge case before this lands.

Advisory IDs in alert titles

In advisory_ids_for_title(), an ID already in the title is excluded from the linked list, so it stays plain text. The substring check can also hide a different CVE whose ID is a prefix of one in the title. Link a complete ID in place and append links for the remaining IDs once. Add tests for both cases and keep the escaping and finding-identity coverage. Please verify the links render in a GitLab MR as well as GitHub.

PR and release notes

  • Suggested title: Link advisory IDs in PR and MR security comments. Keep the before/after example. Trim the body to the behavior, identity compatibility, and rendering checks. Shorten the rendering docstring to its escaping and link contract.
  • Put a single entry under Changed in the shared 2.16.0 changelog: “PR and MR security comments link available GHSA and CVE IDs to their public advisory pages.” Use the same sentence in the PR’s Public Changelog block. The existing CLI reference and README are sufficient for this presentation change.
  • Please fold this into 2.16.0. #478 should set the version because it adds a supported CLI flag. Drop the independent 2.15.7 bump and rerun CI and Bugbot on the final head.

…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.
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.
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.
@dc-larsen
David Larsen (dc-larsen) force-pushed the david/ask-634-pr-comment-cve-links branch from 7ec9f6d to 3f3be31 Compare December 2, 2026 15:44
@dc-larsen David Larsen (dc-larsen) changed the title Link the GHSA and CVE ID on each PR/MR comment alert Link advisory IDs in PR and MR security comments Dec 2, 2026
@dc-larsen

Copy link
Copy Markdown
Contributor Author

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.

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.
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.
@lelia
lelia changed the base branch from main to dl/tracked-branch-pending-head December 4, 2026 19:00
@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.

✅ 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 97ceb80. Configure here.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

🐳 Docker preview published: socketdev/cli:pr-477

This mutable tag is only created when a Docker preview is explicitly requested.

@lelia
lelia changed the base branch from dl/tracked-branch-pending-head to main December 5, 2026 04:59
@lelia
lelia merged commit 3b3ec62 into main Dec 5, 2026
33 checks passed
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