Skip to content

fix(github insights): Improved Analyzer, new properties, severity fixes for codeScanning findings - #2053

Merged
moshloop merged 6 commits into
mainfrom
feat/github-security-alert-properties
Mar 30, 2026
Merged

moshloop merged 6 commits into
mainfrom
feat/github-security-alert-properties

Conversation

@adityathebe

@adityathebe adityathebe commented Mar 27, 2026 •

Copy link
Copy Markdown
Member
image image

Summary by CodeRabbit

  • New Features
    • Analysis now includes full serialized alert objects for Dependabot, Code Scanning, and Secret Scanning.
    • Dependabot: added CWE badges (with MITRE linking when applicable), dependency name+ecosystem, dependency scope, vulnerable version range and first patched version badges; CVSS vector badge removed, CVSS score retained.
    • Code Scanning: updated severity mapping, deterministic code-scanning URLs, and added tool (and version) badge.
    • Secret Scanning: added secret type, validity status, public leak and push-protection bypass indicators.

@coderabbitai

coderabbitai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c560ce8-49f5-4cbb-aaa1-339452bd05b7

📥 Commits

Reviewing files that changed from the base of the PR and between 8763a4c and 0ad0ba2.

📒 Files selected for processing (2)
  • scrapers/github/openssf.go
  • scrapers/github/scraper.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • scrapers/github/openssf.go
  • scrapers/github/scraper.go

Walkthrough

Replaces manual map construction for OpenSSF analysis with a call to collections.ToJSONMap(check). Enhances Dependabot, Code Scanning, and Secret Scanning alert processing: serializes full alert objects into a.Analysis, adjusts severity/analyzer assignments, augments badges/properties (CWE, dependency details, vulnerability metadata, tool info, secret validity/public leak/push-protect flags), and changes URL generation for code-scanning alerts.

Changes

Cohort / File(s) Summary
GitHub OpenSSF Refactoring
scrapers/github/openssf.go
Replaced manual a.Analysis construction with a.Analysis, _ = collections.ToJSONMap(check), delegating structure shaping to the utility and ignoring its error.
GitHub Alert Analysis Enhancement
scrapers/github/scraper.go
Now serializes full Dependabot, Code Scanning, and Secret Scanning alert objects into a.Analysis and sets a.Analyzer. Dependabot: adds CWE badges (with optional MITRE links), dependency package/ecosystem and scope badges, vulnerability range/first-patched badges; removes CVSS vector property emission while keeping CVSS score handling. Code Scanning: uses GetSecuritySeverityLevel() for severity mapping, generates deterministic code-scanning URLs from configID/alert number, and adds a “Tool” badge (with optional version). Secret Scanning: adds secret type, validity (active/inactive with color), publicly leaked and push-protection-bypass boolean badges; keeps existing URL behavior.

Possibly related PRs

Suggested reviewers

  • moshloop
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: improved Analyzer assignment, addition of new properties to security findings, and severity fixes for Code Scanning.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/github-security-alert-properties
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/github-security-alert-properties

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

Benchstat

Base: 6b78220ab34437fb19af4a39d04582ecf4c0c72b
Head: 0ad0ba2e813da82832d1e6701e2023f1dad6c7f3

✅ No significant performance changes detected

Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/config-db/bench
cpu: AMD EPYC 7763 64-Core Processor                
                                         │ bench-base.txt │           bench-head.txt           │
                                         │     sec/op     │    sec/op     vs base              │
