Skip to content

Enhance security-audit skill: CG alerts integration and viewer improvements - #4058

Merged
mattleibow merged 30 commits into
mainfrom
mattleibow/verbose-chainsaw
May 24, 2026
Merged

mattleibow merged 30 commits into
mainfrom
mattleibow/verbose-chainsaw

Conversation

@mattleibow

Copy link
Copy Markdown
Contributor

Summary

Adds Component Governance (CG) alert querying to the security-audit skill and significantly improves the HTML viewer for presenting security findings.

Key Changes

CG Alert Integration

  • New script: query-cg-alerts.py queries AzDO build logs for CG alerts from both SkiaSharp-Native and SkiaSharp pipelines
  • CG alerts are elevated to the same importance level as other security findings (not dismissed as build-time only)
  • Alerts grouped by component with collapsible detail cards showing CVE IDs and severity

Viewer Improvements

  • 5 summary cards (was 4): Needs Attention, CG Alerts, Undiscovered, False Positive, Clean
  • New Severity column in dependency overview table showing highest CVE severity per dep
  • CG components in main table alongside regular deps, clickable to scroll to CG section
  • Version extraction from CG component strings (e.g. "minimatch 3.1.2" → name + version)
  • Correct status mapping: all CVEs = not clean (Low severity → Undiscovered, not Clean)
  • Normalized severity casing (HIGH → High) for consistent display
  • Sort by severity first, then alphabetical

Skill Workflow

  • SKILL.md updated: CG cache-to-file instructions (prevents re-running 3-min query)
  • JSON Schema requires raw alerts[] array (no categories/summaries)
  • Validation script checks schema + semantic consistency
  • queriedAt ISO timestamp for freshness tracking
  • Explicit "DO NOT editorialize" instructions to prevent AI from dismissing CG findings

Schema

  • Single format: cgAlerts.alerts[] required, additionalProperties: false
  • No legacy format support — each run produces fresh data

mattleibow and others added 28 commits May 23, 2026 10:09
The security audit skill previously only checked NVD/web sources for CVEs in
native dependencies. It completely missed the ~112 CG alerts flagged by the
SkiaSharp-Native Azure DevOps pipeline (definition 26493), which scans Docker
container images for OS package, npm, Rust crate, and NuGet vulnerabilities.

Added Step 9 with:
- How to query CG alerts via az CLI (timeline → log IDs → parse CVEs)
- Alert categorization (Alpine sysroot, Debian base, build toolchain, NuGet)
- Key Dockerfile paths that control the vulnerable packages
- JSON report schema extension for cgAlerts section
- CG portal links for manual review

Co-authored-by: Copilot <[email protected]>
Created query-cg-alerts.py that automatically:
- Discovers the latest SkiaSharp-Native build (pipeline 26493)
- Identifies representative CG logs per container type (alpine, debian11,
  debian13, bionic, wasm) from the build timeline
- Parses and deduplicates all CVEs across jobs
- Categorizes by source (Alpine sysroot, Debian base, npm, Rust, NuGet)
- Outputs human-readable summary or structured JSON (--json flag)

Updated skill doc to note that there is NO build-independent CG REST API -
governance.visualstudio.com doesn't expose alert data through any documented
endpoint. The script achieves equivalent results by sampling the latest
build's CG logs, which report all active registration-level alerts.

Co-authored-by: Copilot <[email protected]>
Move CG alert checking from Step 9 to Step 6 in the instruction
sections to match the workflow overview. Renumber subsequent steps
(old 6→7, 7→8, 8→9). Use #### sub-headings within Step 6 instead
of ### to keep the hierarchy correct.

