Przeglądaj źródła

feat(security): track advisory progress with status tags (#1176)

James Read 2 dni temu
rodzic
commit
fcaf50ae81
4 zmienionych plików z 163 dodań i 0 usunięć
  1. 22 0
      .github/SECURITY_ADVISORY_DUPLICATES.md
  2. 1 0
      AGENTS.md
  3. 3 0
      SECURITY.md
  4. 137 0
      scripts/ghsa_status.py

+ 22 - 0
.github/SECURITY_ADVISORY_DUPLICATES.md

@@ -12,6 +12,28 @@ This document lists known duplicate security advisory clusters for [OliveTin/Oli
 4. If unique: accept, patch on a private branch, reassess CVSS with OliveTin context (see SECURITY.md — OliveTin is intentional RCE by design).
 5. Merge fix to `next`, publish advisory, credit reporters in advisory body (not commit message).
 
+Keep each advisory's status tag up to date throughout (see below).
+
+---
+
+## Status tags
+
+Every advisory in triage or draft has one `[status:...]` tag at the end of its summary, so maintainers and reporters can see where it is. Set it with `scripts/ghsa_status.py <GHSA-ID> <status>`, and check all advisories with `scripts/ghsa_status.py --list` (it exits non-zero if any tag is missing, unknown, or left on a published or closed advisory).
+
+| Status | Advisory state | Set when |
+|--------|----------------|----------|
+| `pending-review` | triage | A new report arrives and has not been decided yet. |
+| `awaiting-reporter` | triage or draft | Questions have been asked and the reporter's reply is needed. |
+| `accepted` | draft | The report is accepted and a fix is not yet ready for review. |
+| `feedback-on-fix` | draft | The fix PR is open in the private advisory fork, waiting for review or merge. |
+| `pending-release` | draft | The fix is merged to `next` and is waiting for a release before publishing. |
+
+Remove the tag with `scripts/ghsa_status.py <GHSA-ID> clear`:
+
+- before publishing an advisory;
+- before closing an advisory;
+- before requesting a CVE, so the tag does not end up in the CVE record.
+
 ---
 
 ## shellAfterCompleted command injection

+ 1 - 0
AGENTS.md

@@ -100,6 +100,7 @@ Security advisory fixes follow the process in `SECURITY.md`:
 - Supporting commits in the same PR (for example docs or an upgrade note) use their normal type, and may mention the advisory ID.
 - `security:` commits trigger a patch release and are listed under **Security** in the release notes. Do not use `fix:` for advisory fixes, or they will be listed as bug fixes.
 - When an advisory is closed as not a vulnerability but still worth fixing, the fix is an ordinary public `fix:` commit against `next`, without the advisory ID.
+- Every triage or draft advisory carries a `[status:...]` tag at the end of its summary. Update it with `scripts/ghsa_status.py <GHSA-ID> <status>` whenever you change an advisory's state, ask the reporter a question, open a fork PR, or merge a fix; clear it with `clear` before publishing, closing, or requesting a CVE. The statuses and when to use them are listed in `.github/SECURITY_ADVISORY_DUPLICATES.md` under "Status tags". Run `scripts/ghsa_status.py --list` to check them.
 
 ### Branch Naming
 Use conventional-commit-style branch names with a type prefix, optional issue reference, and a short kebab-case description:

+ 3 - 0
SECURITY.md

@@ -119,6 +119,9 @@ The following have been reported several times and reviewed. Please only report
 
 Once a vulnerability is reported, the process is;
 
+While a report is open, a `[status:...]` tag at the end of the advisory's title shows where it is: `pending-review`, `awaiting-reporter`, `accepted`, `feedback-on-fix` (a fix is ready for review), or `pending-release` (the fix is merged and will be published with the next release). The tag is removed when the advisory is published or closed.
+
+
 * Check [.github/SECURITY_ADVISORY_DUPLICATES.md](.github/SECURITY_ADVISORY_DUPLICATES.md) and open advisories for duplicates before accepting.
 * Confirm the report reproduces on the latest published 3k release or the `next` branch before accepting it or requesting a CVE.
 * Accept or reject the report, and communicate with the reporter about next steps.

+ 137 - 0
scripts/ghsa_status.py

@@ -0,0 +1,137 @@
+#!/usr/bin/env python3
+"""Set or list the [status:...] tag on OliveTin's repository security advisories.
+
+Advisories in triage or draft carry a status tag at the end of their summary,
+so maintainers and reporters can see where each one is. The tag is removed
+when an advisory is published or closed, and before a CVE is requested.
+
+Usage:
+    ghsa_status.py --list
+    ghsa_status.py <GHSA-ID> <status>
+    ghsa_status.py <GHSA-ID> clear
+
+Statuses: pending-review, awaiting-reporter, accepted, feedback-on-fix,
+pending-release. Requires the GitHub CLI (gh), authenticated with access to
+the repository's security advisories.
+"""
+
+from __future__ import annotations
+
+import json
+import re
+import subprocess
+import sys
+
+REPO = "OliveTin/OliveTin"
+
+STATUSES = (
+    "pending-review",
+    "awaiting-reporter",
+    "accepted",
+    "feedback-on-fix",
+    "pending-release",
+)
+
+OPEN_STATES = ("triage", "draft")
+
+TRAILING_TAGS_PATTERN = re.compile(r"(?:\s*\[status:[^\]]*\])+\s*$")
+TAG_PATTERN = re.compile(r"\[status:([^\]]*)\]")
+GHSA_PATTERN = re.compile(r"^GHSA(-[23456789cfghjmpqrvwx]{4}){3}$")
+
+
+def gh_api(path: str, method: str = "GET", body: dict | None = None, paginate: bool = False) -> object:
+    command = ["gh", "api", "-X", method, path]
+    if paginate:
+        command += ["--paginate", "--slurp"]
+    if body is not None:
+        command += ["--input", "-"]
+    result = subprocess.run(
+        command,
+        input=json.dumps(body) if body is not None else None,
+        capture_output=True,
+        text=True,
+        check=False,
+    )
+    if result.returncode != 0:
+        raise SystemExit(f"gh api {method} {path} failed: {result.stderr.strip() or result.stdout.strip()}")
+    return json.loads(result.stdout)
+
+
+def strip_status(summary: str) -> str:
+    return TRAILING_TAGS_PATTERN.sub("", summary).rstrip()
+
+
+def status_tags(summary: str) -> list[str]:
+    match = TRAILING_TAGS_PATTERN.search(summary)
+    if not match:
+        return []
+    return TAG_PATTERN.findall(match.group(0))
+
+
+def has_valid_status(tags: list[str]) -> bool:
+    return len(tags) == 1 and tags[0] in STATUSES
+
+
+def with_status(summary: str, status: str) -> str:
+    base = strip_status(summary)
+    if status == "clear":
+        return base
+    return f"{base} [status:{status}]"
+
+
+def list_advisories() -> int:
+    pages = gh_api(f"/repos/{REPO}/security-advisories?per_page=100", paginate=True)
+    advisories = [advisory for page in pages for advisory in page]
+    problems = 0
+
+    for advisory in advisories:
+        tags = status_tags(advisory["summary"])
+        is_open = advisory["state"] in OPEN_STATES
+
+        note = ""
+        if is_open and not has_valid_status(tags):
+            note = "  <- missing, unknown or multiple statuses"
+            problems += 1
+        elif not is_open and tags:
+            note = "  <- should not have a status"
+            problems += 1
+
+        if is_open or tags:
+            shown = ",".join(tag or "(empty)" for tag in tags) or "-"
+            print(f"{advisory['ghsa_id']}  {advisory['state']:<9} {shown:<18} {strip_status(advisory['summary'])}{note}")
+
+    return 1 if problems else 0
+
+
+def set_status(ghsa_id: str, status: str) -> int:
+    if not GHSA_PATTERN.match(ghsa_id):
+        raise SystemExit(f"Not a GHSA ID: {ghsa_id}")
+    if status != "clear" and status not in STATUSES:
+        raise SystemExit(f"Unknown status '{status}'. Use one of: {', '.join(STATUSES)}, or clear")
+
+    advisory = gh_api(f"/repos/{REPO}/security-advisories/{ghsa_id}")
+    if status != "clear" and advisory["state"] not in OPEN_STATES:
+        raise SystemExit(f"{ghsa_id} is {advisory['state']}; only triage and draft advisories carry a status")
+
+    summary = with_status(advisory["summary"], status)
+    if summary == advisory["summary"]:
+        print(f"{ghsa_id} already has that status.")
+        return 0
+
+    updated = gh_api(f"/repos/{REPO}/security-advisories/{ghsa_id}", method="PATCH", body={"summary": summary})
+    print(f"{ghsa_id}: {updated['summary']}")
+    return 0
+
+
+def main(argv: list[str]) -> int:
+    if argv[1:] == ["--list"]:
+        return list_advisories()
+    if len(argv) == 3:
+        return set_status(argv[1], argv[2])
+
+    print(__doc__, file=sys.stderr)
+    return 2
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))