|
| 1 | +--- |
| 2 | +description: Find duplicate reports among the GitHub private vulnerability (GHSA) exports and write .github/ghsa/ghsa-dupes.md |
| 3 | +argument-hint: "[use existing files]" |
| 4 | +allowed-tools: Bash(scripts/ghsa/*), Bash(scripts/collect-ghsa-reports.sh), Read, Write, Edit, Agent |
| 5 | +--- |
| 6 | + |
| 7 | +# GHSA Duplicate Detection |
| 8 | + |
| 9 | +Find duplicate reports among the GitHub private vulnerability (GHSA) exports in |
| 10 | +`.github/ghsa`. The output of a run is `.github/ghsa/ghsa-dupes.md`. |
| 11 | + |
| 12 | +All paths are relative to the repository root; run the scripts from there. The helper |
| 13 | +scripts live in `scripts/ghsa/` and are run as-is -- **do not rewrite or inline them**. |
| 14 | + |
| 15 | +User arguments: `$ARGUMENTS` |
| 16 | + |
| 17 | +## Goal |
| 18 | + |
| 19 | +Given the JSON exports of GitHub Security Advisory reports (in `triage` and `draft` |
| 20 | +states), identify clusters of reports that describe the **same underlying vulnerability**, |
| 21 | +so they can be de-duplicated during triage. The `published` advisories are searched as |
| 22 | +well, but only in one direction: an open report may turn out to duplicate something already |
| 23 | +published. Published advisories are set in stone and are never changed by this exercise. |
| 24 | + |
| 25 | +**Definition of a true duplicate** (the bar every cluster must clear): |
| 26 | + |
| 27 | +> Two or more reports share the **same root cause** AND the **same vulnerable code |
| 28 | +> location / function** AND essentially the **same attack and impact**. |
| 29 | +
|
| 30 | +Explicitly **not** duplicates: |
| 31 | +- Same component/file but a *different* function or root cause. |
| 32 | +- Different protocol or code path (e.g. HTTP/1 codec-http vs HTTP/2 codec-http2) even if |
| 33 | + the *class* of bug is identical ("sibling" findings). |
| 34 | +- Most "incomplete fix" variants -- they usually target a different code path than the |
| 35 | + original. Only group them if they point at the same line / root cause. |
| 36 | + |
| 37 | +When in doubt, keep them separate and add a note. It is cheaper to under-merge (flag an |
| 38 | +overlap for a human) than to wrongly collapse two distinct vulnerabilities. |
| 39 | + |
| 40 | +## Inputs |
| 41 | + |
| 42 | +- `.github/ghsa/triage/GHSA-*.json` -- reports in the triage state. |
| 43 | +- `.github/ghsa/draft/GHSA-*.json` -- reports in the draft state. |
| 44 | +- `.github/ghsa/published/GHSA-*.json` -- published advisories, read-only reference: an open |
| 45 | + report matching one of these is a re-report of a known CVE. |
| 46 | + |
| 47 | +`.github/ghsa/closed/*.json` is **not** an input. Closed reports were already dispositioned |
| 48 | +as duplicates or as not relevant, and a real duplicate of one would have its original in |
| 49 | +`draft` or `published` anyway. |
| 50 | + |
| 51 | +All three input directories share the same JSON schema. Each file is named |
| 52 | +`<GHSA-ID>.json`. Relevant fields: |
| 53 | + |
| 54 | +| Field | Use | |
| 55 | +|-------|-----| |
| 56 | +| `ghsa_id` | Identity. | |
| 57 | +| `summary` | One-line title -- primary clustering signal. | |
| 58 | +| `description` | Full technical detail: root cause, vulnerable file/function, PoC, fix. **This is what confirms a duplicate.** | |
| 59 | +| `vulnerabilities[].package` + `vulnerable_version_range` | Component -- primary clustering signal. | |
| 60 | +| `cwe_ids` | Weak signal for clustering. | |
| 61 | +| `created_at` | Ordering within a cluster (oldest = presumptive original). | |
| 62 | +| `author.login` | Provenance; helps spot maintainer-authored drafts. | |
| 63 | +| `state` | `triage` / `draft` (open, actionable) vs `published` (reference only). | |
| 64 | +| `cve_id` | Set on published advisories -- the handle to cite when an open report duplicates one. | |
| 65 | + |
| 66 | +The bulk of each file is author/URL boilerplate -- ignore it. |
| 67 | + |
| 68 | +## Why not just read everything |
| 69 | + |
| 70 | +At over 150 reports and several MB of raw JSON, the full corpus is large and mostly boilerplate. |
| 71 | +The efficient path is: **extract a tiny index, cluster from the index, then read only the |
| 72 | +full descriptions of candidate clusters** (fan out to sub-agents so no single context |
| 73 | +holds all descriptions). |
| 74 | + |
| 75 | +## Procedure |
| 76 | + |
| 77 | +### Step 0 -- Make sure the extracted reports are fresh |
| 78 | + |
| 79 | +1. Run `scripts/ghsa/check-freshness.sh`. It exits 0 if every extracted `GHSA-*.json` file is |
| 80 | + at most 4 hours old (override with `GHSA_MAX_AGE_MINUTES`), 1 if some file is older, and 2 if |
| 81 | + there are no files at all. |
| 82 | +2. Exit 0: continue to step 1. |
| 83 | +3. Exit 1 or 2: run `scripts/collect-ghsa-reports.sh`. It needs `gh` (authenticated against |
| 84 | + `netty/netty` with access to security advisories) and `jq`, and it first deletes every |
| 85 | + `*.json` file under `.github/ghsa` before re-downloading, so it can take a while. |
| 86 | +4. If the collect script succeeds, run `scripts/ghsa/check-freshness.sh` again and continue |
| 87 | + only once it exits 0. |
| 88 | +5. If the collect script fails (missing tool, no auth, no network, sandbox restrictions, ...), |
| 89 | + do not try to work around it. Tell the user what failed and ask them to run it |
| 90 | + themselves, then continue once they confirm. |
| 91 | + The only exception is when the user explicitly insists on deduplicating the |
| 92 | + existing files (including via the arguments above): then skip the refresh, say in the final |
| 93 | + report that the data may be outdated, and proceed. Because the script deletes the old files |
| 94 | + before downloading, a failed run may leave the directory empty or partial: re-run |
| 95 | + `scripts/ghsa/check-freshness.sh` and, if it exits 2, there is nothing to deduplicate, so |
| 96 | + the user must run the collect script. |
| 97 | + |
| 98 | +If the user's arguments already say to use the existing files, skip this step. |
| 99 | + |
| 100 | +### Step 1 -- Extract a compact index |
| 101 | + |
| 102 | +Run `python3 scripts/ghsa/extract-index.py`. It walks the three input directories and writes: |
| 103 | + |
| 104 | +- `/tmp/reports.json` -- per report: `ghsa_id`, `state`, `created_at`, `severity`, |
| 105 | + `author`, `cve_id`, `cwe_ids`, `packages`, `summary`, `description`. Sorted by `created_at`. |
| 106 | +- `/tmp/index.json` -- the same **minus `description`** (the scannable overview). |
| 107 | + |
| 108 | +It prints the number of reports per state; sanity-check that against the directories. |
| 109 | + |
| 110 | +### Step 2 -- Cluster candidates from the index |
| 111 | + |
| 112 | +Read `/tmp/index.json` and group reports into **candidate clusters** by (a) affected |
| 113 | +package/component and (b) summary/mechanism. Err toward *over*-grouping here -- this stage |
| 114 | +only decides what to read together; false candidates get rejected in step 3. |
| 115 | + |
| 116 | +Cluster **across states**: a `triage` report and a `published` advisory on the same |
| 117 | +component belong in the same candidate cluster. Drop any candidate cluster made up |
| 118 | +entirely of `published` advisories -- duplicates among those are not actionable. Every |
| 119 | +cluster carried into step 3 must contain at least one `triage` or `draft` report. |
| 120 | + |
| 121 | +Watch for these recurring, easy-to-confuse families (they need care in step 3): |
| 122 | +- Multiple "incomplete fix of CVE-XXXX" reports on the same component. |
| 123 | +- Protocol-downgrade / request-smuggling variants (H1/H2/H3, `:authority`/`Host`/`:path`, |
| 124 | + Transfer-Encoding, chunk-size parsing). |
| 125 | +- `maxAllocation` / decompression-bomb reports across different codecs (br/zstd/snappy, |
| 126 | + websocket deflate, bzip2, lz4). |
| 127 | +- QPACK / HPACK DoS variants. |
| 128 | + |
| 129 | +### Step 3 -- Confirm clusters by reading full descriptions (fan out) |
| 130 | + |
| 131 | +Split the candidate clusters across several sub-agents (about 4 worked well; keep related |
| 132 | +clusters with the same agent so it has the context to judge). Each agent reads the full |
| 133 | +`description` of every report in its assigned clusters directly from the JSON files and |
| 134 | +returns, per cluster: |
| 135 | + |
| 136 | +1. Which GHSA-IDs are **true duplicates** (grouped), and which stand alone. |
| 137 | +2. For every report: `ghsa_id`, `created_at`, `author`, `state`, and `cve_id` if set. |
| 138 | +3. A 1-2 sentence rationale citing the **specific shared or differing root cause / |
| 139 | + vulnerable function / file**. |
| 140 | + |
| 141 | +Give every agent the same duplicate definition (above). Instruct them to be |
| 142 | +evidence-based, to explicitly call out non-duplicates, and to write no files. |
| 143 | + |
| 144 | +**Boundary risk:** duplicates that straddle two agents' assignments can be missed. Keep |
| 145 | +topically related clusters (e.g. all request-smuggling variants) with a single agent, and |
| 146 | +in the assignment note tell each agent which neighboring reports exist so it can flag a |
| 147 | +cross-boundary match. |
| 148 | + |
| 149 | +### Step 4 -- Synthesize the report |
| 150 | + |
| 151 | +Consolidate agent verdicts into `.github/ghsa/ghsa-dupes.md`: |
| 152 | + |
| 153 | +- Keep only confirmed duplicate clusters (2+ reports). |
| 154 | +- **Order reports within each cluster by `created_at`, oldest first**; mark the oldest as |
| 155 | + "(original)". |
| 156 | +- Order the clusters themselves by their oldest member's `created_at`. |
| 157 | +- For each cluster: a "Same bug:" paragraph (shared root cause + vulnerable function) and |
| 158 | + a table of `created_at | GHSA | state | author`. |
| 159 | +- Give clusters where an open report duplicates a `published` advisory their own section -- |
| 160 | + the disposition is "close as duplicate of <CVE/GHSA>", not a merge of two open reports. |
| 161 | +- Add a **"Notable non-duplicates"** section listing the families that were considered and |
| 162 | + rejected, with a one-line reason each -- this shows they were examined, not missed. |
| 163 | +- Flag caveats inline: near-duplicates/overlaps, reports that bridge two clusters, and |
| 164 | + maintainer-authored drafts (which may be the project's own canonical write-up rather than |
| 165 | + a true duplicate -- consider which report in a cluster should be called the "original"). |
| 166 | +- If step 0 was skipped because the user insisted on the existing files, say so at the top |
| 167 | + of the report, together with the age of the data if known. |
| 168 | + |
| 169 | +**Never put a GHSA ID in backticks.** A markdown link inside a code span renders as literal |
| 170 | +text, not a clickable link. Write GHSA IDs bare and let step 5 wrap them. Backticks are for |
| 171 | +code identifiers only (file names, methods, fields); a GHSA ID is neither. Bold is fine: |
| 172 | +`**[id](url)**` renders correctly. |
| 173 | + |
| 174 | +### Step 5 -- Linkify and verify |
| 175 | + |
| 176 | +Run `python3 scripts/ghsa/linkify.py`. It makes every `GHSA-####-####-####` reference in |
| 177 | +`.github/ghsa/ghsa-dupes.md` a link to the advisory (idempotent), then verifies the result and |
| 178 | +prints three counts -- backticked links, double-wrapped links, unlinked IDs. It exits non-zero |
| 179 | +unless all three are zero; if it does, fix the markdown and re-run. |
| 180 | + |
| 181 | +## Notes / gotchas |
| 182 | + |
| 183 | +- **`created_at` is the tiebreaker for "original".** But a maintainer's `draft` may be an |
| 184 | + internal tracking advisory filed *after* an external report -- note this rather than |
| 185 | + blindly calling the earliest the original. |
| 186 | +- **Sibling is not duplicate.** The same bug class in codec-http vs codec-http2 vs codec-http3, |
| 187 | + or in encode vs decode paths, is almost always two distinct findings. |
| 188 | +- **Read the description, not just the summary.** Summaries of distinct bugs often look |
| 189 | + near-identical (e.g. several "SmtpResponseDecoder ... DoS" titles that are genuinely the |
| 190 | + same, vs several "Transfer-Encoding smuggling" titles that are not). |
| 191 | +- Re-running is cheap: only the contents of the input directories change between runs. |
| 192 | + Re-run step 0, regenerate the index and repeat. |