| 1 | --- |
| 2 | name: graphql-audit |
| 3 | description: Triage GitHub Code Scanning alerts (CodeQL with security-extended suite) for this repository — list open alerts, dismiss as false positive / won't fix / used in tests, query via GitHub REST + GraphQL. Use when the user asks to "review GitHub security alerts", "check CodeQL findings", "triage code scanning", or anything mentioning Code Scanning, CodeQL, security-extended, or github.com/$repo/security/code-scanning. |
| 4 | --- |
| 5 | |
| 6 | # GitHub Code Scanning triage skill |
| 7 | |
| 8 | This skill drives the GitHub Code Scanning API (REST + GraphQL via `gh`) for |
| 9 | the repository's CodeQL alerts. The repo's CI runs the **security-extended** |
| 10 | CodeQL suite, which surfaces a wider set of findings than the default suite. |
| 11 | |
| 12 | The skill operates on whatever repo this checkout points at — it derives the |
| 13 | `owner/repo` from the `upstream` (or `origin`) git remote. Auth uses the |
| 14 | `gh` CLI's stored credentials; no token is needed in `.env`. |
| 15 | |
| 16 | ## MANDATORY — keep this skill alive |
| 17 | |
| 18 | **If you (the agent) discover a new pattern, gotcha, working flow, correction, |
| 19 | or any piece of knowledge while running this skill — update this `SKILL.md` |
| 20 | AND commit it BEFORE proceeding. Knowledge that isn't committed is lost.** |
| 21 | |
| 22 | Examples of things to capture: |
| 23 | - A CodeQL rule with a known FP pattern + the canonical comment to use |
| 24 | - A query (GraphQL or REST) that returns useful aggregate views not available in the UI |
| 25 | - An alert format change or new field that started appearing |
| 26 | - A way to bulk-dismiss without hitting REST rate limits |
| 27 | |
| 28 | ## Setup |
| 29 | |
| 30 | ### Prerequisite — `gh` CLI authenticated |
| 31 | |
| 32 | ``` |
| 33 | gh auth status |
| 34 | ``` |
| 35 | |
| 36 | Must show authentication for github.com. If not, run `gh auth login`. |
| 37 | |
| 38 | The `gh` user needs **write** scope on the repository to dismiss alerts; |
| 39 | read scope is enough for listing. |
| 40 | |
| 41 | ### .env entries |
| 42 | |
| 43 | None required for this skill. `gh` handles auth. |
| 44 | |
| 45 | (Optional `GITHUB_TOKEN` could go in `.env` if you ever need to bypass `gh` |
| 46 | and call REST/GraphQL directly via curl, e.g. from a script that runs |
| 47 | without an authenticated `gh` session.) |
| 48 | |
| 49 | ## Triage decision matrix |
| 50 | |
| 51 | GitHub Code Scanning alerts have three lifecycle states: `open`, `dismissed`, |
| 52 | `fixed` (auto-detected when the underlying code changes). Manual triage uses |
| 53 | `dismissed` with one of three reasons: |
| 54 | |
| 55 | | Decision | API value | When to use | |
| 56 | |------------------|-------------------|---------------------------------------------------------------------| |
| 57 | | False Positive | `false positive` | CodeQL is wrong (path is unreachable, type is wider, guard exists) | |
| 58 | | Won't Fix | `won't fix` | Real but acceptable risk; not addressing in this codebase | |
| 59 | | Used in Tests | `used in tests` | Alert is in test fixtures / vendored test code, not production | |
| 60 | |
| 61 | A dismissed alert can be **reopened** later (manually in the UI or via |
| 62 | `PATCH /alerts/<n>` with `state=open`); the dismissal history is preserved. |
| 63 | |
| 64 | ## Workflow |
| 65 | |
| 66 | ### Step 1 — see what's open |
| 67 | |
| 68 | ``` |
| 69 | bash .agents/skills/graphql-audit/scripts/codeql-list.sh |
| 70 | ``` |
| 71 | |
| 72 | Default output is a count-by-rule summary for **open** alerts: |
| 73 | |
| 74 | ``` |
| 75 | 42 cpp/integer-overflow|warning |
| 76 | 17 cpp/uninitialized-local|error |
| 77 | ... |
| 78 | ``` |
| 79 | |
| 80 | Filters: |
| 81 | ``` |
| 82 | bash .agents/skills/graphql-audit/scripts/codeql-list.sh --state=open --severity=high |
| 83 | bash .agents/skills/graphql-audit/scripts/codeql-list.sh --tool=CodeQL --severity=critical |
| 84 | bash .agents/skills/graphql-audit/scripts/codeql-list.sh --raw # full JSON |
| 85 | ``` |
| 86 | |
| 87 | ### Step 2 — inspect a single alert |
| 88 | |
| 89 | ``` |
| 90 | gh api /repos/<owner>/<repo>/code-scanning/alerts/<n> |
| 91 | ``` |
| 92 | |
| 93 | Or visit `https://github.com/<owner>/<repo>/security/code-scanning/<n>` in |
| 94 | the browser for the full data-flow view. |
| 95 | |
| 96 | ### Step 3 — dismiss |
| 97 | |
| 98 | ``` |
| 99 | bash .agents/skills/graphql-audit/scripts/codeql-dismiss.sh \ |
| 100 | <alert_number> "false positive" "<short ASCII comment>" |
| 101 | ``` |
| 102 | |
| 103 | Comments are stored verbatim; keep them short, factual, and ASCII. |
| 104 | |
| 105 | ### Step 4 — bulk dismissal |
| 106 | |
| 107 | For a known-FP rule pattern (e.g., `cpp/uninitialized-local` always firing |
| 108 | on a particular header), GitHub does NOT have a REST bulk endpoint. The |
| 109 | working pattern is: |
| 110 | |
| 111 | ```bash |
| 112 | bash .agents/skills/graphql-audit/scripts/codeql-list.sh --raw \ |
| 113 | | jq -r '.[] | select(.rule.id=="cpp/uninitialized-local") | .number' \ |
| 114 | | while read n; do |
| 115 | bash .agents/skills/graphql-audit/scripts/codeql-dismiss.sh \ |
| 116 | "$n" "false positive" "FP: rule firing on a stub model not real code" |
| 117 | done |
| 118 | ``` |
| 119 | |
| 120 | Throttle if you have many — the REST API tolerates ~10 req/s for a single |
| 121 | user. |
| 122 | |
| 123 | ## What this skill does NOT do |
| 124 | |
| 125 | - **CodeQL query authoring**: this skill triages results, not the queries |
| 126 | that produce them. To suppress a class of FPs at the source, edit |
| 127 | `.github/codeql/` config or the queries themselves. |
| 128 | - **Workflow management**: enabling/disabling CodeQL runs is in |
| 129 | `.github/workflows/codeql.yml` — not here. |
| 130 | - **Other Advanced Security features** (secret scanning alerts, dependabot) |
| 131 | use sibling APIs (`/secret-scanning/alerts`, `/dependabot/alerts`). They |
| 132 | could be added to this skill if needed. |
| 133 | |
| 134 | ## REST vs GraphQL |
| 135 | |
| 136 | CodeQL alerts are exposed via REST (`/repos/{owner}/{repo}/code-scanning/...`). |
| 137 | GraphQL (`gh api graphql`) is useful for cross-repo queries or reaching |
| 138 | combined data (e.g., alert + commit history in one call): |
| 139 | |
| 140 | ``` |
| 141 | gh api graphql -f query=' |
| 142 | query($owner:String!,$name:String!) { |
| 143 | repository(owner:$owner, name:$name) { |
| 144 | vulnerabilityAlerts(first: 100, states:OPEN) { |
| 145 | nodes { securityAdvisory { ghsaId, severity } } |
| 146 | } |
| 147 | } |
| 148 | }' -F owner=netdata -F name=netdata |
| 149 | ``` |
| 150 | |
| 151 | The above is for **Dependabot** advisories, not CodeQL — CodeQL alerts |
| 152 | remain REST-only at the time of writing. |
| 153 | |
| 154 | ## Failure modes — quick diagnosis |
| 155 | |
| 156 | | Symptom | Likely cause | |
| 157 | |------------------------------------------|---------------------------------------------------------| |
| 158 | | `HTTP 403 Resource not accessible by integration` | gh token lacks `security_events` scope | |
| 159 | | `HTTP 404` on the alerts endpoint | Code Scanning not enabled for the repo, or wrong slug | |
| 160 | | `gh: not found` | gh CLI not installed | |
| 161 | | Empty output, no error | No alerts in that state — try `--state=dismissed` to confirm gh is reaching the API | |
| 162 | | Pagination cuts off at 100 | Use `--paginate` (already in `codeql-list.sh`) | |