BenchSaveResultsSeed/N=1000-4                611.0m ±  7%   610.1m ±  7%       ~ (p=0.937 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     700.4m ±  3%   691.6m ± 16%       ~ (p=0.240 n=6)
BenchSaveResultsUpdateChanged/N=1000-4        1.136 ± 19%    1.125 ±  2%       ~ (p=0.065 n=6)
geomean                                      786.4m         780.2m        -0.79%

                                         │ bench-base.txt │           bench-head.txt           │
                                         │      MB/s      │    MB/s     vs base                │
BenchSaveResultsSeed/N=1000-4                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateUnchanged/N=1000-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateChanged/N=1000-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                 ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                         │ bench-base.txt │           bench-head.txt           │
                                         │      B/op      │     B/op      vs base              │
BenchSaveResultsSeed/N=1000-4                34.58Mi ± 0%   34.61Mi ± 0%       ~ (p=0.310 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     24.84Mi ± 0%   24.83Mi ± 0%       ~ (p=0.394 n=6)
BenchSaveResultsUpdateChanged/N=1000-4       72.36Mi ± 0%   72.35Mi ± 0%       ~ (p=1.000 n=6)
geomean                                      39.61Mi        39.62Mi       +0.01%

                                         │ bench-base.txt │          bench-head.txt           │
                                         │   allocs/op    │  allocs/op   vs base              │
BenchSaveResultsSeed/N=1000-4                 454.0k ± 0%   454.0k ± 0%       ~ (p=1.000 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4      287.9k ± 0%   287.9k ± 0%       ~ (p=0.394 n=6)
BenchSaveResultsUpdateChanged/N=1000-4        856.5k ± 1%   856.5k ± 1%       ~ (p=0.699 n=6)
geomean                                       482.0k        482.0k       +0.00%

@adityathebe
adityathebe marked this pull request as draft March 27, 2026 10:59

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
scrapers/github/openssf.go (1)

222-222: Consider logging the error from ToJSONMap instead of discarding it.

While CheckResult contains only basic JSON-serializable types, silently discarding errors can mask unexpected issues. The same pattern is used consistently in scraper.go, so this is a minor consistency point.

🔧 Optional: Log serialization errors
-		a.Analysis, _ = collections.ToJSONMap(check)
+		if analysisMap, err := collections.ToJSONMap(check); err != nil {
+			ctx.Warnf("failed to serialize OpenSSF check %q to JSON: %v", check.Name, err)
+		} else {
+			a.Analysis = analysisMap
+		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scrapers/github/openssf.go` at line 222, Replace the discarded error from
collections.ToJSONMap(check) by capturing it and logging it with the file's
existing logger; e.g., call result, err := collections.ToJSONMap(check), assign
a.Analysis = result only if err == nil (or assign anyway) and if err != nil emit
a clear log entry including context (mention a, check or check.ID) using the
logger available in this file (e.g., log/processLogger) so serialization
problems are not silently ignored; keep behavior otherwise unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scrapers/github/scraper.go`:
- Around line 236-246: The loop over alert.SecurityAdvisory.CWEs currently
slices cweID with cweID[4:] which can panic on malformed IDs; update the code in
the loop (where cweID is obtained and cweURL is built) to first validate the
format (e.g., check strings.HasPrefix(cweID, "CWE-") and len(cweID) > 4 or use
strings.Split/TrimPrefix) before slicing or constructing cweURL, and if the
format is unexpected simply skip adding the URL/Link (but still add the Property
text if desired) to avoid runtime panics.
- Line 186: The assignment a.Analyzer =
alert.GetDependency().GetPackage().GetEcosystem() can panic due to nil returns
from alert.GetDependency() or dependency.GetPackage(); update the code in
scraper.go (around the assignment) to perform defensive nil checks: fetch dep :=
alert.GetDependency(), return or skip if dep==nil, then pkg := dep.GetPackage(),
return or skip if pkg==nil, and only then set a.Analyzer = pkg.GetEcosystem()
(or set a.Analyzer to an empty string/default when nil); ensure you reference
alert.GetDependency(), dependency.GetPackage(), and GetEcosystem() in your
changes so the chain is safely guarded.

---

Nitpick comments:
In `@scrapers/github/openssf.go`:
- Line 222: Replace the discarded error from collections.ToJSONMap(check) by
capturing it and logging it with the file's existing logger; e.g., call result,
err := collections.ToJSONMap(check), assign a.Analysis = result only if err ==
nil (or assign anyway) and if err != nil emit a clear log entry including
context (mention a, check or check.ID) using the logger available in this file
(e.g., log/processLogger) so serialization problems are not silently ignored;
keep behavior otherwise unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f843efe-c10c-4397-86cb-e57f1e964cb4

📥 Commits

Reviewing files that changed from the base of the PR and between aef9437 and d42c549.

📒 Files selected for processing (3)
  • .gitignore
  • scrapers/github/openssf.go
  • scrapers/github/scraper.go

Comment thread scrapers/github/scraper.go
Comment thread scrapers/github/scraper.go
@adityathebe
adityathebe force-pushed the feat/github-security-alert-properties branch from d42c549 to 4d9311c Compare March 29, 2026 12:52
@adityathebe
adityathebe marked this pull request as ready for review March 29, 2026 12:53
@adityathebe
adityathebe force-pushed the feat/github-security-alert-properties branch from 4d9311c to 8763a4c Compare March 29, 2026 13:05

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scrapers/github/scraper.go`:
- Around line 321-322: The build breaks because the undefined variable configID
is used to derive repoFullName and build codeScanningURL; replace configID with
the function parameter externalConfigID (i.e., use
strings.TrimPrefix(externalConfigID, "github/") when computing repoFullName) so
repoFullName and the fmt.Sprintf call that uses alert.GetNumber() reference the
correct variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94b56cde-98de-45db-aac2-a5c6183a3bfa

📥 Commits

Reviewing files that changed from the base of the PR and between d42c549 and 8763a4c.

📒 Files selected for processing (2)
  • scrapers/github/openssf.go
  • scrapers/github/scraper.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • scrapers/github/openssf.go

Comment thread scrapers/github/scraper.go Outdated
@adityathebe
adityathebe force-pushed the feat/github-security-alert-properties branch from 8763a4c to 0ad0ba2 Compare March 29, 2026 13:31
@moshloop
moshloop merged commit 5da3f61 into main Mar 30, 2026
15 checks passed
@moshloop
moshloop deleted the feat/github-security-alert-properties branch March 30, 2026 05:01
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