Co-authored-by: Copilot <[email protected]>
The script now automatically discovers and queries the latest builds
from main AND all active release/* branches. Results are deduplicated
and annotated with branch coverage, showing which CVEs are exclusive
to specific branches.

Also switched from az CLI subprocess calls to direct REST API requests
using urllib for faster execution and better error handling.

Key improvements:
- --branch flag to query a specific branch
- Branch coverage summary showing per-branch alert counts
- Branch-exclusive alert highlighting
- GHSA advisory ID support in addition to CVEs
- Debian 13 rsync alerts now properly categorized

Co-authored-by: Copilot <[email protected]>
- Query both SkiaSharp-Native (26493) and SkiaSharp (10789) pipelines
  since together they make up the shipped build
- Add --pipeline flag (native/managed/both, default: both)
- Add 'COMPONENT STACKS' output section showing components with most CVEs
  (e.g., binutils 2.39-r2 has 15 CVEs, busybox has 35)
- Track which pipeline each alert comes from
- Fix branch deduplication in coverage report
- Update SKILL.md to document both pipelines

Co-authored-by: Copilot <[email protected]>
Security auditing must not sample or skip any jobs. The script now
queries every successful Component Governance log in each build
(60+ jobs in the native pipeline alone) and deduplicates the results.

Co-authored-by: Copilot <[email protected]>
Categorization now derives from job names (where the alert was found)
rather than a brittle list of hardcoded component names. This handles
new packages, versions, or distros appearing without code changes:

- Distro:N: prefix + alpine job → Alpine sysroot
- Distro:N: prefix + non-alpine job → Debian N base image
- Microsoft.*/System.*/NuGet.* → NuGet dependency
- Found only in Prepare/Merge jobs → SDK/toolchain dependency
- Everything else → Build toolchain dependency

Co-authored-by: Copilot <[email protected]>
The script is consumed by AI (security-audit skill), so:
- Default output is now JSON with every alert fully enumerated
- Each alert includes: id, component, severity, category, all source
  jobs, branches, and pipelines — nothing truncated or summarized
- --text flag for human-readable output (also lists every CVE)
- Removed --json flag (JSON is now the default)

Co-authored-by: Copilot <[email protected]>
The script takes 2-3 minutes to query all build logs. Skill instructions
now tell AI to run it once, cache the JSON, and reference the cached
result for the remainder of the audit — never re-running mid-session.

Co-authored-by: Copilot <[email protected]>
Progress messages are now opt-in with --verbose/-v since the script
is consumed by AI which only needs the JSON on stdout.

Co-authored-by: Copilot <[email protected]>
- Add Component Governance section with severity cards, category table,
  high alerts detail, and pipeline links
- Fix PR links rendering #[object Object] by handling {number, repo, title}
  objects alongside plain number format
- Fix issue links similarly for {number, state} objects
- Add warning banner: build-chain vulnerabilities can compromise artifacts

Co-authored-by: Copilot <[email protected]>
- Replace 'highAlerts only' with full allAlerts table (all 121 alerts)
- Show every severity: High, Medium, Low — no filtering
- Remove dismissive 'note' about not shipping
- Remove 'Fix' column from categories (editorial suggestion)
- Add columns: Severity, Pipelines, Branches per alert
- No decisions made about what to show — everything listed

Co-authored-by: Copilot <[email protected]>
- Remove categorize_alert() function from query script
- Remove byCategory from JSON output
- Remove category column from HTML viewer table
- Remove categories section from HTML viewer
- Text mode now groups directly by component

Co-authored-by: Copilot <[email protected]>
- Parse '--- Found at: ---' sections from CG logs to extract actual
  file paths where each component was discovered
- Add 'paths' field to each alert in JSON output
- Show 'Found At' column in HTML viewer with code-formatted paths
- Add 'Open in AzDO' link to CG registration page in header
- Show paths in text mode output per component

Co-authored-by: Copilot <[email protected]>
- Each component gets its own collapsible card showing:
  - Highest severity badge + component name + CVE count + branches
  - Found-at paths (code formatted)
  - CVE table with NVD links
  - Pipeline list
- Sorted: highest severity first, then by CVE count
- All collapsed by default for scannability

Co-authored-by: Copilot <[email protected]>
- Add security-audit-schema.json (Draft 2020-12) covering all report fields
- Add validate-security-audit.py with schema + semantic checks:
  - Summary counts match finding statuses
  - totalCves matches actual CVE arrays
  - CG alerts have enumerable data (allAlerts or uniqueCVEs)
  - bySeverity counts match alert severities
  - Findings have unique dependencies
  - nextSteps sorted by priority
- Viewer now handles both allAlerts and uniqueCVEs/categories formats
- SKILL.md: added validation as Step 8 (mandatory before render)

