Skip to content

fix(vulns): GHSA advisory references are string-array, not [{url}] (repairs enrichment) - #110

Merged
msitarzewski merged 1 commit into
mainfrom
fix/ghsa-references-shape
Jul 12, 2026
Merged

msitarzewski merged 1 commit into
mainfrom
fix/ghsa-references-shape

Conversation

@msitarzewski

Copy link
Copy Markdown
Owner

Live verification (fetching a real advisory from api.github.com) caught a latent parser bug.

The bug

GET /advisories/{ghsa_id} returns references as an array of plain URL strings:

"references": ["https://github.com/.../GHSA-…"]

…but both parsers modeled it as [{ "url": … }] objects.

  • Rust (enrich.rs, since v0.5.0): a present field with the wrong element type makes the whole RawAdvisory deserialize fail → fetch_advisory_with returns Ok(None)GHSA enrichment was a silent no-op for any advisory with references (≈ all of them).
  • Swift (VulnsEnrich.swift): tolerant per-field decode kept summary/details/fixed-in working but silently dropped all references.

The fix

RawReference now accepts both shapes — an untagged enum in Rust, a custom decoder in Swift — so neither the real string shape nor the object shape (nor a future change) can silently break enrichment.

Why we missed it

The unit-test fixtures used the invented [{url}] shape — the same wrong assumption as the code — so they validated a shape the real API never sends. Fixtures are now corrected to the real captured shape (string array), plus a both-shapes regression test in each shell.

Tests

cargo enrich 17, swift 171 (each +1). clippy clean.

🤖 Generated with Claude Code

The global advisories endpoint (`GET api.github.com/advisories/{id}`) returns
`references` as an array of plain URL STRINGS, but both the Rust enrich layer
and its Swift port modeled it as `[{ "url": … }]` objects. Consequences:
- Rust: a present-but-wrong-type `references` made the WHOLE `RawAdvisory`
  parse fail, so `fetch_advisory_with` returned `Ok(None)` — GHSA enrichment
  was a silent no-op for essentially every advisory (latent since v0.5.0).
- Swift: tolerant per-field decode kept summary/details/fixed-in working but
  silently dropped all references.

Both `RawReference` parsers now accept BOTH shapes (untagged enum in Rust, a
custom decoder in Swift) so neither endpoint variant nor a future change can
silently disable enrichment again.

Root cause of the miss: the unit-test fixtures used the invented `[{url}]`
shape — the same wrong assumption as the code — so they passed against a shape
the real API never sends. Fixtures are now corrected to the REAL captured
shape (string array), plus a both-shapes regression test in each shell.

Tests: cargo enrich 17, swift 171 (each +1). clippy clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@msitarzewski

Copy link
Copy Markdown
Owner Author

Verification status

Should be fixed — verified against live api.github.com, but not driven end-to-end in the GUI (no GHSA test subject available).

What was checked:

  • Live fetch through the real code path — ran the app's actual build_client() + fetch_advisory_with() against GET api.github.com/advisories/GHSA-jfvp-7x6p-h2pv. On this branch it returns Ok(Some(advisory)) with 9 references (plus summary/severity/first-fix) populated. On main the same call returns Ok(None) — enrichment silently no-ops.
  • Unit tests green both shells — cargo vulns::enrich 17/17, swift VulnsEnrichTests 17/17, each including a new both-shapes (string-array and legacy [{url}]) regression test.
  • Fixtures corrected from the invented [{url}] shape to the real captured string-array shape.

What was not verified:

  • The in-app render. Couldn't reach it locally: brew vulns on the test machine returns 15 flagged formulae, but every id is CVE-…/OSV-…zero GHSA-…, and enrichment only fires for GHSA-primary ids. This PR only touches the parser (not the render), so this gap is low-risk — but it wasn't exercised through the UI.

If you're running with GitHub sign-in on and have a package that surfaces a GHSA advisory, please confirm the enriched references now show on the Security card (they were blank before) — or let us know if anything looks off.

@msitarzewski
msitarzewski merged commit 6799e98 into main Jul 12, 2026
@msitarzewski
msitarzewski deleted the fix/ghsa-references-shape branch July 12, 2026 21:59
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.

1 participant