From 0e4e17b14fc5ca756500366668586691e40535ea Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 17 Nov 2026 11:18:35 +0000 Subject: [PATCH 01/14] docs: design and plan for the CVEs tab Signed-off-by: Ricardo Dias --- docs/superpowers/plans/2026-11-17-cve-tab.md | 787 ++++++++++++++++++ .../plans/2026-11-17-cve-tab.md.tasks.json | 102 +++ .../specs/2026-11-17-cve-tab-design.md | 294 +++++++ .../specs/2026-11-17-cve-tab-mockup.html | 91 ++ 4 files changed, 1274 insertions(+) create mode 100644 docs/superpowers/plans/2026-11-17-cve-tab.md create mode 100644 docs/superpowers/plans/2026-11-17-cve-tab.md.tasks.json create mode 100644 docs/superpowers/specs/2026-11-17-cve-tab-design.md create mode 100644 docs/superpowers/specs/2026-11-17-cve-tab-mockup.html diff --git a/docs/superpowers/plans/2026-11-17-cve-tab.md b/docs/superpowers/plans/2026-11-17-cve-tab.md new file mode 100644 index 0000000..4467827 --- /dev/null +++ b/docs/superpowers/plans/2026-11-17-cve-tab.md @@ -0,0 +1,787 @@ +# CVE Tab Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers-extended-cc:subagent-driven-development (recommended) or superpowers-extended-cc:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** A "CVEs" main tab that lists what to bump on staging (ours vs. base OS, with new-since-last-look markers) and, for released images, which CVEs the current staging image already fixes. + +**Architecture:** The scanner keeps a few extra trivy fields per finding in the existing `findings_json`. A new pure Go package `internal/cvereport` classifies findings and aggregates them into one report; `GET /api/cve/report` serves it from a short TTL cache. The frontend fetches the report once per app (for the tab badge), keeps "seen" state in `localStorage`, and renders three views; the existing `CveExposureTable` moves in unchanged as "By image". + +**Tech Stack:** Go 1.25 (chi, modernc sqlite), Vue 3 ` + + diff --git a/frontend/src/composables/useCveReport.test.ts b/frontend/src/composables/useCveReport.test.ts new file mode 100644 index 0000000..2e57ca7 --- /dev/null +++ b/frontend/src/composables/useCveReport.test.ts @@ -0,0 +1,74 @@ +// @vitest-environment jsdom +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { flushPromises } from '@vue/test-utils' +import { resetCveReportForTests, useCveReport } from './useCveReport' +import { resetCveSeenForTests, useCveSeen } from './useCveSeen' +import type { CveReport, CveRow } from '../types/cveReport' + +function row(name: string, ids: string[]): CveRow { + return { + key: `ours|${name}`, name, kind: 'obs_package', worst: 'HIGH', cves: ids.length, fixes: [], images: [], + entries: ids.map(id => ({ id, pkg: name, severity: 'HIGH' as const, title: 't', seen_key: `${id}|${name}|` })), + } +} + +export const fixtureReport: CveReport = { + generated_at: '2026-11-17T00:00:00Z', + staging: { ours: [row('etcd', ['CVE-1', 'CVE-2'])], base_os: [row('openssl', ['CVE-3'])], unclassified: [], cves: 3, images: 2 }, + released: [], +} + +class FakeES { static last: FakeES | null = null; onmessage: (() => void) | null = null; constructor() { FakeES.last = this } close() {} } + +let fetchMock: ReturnType +beforeEach(() => { + localStorage.clear() + resetCveSeenForTests() + resetCveReportForTests() + fetchMock = vi.fn(async () => ({ ok: true, statusText: 'OK', json: async () => fixtureReport })) + vi.stubGlobal('fetch', fetchMock) + vi.stubGlobal('EventSource', FakeES) +}) +afterEach(() => { vi.unstubAllGlobals(); vi.useRealTimers() }) + +describe('useCveReport', () => { + it('start() fetches once even when called twice', async () => { + const r = useCveReport() + r.start(); r.start() + await flushPromises() + expect(fetchMock).toHaveBeenCalledTimes(1) + expect(fetchMock.mock.calls[0][0]).toBe('/api/cve/report') + expect(r.report.value).toEqual(fixtureReport) + }) + + it('a 500 sets error and leaves report null; refresh() clears it on success', async () => { + fetchMock.mockResolvedValueOnce({ ok: false, statusText: 'Internal Server Error', json: async () => ({}) }) + const r = useCveReport() + await r.refresh() + expect(r.error.value).toBe('Internal Server Error') + expect(r.report.value).toBeNull() + await r.refresh() + expect(r.error.value).toBeNull() + expect(r.report.value).not.toBeNull() + }) + + it('newCount counts distinct unseen keys, and is 0 after markAllSeen', async () => { + const r = useCveReport() + expect(r.newCount.value).toBe(0) + await r.refresh() + expect(r.newCount.value).toBe(3) + useCveSeen().markAllSeen(['CVE-1|etcd|', 'CVE-2|etcd|', 'CVE-3|openssl|']) + expect(r.newCount.value).toBe(0) + }) + + it('refetches 2 s after a stream message', async () => { + vi.useFakeTimers() + const r = useCveReport() + r.start() + await vi.advanceTimersByTimeAsync(0) + expect(fetchMock).toHaveBeenCalledTimes(1) + FakeES.last!.onmessage!() + await vi.advanceTimersByTimeAsync(2000) + expect(fetchMock).toHaveBeenCalledTimes(2) + }) +}) diff --git a/frontend/src/composables/useCveReport.ts b/frontend/src/composables/useCveReport.ts new file mode 100644 index 0000000..a801b8d --- /dev/null +++ b/frontend/src/composables/useCveReport.ts @@ -0,0 +1,66 @@ +import { computed, readonly, ref } from 'vue' +import type { CveReport } from '../types/cveReport' +import { countNew } from '../lib/cveReport' +import { useCveSeen } from './useCveSeen' + +// Module-level singleton: the header badge and the CVEs panel share one +// report and one stream subscription. +const report = ref(null) +const loading = ref(false) +const error = ref(null) + +let es: EventSource | null = null +let debounce: ReturnType | null = null +let started = false + +async function refresh(): Promise { + loading.value = true + try { + const res = await fetch('/api/cve/report') + if (!res.ok) throw new Error(res.statusText) + report.value = await res.json() as CveReport + error.value = null + } catch (e) { + error.value = e instanceof Error ? e.message : 'failed to load CVE report' + } finally { + loading.value = false + } +} + +// Idempotent: the first call fetches and subscribes to the app's global +// stream; any message schedules a debounced refetch (mirrors useOverviewData). +function start(): void { + if (started) return + started = true + void refresh() + es = new EventSource('/api/stream') + es.onmessage = () => { + if (debounce) clearTimeout(debounce) + debounce = setTimeout(() => { void refresh() }, 2000) + } +} + +const { isNew } = useCveSeen() +const newCount = computed(() => (report.value ? countNew(report.value.staging, isNew) : 0)) + +export function useCveReport() { + return { + report: readonly(report), + loading: readonly(loading), + error: readonly(error), + refresh, + start, + newCount, + } +} + +export function resetCveReportForTests(): void { + es?.close() + es = null + if (debounce) clearTimeout(debounce) + debounce = null + started = false + report.value = null + loading.value = false + error.value = null +} diff --git a/frontend/src/composables/useUrlState.ts b/frontend/src/composables/useUrlState.ts index 2560fb0..3827e13 100644 --- a/frontend/src/composables/useUrlState.ts +++ b/frontend/src/composables/useUrlState.ts @@ -2,8 +2,9 @@ import { watch, watchEffect, onMounted, ref, type Ref } from 'vue' import type { Context } from '../types/api' import { PPG_STAGING_CONTEXT } from '../lib/contexts' import type { WindowKey } from '../types/overview' +import type { CveView } from '../types/cveReport' -export type MainTab = 'board' | 'artifacts' | 'overview' | 'release' | 'settings' +export type MainTab = 'board' | 'artifacts' | 'overview' | 'release' | 'settings' | 'cves' export function contextToKey(ctx: Context): string { const parts = ctx.prefix.split(':') @@ -30,6 +31,7 @@ interface UrlStateOptions { artifactsContexts: Ref overviewWindow: Ref activeInstances: Ref + cveView: Ref } export function useUrlState(state: UrlStateOptions): void { @@ -37,7 +39,7 @@ export function useUrlState(state: UrlStateOptions): void { mainTab, boardCtx, version, activeTags, artifactsCtx, artifactsVersion, artifactsTab, boardContexts, artifactsContexts, overviewWindow, - activeInstances, + activeInstances, cveView, } = state // Pending raw URL keys awaiting context list population (PR contexts load async) @@ -50,7 +52,7 @@ export function useUrlState(state: UrlStateOptions): void { const params = new URLSearchParams(window.location.search) const tab = params.get('tab') - if (tab === 'board' || tab === 'artifacts' || tab === 'overview' || tab === 'release' || tab === 'settings') mainTab.value = tab + if (tab === 'board' || tab === 'artifacts' || tab === 'overview' || tab === 'release' || tab === 'settings' || tab === 'cves') mainTab.value = tab const ver = params.get('version') if (ver) version.value = ver @@ -70,6 +72,9 @@ export function useUrlState(state: UrlStateOptions): void { const owin = params.get('owin') if (owin === '24h' || owin === '48h' || owin === '7d') overviewWindow.value = owin + const cview = params.get('cview') + if (cview === 'released' || cview === 'images') cveView.value = cview + const ctxKey = params.get('ctx') if (ctxKey) { const resolved = keyToContext(ctxKey, boardContexts.value) @@ -134,6 +139,8 @@ export function useUrlState(state: UrlStateOptions): void { if (overviewWindow.value !== '24h') params.set('owin', overviewWindow.value) + if (cveView.value !== 'staging') params.set('cview', cveView.value) + const search = params.toString() history.replaceState(null, '', search ? `?${search}` : window.location.pathname) }) diff --git a/frontend/src/lib/overview.ts b/frontend/src/lib/overview.ts index 77a555c..48479e0 100644 --- a/frontend/src/lib/overview.ts +++ b/frontend/src/lib/overview.ts @@ -6,6 +6,14 @@ import { isPRProject } from './project' export const PROJECT_ACCENTS = ['#6E3FF3', '#2A78D4', '#1F9D55', '#E08A00', '#B0203A'] +// Accent for a project by its position in the NAME-sorted project list (not +// snapshot ordering, which is rebuild-sorted and would shuffle colours between +// windows/refetches). +export function projectAccent(sortedProjects: string[], project: string): string { + const idx = sortedProjects.indexOf(project) + return PROJECT_ACCENTS[Math.max(0, idx) % PROJECT_ACCENTS.length] +} + export function ageColor(days: number): string { if (days >= 45) return 'var(--crit)' if (days >= 21) return 'var(--high)' From ca2eb0920a64f302f43145ab18fa40d38f66b00d Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 17 Nov 2026 11:29:07 +0000 Subject: [PATCH 10/14] feat(frontend): the staging work list in the CVEs tab Signed-off-by: Ricardo Dias --- frontend/src/components/CveExposureTable.vue | 43 +---- frontend/src/components/cve/CvePanel.vue | 5 +- .../src/components/cve/CveStagingView.test.ts | 176 ++++++++++++++++++ .../src/components/cve/CveStagingView.vue | 63 +++++++ .../src/components/cve/CveWorklistTable.vue | 126 +++++++++++++ frontend/src/composables/useCveRescan.ts | 48 +++++ 6 files changed, 420 insertions(+), 41 deletions(-) create mode 100644 frontend/src/components/cve/CveStagingView.test.ts create mode 100644 frontend/src/components/cve/CveStagingView.vue create mode 100644 frontend/src/components/cve/CveWorklistTable.vue create mode 100644 frontend/src/composables/useCveRescan.ts diff --git a/frontend/src/components/CveExposureTable.vue b/frontend/src/components/CveExposureTable.vue index 1617131..4ea2c61 100644 --- a/frontend/src/components/CveExposureTable.vue +++ b/frontend/src/components/CveExposureTable.vue @@ -1,12 +1,12 @@ diff --git a/frontend/src/components/cve/CveReleasedView.test.ts b/frontend/src/components/cve/CveReleasedView.test.ts new file mode 100644 index 0000000..e79aba5 --- /dev/null +++ b/frontend/src/components/cve/CveReleasedView.test.ts @@ -0,0 +1,66 @@ +// @vitest-environment jsdom +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils' +import CveReleasedView from './CveReleasedView.vue' +import type { ReleasedImage } from '../../types/cveReport' + +const image: ReleasedImage = { + project: 'ppg:releases:18:containers', + package: 'percona-distribution-postgresql', + repo: 'ubi9', + version: '18.4-1-1.1', + staging_project: 'ppg:staging:18:containers', + staging_version: '18.4-1-2.34', + total: 3, + fixed_in_staging: 1, + cves: [ + { id: 'CVE-2025-0001', pkg: 'openssl', installed: '3.0.1', fixed: '3.0.2', severity: 'HIGH', title: 't1', status: 'fixed' }, + { id: 'CVE-2025-0002', pkg: 'golang', installed: '1.22.1', fixed: '1.22.5', severity: 'CRITICAL', title: 't2', status: 'open', staging_row_key: 'ours|golang' }, + { id: 'CVE-2025-0003', pkg: 'zlib', installed: '1.2.1', fixed: '1.2.2', severity: 'HIGH', title: 't3', status: 'no_staging' }, + ], +} + +describe('CveReleasedView', () => { + it('shows the fixed count, both versions and the PG major with repo', () => { + const w = mount(CveReleasedView, { props: { released: [image] } }) + const text = w.text() + expect(text).toContain('1 of 3') + expect(text).toContain('18.4-1-1.1') + expect(text).toContain('18.4-1-2.34') + expect(text).toContain('18 · ubi9') + }) + + it('expands to the status of each CVE and links an open one to its staging row', async () => { + const w = mount(CveReleasedView, { props: { released: [image] } }) + const head = w.find('button[aria-expanded]') + expect(head.attributes('aria-expanded')).toBe('false') + await head.trigger('click') + expect(head.attributes('aria-expanded')).toBe('true') + const text = w.text() + expect(text).toContain('Fixed in staging') + expect(text).toContain('Still open in staging') + expect(text).toContain('No staging image to compare') + expect(text).toContain('CVE-2025-0002') + const link = w.findAll('button').find(b => b.text() === 'golang')! + expect(link).toBeTruthy() + await link.trigger('click') + expect(w.emitted('open-staging-row')).toEqual([['ours|golang']]) + }) + + it('shows a dash when there is no staging version', () => { + const w = mount(CveReleasedView, { props: { released: [{ ...image, staging_version: undefined, fixed_in_staging: 0 }] } }) + expect(w.text()).toContain('—') + }) + + it('has no new markers and no mark-all-as-seen', async () => { + const w = mount(CveReleasedView, { props: { released: [image] } }) + await w.find('button[aria-expanded]').trigger('click') + expect(w.find('[data-testid="cve-new-tag"]').exists()).toBe(false) + expect(w.find('[data-testid="cve-mark-seen"]').exists()).toBe(false) + }) + + it('renders an empty state for no released images', () => { + const w = mount(CveReleasedView, { props: { released: [] } }) + expect(w.find('[data-testid="cve-empty"]').exists()).toBe(true) + }) +}) diff --git a/frontend/src/components/cve/CveReleasedView.vue b/frontend/src/components/cve/CveReleasedView.vue new file mode 100644 index 0000000..fe37200 --- /dev/null +++ b/frontend/src/components/cve/CveReleasedView.vue @@ -0,0 +1,112 @@ + + + From eaa6c417ede3f882d0d97b221c640d7ecdd44ceb Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 17 Nov 2026 11:33:39 +0000 Subject: [PATCH 12/14] docs: the CVEs tab Signed-off-by: Ricardo Dias --- CHANGELOG.md | 10 ++++++++++ README.md | 1 + docs/superpowers/specs/2026-11-17-cve-tab-design.md | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b9c18..962e147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ an example value. See `deploy/host/README.md`. ## [Unreleased] +### Added + +- A "CVEs" tab after Artifacts has three views. "Staging" lists the packages to bump to clear the HIGH and CRITICAL CVEs found in the staging images, split into "Ours to bump", "Base OS" and "Not classified yet". Entries that are new since you last looked are marked, and "Mark all as seen" clears the markers; the markers are kept in your browser, and the tab shows a badge when there are new entries. "Released" shows, for each released image, how many of its CVEs the current staging image already fixes. "By image" is the CVE table that used to be on Overview. +- `GET /api/cve/report` returns the data behind the CVEs tab: the staging work list and the released-image view. It is public, like the other CVE endpoints. + +### Changed + +- The CVE table moved from Overview to the "By image" view of the new CVEs tab. +- After upgrading, images scanned before this version are rescanned once at startup so their findings can be classified. Until the rescan finishes, their packages appear under "Not classified yet". + ## [0.2.10] - 2026-11-17 ### Added diff --git a/README.md b/README.md index 1743ea4..d0c608b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ The dashboard polls OBS on a schedule and consumes RabbitMQ build events, stores - Package cards showing live rollup state (building, failed, succeeded, published) across all PPG OBS projects. - Per-target build event log: build started, succeeded, failed, published — filterable by tag and time window. - Artifacts view — binary package download links and container image pull commands, browsable by version, repo, and arch; covers dev builds, releases, and PRs. +- CVEs tab — the packages to bump to clear HIGH and CRITICAL CVEs in staging images, what the current staging image already fixes for each released image, and the per-image CVE table; new entries since your last look are marked. - Tag-based filtering (RPM, DEB, container) and version selector. - PR build tracking: dedicated board context per OBS PR branch. - SSE-based live updates — cards and event log update in real time without a page refresh. diff --git a/docs/superpowers/specs/2026-11-17-cve-tab-design.md b/docs/superpowers/specs/2026-11-17-cve-tab-design.md index 8e02020..bb0bbc0 100644 --- a/docs/superpowers/specs/2026-11-17-cve-tab-design.md +++ b/docs/superpowers/specs/2026-11-17-cve-tab-design.md @@ -1,6 +1,6 @@ # CVE tab: what to bump, and what a release would clear -Date: 2026-11-17. Status: design, awaiting approval. +Date: 2026-11-17. Status: implemented. Lines marked **(call)** are choices made by the author of this document, not decisions the user made. Everything else under "Decided" came from the user. From db85c349fda84d159c28cad33ace8b7472a94056 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 17 Nov 2026 11:44:53 +0000 Subject: [PATCH 13/14] fix(cve): review fixes for the CVEs tab Signed-off-by: Ricardo Dias --- CHANGELOG.md | 2 +- backend/internal/cve/owner.go | 11 +++----- backend/internal/cve/scanner.go | 7 ++++- backend/internal/cve/scanner_test.go | 26 +++++++++++++++++++ backend/internal/cvereport/classify.go | 11 +++++++- backend/internal/cvereport/classify_test.go | 9 +++++++ frontend/src/components/AppHeader.test.ts | 3 +-- .../src/components/cve/CveByImageView.vue | 19 ++++++++++++++ frontend/src/components/cve/CvePanel.test.ts | 18 ++++++++++++- frontend/src/components/cve/CvePanel.vue | 16 +++--------- .../src/components/cve/CveStagingView.test.ts | 21 +++++++++++++++ .../src/components/cve/CveStagingView.vue | 9 ++++++- .../src/components/cve/CveWorklistTable.vue | 2 +- frontend/src/lib/cveReport.test.ts | 6 +++++ frontend/src/lib/cveReport.ts | 14 ++++++++-- 15 files changed, 144 insertions(+), 30 deletions(-) create mode 100644 frontend/src/components/cve/CveByImageView.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 962e147..8dbe9b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ an example value. See `deploy/host/README.md`. ### Changed - The CVE table moved from Overview to the "By image" view of the new CVEs tab. -- After upgrading, images scanned before this version are rescanned once at startup so their findings can be classified. Until the rescan finishes, their packages appear under "Not classified yet". +- After upgrading, images scanned before this version are rescanned once at startup so their findings can be classified. Until the rescan finishes, their packages appear under "Not classified yet". Entries marked as seen before that rescan finishes may show as new once more afterwards, because the rescan adds the file a library was found in. ## [0.2.10] - 2026-11-17 diff --git a/backend/internal/cve/owner.go b/backend/internal/cve/owner.go index 14d292f..e5a2be3 100644 --- a/backend/internal/cve/owner.go +++ b/backend/internal/cve/owner.go @@ -4,16 +4,13 @@ import ( "path" "regexp" "strings" + + "github.com/percona/obs-dashboard/internal/cvereport" ) // rpmInfo is one RPM from trivy's package list. type rpmInfo struct{ Name, Version, Src, Vendor string } -// oursVendor reports whether an RPM vendor is the team's. -func oursVendor(vendor string) bool { - return strings.HasPrefix(vendor, "Percona") || strings.HasPrefix(vendor, "obs://") -} - var pythonPrefix = regexp.MustCompile(`python(\d+(\.\d+)?)?`) // normLangName reduces a Python distribution or RPM name to a comparable stem: @@ -42,7 +39,7 @@ func goBinaryOwner(p string, rpms []rpmInfo) string { base := path.Base(p) srcs := map[string]bool{} for _, r := range rpms { - if oursVendor(r.Vendor) && (r.Name == base || r.Name == "percona-"+base) { + if cvereport.OursVendor(r.Vendor) && (r.Name == base || r.Name == "percona-"+base) { srcs[r.Src] = true } } @@ -55,7 +52,7 @@ func pythonOwner(name, version string, rpms []rpmInfo) string { want := normLangName(name) srcs := map[string]bool{} for _, r := range rpms { - if oursVendor(r.Vendor) && r.Version == version && normLangName(r.Name) == want { + if cvereport.OursVendor(r.Vendor) && r.Version == version && normLangName(r.Name) == want { srcs[r.Src] = true } } diff --git a/backend/internal/cve/scanner.go b/backend/internal/cve/scanner.go index 85a3869..53f8d9f 100644 --- a/backend/internal/cve/scanner.go +++ b/backend/internal/cve/scanner.go @@ -431,7 +431,9 @@ func parseTrivyOutput(data []byte, imageRef, repo, arch string) (model.CveScan, for _, p := range result.Packages { r := rpmInfo{Name: p.Name, Version: p.Version, Src: p.SrcName, Vendor: p.Maintainer} rpms = append(rpms, r) - rpmByID[p.ID] = r + if p.ID != "" { + rpmByID[p.ID] = r + } } } @@ -449,6 +451,9 @@ func parseTrivyOutput(data []byte, imageRef, repo, arch string) (model.CveScan, } switch { case result.Class == "os-pkgs": + if v.PkgID == "" { + break + } if r, ok := rpmByID[v.PkgID]; ok { f.Src, f.Vendor = r.Src, r.Vendor } diff --git a/backend/internal/cve/scanner_test.go b/backend/internal/cve/scanner_test.go index ff4eb32..859ce31 100644 --- a/backend/internal/cve/scanner_test.go +++ b/backend/internal/cve/scanner_test.go @@ -289,3 +289,29 @@ func TestRunTrivyListsAllPackages(t *testing.T) { t.Errorf("args missing --list-all-pkgs: %v", args) } } + +func TestParseTrivyOutputEmptyPkgIDStaysUnclassified(t *testing.T) { + data := []byte(`{"Results":[{"Target":"img","Class":"os-pkgs","Type":"redhat", +"Packages":[{"Name":"noid","Version":"1","SrcName":"noid-src","Maintainer":"Percona, LLC"}], +"Vulnerabilities":[{"VulnerabilityID":"CVE-2026-9000","PkgName":"other","InstalledVersion":"1","FixedVersion":"2","Severity":"HIGH","Title":"t"}]}]}`) + db, err := store.Open(":memory:") + if err != nil { + t.Fatal(err) + } + defer db.Close() + s := cve.NewScanner(db, hub.New(), 1, cve.WithExecFn(func(ctx context.Context, name string, args ...string) ([]byte, error) { + return data, nil + })) + s.ScanNow(context.Background(), cve.ScanRequest{ + Project: "proj", Package: "mypkg", PrimaryTag: "1.0", + Targets: []model.Target{{Repo: "images", Arch: "x86_64", State: "succeeded"}}, + }) + scans, err := store.QueryCveScans(db, "proj", "mypkg") + if err != nil || len(scans) != 1 || len(scans[0].Findings) != 1 { + t.Fatalf("scans=%v err=%v", scans, err) + } + f := scans[0].Findings[0] + if f.Vendor != "" || f.Src != "" { + t.Errorf("vendor=%q src=%q, want both empty", f.Vendor, f.Src) + } +} diff --git a/backend/internal/cvereport/classify.go b/backend/internal/cvereport/classify.go index 63b0323..93580b4 100644 --- a/backend/internal/cvereport/classify.go +++ b/backend/internal/cvereport/classify.go @@ -30,6 +30,12 @@ const ( goRuntimePkg = "golang" ) +// OursVendor reports whether an RPM vendor is the team's: it starts with +// Percona or obs://. +func OursVendor(vendor string) bool { + return strings.HasPrefix(vendor, "Percona") || strings.HasPrefix(vendor, "obs://") +} + // Classify places one finding. name is the package to bump (or the file // path / package name when no owner is known). Vendor rule: Percona or obs:// // is ours; Red Hat, Inc. or Fedora Project is base OS; anything else is @@ -46,7 +52,7 @@ func Classify(f model.CveFinding) (list, name, kind string) { return ListUnclassified, name, KindUnclassified } switch { - case strings.HasPrefix(f.Vendor, "Percona") || strings.HasPrefix(f.Vendor, "obs://"): + case OursVendor(f.Vendor): return ListOurs, name, KindOBSPackage case f.Vendor == "Red Hat, Inc." || f.Vendor == "Fedora Project": return ListBaseOS, name, KindBaseOS @@ -64,6 +70,9 @@ func classifyLang(f model.CveFinding) (string, string, string) { case f.Type == typeGoBinary: return ListOurs, f.Path, KindBundled } + if f.Path == "" { + return ListOurs, f.PkgName, KindBundled + } return ListOurs, f.PkgName + " (" + f.Path + ")", KindBundled } diff --git a/backend/internal/cvereport/classify_test.go b/backend/internal/cvereport/classify_test.go index 66e15a2..81d00b3 100644 --- a/backend/internal/cvereport/classify_test.go +++ b/backend/internal/cvereport/classify_test.go @@ -26,6 +26,7 @@ func TestClassify(t *testing.T) { {"go library unowned", model.CveFinding{Class: "lang-pkgs", Type: "gobinary", PkgName: "golang.org/x/net", Path: "usr/local/bin/mystery"}, ListOurs, "usr/local/bin/mystery", KindBundled}, {"python owned", model.CveFinding{Class: "lang-pkgs", Type: "python-pkg", PkgName: "dnspython", Path: "usr/lib/python3.12/site-packages/dnspython-2.0.dist-info/METADATA", Owner: "python3.12-dns"}, ListOurs, "python3.12-dns", KindBundled}, {"python unowned", model.CveFinding{Class: "lang-pkgs", Type: "python-pkg", PkgName: "requests", Path: "opt/app/requests-2.0.0.dist-info/METADATA"}, ListOurs, "requests (opt/app/requests-2.0.0.dist-info/METADATA)", KindBundled}, + {"python unowned no path", model.CveFinding{Class: "lang-pkgs", Type: "python-pkg", PkgName: "requests"}, ListOurs, "requests", KindBundled}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -42,3 +43,11 @@ func TestRowKey(t *testing.T) { t.Errorf("got %q", got) } } + +func TestOursVendor(t *testing.T) { + for v, want := range map[string]bool{"Percona, LLC": true, "obs://x/y": true, "Red Hat, Inc.": false, "": false} { + if got := OursVendor(v); got != want { + t.Errorf("OursVendor(%q) = %v", v, got) + } + } +} diff --git a/frontend/src/components/AppHeader.test.ts b/frontend/src/components/AppHeader.test.ts index 47d014c..d86df9d 100644 --- a/frontend/src/components/AppHeader.test.ts +++ b/frontend/src/components/AppHeader.test.ts @@ -1,5 +1,5 @@ // @vitest-environment jsdom -import { describe, it, expect, beforeEach } from 'vitest' +import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest' import { mount } from '@vue/test-utils' import AppHeader from './AppHeader.vue' import { useAuth, resetAuthForTests } from '../composables/useAuth' @@ -7,7 +7,6 @@ import { useUpgrades, resetUpgradesForTests } from '../composables/useUpgrades' import { useRelease, resetReleaseForTests } from '../composables/useRelease' import { useCveReport, resetCveReportForTests } from '../composables/useCveReport' import { resetCveSeenForTests } from '../composables/useCveSeen' -import { vi, afterEach } from 'vitest' function mountHeader() { return mount(AppHeader, { props: { theme: 'light', mainTab: 'overview' } }) diff --git a/frontend/src/components/cve/CveByImageView.vue b/frontend/src/components/cve/CveByImageView.vue new file mode 100644 index 0000000..9b7f55a --- /dev/null +++ b/frontend/src/components/cve/CveByImageView.vue @@ -0,0 +1,19 @@ + + + diff --git a/frontend/src/components/cve/CvePanel.test.ts b/frontend/src/components/cve/CvePanel.test.ts index ab00059..f99b526 100644 --- a/frontend/src/components/cve/CvePanel.test.ts +++ b/frontend/src/components/cve/CvePanel.test.ts @@ -56,6 +56,17 @@ describe('CvePanel', () => { expect(w.findComponent({ name: 'CveExposureTable' }).exists()).toBe(true) }) + it('fetches overview data only while the By image view is shown', async () => { + stubFetch(true) + const overviewCalls = () => (fetch as unknown as ReturnType).mock.calls.filter(c => String(c[0]).startsWith('/api/overview')).length + const w = mount(CvePanel, { props: { view: 'staging' } }) + await flushPromises() + expect(overviewCalls()).toBe(0) + await w.setProps({ view: 'images' }) + await flushPromises() + expect(overviewCalls()).toBeGreaterThan(0) + }) + it('emits update:view when a segment is clicked', async () => { stubFetch(true) const w = mount(CvePanel, { props: { view: 'staging' } }) @@ -69,13 +80,18 @@ describe('CvePanel', () => { stubFetch(false) const w = mount(CvePanel, { props: { view: 'staging' } }) await w.vm.$nextTick() - // the panel itself does not start the fetch; trigger it through Retry-less path + // the panel does not start the fetch itself; trigger the first (failing) load here const { useCveReport } = await import('../../composables/useCveReport') await useCveReport().refresh() await flushPromises() const err = w.find('[data-testid="cve-report-error"]') expect(err.exists()).toBe(true) expect(err.find('button').text()).toBe('Retry') + stubFetch(true) + await err.find('button').trigger('click') + await flushPromises() + expect(w.find('[data-testid="cve-report-error"]').exists()).toBe(false) + expect(w.findComponent({ name: 'CveStagingView' }).exists()).toBe(true) await w.setProps({ view: 'images' }) await flushPromises() expect(w.findComponent({ name: 'CveExposureTable' }).exists()).toBe(true) diff --git a/frontend/src/components/cve/CvePanel.vue b/frontend/src/components/cve/CvePanel.vue index acb7817..822904e 100644 --- a/frontend/src/components/cve/CvePanel.vue +++ b/frontend/src/components/cve/CvePanel.vue @@ -1,11 +1,8 @@