Co-authored-by: Copilot <[email protected]>
- Add queriedAt ISO timestamp to JSON output for freshness verification
- Rewrite SKILL.md caching instructions to use file (not shell variable)
  The old CG_DATA=$(...) pattern was lost between tool calls since
  sync shells are ephemeral. Saving to /tmp/cg-alerts-cache.json
  persists across calls and makes the caching foolproof.
- Upgraded warning from ⚠️ to 🛑 CRITICAL to emphasize importance

Co-authored-by: Copilot <[email protected]>
The agent was running query-cg-alerts.py 3 times (observed in session
eceb5fb5) because the caching instruction was buried in a subsection.
Now the FIRST thing in Step 6 is the cache command with a stop-sign
emoji and explicit 'do NOT run again' language.

Co-authored-by: Copilot <[email protected]>
Root cause: the skill agent summarized CG data into categories instead
of including the full alerts array. The viewer groups by component
itself — it needs individual alerts with id/component/severity/paths.

Changes:
- SKILL.md: explicit DO NOT list for categories/uniqueCVEs formats
- Validator: errors if 'alerts' array is missing (categories alone fails)
- Viewer: accepts 'alerts' key (script output) in addition to 'allAlerts'
- Viewer: improved categories fallback for older reports (topComponents)
- Schema: added 'alerts' as primary key alongside legacy 'allAlerts'

Co-authored-by: Copilot <[email protected]>
Each audit run produces a fresh JSON/HTML pair. No need for backwards
compatibility with old formats. Simplified to one format:

- cgAlerts.alerts[] is REQUIRED (not allAlerts, uniqueCVEs, or categories)
- Schema: additionalProperties: false on cgAlerts (strict)
- Viewer: reads cg.alerts directly, no fallback normalization
- Validator: errors if alerts array is missing

Co-authored-by: Copilot <[email protected]>
- Add CG Alerts card to top summary row (5 cards now)
- HIGH CG alerts count toward 'Needs Attention' total
- CG components appear in Dependency Overview table sorted by severity
- Clicking a CG row scrolls to the CG detail section
- Remove 'Ships in NuGet?' column from SKILL.md category table
- Add explicit instruction: do NOT editorialize about shipping
- Viewer uses col-md (auto-width) for 5 cards instead of col-md-3

Co-authored-by: Copilot <[email protected]>
'minimatch 3.1.2' -> name: 'minimatch', version: '3.1.2'
'Debian:12:binutils 2.39-r2' -> name: 'Debian:12:binutils', version: '2.39-r2'

The py script stores name+version as one string (from CG log format).
The viewer now splits on the last space before a digit-leading token
to populate both the Dependency and Current Version columns.

Co-authored-by: Copilot <[email protected]>
…t check

- Sort 'Dependencies with CVEs' alphabetically (not by severity —
  was jamming CG HIGH items at top above everything else)
- CG entries don't count toward 'missing from cgmanifest' warning
- Add '🛡️ N CG components' to status text

Co-authored-by: Copilot <[email protected]>
- Sort by severity first (High at top), then alphabetical
- CG status mapping: High/Critical -> needs_attention,
  Medium -> undiscovered (new/unresolved), Low -> clean
- Removes incorrect 'in_progress' for Medium/Low CG items

Co-authored-by: Copilot <[email protected]>
Low severity = undiscovered (not clean). A CVE is a CVE regardless
of severity level. Only items with zero CVEs should be 'clean'.

Co-authored-by: Copilot <[email protected]>
The 'Security' column (now renamed 'Status') shows the audit action status.
The new 'Severity' column shows the highest CVE severity (Critical/High/Medium/Low)
for each dependency, color-coded with the same classes used elsewhere.

Regular deps derive severity from their CVE list; CG items use their
alert severity directly.

Co-authored-by: Copilot <[email protected]>
CVEs from different sources use inconsistent casing (HIGH vs High).
Normalize to title-case for display and for sevOrder lookups.

Co-authored-by: Copilot <[email protected]>
@github-actions

github-actions Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 4058

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 4058"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-4058/packages --name skiasharp-pr-4058
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-4058

Viewer fixes:
- C5: 'verified from SkMilestone.h' now conditional on upstreamVerified
- C6: Add Critical severity card, include Critical+High in Needs Attention count
- C7: CG Medium/Low mapped to 'cg_tracked' (not 'undiscovered' — wrong semantics)
- S2: Guard optional commit fields (no more undefined links)
- S3: Unknown severity renders as italic red (not silently Low)
- S5: Header shows 'X CVEs · Y CG alerts' (not just 'X CVEs analyzed')
- S6: GHSA IDs link to github.com/advisories (not broken NVD links)

SKILL.md fixes:
- C1: Replace /tmp/ paths with output/ai/ (agent runtime may forbid /tmp)
- C2: Fix duplicate Step 9 → Step 10 for markdown summary
- C3: 'sampling' → 'enumerating every CG log' (matches script behavior)
- C4: Remove 'Categorize by source' contradiction, add clarifying note
- Q3: Remove 2>/dev/null that hides auth errors
- Q8: 'tens of build logs' instead of hard-coded '60+'

Schema fixes:
- S4: Lock summary with additionalProperties: false
- S7: Enum-validate CG alert severity (Critical/High/Medium/Low)

Validator fix:
- Q9: Warn when cgAlerts block is missing entirely

Co-authored-by: Copilot <[email protected]>

Copilot AI 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.

Pull request overview

This PR enhances the .agents/skills/security-audit workflow by integrating Azure DevOps Component Governance (CG) alert collection into the security-audit skill, and upgrading the generated HTML viewer + JSON validation to treat CG findings as first-class security signals alongside dependency CVEs.

Changes:

  • Add a CG alert query script that enumerates CG logs across SkiaSharp-Native and SkiaSharp pipelines and outputs a structured cgAlerts payload.
  • Upgrade the HTML viewer to surface CG alerts in the summary, dependency overview table, and a dedicated collapsible CG details section (including GHSA link handling).
  • Introduce a Draft 2020-12 JSON Schema and a validator script that performs schema + semantic consistency checks before rendering.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
.agents/skills/security-audit/SKILL.md Updates the skill workflow and instructions to require CG alert querying + caching and adds a mandatory validation step.
.agents/skills/security-audit/scripts/viewer.html Enhances the HTML viewer with CG alert rendering, summary/overview integration, severity display, and robust PR/issue/advisory linking.
.agents/skills/security-audit/scripts/validate-security-audit.py Adds a report validation CLI that checks schema compliance and key semantic invariants.
.agents/skills/security-audit/scripts/query-cg-alerts.py Adds an AzDO API-backed CG log enumerator/parser producing structured cgAlerts output for audits.
.agents/skills/security-audit/references/security-audit-schema.json Adds a strict machine-readable schema defining the security audit JSON format, including required cgAlerts.alerts[].
Comments suppressed due to low confidence (1)

.agents/skills/security-audit/references/security-audit-schema.json:249

  • Similarly, the viewer supports prs entries as either plain numbers or objects, but the schema restricts prs[] items to type: object only. This can cause schema validation failures for otherwise-renderable reports. Consider widening the schema to match the accepted formats (or standardize the report format and update viewer/skill accordingly).
          "prs": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true

Comment thread .agents/skills/security-audit/SKILL.md Resolved
@github-actions

github-actions Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

The documentation for this PR has been deployed and is available at:

🔗 View Staging Site
🔗 View Staging Docs
🔗 View Staging Gallery (Blazor)
🔗 View Staging Gallery (Uno Platform)
🔗 View Staging SkiaFiddle

This preview will be updated automatically when you push new commits to this PR.


This comment is automatically updated by the documentation staging workflow.

… validator errors

- Make git remote add idempotent (fallback to set-url)
- CG badge includes Critical+High in danger condition
- Schema enforces objects with required 'number' for issues/prs
- Validator promotes summary count mismatches to errors (exit 1)

Co-authored-by: Copilot <[email protected]>
@mattleibow
mattleibow merged commit 23e8f1a into main May 24, 2026
3 of 4 checks passed
@mattleibow
mattleibow deleted the mattleibow/verbose-chainsaw branch May 24, 2026 21:28
github-actions Bot pushed a commit that referenced this pull request May 24, 2026
mattleibow added a commit that referenced this pull request May 26, 2026
@mattleibow mattleibow added this to the 4.148.0-rc.1 milestone Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants