diff --git a/changelog.d/added-code-scanning-issues.md b/changelog.d/added-code-scanning-issues.md new file mode 100644 index 0000000000..50ed480f49 --- /dev/null +++ b/changelog.d/added-code-scanning-issues.md @@ -0,0 +1 @@ +- Added an opt-in code scanning sweep (`code_scanning`, off by default, per repo): it files a repository's open GitHub code scanning alerts (CodeQL, OSSF Scorecard, Trivy, …) at or above `min_severity` (default `high`) as grouped `[governor] Code scanning: …` issues sized for one PR, at most five new issues per repo per hourly pass, updates them as alerts are added, fixed or dismissed, and closes them when every alert is gone. OSSF Scorecard's repo-posture checks are left out by default. It needs the GitHub App permission "Code scanning alerts: Read-only"; without it the dashboard shows a notice for the repo. See `src/docs/code-scanning.md`. diff --git a/src/cmd/hive/code_scanning.go b/src/cmd/hive/code_scanning.go new file mode 100644 index 0000000000..929f9d7a7b --- /dev/null +++ b/src/cmd/hive/code_scanning.go @@ -0,0 +1,25 @@ +package main + +import ( + "context" + "log/slog" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" +) + +// runCodeScanningSweep is the code_scanning sweep job: one pass of the +// opt-in code scanning sweep over every repo it is enabled on +// (src/docs/code-scanning.md). The worker already sheds it outside normal +// API budget mode; the client re-checks between repos. +func runCodeScanningSweep(ctx context.Context, ghClient *github.Client, cfg *config.Config, logger *slog.Logger) { + if ghClient == nil || cfg == nil { + return + } + res := ghClient.RunCodeScanningSweep(ctx, cfg, time.Now()) + if logger != nil && (res.Errors > 0 || res.BudgetSkipped) { + logger.Info("code scanning sweep", "repos", res.Repos, "filed", res.Filed, "updated", res.Updated, + "closed", res.Closed, "errors", res.Errors, "budget_skipped", res.BudgetSkipped) + } +} diff --git a/src/cmd/hive/sweep_workers.go b/src/cmd/hive/sweep_workers.go index 2928a06633..b23d4c1047 100644 --- a/src/cmd/hive/sweep_workers.go +++ b/src/cmd/hive/sweep_workers.go @@ -189,6 +189,11 @@ func (b *boot) sweepJobs() []sweepJob { {"rfc_notify", fixed(rfcnotify.DefaultInterval + time.Second), sweepOptional, func(ctx context.Context, gh *github.Client, cfg *config.Config) { runRFCNotifySweep(ctx, newRFCNotifySource(gh, notify), len(cfg.Project.Repos), cfg, b.dashSrv, notify, b.logger) }}, + // Opt-in per repo (code_scanning.*); a pass with no enabled repo + // makes no GitHub call. + {"code_scanning", func(cfg *config.Config) time.Duration { return cfg.CodeScanning.IntervalOrDefault() }, sweepOptional, func(ctx context.Context, gh *github.Client, cfg *config.Config) { + runCodeScanningSweep(ctx, gh, cfg, b.logger) + }}, } } diff --git a/src/cmd/hive/sweep_workers_test.go b/src/cmd/hive/sweep_workers_test.go index a3a546dc87..0344693d37 100644 --- a/src/cmd/hive/sweep_workers_test.go +++ b/src/cmd/hive/sweep_workers_test.go @@ -282,3 +282,36 @@ func TestSweepJobRunTaggedAttributesRESTCalls(t *testing.T) { } t.Fatalf("REST accounting has no hive:p34_caller_probe timeline row: %+v", github.RESTTopConsumers(1000)) } + +// The code scanning sweep (code_scanning) is an optional sweep: it gets a +// staggered first pass, runs on its own configurable interval (hourly by +// default), and is shed whenever the GitHub API budget is not normal. +func TestCodeScanningSweepJobIsOptionalStaggeredAndHourly(t *testing.T) { + b := &boot{} + jobs := b.sweepJobs() + delays := sweepFirstDelays(jobs) + for i, job := range jobs { + if job.name != "code_scanning" { + continue + } + if job.class != sweepOptional { + t.Fatalf("code_scanning class %v, want optional", job.class) + } + if delays[i] <= 0 || delays[i] >= sweepStartupSpread { + t.Fatalf("code_scanning first pass at %s, want inside the startup spread", delays[i]) + } + cfg := &config.Config{} + if got := job.interval(cfg); got != time.Hour { + t.Fatalf("default interval %s, want 1h", got) + } + cfg.CodeScanning.Interval = 3 * time.Hour + if got := job.interval(cfg); got != 3*time.Hour { + t.Fatalf("configured interval %s, want 3h", got) + } + if !sweepBudgetSkipped(job.class, decideEvalBudgetWork(github.APIBudgetConserve, 1, 1)) { + t.Fatal("code_scanning runs in conserve mode") + } + return + } + t.Fatal("no code_scanning sweep job") +} diff --git a/src/docs/api-reference/health-status-events.md b/src/docs/api-reference/health-status-events.md index e92cfd5633..0fbbde359a 100644 --- a/src/docs/api-reference/health-status-events.md +++ b/src/docs/api-reference/health-status-events.md @@ -28,7 +28,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/health/deep` | Public | Deep health probe; the `webhooks` check (`status`, `detail`, `mode`, `mode_reason_code`, `rejected_1h`) warns when deliveries arrive but cannot be used — no `GITHUB_WEBHOOK_SECRET`, signature mismatch, undecodable payload — and never changes the overall verdict | `pkg/dashboard/server.go:1812` | | `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1813` | | `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1819` | -| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `workflow_approvals` `{approved, denied, permission_errors, last}` counts the hive's approvals of GitHub-gated workflow runs since boot (#16603) — runs approved, runs refused by the trust policy (once per head), `403`/`404` refusals for want of `actions: write`, and the most recent decision `{repo, number, head, run_id, outcome, at}`; `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`); `config.gate_regressions[]` `{gate, previous, effective, source}` is the boot-time safety-gate regression list (#16438) — gates a previous runtime overlay on the PVC carried that the running config lacks or loosens (`review.require_labels`, `project.issue_filter.require_labels`, `project.paused_repos[]`, `writeback.per_repo[].mode`), empty on a healthy boot | `pkg/dashboard/server.go:1824` | +| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `workflow_approvals` `{approved, denied, permission_errors, last}` counts the hive's approvals of GitHub-gated workflow runs since boot (#16603) — runs approved, runs refused by the trust policy (once per head), `403`/`404` refusals for want of `actions: write`, and the most recent decision `{repo, number, head, run_id, outcome, at}`; `code_scanning` `{enabled, repos[], notices[]}` is the code scanning sweep's picture, absent while the sweep is off everywhere — per repo `{repo, security_url, checked_at, open_alerts, by_severity{critical,high,medium,low,note}, qualifying, below_threshold, excluded, tracked, tracked_closed, untracked, open_issues, filed, updated, closed, truncated, notice, notice_kind, error}`, where `tracked` is open alerts listed on an open hive issue and `notice_kind` is `missing_permission` (the App lacks Code scanning alerts: Read) or `not_enabled` (see `docs/code-scanning.md`); `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`); `config.gate_regressions[]` `{gate, previous, effective, source}` is the boot-time safety-gate regression list (#16438) — gates a previous runtime overlay on the PVC carried that the running config lacks or loosens (`review.require_labels`, `project.issue_filter.require_labels`, `project.paused_repos[]`, `writeback.per_repo[].mode`), empty on a healthy boot | `pkg/dashboard/server.go:1824` | | `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1825` | | `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1828` | | `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1829` | diff --git a/src/docs/code-scanning.md b/src/docs/code-scanning.md new file mode 100644 index 0000000000..a8e708fa7b --- /dev/null +++ b/src/docs/code-scanning.md @@ -0,0 +1,244 @@ +# Code scanning issues + +GitHub code scanning (CodeQL, OSSF Scorecard, Trivy, or any tool that uploads +SARIF) shows its findings on a repository's **Security → Code scanning** tab. +Nothing there reaches the hive's lanes on its own: an owner has to read the +alerts and file issues by hand. + +The code scanning sweep does that filing. It reads a repository's open alerts, +groups them into a few issues sized for one PR each, and keeps those issues in +step with the alerts. It is **off by default** and turned on per repository. + +It opens issues only. It never opens PRs, never dismisses an alert, and never +changes the code scanning setup. + +## Turning it on + +```yaml +code_scanning: + repos: + acme/widget: # owner/repo, or the bare name under project.org + enabled: true +``` + +That is enough: the defaults file `critical` and `high` alerts, at most five new +issues per repository per pass, once an hour. Every key under `code_scanning` +is a default for all repositories. `repos.` turns one repository on or +off and can override any of them. + +| Key | Default | What it does | +| --- | --- | --- | +| `code_scanning.enabled` | `false` | Turn the sweep on for every repository in `project.repos`. A `repos..enabled` value wins. | +| `code_scanning.interval` | `1h` | Time between passes. At least `10m`. | +| `code_scanning.min_severity` | `high` | The lowest severity filed: `critical`, `high`, `medium`, `low` or `note` (see [Severity](#severity)). | +| `code_scanning.include_tools` | every tool | File only alerts from these tools, by name: `CodeQL`, `Scorecard`, `Trivy`, … | +| `code_scanning.exclude_rules` | the [posture checks](#what-is-not-filed) | Rule-ID patterns to leave out, added to the default list. `*` matches within a path segment (`cpp/commented-out-*`). An entry starting with `!` takes a default back out (`!SASTID`). | +| `code_scanning.max_new_issues_per_run` | `5` | The most new issues filed in one repository in one pass. | +| `code_scanning.repos..enabled` | the top-level `enabled` | Turn this repository on or off. | +| `code_scanning.repos..min_severity`, `.include_tools`, `.exclude_rules`, `.max_new_issues_per_run` | the top-level value | Per-repository overrides. | + +Loading fails when a `repos` key is not in `project.repos`, a severity is not +one of the names above, a pattern is malformed, the cap is negative, or the +interval is under ten minutes. These keys are YAML-only for now; the Settings +dialog does not edit them. + +## Severity + +GitHub gives an alert up to two severities: every rule has a SARIF level +(`error`, `warning`, `note`), and security rules also have a security severity +(`critical`, `high`, `medium`, `low`). The sweep puts both on one scale: + +| The alert has | Level on the sweep's scale | +| --- | --- | +| security severity `critical` | critical | +| security severity `high` | high | +| security severity `medium` | medium | +| security severity `low` | low | +| no security severity, SARIF `error` | medium | +| no security severity, SARIF `warning` | low | +| no security severity, SARIF `note` | note | + +So `min_severity: high` files exactly what the Security tab shows as High or +Critical. Quality findings without a security severity (for example CodeQL's +`cpp/commented-out-code` notes) start at `medium` at most. In `min_severity`, +`error` and `warning` are accepted as names for `medium` and `low`. + +## What is not filed + +OSSF Scorecard reports some checks as code scanning alerts even though they +score repository settings or project policy, not code. No PR an agent can write +fixes "add branch protection" or "get an OpenSSF badge", so filing them would +only park issues with the owner. These rules are left out by default: + +`BinaryArtifactsID`, `BranchProtectionID`, `CIIBestPracticesID`, `CITestsID`, +`CodeReviewID`, `ContributorsID`, `DependencyUpdateToolID`, `FuzzingID`, +`LicenseID`, `MaintainedID`, `PackagingID`, `SASTID`, `SecurityPolicyID`, +`SignedReleasesID`, `VulnerabilitiesID`, `WebhooksID`. + +`VulnerabilitiesID` is on the list because it repeats what the repository's +dependency scanners already report. `BinaryArtifactsID` asks to delete +checked-in binaries, which is the project's decision. The left-out alerts still +count on the dashboard as `excluded`. To file one anyway, add `!` to +`exclude_rules`. + +Scorecard's file-based checks (`TokenPermissionsID`, `PinnedDependenciesID`, +`DangerousWorkflowID`) are ordinary fixable work and are filed. + +## How alerts become issues + +Each issue covers alerts a single PR can fix: + +- **Code alerts** are grouped by tool and rule. If a rule's alerts are in at + most five files, they make one issue. Otherwise the files are taken directory + by directory, in path order, and packed into issues of at most five files. + A directory is only split when it alone holds more than five files. +- **Dependency alerts** (an alert whose message names a `Package:`, as Trivy's + do) are grouped by tool and package: one issue per package, listing every + CVE and every flagged artifact, because one version bump fixes them all. +- **Repository-level alerts** (no file) make one issue per rule. With the + default exclude list, that only happens for a posture check you re-included. + +New issues are filed highest severity first, then by tool, rule and path. Once +a pass has filed `max_new_issues_per_run` issues, it stops; the rest wait for +later passes and show as `untracked` on the dashboard. On the real CodeQL +results of `Danathar/exult`, a C++ game engine fork (84 critical and high alerts over 13 rules), +that is 18 issues, filed five an hour. + +A new alert joins an **open** issue that already lists the same tool and rule +in the same file (or the same package). Otherwise it waits for a new group. + +## What an issue says + +The title is `[governor] Code scanning: in ( alerts)`, +or `[governor] Code scanning: has known vulnerabilities ()`. +The issue carries `origin/governor` and `hive/code-scanning`. + +The body is written so a lane can do the work without other context: + +- **Summary**, with a plain warning that the alerts may be false positives and + must be checked before changing code. +- **Evidence**: the analysed commit, a table of every alert (link, status, + `path:line`, severity, message), a numbered excerpt of the code around the + first file's alerts at that commit, and the rule's documentation link. +- **Wanted behaviour**, **Acceptance criteria**, **Test plan**, and **Out of + scope** (other alerts, the code scanning setup, dismissing alerts). +- **If an alert is a false positive**: say so on the issue with the reason. + Do not weaken code, add suppression comments or change the analysis config; + a maintainer decides whether to dismiss the alert. + +Some issues carry more: + +- **Workflow files.** When every file is under `.github/workflows/` (typical of + Scorecard's `TokenPermissionsID` and `PinnedDependenciesID`), the body says the + fix needs the Workflows permission to push. If an enabled lane serving the + repository can push workflow files, the issue also gets `hive/workflows-lane`, + so the scheduler sends it to that lane + ([hive-open-issue](hive-open-issue.md), [labels reference](labels-and-control-signals/reference.md#hiveworkflows-lane)). + If none can, the body tells a lane to park the issue with the workflows + blocker rather than try and fail. +- **Dependency alerts.** The body says the flagged path is often a built binary, + and to find where it gets the package (the program's `go.mod` or lockfile, or + the `Containerfile`/`Dockerfile`) and bump it there, to the scanner's fixed + version. For Go's `stdlib` that means a newer Go toolchain. +- **Forks.** On a fork, the sweep reads the same file at the upstream parent's + HEAD and looks for the flagged lines. If they are gone, it reads the last + upstream commit to touch the file and says "port upstream ``" if that + change fixes the alert. If they are still there, it says upstream has no fix + to port. That is at most two reads per new issue. + +The first line of the body is a hidden marker: + +``` + +``` + +Values are URL-escaped. `alerts=` is every alert number the issue has ever +tracked. + +## Keeping issues in step + +Each pass, for each open code scanning issue: + +- When some of its alerts were fixed or dismissed, the table row's status + changes to `fixed` or `dismissed`. Added alerts get new rows. The body is + edited only when the table actually changed, and an edit does not notify + anyone. +- When **all** its alerts are fixed or dismissed, the sweep posts one comment + listing them and closes the issue: as completed if any were fixed, as not + planned if all were dismissed. A merged PR does not close it; the next + analysis does. + +The sweep **never reopens** an issue, and an alert number that appears on any +of its issues, open or closed, is never filed again. So an issue a person +closes as not planned stays closed even while its alerts are open, and a +dismissed alert that is later reopened on GitHub is not filed a second time. +Those alerts count as `tracked_closed` on the dashboard. + +If the open-alert listing hits its bound (1,000 alerts), the pass does not +mark anything fixed or close anything, because an alert missing from a partial +list may still be open. + +### Where the state lives + +There is no local state file. The sweep lists its own issues by the +`hive/code-scanning` label and reads the marker from each one written by the +hive's App account, so a restart or a lost volume rebuilds everything from +GitHub. A marker on an issue someone else wrote is ignored. + +## GitHub App permission + +Reading alerts needs the repository permission **Code scanning alerts: +Read-only** (`security_events`). It is only needed on repositories where the +sweep is on. See [GitHub App setup](github-app-setup.md). + +Without it, GitHub answers the alert listing with `403` (or a `404` for no +access). The sweep then: + +- shows a notice on the dashboard: a pinned **Code Scanning Alerts Not + Readable** banner naming the repository and the permission, with a link to + its Security tab, and the same text in `/api/status` `code_scanning.notices`; +- logs `code scanning sweep: cannot read alerts; backing off` once; +- leaves the repository alone for six hours, then asks again. Granting the + permission (and accepting it on the installation) takes effect at that next + try or after a restart. + +A repository with no code scanning analysis (`404 no analysis found`, or a +private repository without GitHub Advanced Security) gets the same treatment +with a "not set up" notice. + +## GitHub API budget + +The sweep is an optional sweep in the sweep scheduler: its first pass after a +restart is staggered with the others, and it is skipped entirely whenever the +API budget mode is not `normal`. A pass on one repository costs: + +- one request per 100 open alerts (bounded at ten), plus one for the issue + list. These URLs carry no time filter, so an unchanged list comes back as a + free `304` from the ETag cache; +- one request for dismissed alerts, only when a tracked alert left the open + list; +- for each new issue: one file read for the excerpt, and on a fork one or two + upstream reads; +- one write per new issue, body edit or close (plus one comment per close). + +Its calls appear as `hive:code_scanning` in `/api/gh-rate-limits`. + +## Write-back gate + +Every write (create, edit, comment, close) asks the write-back gate as an +`issue_file` write on the hive's own issue. A paused repository, or +`writeback.per_repo..mode: off` or `labels-only`, stops it; the pass +records the refusal as the repository's `error` and writes nothing. + +## Dashboard + +`/api/status` carries `code_scanning` while the sweep is on for any repository: + +- `enabled`; +- `repos[]`: per repository, `open_alerts`, `by_severity` (`critical`, `high`, + `medium`, `low`, `note`), `qualifying`, `below_threshold`, `excluded`, + `tracked` (open alerts on an open hive issue), `tracked_closed`, `untracked` + (waiting for the cap), `open_issues`, this pass's `filed` / `updated` / + `closed`, `truncated`, `security_url` (the Security tab), `checked_at`, and + `notice` / `notice_kind` / `error` when something is wrong; +- `notices[]`: the notice texts the banner shows. diff --git a/src/docs/dashboard-glossary.md b/src/docs/dashboard-glossary.md index f7d9cda78b..1d90740211 100644 --- a/src/docs/dashboard-glossary.md +++ b/src/docs/dashboard-glossary.md @@ -26,6 +26,7 @@ For a plain-language explanation of every dashboard section — what it shows, h | Verdict / dwell / soak | A verdict is a review result. Dwell is time at a stage before it is considered stalled. Soak is an admitted PR's waiting period before merge. | | Swarm | Several reviewers working on the same review. Their results still pass through the merge policy. | | Re-home | Continue work in a replacement PR owned by the appropriate author; do not silently rewrite the original author's commits. | +| Code scanning issue | An issue the hive filed from GitHub code scanning alerts (label `hive/code-scanning`). Its body starts with a hidden `` marker listing every alert number it tracks; the sweep updates the alert table, and closes the issue when every alert is fixed or dismissed. See [Code scanning issues](code-scanning.md). | | Issue band / PR band | A display group in Projects, not a scheduler or merge permission. See the exact groups below. | For exact stage labels, repair ownership and hold rules, see [Labels and control signals](labels-and-control-signals.md). For commands that inspect beads, see [`hivectl bead`](hivectl.md#bead--work-items). diff --git a/src/docs/documentation-map.md b/src/docs/documentation-map.md index 064e9efe9b..48f81f8011 100644 --- a/src/docs/documentation-map.md +++ b/src/docs/documentation-map.md @@ -198,6 +198,7 @@ Documentation for the current Hive line (branch `v5`; the code and docs live und - [Portfolio search](search.md) — the opt-in (`search.enabled`) spoke-local search index over evidence, findings, sentinel hits, beads and facts: every `search.*` config key, `GET /api/search`, the report-only repo health score, and the `hivectl search` / `hivectl repo health` commands. - [SOC 2 control mapping (not a compliance claim)](soc2-control-mapping.md) — maps common auditor change-management questions to bundle fields, with sample policy language and the gaps Hive does not cover. - [Duplicate PR sweep](duplicate-sweep.md) — **Opt-in; recommendations only:** identify overlapping PRs and suggest which to keep. Never closes them automatically. +- [Code scanning issues](code-scanning.md) — the opt-in `code_scanning` block (per-repo `enabled`, `min_severity`, `include_tools`, `exclude_rules`, `max_new_issues_per_run`): the severity scale, the default OSSF Scorecard posture exclusions, how alerts group into one-PR issues, the hidden `hive:code-scanning` marker, closing on fixed/dismissed, the `security_events` App permission and its dashboard notice, and the `/api/status` `code_scanning` block. - [Upstream watch](upstream-watch.md) — the opt-in `upstream_watch` block (per-repo `upstream` or the GitHub fork parent, `sources`, `pr_labels`, `max_issues_per_run`, `label`, `start_from`) and the poll loop it drives: the first-pass start point (fork point or `start_from`), the truncated-listing rule, classification, fork applicability, labelled `upstream:` issues with a hidden `upstream-ref` marker, dedupe and dismissal, and the `/data/upstream-watch.json` state file. - [Hold-gated review queue triage](review-queue-triage.md) — the triage-class policy for the human review queue (T0 fixes, T1 behavior-adjacent, T2 additive), the shipped `review_class` presentational sort in `last-actionable.json` and the dashboard PR list, and the open mechanism options awaiting maintainer decisions (#6183). - [Retro lane](retro-lane.md) — the opt-in (`retro.enabled`) post-completion pass that reconstructs a record for each closed bead and flags patterns such as excessive fix attempts or kicks; deterministic by default, with LLM analysis separately opt-in. diff --git a/src/docs/github-app-setup.md b/src/docs/github-app-setup.md index e020b3db41..7c1f10e4fc 100644 --- a/src/docs/github-app-setup.md +++ b/src/docs/github-app-setup.md @@ -93,6 +93,7 @@ Repository permissions used by the dashboard setup UI are: | Actions | Read and write (Read-only with `governor.ci.auto_approve_workflows: false`) | Inspect workflow runs; the default-on approval sweep approves gated `pull_request` runs for trusted bots, the App and dashboard-admitted heads with the App token ([#16603](https://github.com/hivecommons/hive/issues/16603)). If the sweep is off or refused and GitHub holds trusted Dependabot/App/clanker runs in `action_required`, Hive posts `/ok-to-test`; the repository-local `hive-ok-to-test` workflow uses its own `GITHUB_TOKEN` with Actions write to approve those runs. With Read and write, the contributor lane also approves held runs directly for a PR author the contributor registry admitted at a `require_tiers` tier (`auto_merge.contributor_lane.approve_held_runs_for_registry_trusted`). Optional: without it the hive marks such a PR `hive:unauthorized` and waits for a maintainer to click **Approve and run** ([#14589](https://github.com/hivecommons/hive/issues/14589)). | | Administration | Read-only | Read branch-protection rules before the merge-request watcher lands a PR; Hive refuses closed if it cannot verify the base branch is protected. | | Commit statuses | Read/write | Needed when `governor.labels.automerge` is the default `lgtm` on a repository running Prow's commit-bound `lgtm` (prow-github-actions v3): the queue action sets a `prow/lgtm` success status on the approved head so Prow does not strip the label. Without the write grant the label and approval still land, but every queue action takes the failure branch and posts a PR comment saying the status could not be set. Choose a distinct label such as `hive/auto-merge` if you would rather keep this at Read. | +| Code scanning alerts | Read-only (optional) | Only for the opt-in code scanning sweep (`code_scanning`, off by default): it reads a repository's open alerts to file grouped issues ([code-scanning.md](code-scanning.md)). This is GitHub's `security_events` permission. Without it the sweep shows a "Code Scanning Alerts Not Readable" notice for that repository and retries every six hours; nothing else uses it. | | Workflows | Read/write | Let trusted-tier agents push branches that modify `.github/workflows/`, and let the contributor lane merge an owner-approved PR that edits `.github/workflows/**` (`auto_merge.contributor_lane.owner_approval_releases_workflow_fence`, [#14664](https://github.com/hivecommons/hive/issues/14664)); without the grant such a merge is refused and the hive marks the PR `hive:unauthorized` (`merge-workflow-path`) and parks it at 090 for a maintainer's **Merge** click. Without it GitHub also rejects any GitHub App-token push touching those files server-side ("refusing to allow a GitHub App to create or update workflow … without workflows permission") no matter what the token requests. Maintainer user credentials are separate and can still push workflow-file changes when their account has the normal repository rights; the Hive App cannot until this grant is added **and re-accepted on each installation** (an existing install must approve the new permission under Settings → Integrations → the app → Review request). See [`hive-open-pr`](hive-open-pr.md#workflow-file-pushes-rejected-by-app-tokens) for the agent delivery procedure and [#6985](https://github.com/hivecommons/hive/issues/6985) for the outstanding permission change. | Organization permission: diff --git a/src/docs/labels-and-control-signals/reference.md b/src/docs/labels-and-control-signals/reference.md index 39534ea5a0..a29403bf31 100644 --- a/src/docs/labels-and-control-signals/reference.md +++ b/src/docs/labels-and-control-signals/reference.md @@ -54,7 +54,7 @@ The `` is the component that created the issue, never the person or hive | `origin/` | Created by | Code path | | --- | --- | --- | | `origin/selfreport` | Fleet runtime selfreports (`[selfreport] …`), filed directly or relayed by the hub. Sits next to the deprecated `hive/selfreport` for now. | `src/pkg/github/fleet_report.go`, `src/pkg/fleetreport/runtime.go`, `src/pkg/hub/selfreport_relay.go` | -| `origin/governor` | Governor automation: the advisory meta issue, the recommendations issue, upstream-watch filings. Task-list sweeps, stage regress and unpark notices do not file issues today; if they ever do, they use this source. | `src/pkg/github/advisory.go`, `src/pkg/github/recommendations.go`, `src/pkg/upstreamwatch/render.go` | +| `origin/governor` | Governor automation: the advisory meta issue, the recommendations issue, upstream-watch filings, code scanning issues. Task-list sweeps, stage regress and unpark notices do not file issues today; if they ever do, they use this source. | `src/pkg/github/advisory.go`, `src/pkg/github/recommendations.go`, `src/pkg/upstreamwatch/render.go`, `src/pkg/github/code_scanning.go` | | `origin/dashboard` | Operator actions in the SPA that file an issue (ACMM eval filing). | `src/pkg/dashboard/api_acmm_eval.go` | | `origin/forge` | The forge issue seam, when its consumer passes no origin label of its own. | `src/pkg/forge/github_forge.go` | | `origin/convergence` | The convergence publisher and its GitHub channel. | `src/pkg/convergence/publish/publisher.go`, `src/pkg/convergence/publish/channel.go` | @@ -100,6 +100,7 @@ Some hive-authored labels look like provenance but are read as signals, so they | `stage/017-possible-existing` from the prior-art gate | Issues | Scheduler kick assembly (`runs.triage.prior_art`) | With the gate on (default on), an unclaimed feature / RFC / epic issue whose key terms match an existing knowledge bead, setting, merged PR, closed issue, doc or code identifier at `runs.triage.prior_art.threshold` (default 70) gets one `` comment quoting the findings and the `stage/017-possible-existing` label instead of a claim; hive-filed issues get a `` note and are never parked ([#13575](https://github.com/hivecommons/hive/issues/13575)). | Hard suppress | Hive | Before kicks are built | The author or a write+ commenter replies `/hive decision proceed — ` (label lifted, a *Scope vs existing* section appended to the body, re-derives 010) or `/hive decision exists` (closed `not_planned` with `already-exists`); a plain reply lifts the label too. A clanker-filed park with no reply is closed `already-exists` after `runs.triage.prior_art.bot_close_ttl` (default 72h); reopen to continue. A 017 a person added is never lifted by the sweep | `runs.triage.prior_art` (`src/pkg/priorart`, `src/pkg/scheduler/prior_art_gate.go`, `src/pkg/github/prior_art_gate_resume.go`) | | `hive/handoff` | Issues | Task-list sweep | Soft hand-off marker. When a merged PR's `Refs #N` remainder section says in prose that the rest needs a person or another lane ("needs a human", "fix lane", "quality lane", "production change", …) without the explicit `needs-human:` marker, the sweep adds this label and notes "handed off to the next lane" in its remainder comment instead of parking the issue. It is not a hold, suppress, or enumeration filter: the issue stays actionable, so the next lane can still claim it ([#12002](https://github.com/hivecommons/hive/issues/12002)). Not added when the same sweep is applying `needs-human`. | Informational | Hive (task-list sweep) | Task-list sweep | Human or the claiming lane removes it; Hive never removes it | Fixed label (`src/pkg/github/task_list_sweep.go:85`, `src/pkg/github/task_list_sweep.go:576-596`, `src/pkg/github/task_list_sweep.go:635-665`) | | `hive/workflows-lane` | Issues | Issue-request relay | Workflow hand-off. A lane whose token cannot push `.github/workflows/**` (ISSUES_AND_PRS, contributor tier) parks a change that is only in a workflow file (`--needs-decision`, no lettered options), and an enabled ISSUES_PRS_MERGE lane serves the repository: the relay does not park it, adds this label and a "Handed to ``" note, and the scheduler routes the issue to that lane instead of back to the one that filed it. It is not a hold or filter: the issue stays actionable. | Routing | Hive (issue-request relay) | Scheduler kick assembly | Human removes it; `/hive hold` or `needs-human` keeps the issue with a person | Fixed label (`src/pkg/github/issue_workflows_handoff.go`, `src/pkg/scheduler/policy_overlays.go` `routeWorkflowsLane`) | +| `hive/code-scanning` | Issues | Code scanning sweep | Marks an issue the code scanning sweep filed from GitHub code scanning alerts; the sweep lists its own issues by this label and reads the hidden `` marker. Not a hold or filter: the issue is ordinary work for the lanes. | Informational | Hive (code scanning sweep) | Code scanning sweep, every pass | Remove it and the sweep no longer sees the issue (its alerts may then be filed again) | `code_scanning.*` (`src/pkg/github/code_scanning.go`, `src/pkg/codescanning`, see `docs/code-scanning.md`) | | `hive:unauthorized` | PRs (issues when a step on one is blocked) | Contributor lane (`markUnauthorized`), dashboard activity monitor | The hive's GitHub App was refused (`403 Resource not accessible by integration`) on an API call the lane needs to advance, so only a person can take the next step. First wired call site: approving held `action_required` workflow runs for a registry-trusted author needs `actions: write`, which an operator may decline to grant ([#14589](https://github.com/hivecommons/hive/issues/14589)). The lane reports `unauthorized:` (`unauthorized:approve-workflow-runs`), the stage engine parks the PR at 085, one `` comment names the missing permission, the exact human step (**Approve and run** on the checks banner or Actions tab, with the run ids) and the alternative of granting the permission, and the hive logs `lane unauthorized` once per head at INFO instead of a WARN per tick. The activity monitor draws a muted `unauthorized` pill (counted under Needs attention) whose tooltip repeats the permission and the step, and the 085 cell reads **Awaiting human: approve workflow runs**. | Human-gated hold | Hive | Every lane tick that hits the refused call | Removed by the hive in the tick the step is no longer needed (the required checks for the head report, the lane advances); a new head re-posts the comment once. No human label edit required; removing it by hand is harmless — it is re-applied if the step is still refused | Not configurable; outside `stage/`, so the reconciler never strips it (`src/pkg/github/automerge/automerge_unauthorized.go`) | | `needs-human` | PRs | Escalation ledger, reviewer lane, self-authored auto-merge sweep, queued auto-merge sweep, supersession sweep | Applied when red-CI fix budget is exhausted or a workflow needs a person; stops automated fix dispatch, sends the PR to the human/reviewer lane, and blocks auto-merge sweeps while present. It is not a PR enumeration filter. The stage engine reads it as a park (`label:needs-human` → `stage/085-needs-decision`), so a writer that adds it must also submit a `Parked` fact (`FactSink.Parked(ref, "needs-human")`) in the same pass; the label alone leaves the previous lane stage standing until the next auto-merge tick. The supersession sweep does this for a contributor PR that touches files the merged closer PR did not, and for a hive PR below ACMM L6; it never adds the label to a hive PR at L6, which it resolves itself (see [Supersession](stage-labels.md#supersession-closed-issue-another-merged-pr)). | Hard fix-dispatch and merge gate | Hive | Escalation pass/kick building/auto-merge sweeps/supersession sweep | Human removes after root cause or reviewer un-escalates; budget resets after grace; auto-merge reconsiders on the next tick because no persisted hold state is kept; the supersession sweep removes only the `needs-human` it applied itself (label timeline actor is a hive account) when it takes a hive PR's resolution over | Fixed label (`src/pkg/escalation/escalation.go:400-470`, `src/pkg/escalation/escalation.go:1185-1205`) | | `hive/advisory` | Issues | Standing meta classifier | Hive advisory report is never actionable and never appears on the Hold list. | Hard exclusion | Hive | Before holds/exempts | Remove label, but exact advisory title still excludes | Fixed label/name (`src/pkg/github/standing_issues.go:1-57`, `src/pkg/github/client.go:983-1001`) | @@ -406,6 +407,20 @@ Workflow hand-off. An ISSUES_AND_PRS lane's token is minted at the `contributor` **Configuration and implementation.** Fixed label (`src/pkg/github/issue_workflows_handoff.go`, `src/pkg/config/workflows_lane.go`, `src/pkg/scheduler/policy_overlays.go` `routeWorkflowsLane`) +#### `hive/code-scanning` + +**Applies to:** Issues. **Kind:** Informational. + +Marks an issue the code scanning sweep filed from a repository's GitHub code scanning alerts ([Code scanning issues](../code-scanning.md)). The sweep lists its own issues by this label, and reads the hidden `` marker on each one the hive's App account wrote to know which alerts are already tracked. It is not a hold or a filter: lanes pick the issue up like any other. + +**Who applies it:** Hive (code scanning sweep). + +**Checked by:** The code scanning sweep. **When:** Every pass. + +**Release or override.** Removing it hides the issue from the sweep, so its alerts may be filed again; close the issue as not planned instead to stop the sweep filing them. + +**Configuration and implementation.** `code_scanning.*` (`src/pkg/github/code_scanning.go`, `src/pkg/codescanning`) + #### `hive/advisory` **Applies to:** Issues. **Kind:** Hard exclusion. diff --git a/src/docs/notifications.md b/src/docs/notifications.md index c44ee86374..2716f1a3a6 100644 --- a/src/docs/notifications.md +++ b/src/docs/notifications.md @@ -575,6 +575,7 @@ without a class. Review submissions and review requests are always counted as | `dashboard.(*Server).handleReviewQueueSupersededClose` | `status` | | | `dashboard.(*Server).mirrorPlanWith` | `status` | | | `github.(*Client).CloseIssueForConfiguredLinePR` | `status` | | +| `github.codeScanningForge.CloseIssue` | `status` | closing note on a code scanning issue whose alerts are all fixed or dismissed ([code-scanning.md](code-scanning.md)) | | `github.(*Client).ApproveIssueRelease` | `status` | solicited authenticated release approval response | | `github.(*Client).CreateIssueCommentBudgeted` | `status` | passthrough wrapper; attributed to its caller | | `github.(*Client).PostFleetReportCleared` | `status` | | diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index 490cd81990..7eb9453b99 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -226,6 +226,7 @@ Top-level YAML keys accepted by `config.Config`: | `claims` | The worker-claim ledger ([#8380](https://github.com/hivecommons/hive/issues/8380)): who is on an issue right now, ranked human > agent > contributor > external, so a person can take an issue over from a hive agent or a relay contributor and the displaced holder is told to stop. | Default ON. `enabled: false` turns recording, enforcement and `/api/claims` off. `human_ttl_s` 4h, `agent_ttl_s` 2h, `contributor_ttl_s` 30m, `max_ttl_s` 24h; the owner can also set these four from **Governor Config → Features → Work intake & issue lifecycle → Issue claims** (a value of 0 or *Reset to default* uses the default; human, agent and contributor may not exceed the max), and a saved change applies without a restart to claims made or renewed afterwards while existing claims keep their expiry ([#10981](https://github.com/hivecommons/hive/issues/10981)); `comment: false` / `label: false` suppress the GitHub issue comment / `stage/020-claimed` label mirror (`label: false` also suppresses the `stage/030-pr-in-progress` start label an agent claim mirrors — formerly `claimed` / `hive/in-progress`, [#11841](https://github.com/hivecommons/hive/issues/11841)). A governor kick only *lists* the issues it names (30-minute hold, no comment, not a claim); the agent claim, with its comment, is recorded on the agent's first start signal on an issue — its own `hive-open-issue claim` request, a `hive-open-pr` request naming it, or a comment with an explicit start statement (``, "starting now", an opening "Starting …" / "Implementing …"; see the [recognized forms](../hive-open-issue.md#comment)); a report-only comment (triage, verification, gate check, status), an explicit deferral ([#12387](https://github.com/hivecommons/hive/issues/12387)) or escalation, and any `label` request record no claim. `never_claim_labels` (default `[epic]`, case-insensitive; `[]` turns it off) names umbrella/tracking labels no automated producer may claim and no claim ever stages `stage/020`/`stage/030`; the same admission gate also refuses issues parked on a person (`stage/045-needs-decision`, `needs-spec`, …), `needs-human` and held issues. `escalate_after_claims` (default `2`, negative turns it off) counts those claims only: once one agent's last that-many claims on a free issue were followed by no linked PR, referencing commit, label or assignee change and no close/reopen, the issue is withheld from every kick, labelled `needs-human` and given one comment listing the claims, instead of being claimed again. A `hive/likely-done` issue an agent already started on after the merged PR (its verification) is withheld from kicks until a person comments, labels, assigns, closes or reopens it, so it is verified once rather than every cycle ([#10527](https://github.com/hivecommons/hive/issues/10527)). `reclaim_cooldown_s` (default `21600` = 6h; negative turns it off) keeps a relay contributor session off an issue it released without shipping — task failed, abandoned, or its lease revoked — while other contributors may retry at once after the short global failure cooldown; before it, a relay whose environment could not run a task took the same issue back every ten minutes, flapping its claim ([#13093](https://github.com/hivecommons/hive/issues/13093)). A relay's *disconnect* release (after the [#7838](https://github.com/hivecommons/hive/issues/7838) grace window), a revoked lease and a lease that aged out unresumed each release the issue claim on GitHub too — release marker posted, claim labels removed — so hive agents may claim the issue on the next cycle; `contributor_flap_threshold` (default `3`; negative turns it off) disconnect releases of one issue inside `contributor_flap_window_s` (default `7200` = 2h) put the issue in *contributor cool-off* for `contributor_flap_cooloff_s` (default `21600` = 6h): withheld from every contributor, immediately eligible for hive agents, work detail `contributor cool-off: N drops in W`; and `contributor_starvation_s` (default `14400` = 4h; negative turns it off) is how long contributor claims may keep hive agents off an issue with no PR before the claim becomes advisory and a hive agent may claim it anyway ([#13579](https://github.com/hivecommons/hive/issues/13579)). An issue labelled `blocked` (the review backlog's parking for a finding whose file exists only on an unmerged PR, or `hive-open-issue comment --blocked-on-pr`) is refused by the same admission gate until the tracked PR merges or closes. Driven from `hivectl claim` — see [hivectl.md](../hivectl.md#claim--unclaim--claims--issue-claims). | | `removed_agents` | Persistent tombstones for deleted agents. | Dashboard/overlay-owned; do not seed casually. | | `good_first_issue` | Hive-curated `good first issue` advertising: a 15-minute sweep scores open, unclaimed issues and gives the few that qualify GitHub's `good first issue` + `help wanted` labels and one welcome comment pointing at this hive's contributor relay. Not a hold — a hive agent starting the issue removes the label. | Default ON; `enabled: false` opts out. Silent until `dashboard.public_url` (or a hub-assigned dashboard URL) exists. See [Hive-curated good first issues](../good-first-issue.md). | +| `code_scanning` | Code scanning issues: an hourly sweep reads a repository's open GitHub code scanning alerts (CodeQL, OSSF Scorecard, Trivy, …) and files them as grouped `[governor] Code scanning: …` issues sized for one PR, at most `max_new_issues_per_run` (default `5`) per repo per pass, and keeps them in step: rows marked fixed/dismissed, issues closed when every alert is gone, never reopened. Keys: `enabled`, `interval` (`1h`), `min_severity` (`high`), `include_tools`, `exclude_rules` (adds to the default OSSF Scorecard repo-posture list; `!` re-includes), `max_new_issues_per_run`, and `repos..*` overrides. | Default OFF; turn on per repo with `code_scanning.repos..enabled: true`. Needs the App permission **Code scanning alerts: Read-only** (`security_events`); without it the dashboard shows a notice and the repo is retried every six hours. See [Code scanning issues](../code-scanning.md). | | `decisions.delegate` | "Let hive decide": the activity monitor's Decide… › *Let hive decide* action has the hive decide an issue or PR parked at *Needs human decision* itself, as the owner's delegate under the owner-delegate policy, recording it as a human decision would be (`/hive decision`, park lifted, queue approval on a PR) with an audit marker. | Default ON (`enabled: true`); `enabled: false` hides the action hive-wide; `repos..enabled` overrides per repository. `llm.enabled` (default OFF) consults the owner-delegate decider model for items the rules leave at the reversible default, on the governor reviewer endpoint; `llm.model` overrides the model. `effect_timeout` (default `30m`) is how long a recorded decision may go without its expected effect before a repeat click answers "decided, but it hasn't taken effect" with the plain reason and the next actions, and the hive posts one follow-up comment. Rails and policy in [Dashboard sections → Let hive decide](../dashboard-sections/activity-monitor.md#let-hive-decide). | | `chat.grounded_answers` | Hive Chat grounded answers: a chat message that is not a bare command (`/agents stuck`, `/prs waiting on review`, "which agent completed last?") is answered by one read-only model turn over a capped snapshot of the hive state the dashboard already holds (agents, open PRs, actionable issues, decisions, governor, alerts, version), citing the items used or saying it does not have the data. Chat never takes actions on this path; every attempt is audited as `chat_grounded_answer`. | Default ON (`enabled: true`); `enabled: false` makes scoped questions answer with the command's usage instead. `model` overrides the governor reviewer model for the turn. See [Hive Chat](../dashboard.md#hive-chat). | | `governor.first_timer_welcome` | First-time contributor welcome: when a human whose GitHub `author_association` is `FIRST_TIME_CONTRIBUTOR`/`FIRST_TIMER` opens a PR, post one comment (per author per repo, marker ``) that thanks them and invites them to run their own hive — profile, leaderboard, trust-tier progression, offline review-fix/rebase handling. Bots, `author/clanker`/`author/hive` PRs, drafts and known relay contributors are skipped. | Default ON; `enabled: false` opts out; `template_path` overrides the text. Silent without a public dashboard URL. See [Welcoming first-time contributors](../good-first-issue.md#welcoming-first-time-contributors). | diff --git a/src/docs/operator-reference/sweeps-and-operations.md b/src/docs/operator-reference/sweeps-and-operations.md index 2e6ca7b707..266c91efb4 100644 --- a/src/docs/operator-reference/sweeps-and-operations.md +++ b/src/docs/operator-reference/sweeps-and-operations.md @@ -454,6 +454,7 @@ that level, the power the write-back exists to govern? | Gate comments (`pkg/scheduler/clarity_gate.go`, `prior_art_gate.go`, `triage.go`, `issue_blocked.go`, `issue_recheck_soak.go`) | scheduler intake | clarity/prior-art/triage questions, `blocked` labels | issues admitted by the issue filter | `gate_comment` → L5 + label; items carrying the intake label are opted in | | Welcome / outreach (`pkg/gfi`, `gfi_forge.go`, `pr_clanker_requested.go`) | good-first-issue selection | welcome comment, `good first issue` label | issues hive advertises | `welcome_comment` → L5 with label, L6 without | | Issue filing (`pkg/upstreamwatch/github_filer.go`, `advisory.go`, scanner/deps/regression agents, `dedupe_advisory_close.go`) | agents, advisory digest, upstream watch | **new** issues hive authors, pinned advisory issue + comments | `project.repos` | `issue_file` → L3, no label (this is what listing a repo opts in to; `per_repo.mode: issues-only` keeps only this) | +| Code scanning sweep (`pkg/github/code_scanning.go`, `pkg/codescanning`) | hourly sweep (`code_scanning`, opt-in per repo) | **new** grouped issues from code scanning alerts, alert-table body edits, one closing comment + close when every alert is fixed or dismissed | the hive's own `hive/code-scanning` issues in repos with `code_scanning` on | `issue_file` → L3, no label (own items); see [code-scanning.md](../code-scanning.md) | | Shared-CI rerun (`shared_ci_rerun.go`) | CI failure watcher | `rerun-failed-jobs`, `hive-shared-ci-rerun-` comment | PRs with failed shared workflows | `ci_rerun` → L6 + label | | Transient-CI rerun (`transient_ci_rerun.go`) | eval cycle, before the stuck-PR reaper | `rerun-failed-jobs`, once per head, no comment | hive-authored red PRs whose every failing run carries `hive-ci-transient` | `ci_rerun` (own items: allowed unless the repo is paused, off or issues-only) | | Level hold, self-authorization & reporter-trust releases (`pr_level_hold.go`, `automerge/self_authorization_release.go`, `reporter_trust_release.go`) | PR watcher | `hold` label add/remove | agent PRs | own items (hive-authored) — not gated | @@ -914,6 +915,8 @@ Mode exits use hysteresis: Hive leaves conserve/critical only after quota rises **After a restart the periodic sweeps start one at a time.** Each sweep checks the budget mode when it starts a pass. After a restart every in-memory cache is empty. If all the sweeps started in the same second, each would list every repo in full, and all of them would decide against the same budget reading. On 2026-11-06 a hosted hive with 20 repos used up its 7000-request hourly limit about five minutes after a restart. Now the merge sweep runs at once. The other sweeps make their first pass at evenly spaced points over the first five minutes, in a fixed order. A sweep with a short interval never waits longer than that interval. So a later sweep sees the budget mode the earlier passes left behind, and it can get free `304` answers for lists an earlier sweep already fetched. After the first pass, each sweep keeps its own interval. +**The code scanning sweep runs only in a normal budget.** It is an optional sweep (`code_scanning`, opt-in per repo, hourly by default), so the scheduler skips it in `conserve` and `critical`, and the sweep checks the mode again before each repository. Its alert and issue listings carry no time filter, so an unchanged list is a free `304`. See [Code scanning issues](../code-scanning.md#github-api-budget). + **Historical PR accounting waits for a normal budget.** The worker that reads each recently merged or closed PR's merger and reviews (for the throughput and review counts) runs only in `normal` mode. In `conserve` and `critical` it makes no GitHub calls; its queue is kept and drained once the budget is back to `normal`. The hive logs `historical PR enrichment paused for GitHub API budget` once when it pauses and `historical PR enrichment resumed` once when it starts again. This matters most after a restart: the 72-hour settle replay queues every recent merged or closed PR again, at about two calls each. **Sweeps that read "everything since a time" round that time down to the hour.** A free `304` answer needs the request URL to match the one the hive fetched before, query string included. The un-park sweep's comment reads (comments from the last seven days), the closed-issue stage sweep and the review backlog split (issues closed since the last pass), the shared-CI rerun sweep (incidents closed in its lookback) and the same-component check when an agent files an issue all used to build that time from the current clock, so the URL changed on every pass and every pass was charged in full. Now the time sent to GitHub is rounded down to the hour, so every pass in the same hour asks for the same URL. The window only gets wider, by less than an hour, and each sweep still filters on its exact cutoff, so nothing is missed and no old command is answered again. diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index 9c7548eab1..dfb17e17c9 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:5470-5480`, descending `AgeMinutes` within each tier). + (`RankActionableIssues`, `src/pkg/github/client.go:5475-5485`, descending `AgeMinutes` within each tier). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests). diff --git a/src/hive.yaml.example b/src/hive.yaml.example index 2318d8214d..95c3788283 100644 --- a/src/hive.yaml.example +++ b/src/hive.yaml.example @@ -108,6 +108,20 @@ project: # docs_url: https://github.com/hivecommons/hive/blob/v5/src/docs # comment_template: "" # text/template over gfi.Vars; must contain {{ .Marker }} +# Code scanning issues (default OFF): file a repo's open GitHub code scanning +# alerts (CodeQL, OSSF Scorecard, Trivy, ...) as grouped issues sized for one +# PR, and close them when every alert is fixed or dismissed. Needs the App +# permission "Code scanning alerts: Read-only". See docs/code-scanning.md. +# code_scanning: +# interval: 1h # pass cadence (at least 10m) +# min_severity: high # critical | high | medium | low | note +# include_tools: [] # empty = every tool, e.g. [CodeQL, Trivy] +# exclude_rules: [] # added to the default Scorecard posture list; "!SASTID" re-includes +# max_new_issues_per_run: 5 # new issues per repo per pass +# repos: +# acme/widget: +# enabled: true + # Optional contributor help/community links. Shown on /contribute Onboarding, # Operations, and printed by relays when they connect. Empty/omitted defaults to # Hive's contributor docs and issue tracker. URLs must be absolute http(s). diff --git a/src/pkg/codescanning/alert.go b/src/pkg/codescanning/alert.go new file mode 100644 index 0000000000..cc13a29d0c --- /dev/null +++ b/src/pkg/codescanning/alert.go @@ -0,0 +1,341 @@ +// Package codescanning turns a repository's open GitHub code scanning alerts +// (CodeQL, OSSF Scorecard, Trivy, any SARIF uploader) into a small number of +// hive issues sized for one PR each, and keeps those issues in step with the +// alerts: new alerts are added, fixed or dismissed ones are marked, and an +// issue whose alerts are all gone is closed. +// +// The package is GitHub-free: Run talks to a Forge, which pkg/github +// implements with the App client (every write gated by the write-back gate). +// Dedupe state is the hidden marker on the hive's own issues, so a restart or +// a lost volume rebuilds it from GitHub. +package codescanning + +import ( + "errors" + "path" + "regexp" + "sort" + "strings" +) + +// Alert is the subset of a GitHub code scanning alert +// (GET /repos/{owner}/{repo}/code-scanning/alerts) the sweep reads. The json +// tags match the API, so a response page decodes straight into []Alert. +type Alert struct { + Number int `json:"number"` + HTMLURL string `json:"html_url,omitempty"` + State string `json:"state,omitempty"` + DismissedReason string `json:"dismissed_reason,omitempty"` + Rule Rule `json:"rule"` + Tool Tool `json:"tool"` + Instance Instance `json:"most_recent_instance"` +} + +// Rule is the alert's rule. SecuritySeverityLevel is set only for rules +// tagged security (critical, high, medium, low); Severity is the SARIF level +// every rule has (error, warning, note). +type Rule struct { + ID string `json:"id"` + Name string `json:"name,omitempty"` + Severity string `json:"severity,omitempty"` + SecuritySeverityLevel string `json:"security_severity_level,omitempty"` + Description string `json:"description,omitempty"` + HelpURI string `json:"help_uri,omitempty"` + Tags []string `json:"tags,omitempty"` +} + +// Tool names the analyser that raised the alert ("CodeQL", "Scorecard", +// "Trivy"). +type Tool struct { + Name string `json:"name"` +} + +// Instance is the alert's most recent instance on the default branch. +type Instance struct { + Ref string `json:"ref,omitempty"` + CommitSHA string `json:"commit_sha,omitempty"` + Message Message `json:"message"` + Location Location `json:"location"` +} + +// Message is the analyser's text for this instance. +type Message struct { + Text string `json:"text,omitempty"` +} + +// Location is where the instance points. +type Location struct { + Path string `json:"path,omitempty"` + StartLine int `json:"start_line,omitempty"` + EndLine int `json:"end_line,omitempty"` +} + +// noFilePath is what OSSF Scorecard reports as the path of a repo-level +// check ("score is 0: project is not fuzzed"). +const noFilePath = "no file associated with this alert" + +// Path is the file the alert points at, or "" for a repo-level alert. +func (a Alert) Path() string { + p := strings.TrimSpace(a.Instance.Location.Path) + if p == "" || strings.EqualFold(p, noFilePath) { + return "" + } + return strings.TrimPrefix(p, "./") +} + +// Level is the sweep's one severity scale. +type Level int + +// The scale, lowest first. See Alert.Level for how GitHub's two severity +// fields map onto it. +const ( + LevelNone Level = iota + LevelNote + LevelLow + LevelMedium + LevelHigh + LevelCritical +) + +var levelNames = map[Level]string{LevelNote: "note", LevelLow: "low", LevelMedium: "medium", LevelHigh: "high", LevelCritical: "critical"} + +// String is the level's config spelling. +func (l Level) String() string { + if s, ok := levelNames[l]; ok { + return s + } + return "none" +} + +// LevelNames lists the scale highest first, for status payloads. +func LevelNames() []string { + return []string{"critical", "high", "medium", "low", "note"} +} + +// ParseLevel reads a min_severity value: one of critical, high, medium, low, +// note, or the SARIF names error (= medium) and warning (= low). +func ParseLevel(s string) (Level, bool) { + switch strings.ToLower(strings.TrimSpace(s)) { + case "critical": + return LevelCritical, true + case "high": + return LevelHigh, true + case "medium", "moderate", "error": + return LevelMedium, true + case "low", "warning": + return LevelLow, true + case "note": + return LevelNote, true + } + return LevelNone, false +} + +// Level maps an alert onto the scale. A security rule's +// security_severity_level wins (critical, high, medium, low map to +// themselves). A rule without one is a quality finding and uses its SARIF +// severity one step lower than its name suggests: error → medium, +// warning → low, note → note. So min_severity: high selects exactly the +// alerts GitHub's Security tab shows as High or Critical. +func (a Alert) Level() Level { + switch strings.ToLower(strings.TrimSpace(a.Rule.SecuritySeverityLevel)) { + case "critical": + return LevelCritical + case "high": + return LevelHigh + case "medium": + return LevelMedium + case "low": + return LevelLow + } + switch strings.ToLower(strings.TrimSpace(a.Rule.Severity)) { + case "error": + return LevelMedium + case "warning": + return LevelLow + case "note": + return LevelNote + } + return LevelNone +} + +// Dependency is the vulnerable package a dependency scanner (Trivy, Grype) +// reports in its message ("Package: golang.org/x/net\nInstalled Version: …"). +type Dependency struct { + Package string + Installed string + Fixed string +} + +var ( + depPackageRE = regexp.MustCompile(`(?m)^Package:\s*(\S+)\s*$`) + depInstalledRE = regexp.MustCompile(`(?m)^Installed Version:\s*(.+?)\s*$`) + depFixedRE = regexp.MustCompile(`(?m)^Fixed Version:\s*(.+?)\s*$`) +) + +// Dependency returns the vulnerable package, if the alert is a dependency +// finding. +func (a Alert) Dependency() (Dependency, bool) { + text := a.Instance.Message.Text + m := depPackageRE.FindStringSubmatch(text) + if m == nil { + return Dependency{}, false + } + d := Dependency{Package: m[1]} + if m := depInstalledRE.FindStringSubmatch(text); m != nil { + d.Installed = m[1] + } + if m := depFixedRE.FindStringSubmatch(text); m != nil { + d.Fixed = m[1] + } + return d, true +} + +// DefaultMinLevel is min_severity when unset. +const DefaultMinLevel = LevelHigh + +// DefaultMaxNewIssues is the per-repo, per-pass cap on new issues when unset. +const DefaultMaxNewIssues = 5 + +// DefaultExcludeRules are OSSF Scorecard checks that score repository +// settings or project policy, not code: branch protection, code review, +// maintenance, a security policy, fuzzing, SAST, the CII badge, signed +// releases, and so on. No PR an agent can write fixes them, so filing them +// would only park issues for the owner. VulnerabilitiesID repeats the +// dependency alerts the repo's dependency scanners already raise. +// BinaryArtifactsID asks to delete checked-in binaries, which is a project +// decision. They are still counted on the dashboard. An operator re-includes +// one with a "!" entry in exclude_rules ("!SASTID"). +var DefaultExcludeRules = []string{ + "BinaryArtifactsID", + "BranchProtectionID", + "CIIBestPracticesID", + "CITestsID", + "CodeReviewID", + "ContributorsID", + "DependencyUpdateToolID", + "FuzzingID", + "LicenseID", + "MaintainedID", + "PackagingID", + "SASTID", + "SecurityPolicyID", + "SignedReleasesID", + "VulnerabilitiesID", + "WebhooksID", +} + +// Policy is one repo's effective filter. +type Policy struct { + // MinLevel is the lowest level filed. LevelNone means DefaultMinLevel. + MinLevel Level + // IncludeTools, when set, files only alerts from these tools (by + // name, case-insensitive). + IncludeTools []string + // ExcludeRules are rule-ID patterns (path.Match syntax, case-insensitive) + // added to DefaultExcludeRules; a "!pattern" entry takes a default back + // out of the list. + ExcludeRules []string + // MaxNewIssues caps new issues per pass. 0 means DefaultMaxNewIssues. + MaxNewIssues int +} + +// ValidateRulePatterns rejects a malformed exclude_rules pattern. +func ValidateRulePatterns(patterns []string) error { + for _, p := range patterns { + p = strings.TrimPrefix(strings.TrimSpace(p), "!") + if p == "" { + return errors.New("empty rule pattern") + } + if _, err := path.Match(strings.ToLower(p), ""); err != nil { + return errors.New("bad rule pattern " + p + ": " + err.Error()) + } + } + return nil +} + +func (p Policy) minLevel() Level { + if p.MinLevel == LevelNone { + return DefaultMinLevel + } + return p.MinLevel +} + +func (p Policy) maxNewIssues() int { + if p.MaxNewIssues <= 0 { + return DefaultMaxNewIssues + } + return p.MaxNewIssues +} + +// excludeList is DefaultExcludeRules plus ExcludeRules, minus "!" entries. +func (p Policy) excludeList() []string { + unexclude := map[string]bool{} + var extra []string + for _, r := range p.ExcludeRules { + r = strings.TrimSpace(r) + if strings.HasPrefix(r, "!") { + unexclude[strings.ToLower(strings.TrimPrefix(r, "!"))] = true + continue + } + if r != "" { + extra = append(extra, r) + } + } + var out []string + for _, r := range DefaultExcludeRules { + if !unexclude[strings.ToLower(r)] { + out = append(out, r) + } + } + return append(out, extra...) +} + +// Verdict is why an alert is or is not filed. +type Verdict int + +// Verdicts, in the order Policy.Judge checks them. +const ( + Qualifies Verdict = iota + BelowThreshold + Excluded +) + +// Judge decides whether the policy files an alert. +func (p Policy) Judge(a Alert) Verdict { + if len(p.IncludeTools) > 0 { + ok := false + for _, t := range p.IncludeTools { + if strings.EqualFold(strings.TrimSpace(t), a.Tool.Name) { + ok = true + break + } + } + if !ok { + return Excluded + } + } + rule := strings.ToLower(a.Rule.ID) + for _, pat := range p.excludeList() { + if ok, _ := path.Match(strings.ToLower(pat), rule); ok { + return Excluded + } + } + if a.Level() < p.minLevel() { + return BelowThreshold + } + return Qualifies +} + +// sortAlerts orders alerts by path, line, number. +func sortAlerts(alerts []Alert) { + sort.SliceStable(alerts, func(i, j int) bool { + a, b := alerts[i], alerts[j] + if a.Path() != b.Path() { + return a.Path() < b.Path() + } + if a.Instance.Location.StartLine != b.Instance.Location.StartLine { + return a.Instance.Location.StartLine < b.Instance.Location.StartLine + } + return a.Number < b.Number + }) +} diff --git a/src/pkg/codescanning/group.go b/src/pkg/codescanning/group.go new file mode 100644 index 0000000000..55a053429e --- /dev/null +++ b/src/pkg/codescanning/group.go @@ -0,0 +1,296 @@ +package codescanning + +import ( + "net/url" + "path" + "regexp" + "sort" + "strconv" + "strings" +) + +// MaxFilesPerIssue is the most files one new issue covers. A rule whose +// alerts span more files is split by directory (see Cluster). +const MaxFilesPerIssue = 5 + +// Group is the alerts one issue tracks. +type Group struct { + Tool string + // Rules are the rule IDs in the group: one for a code rule, one per + // advisory (CVE) for a dependency group. + Rules []string + // Package is set for a dependency group (every alert names it). + Package string + Paths []string + Alerts []Alert +} + +// Level is the highest level in the group. +func (g Group) Level() Level { + var l Level + for _, a := range g.Alerts { + l = max(l, a.Level()) + } + return l +} + +// WorkflowOnly reports whether every path is a GitHub Actions workflow file, +// so the fix needs the Workflows permission to push. +func (g Group) WorkflowOnly() bool { + if len(g.Paths) == 0 { + return false + } + for _, p := range g.Paths { + if !strings.HasPrefix(p, ".github/workflows/") { + return false + } + } + return true +} + +// Cluster groups new alerts into issues, each sized for one PR: +// +// - A dependency alert (one whose message names a Package, as Trivy's do) +// groups with every other alert on the same tool and package: one issue +// per package, listing each CVE and each flagged artifact. Bumping the +// package fixes them together. +// - Any other alert groups by (tool, rule). When the rule's alerts span at +// most MaxFilesPerIssue files they are one issue. Otherwise the files are +// taken directory by directory (sorted) and packed into issues of at +// most MaxFilesPerIssue files, never splitting a directory unless it +// alone holds more than MaxFilesPerIssue files, which is then split into +// runs of MaxFilesPerIssue files in path order. A repo-level alert (no +// file) is its own one-alert-per-rule issue. +// +// The result is ordered highest level first, then tool, rule and first path, +// which is the order a per-pass cap files them in. +func Cluster(alerts []Alert) []Group { + type key struct{ tool, rule, pkg string } + buckets := map[key][]Alert{} + var keys []key + for _, a := range alerts { + k := key{tool: a.Tool.Name, rule: a.Rule.ID} + if d, ok := a.Dependency(); ok { + k = key{tool: a.Tool.Name, pkg: d.Package} + } + if _, seen := buckets[k]; !seen { + keys = append(keys, k) + } + buckets[k] = append(buckets[k], a) + } + var out []Group + for _, k := range keys { + as := buckets[k] + sortAlerts(as) + if k.pkg != "" { + out = append(out, newGroup(k.tool, k.pkg, as)) + continue + } + for _, files := range packFiles(distinctPaths(as)) { + in := map[string]bool{} + for _, f := range files { + in[f] = true + } + var sub []Alert + for _, a := range as { + if in[a.Path()] { + sub = append(sub, a) + } + } + out = append(out, newGroup(k.tool, "", sub)) + } + } + sort.SliceStable(out, func(i, j int) bool { + a, b := out[i], out[j] + if a.Level() != b.Level() { + return a.Level() > b.Level() + } + if a.Tool != b.Tool { + return a.Tool < b.Tool + } + if ra, rb := strings.Join(a.Rules, ","), strings.Join(b.Rules, ","); ra != rb { + return ra < rb + } + return strings.Join(a.Paths, ",") < strings.Join(b.Paths, ",") + }) + return out +} + +func newGroup(tool, pkg string, alerts []Alert) Group { + g := Group{Tool: tool, Package: pkg, Alerts: alerts, Paths: distinctPaths(alerts)} + seen := map[string]bool{} + for _, a := range alerts { + if !seen[a.Rule.ID] { + seen[a.Rule.ID] = true + g.Rules = append(g.Rules, a.Rule.ID) + } + } + sort.Strings(g.Rules) + return g +} + +func distinctPaths(alerts []Alert) []string { + seen := map[string]bool{} + var out []string + for _, a := range alerts { + p := a.Path() + if p != "" && !seen[p] { + seen[p] = true + out = append(out, p) + } + } + sort.Strings(out) + return out +} + +// packFiles splits sorted files into bins (see Cluster). No files (all +// repo-level) is one empty bin, so a repo-level rule still gets an issue. +func packFiles(files []string) [][]string { + if len(files) <= MaxFilesPerIssue { + return [][]string{files} + } + var dirs []string + byDir := map[string][]string{} + for _, f := range files { + d := path.Dir(f) + if _, ok := byDir[d]; !ok { + dirs = append(dirs, d) + } + byDir[d] = append(byDir[d], f) + } + sort.Strings(dirs) + var out [][]string + var bin []string + flush := func() { + if len(bin) > 0 { + out = append(out, bin) + bin = nil + } + } + for _, d := range dirs { + fs := byDir[d] + if len(fs) > MaxFilesPerIssue { + flush() + for i := 0; i < len(fs); i += MaxFilesPerIssue { + out = append(out, fs[i:min(i+MaxFilesPerIssue, len(fs))]) + } + continue + } + if len(bin)+len(fs) > MaxFilesPerIssue { + flush() + } + bin = append(bin, fs...) + } + flush() + return out +} + +// MarkerPrefix opens the hidden marker every code scanning issue carries. +const MarkerPrefix = " +// +// Alerts is every alert number the issue has ever tracked; an alert number +// on any hive issue, open or closed, is never filed again. Values are +// query-escaped so a path cannot end the comment. +type Marker struct { + Tool string + Rules []string + Package string + Paths []string + Alerts []int +} + +var markerRE = regexp.MustCompile(``) + +// String renders the marker. +func (m Marker) String() string { + esc := func(vs []string) string { + out := make([]string, len(vs)) + for i, v := range vs { + out[i] = url.QueryEscape(v) + } + return strings.Join(out, ",") + } + nums := make([]string, len(m.Alerts)) + for i, n := range m.Alerts { + nums[i] = strconv.Itoa(n) + } + s := MarkerPrefix + "tool=" + url.QueryEscape(m.Tool) + " rule=" + esc(m.Rules) + if m.Package != "" { + s += " package=" + url.QueryEscape(m.Package) + } + return s + " paths=" + esc(m.Paths) + " alerts=" + strings.Join(nums, ",") + " -->" +} + +// ParseMarker reads the marker from an issue body. +func ParseMarker(body string) (Marker, bool) { + sm := markerRE.FindStringSubmatch(body) + if sm == nil { + return Marker{}, false + } + var m Marker + split := func(v string) []string { + var out []string + for _, p := range strings.Split(v, ",") { + if u, err := url.QueryUnescape(p); err == nil && u != "" { + out = append(out, u) + } + } + return out + } + for _, field := range strings.Fields(sm[1]) { + k, v, ok := strings.Cut(field, "=") + if !ok { + continue + } + switch k { + case "tool": + m.Tool, _ = url.QueryUnescape(v) + case "rule": + m.Rules = split(v) + case "package": + m.Package, _ = url.QueryUnescape(v) + case "paths": + m.Paths = split(v) + case "alerts": + for _, n := range strings.Split(v, ",") { + if i, err := strconv.Atoi(n); err == nil && i > 0 { + m.Alerts = append(m.Alerts, i) + } + } + } + } + return m, len(m.Alerts) > 0 +} + +// covers reports whether a new alert belongs on the issue this marker is +// on: same tool and package for a dependency alert; otherwise same tool and +// rule in a file the issue already lists. +func (m Marker) covers(a Alert) bool { + if !strings.EqualFold(m.Tool, a.Tool.Name) { + return false + } + if d, ok := a.Dependency(); ok { + return m.Package != "" && m.Package == d.Package + } + if m.Package != "" || !containsString(m.Rules, a.Rule.ID) { + return false + } + p := a.Path() + if p == "" { + return len(m.Paths) == 0 + } + return containsString(m.Paths, p) +} + +func containsString(vs []string, s string) bool { + for _, v := range vs { + if v == s { + return true + } + } + return false +} diff --git a/src/pkg/codescanning/render.go b/src/pkg/codescanning/render.go new file mode 100644 index 0000000000..62de11080a --- /dev/null +++ b/src/pkg/codescanning/render.go @@ -0,0 +1,375 @@ +package codescanning + +import ( + "fmt" + "path" + "regexp" + "sort" + "strconv" + "strings" +) + +// Alert-table delimiters. The sweep rewrites only the marker and the text +// between these on later passes, so the summary, code excerpt and upstream +// note written at filing time survive. +const ( + alertsStart = "" + alertsEnd = "" +) + +// maxAlertRows bounds the table so a large group cannot outgrow GitHub's +// 65,536-character body limit; the marker still lists every alert. +const maxAlertRows = 100 + +// workflowsDocURL is the hive doc on handing workflow-file work to the lane +// that can push it. +const workflowsDocURL = "https://github.com/hivecommons/hive/blob/v6/src/docs/hive-open-issue.md" + +// AlertStatus is a tracked alert's state on GitHub as the sweep last saw it. +type AlertStatus string + +// Alert states the table shows. +const ( + StatusOpen AlertStatus = "open" + StatusFixed AlertStatus = "fixed" + StatusDismissed AlertStatus = "dismissed" +) + +// Title is the issue title, before the filer tag ("[governor] ") the forge +// adds. +func Title(g Group) string { + n := len(g.Alerts) + plural := "s" + if n == 1 { + plural = "" + } + if g.Package != "" { + return fmt.Sprintf("Code scanning: %s has %d known vulnerabilit%s (%s)", g.Package, len(g.Rules), map[bool]string{true: "y", false: "ies"}[len(g.Rules) == 1], g.Level()) + } + rule := strings.Join(g.Rules, ", ") + return fmt.Sprintf("Code scanning: %s in %s (%d %s alert%s)", rule, where(g.Paths), n, g.Level(), plural) +} + +func where(paths []string) string { + switch { + case len(paths) == 0: + return "repository settings" + case len(paths) == 1: + return paths[0] + } + dir := path.Dir(paths[0]) + for _, p := range paths[1:] { + if path.Dir(p) != dir { + return fmt.Sprintf("%d files", len(paths)) + } + } + return fmt.Sprintf("%s/ (%d files)", dir, len(paths)) +} + +// BodyInput is what Body needs beyond the group. +type BodyInput struct { + Repo string + Group Group + // Excerpt is the source around the first alert's lines at the analysed + // commit ("" when it could not be read or the group has no source file). + Excerpt string + ExcerptPath string + // Upstream is the fork-parent note ("" when the repo is not a fork or + // the check found nothing to say). + Upstream string + // WorkflowsLane is the lane that can push .github/workflows/** in this + // repo ("" when none can). + WorkflowsLane string +} + +// Body renders a new issue: executive summary, evidence, wanted behaviour, +// acceptance criteria, test plan, false-positive handling and scope, so a +// lane can do it cold. +func Body(in BodyInput) string { + g := in.Group + var b strings.Builder + b.WriteString(markerFor(g, nil).String() + "\n\n") + b.WriteString("## Summary\n\n") + if g.Package != "" { + d, _ := g.Alerts[0].Dependency() + fmt.Fprintf(&b, "GitHub code scanning (%s) reports that `%s` (installed `%s`) has %d known vulnerabilit%s, highest **%s**. ", g.Tool, g.Package, orUnknown(d.Installed), len(g.Rules), map[bool]string{true: "y", false: "ies"}[len(g.Rules) == 1], g.Level()) + if d.Fixed != "" { + fmt.Fprintf(&b, "The scanner says it is fixed in `%s`. ", d.Fixed) + } + b.WriteString("The flagged paths below are where the scanner found the package, often a built binary rather than a source file.\n\n") + } else { + fmt.Fprintf(&b, "GitHub code scanning (%s) reports %d alert%s for `%s` (%s) in %s, highest **%s**. ", g.Tool, len(g.Alerts), map[bool]string{true: "", false: "s"}[len(g.Alerts) == 1], strings.Join(g.Rules, "`, `"), ruleTitle(g), where(g.Paths), g.Level()) + b.WriteString("The hive grouped them into one issue sized for one PR.\n\n") + } + b.WriteString("**These alerts may be false positives.** Verify each one against the code before changing anything; a static analyser does not know which inputs can reach a line.\n\n") + if g.WorkflowOnly() { + b.WriteString(workflowNote(in.WorkflowsLane)) + } + + b.WriteString("## Evidence\n\n") + if sha := g.Alerts[0].Instance.CommitSHA; sha != "" { + fmt.Fprintf(&b, "Analysed commit: `%s`", shortSHA(sha)) + if ref := g.Alerts[0].Instance.Ref; ref != "" { + fmt.Fprintf(&b, " on `%s`", ref) + } + b.WriteString(". Line numbers are at that commit.\n\n") + } + b.WriteString(alertsSection(in.Repo, g.Alerts, nil, nil) + "\n") + if in.Excerpt != "" { + fmt.Fprintf(&b, "\nCode at the analysed commit (`%s`):\n\n```%s\n%s\n```\n", in.ExcerptPath, fenceLang(in.ExcerptPath), strings.TrimRight(in.Excerpt, "\n")) + } + if help := g.Alerts[0].Rule.HelpURI; help != "" { + fmt.Fprintf(&b, "\nRule documentation: %s\n", help) + } else if u := g.Alerts[0].HTMLURL; u != "" { + fmt.Fprintf(&b, "\nThe rule's explanation and recommended fix are on each alert page (for example %s).\n", u) + } + if in.Upstream != "" { + b.WriteString("\n### Upstream\n\n" + in.Upstream + "\n") + } + + b.WriteString("\n## Wanted behaviour\n\n") + switch { + case g.Package != "": + d, _ := g.Alerts[0].Dependency() + fmt.Fprintf(&b, "`%s` is at a version with none of the listed vulnerabilities", g.Package) + if d.Fixed != "" { + fmt.Fprintf(&b, " (`%s` or later)", strings.TrimSpace(strings.Split(d.Fixed, ",")[0])) + } + b.WriteString(". Find where the flagged artifact gets the package: the `go.mod`/lockfile of the program that builds it, or the `Containerfile`/`Dockerfile` that installs it. Bump it there, not in the built output.") + if g.Package == "stdlib" { + b.WriteString(" For Go's `stdlib` that means building with a newer Go toolchain: the `go`/`toolchain` line in `go.mod`, or the Go version of the builder image.") + } + b.WriteString("\n") + case len(g.Paths) == 0: + b.WriteString("The repository-level check passes. This usually needs a settings or policy change by a maintainer; if so, say so here instead of changing code.\n") + default: + b.WriteString("Each listed alert is fixed in the code, so the next code scanning analysis of the default branch no longer reports it, or is shown on this issue to be a false positive. The behaviour of the code is otherwise unchanged.\n") + } + + b.WriteString("\n## Acceptance criteria\n\n") + b.WriteString("- [ ] Every alert listed above is fixed at the cited location, or reported on this issue as a false positive with the reason.\n") + b.WriteString("- [ ] The change touches only what the alerts need; no unrelated refactoring.\n") + b.WriteString("- [ ] No check is weakened to silence an alert: no suppression comments, no edits to the code scanning workflow or its config, no alert dismissed on GitHub.\n") + b.WriteString("- [ ] The repository's build and tests pass.\n") + + b.WriteString("\n## Test plan\n\n") + b.WriteString("- Build the project and run its existing tests.\n") + if g.Package != "" { + b.WriteString("- Rebuild the flagged artifact and confirm it now carries the fixed version (for Go: `go version -m `).\n") + } else if len(g.Paths) > 0 { + b.WriteString("- Where practical, add or extend a test that drives the flagged input through the fixed code.\n") + } + b.WriteString("- After the PR merges, the next code scanning run closes the alerts. The hive then closes this issue on its own; it is not closed by the PR.\n") + + b.WriteString("\n## If an alert is a false positive\n\n") + b.WriteString("Comment on this issue with the alert number and why it cannot happen (which input cannot reach the line, or why the pattern is safe here). Do not change code just to make the analyser quiet. A maintainer decides whether to dismiss the alert on GitHub; the hive closes this issue once every listed alert is fixed or dismissed.\n") + + b.WriteString("\n## Out of scope\n\n") + b.WriteString("- Other code scanning alerts, other rules and files not listed here; the hive files those separately.\n") + b.WriteString("- The code scanning setup itself (its workflow, query suites and config).\n") + b.WriteString("- Dismissing alerts on GitHub, which is a maintainer's call.\n") + return b.String() +} + +func workflowNote(lane string) string { + var b strings.Builder + b.WriteString("**This fix edits GitHub Actions workflow files** (`.github/workflows/`). Pushing them needs the GitHub App's Workflows permission, and the hive's sentinel flags workflow permission changes for maintainer review. ") + if lane != "" { + fmt.Fprintf(&b, "This issue carries `hive/workflows-lane`, so it goes to `%s`, the lane that can push workflow files.", lane) + } else { + fmt.Fprintf(&b, "No lane serving this repository can push workflow files. A lane that cannot push them should not try: park the issue with the workflows blocker as described in [hive-open-issue](%s).", workflowsDocURL) + } + b.WriteString("\n\n") + return b.String() +} + +func ruleTitle(g Group) string { + if d := strings.TrimSpace(g.Alerts[0].Rule.Description); d != "" { + return d + } + return g.Alerts[0].Rule.Name +} + +func orUnknown(s string) string { + if s == "" { + return "unknown" + } + return s +} + +func shortSHA(sha string) string { + if len(sha) > 12 { + return sha[:12] + } + return sha +} + +func fenceLang(p string) string { + switch strings.ToLower(path.Ext(p)) { + case ".c", ".h": + return "c" + case ".cc", ".cpp", ".cxx", ".hpp", ".hh", ".hxx": + return "cpp" + case ".go": + return "go" + case ".py": + return "python" + case ".js", ".mjs", ".cjs": + return "javascript" + case ".ts", ".tsx": + return "typescript" + case ".yml", ".yaml": + return "yaml" + case ".sh", ".bash": + return "bash" + case ".java": + return "java" + case ".rs": + return "rust" + case ".rb": + return "ruby" + } + return "" +} + +// markerFor builds the marker for a group plus alerts appended later. +func markerFor(g Group, extra []int) Marker { + m := Marker{Tool: g.Tool, Rules: g.Rules, Package: g.Package, Paths: g.Paths} + for _, a := range g.Alerts { + m.Alerts = append(m.Alerts, a.Number) + } + m.Alerts = mergeInts(m.Alerts, extra) + return m +} + +func mergeInts(a, b []int) []int { + seen := map[int]bool{} + var out []int + for _, v := range append(append([]int(nil), a...), b...) { + if !seen[v] { + seen[v] = true + out = append(out, v) + } + } + sort.Ints(out) + return out +} + +var alertRowRE = regexp.MustCompile(`(?m)^\| \[#(\d+)\]\([^)]*\) \| [a-z]+ \|.*$`) + +// alertsSection renders the delimited alert table. open holds the alerts +// still open (full rows); gone maps tracked alerts that are no longer open to +// their status, re-using the row from prev (the old section) when there is +// one so the location written at filing time is kept. +func alertsSection(repo string, open []Alert, gone map[int]AlertStatus, prev map[int]string) string { + rows := map[int]string{} + for _, a := range open { + loc := a.Path() + if loc == "" { + loc = "(repository)" + } else if l := a.Instance.Location.StartLine; l > 0 { + loc += ":" + strconv.Itoa(l) + } + rows[a.Number] = fmt.Sprintf("| [#%d](%s) | %s | `%s` | %s | %s |", a.Number, alertURL(repo, a), StatusOpen, loc, a.Level(), cell(a.Rule.ID+": "+a.Instance.Message.Text)) + } + for n, st := range gone { + if old, ok := prev[n]; ok { + rows[n] = alertRowRE.ReplaceAllStringFunc(old, func(r string) string { + i := strings.Index(r, ") | ") + j := strings.Index(r[i+4:], " |") + return r[:i+4] + string(st) + r[i+4+j:] + }) + continue + } + rows[n] = fmt.Sprintf("| [#%d](%s) | %s | | | |", n, alertURL(repo, Alert{Number: n}), st) + } + nums := make([]int, 0, len(rows)) + for n := range rows { + nums = append(nums, n) + } + sort.Ints(nums) + var b strings.Builder + b.WriteString(alertsStart + "\n") + fmt.Fprintf(&b, "%d alert%s, %d still open.\n\n", len(nums), map[bool]string{true: "", false: "s"}[len(nums) == 1], len(open)) + b.WriteString("| Alert | Status | Location | Severity | Rule and message |\n| --- | --- | --- | --- | --- |\n") + for i, n := range nums { + if i == maxAlertRows { + fmt.Fprintf(&b, "\n%d more alerts are tracked; the marker at the top lists every number.\n", len(nums)-i) + break + } + b.WriteString(rows[n] + "\n") + } + b.WriteString(alertsEnd) + return b.String() +} + +func alertURL(repo string, a Alert) string { + if a.HTMLURL != "" { + return a.HTMLURL + } + return "https://github.com/" + repo + "/security/code-scanning/" + strconv.Itoa(a.Number) +} + +// cell flattens analyser text into one table cell. +func cell(s string) string { + s = strings.Join(strings.Fields(s), " ") + s = strings.ReplaceAll(s, "|", `\|`) + s = strings.ReplaceAll(s, "" + +// CloseComment is the note posted when every tracked alert is gone. +func CloseComment(gone map[int]AlertStatus) string { + nums := make([]int, 0, len(gone)) + for n := range gone { + nums = append(nums, n) + } + sort.Ints(nums) + var fixed, dismissed []string + for _, n := range nums { + if gone[n] == StatusDismissed { + dismissed = append(dismissed, "#"+strconv.Itoa(n)) + } else { + fixed = append(fixed, "#"+strconv.Itoa(n)) + } + } + var b strings.Builder + b.WriteString(CloseMarker + "\n") + b.WriteString("Every code scanning alert this issue tracked is no longer open on GitHub") + if len(fixed) > 0 { + b.WriteString("; fixed: " + strings.Join(fixed, ", ")) + } + if len(dismissed) > 0 { + b.WriteString("; dismissed by a maintainer: " + strings.Join(dismissed, ", ")) + } + b.WriteString(". Closing. The hive never reopens this issue and never files these alert numbers again.") + return b.String() +} diff --git a/src/pkg/codescanning/sweep.go b/src/pkg/codescanning/sweep.go new file mode 100644 index 0000000000..c5a497e387 --- /dev/null +++ b/src/pkg/codescanning/sweep.go @@ -0,0 +1,464 @@ +package codescanning + +import ( + "context" + "errors" + "fmt" + "strings" + "time" +) + +// ErrNoAccess is returned by Forge.ListAlerts when GitHub refuses the read: +// the App lacks "Code scanning alerts: read" (security_events), answered as +// a 403, or a 404 GitHub uses for "no access". +var ErrNoAccess = errors.New("code scanning alerts are not readable") + +// ErrNotEnabled is returned by Forge.ListAlerts when the repository has no +// code scanning analysis at all. +var ErrNotEnabled = errors.New("code scanning is not set up") + +// Notice kinds on Status. +const ( + NoticeMissingPermission = "missing_permission" + NoticeNotEnabled = "not_enabled" +) + +// TrackedIssue is one of the hive's own code scanning issues, open or +// closed, as the forge listed it. +type TrackedIssue struct { + Number int + Open bool + Body string + Marker Marker +} + +// Forge is what Run needs from GitHub. pkg/github implements it; every write +// goes through the write-back gate there. +type Forge interface { + // ListAlerts lists the repo's alerts in state ("open" or "dismissed"), + // reading at most maxPages pages. complete is false when the bound + // stopped the listing early. + ListAlerts(ctx context.Context, repo, state string, maxPages int) (alerts []Alert, complete bool, err error) + // ListIssues lists every issue the hive filed with a code scanning + // marker, open and closed. + ListIssues(ctx context.Context, repo string) ([]TrackedIssue, error) + CreateIssue(ctx context.Context, repo, title, body string, labels []string) (int, error) + EditIssueBody(ctx context.Context, repo string, number int, body string) error + // CloseIssue comments, then closes with stateReason ("completed" or + // "not_planned"). + CloseIssue(ctx context.Context, repo string, number int, comment, stateReason string) error + // FileAt reads a text file at ref ("" = the default branch HEAD). + // found is false when the file does not exist there. + FileAt(ctx context.Context, repo, path, ref string) (content string, found bool, err error) + // Upstream returns the fork parent ("owner/repo"), or "" when repo is + // not a fork. + Upstream(ctx context.Context, repo string) (string, error) + // LastCommit returns the newest commit on the default branch that + // touched path. + LastCommit(ctx context.Context, repo, path string) (string, error) +} + +// Options configures one repo's pass. +type Options struct { + Repo string + Policy Policy + // MaxPages bounds the open-alert listing (100 per page). 0 means + // DefaultMaxPages. + MaxPages int + // Labels go on every new issue. + Labels []string + // WorkflowsLane is the lane that can push workflow files in this repo + // ("" when none can); WorkflowsLaneLabel routes an issue to it. + WorkflowsLane string + WorkflowsLaneLabel string + Now time.Time +} + +// DefaultMaxPages bounds the open-alert listing at 1,000 alerts. +const DefaultMaxPages = 10 + +// dismissedMaxPages bounds the dismissed-alert listing, read only when a +// tracked alert has left the open list. +const dismissedMaxPages = 2 + +// Status is one repo's code scanning picture after a pass, for the +// dashboard. +type Status struct { + Repo string `json:"repo"` + SecurityURL string `json:"security_url"` + CheckedAt time.Time `json:"checked_at"` + // OpenAlerts and BySeverity count every open alert, filed or not, on + // the sweep's scale (critical, high, medium, low, note). + OpenAlerts int `json:"open_alerts"` + BySeverity map[string]int `json:"by_severity"` + // Qualifying are open alerts the repo's filter would file. + Qualifying int `json:"qualifying"` + // BelowThreshold are below min_severity; Excluded are left out by + // tool or rule (Scorecard's repo-posture checks by default). + BelowThreshold int `json:"below_threshold"` + Excluded int `json:"excluded"` + // Tracked are open alerts listed on an open hive issue. + Tracked int `json:"tracked"` + // TrackedClosed are open alerts whose hive issue was closed (by a + // person, or before the analysis caught up); they are not filed again. + TrackedClosed int `json:"tracked_closed"` + // Untracked are qualifying alerts with no issue yet, waiting for the + // per-pass cap. + Untracked int `json:"untracked"` + OpenIssues int `json:"open_issues"` + // Filed, Updated and Closed are this pass's writes. + Filed int `json:"filed"` + Updated int `json:"updated"` + Closed int `json:"closed"` + // Truncated is true when the open-alert listing hit its page bound; + // fixed-alert detection and closing are skipped for that pass. + Truncated bool `json:"truncated,omitempty"` + // Notice is an operator-facing problem (a missing App permission, code + // scanning not set up) and NoticeKind its machine name. + Notice string `json:"notice,omitempty"` + NoticeKind string `json:"notice_kind,omitempty"` + Error string `json:"error,omitempty"` +} + +// SecurityURL is the repo's code scanning page. +func SecurityURL(repo string) string { + return "https://github.com/" + repo + "/security/code-scanning" +} + +// NoticeFor is the dashboard text for a listing error, or "" when the error +// is not a notice. +func NoticeFor(repo string, err error) (kind, text string) { + switch { + case errors.Is(err, ErrNoAccess): + return NoticeMissingPermission, fmt.Sprintf("The hive cannot read code scanning alerts in %s. Give the GitHub App the repository permission \"Code scanning alerts: Read-only\" (security_events) and accept the permission update on the installation.", repo) + case errors.Is(err, ErrNotEnabled): + return NoticeNotEnabled, fmt.Sprintf("%s has no code scanning analysis. Set up CodeQL or another SARIF uploader, or turn the code scanning sweep off for this repo.", repo) + } + return "", "" +} + +// Run makes one pass over a repo: list open alerts and the hive's own +// issues, close or update issues whose alerts changed, add new alerts to the +// issue already covering their rule and file, and file at most +// Policy.MaxNewIssues new grouped issues. A failed read writes nothing. +func Run(ctx context.Context, f Forge, o Options) (Status, error) { + st := Status{Repo: o.Repo, SecurityURL: SecurityURL(o.Repo), CheckedAt: o.Now, BySeverity: map[string]int{}} + maxPages := o.MaxPages + if maxPages <= 0 { + maxPages = DefaultMaxPages + } + open, complete, err := f.ListAlerts(ctx, o.Repo, "open", maxPages) + if err != nil { + st.NoticeKind, st.Notice = NoticeFor(o.Repo, err) + return st, err + } + st.Truncated = !complete + openByNum := map[int]Alert{} + for _, a := range open { + openByNum[a.Number] = a + st.OpenAlerts++ + if l := a.Level(); l != LevelNone { + st.BySeverity[l.String()]++ + } + } + issues, err := f.ListIssues(ctx, o.Repo) + if err != nil { + // Never file without the dedupe state. + return st, fmt.Errorf("listing code scanning issues: %w", err) + } + seen := map[int]bool{} + openTracked := map[int]bool{} + var openIssues []*TrackedIssue + for i := range issues { + is := &issues[i] + for _, n := range is.Marker.Alerts { + seen[n] = true + if is.Open { + openTracked[n] = true + } + } + if is.Open { + openIssues = append(openIssues, is) + } + } + + // Alerts that left the open list since an open issue was written. + var dismissed map[int]bool + if complete { + for _, is := range openIssues { + for _, n := range is.Marker.Alerts { + if _, ok := openByNum[n]; !ok && dismissed == nil { + ds, _, derr := f.ListAlerts(ctx, o.Repo, "dismissed", dismissedMaxPages) + if derr != nil { + return st, fmt.Errorf("listing dismissed alerts: %w", derr) + } + dismissed = map[int]bool{} + for _, d := range ds { + dismissed[d.Number] = true + } + } + } + } + } + + // New qualifying alerts: join an open issue that covers them, or wait + // for a new group. + appended := map[int][]Alert{} + var pool []Alert + for _, a := range open { + switch o.Policy.Judge(a) { + case BelowThreshold: + st.BelowThreshold++ + case Excluded: + st.Excluded++ + default: + st.Qualifying++ + } + switch { + case openTracked[a.Number]: + st.Tracked++ + continue + case seen[a.Number]: + st.TrackedClosed++ + continue + } + if o.Policy.Judge(a) != Qualifies { + continue + } + joined := false + for _, is := range openIssues { + if is.Marker.covers(a) { + appended[is.Number] = append(appended[is.Number], a) + joined = true + break + } + } + if joined { + st.Tracked++ + continue + } + pool = append(pool, a) + } + + // Existing open issues: close when every alert is gone, else refresh the + // table when something changed. + for _, is := range openIssues { + if err := ctx.Err(); err != nil { + return st, err + } + var still []Alert + gone := map[int]AlertStatus{} + for _, n := range is.Marker.Alerts { + if a, ok := openByNum[n]; ok { + still = append(still, a) + continue + } + if !complete { + continue + } + if dismissed[n] { + gone[n] = StatusDismissed + } else { + gone[n] = StatusFixed + } + } + add := appended[is.Number] + if complete && len(still) == 0 && len(add) == 0 { + reason := "completed" + allDismissed := true + for _, s := range gone { + allDismissed = allDismissed && s == StatusDismissed + } + if allDismissed { + reason = "not_planned" + } + if err := f.CloseIssue(ctx, o.Repo, is.Number, CloseComment(gone), reason); err != nil { // writeback:gated — codeScanningForge (pkg/github) consults WritebackAllowed + return st, fmt.Errorf("closing #%d: %w", is.Number, err) + } + st.Closed++ + continue + } + st.OpenIssues++ + m := is.Marker + for _, a := range add { + m.Alerts = mergeInts(m.Alerts, []int{a.Number}) + if p := a.Path(); p != "" && !containsString(m.Paths, p) { + m.Paths = append(m.Paths, p) + } + } + rows := append(append([]Alert(nil), still...), add...) + sortAlerts(rows) + if !complete { + // Without the full open list, absent alerts are unknown: keep + // their old rows as they were. + for n, row := range previousRows(is.Body) { + if _, ok := openByNum[n]; !ok && containsInt(m.Alerts, n) { + gone[n] = AlertStatus(rowStatus(row)) + } + } + } + body := rewriteBody(is.Body, m, alertsSection(o.Repo, rows, gone, previousRows(is.Body))) + if strings.TrimSpace(body) == strings.TrimSpace(is.Body) { + continue + } + if err := f.EditIssueBody(ctx, o.Repo, is.Number, body); err != nil { // writeback:gated — codeScanningForge (pkg/github) consults WritebackAllowed + return st, fmt.Errorf("updating #%d: %w", is.Number, err) + } + st.Updated++ + } + + // New groups, highest level first, at most the cap. + groups := Cluster(pool) + limit := o.Policy.maxNewIssues() + var upstream string + upstreamRead := false + for _, g := range groups { + if st.Filed >= limit { + st.Untracked += len(g.Alerts) + continue + } + if err := ctx.Err(); err != nil { + return st, err + } + in := BodyInput{Repo: o.Repo, Group: g} + if !g.WorkflowOnly() || o.WorkflowsLane == "" { + in.WorkflowsLane = "" + } else { + in.WorkflowsLane = o.WorkflowsLane + } + var source string + if g.Package == "" && len(g.Paths) > 0 { + first := g.Alerts[0] + if content, found, ferr := f.FileAt(ctx, o.Repo, first.Path(), first.Instance.CommitSHA); ferr == nil && found { + source = content + in.Excerpt, in.ExcerptPath = Excerpt(content, g.Alerts, first.Path()), first.Path() + } + if !upstreamRead { + upstreamRead = true + upstream, _ = f.Upstream(ctx, o.Repo) + } + if upstream != "" && source != "" { + in.Upstream = upstreamNote(ctx, f, upstream, first.Path(), source, g.Alerts) + } + } + labels := append([]string(nil), o.Labels...) + if in.WorkflowsLane != "" && o.WorkflowsLaneLabel != "" { + labels = append(labels, o.WorkflowsLaneLabel) + } + if _, err := f.CreateIssue(ctx, o.Repo, Title(g), Body(in), labels); err != nil { // writeback:gated — codeScanningForge (pkg/github) consults WritebackAllowed + return st, fmt.Errorf("filing %s: %w", Title(g), err) + } + st.Filed++ + st.OpenIssues++ + st.Tracked += len(g.Alerts) + } + return st, nil +} + +func containsInt(vs []int, n int) bool { + for _, v := range vs { + if v == n { + return true + } + } + return false +} + +func rowStatus(row string) string { + parts := strings.SplitN(row, " | ", 3) + if len(parts) < 2 { + return string(StatusOpen) + } + return strings.TrimSpace(parts[1]) +} + +// excerptContext is the lines shown around each flagged line. +const excerptContext = 3 + +// maxExcerptLines bounds the excerpt. +const maxExcerptLines = 40 + +// Excerpt returns numbered source lines around the group's alerts in file, +// at most maxExcerptLines of them. +func Excerpt(content string, alerts []Alert, file string) string { + lines := strings.Split(content, "\n") + show := map[int]bool{} + flagged := map[int]bool{} + for _, a := range alerts { + if a.Path() != file { + continue + } + start, end := a.Instance.Location.StartLine, a.Instance.Location.EndLine + if start <= 0 || start > len(lines) { + continue + } + end = max(end, start) + for l := start; l <= end; l++ { + flagged[l] = true + } + for l := max(1, start-excerptContext); l <= min(len(lines), end+excerptContext); l++ { + show[l] = true + } + } + var b strings.Builder + shown, last := 0, 0 + for l := 1; l <= len(lines) && shown < maxExcerptLines; l++ { + if !show[l] { + continue + } + if last != 0 && l != last+1 { + b.WriteString("...\n") + } + mark := " " + if flagged[l] { + mark = ">" + } + fmt.Fprintf(&b, "%s%5d %s\n", mark, l, strings.ReplaceAll(lines[l-1], "```", "` ` `")) + shown++ + last = l + } + return b.String() +} + +// upstreamNote is the fork check: does the fork's parent still have the +// flagged lines at HEAD? Two reads at most: the upstream file, and, when the +// lines are gone, the last upstream commit to touch it. +func upstreamNote(ctx context.Context, f Forge, upstream, file, source string, alerts []Alert) string { + content, found, err := f.FileAt(ctx, upstream, file, "") + if err != nil { + return "" + } + if !found { + return fmt.Sprintf("This repository is a fork of `%s`, where `%s` no longer exists at HEAD (moved or removed). Check upstream before fixing it here; the fix may be a port.", upstream, file) + } + lines := strings.Split(source, "\n") + var flagged, present int + for _, a := range alerts { + if a.Path() != file { + continue + } + n := a.Instance.Location.StartLine + if n <= 0 || n > len(lines) { + continue + } + text := strings.TrimSpace(lines[n-1]) + if len(text) < 6 { + continue + } + flagged++ + if strings.Contains(content, text) { + present++ + } + } + switch { + case flagged == 0: + return "" + case present == flagged: + return fmt.Sprintf("This repository is a fork of `%s`. Upstream HEAD still has the flagged code in `%s`, so there is no upstream fix to port; a fix made here may be worth offering upstream.", upstream, file) + } + sha, err := f.LastCommit(ctx, upstream, file) + if err != nil || sha == "" { + return fmt.Sprintf("This repository is a fork of `%s`, and upstream has changed the flagged code in `%s`. Check whether upstream already fixed it and port that change rather than writing a new fix.", upstream, file) + } + return fmt.Sprintf("This repository is a fork of `%s`, and upstream has changed the flagged code in `%s` (last upstream change: %s). If that change fixes the alert, port upstream %s rather than writing a new fix: https://github.com/%s/commit/%s", upstream, file, shortSHA(sha), shortSHA(sha), upstream, sha) +} diff --git a/src/pkg/codescanning/sweep_test.go b/src/pkg/codescanning/sweep_test.go new file mode 100644 index 0000000000..5723b6b27a --- /dev/null +++ b/src/pkg/codescanning/sweep_test.go @@ -0,0 +1,566 @@ +package codescanning + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "sort" + "strings" + "testing" + "time" +) + +func loadAlerts(t *testing.T, name string) []Alert { + t.Helper() + data, err := os.ReadFile(filepath.Join("testdata", name)) + if err != nil { + t.Fatal(err) + } + var out []Alert + if err := json.Unmarshal(data, &out); err != nil { + t.Fatalf("%s: %v", name, err) + } + return out +} + +type fakeIssue struct { + title, body, closeReason, closeComment string + labels []string + open bool +} + +// fakeForge is an in-memory GitHub: alerts by state, the hive's issues, and +// files by repo@ref/path. +type fakeForge struct { + open, dismissed []Alert + listErr error + maxPagesSeen int + pageLimit int // alerts beyond this many make the listing incomplete + issues map[int]*fakeIssue + next int + files map[string]string + upstream string + lastCommit string + writes int + dismissedReads int +} + +func newFakeForge(open []Alert) *fakeForge { + return &fakeForge{open: open, issues: map[int]*fakeIssue{}, next: 100, files: map[string]string{}} +} + +func (f *fakeForge) ListAlerts(_ context.Context, _, state string, maxPages int) ([]Alert, bool, error) { + if f.listErr != nil { + return nil, false, f.listErr + } + f.maxPagesSeen = maxPages + if state == "dismissed" { + f.dismissedReads++ + return f.dismissed, true, nil + } + if f.pageLimit > 0 && len(f.open) > f.pageLimit { + return f.open[:f.pageLimit], false, nil + } + return f.open, true, nil +} + +func (f *fakeForge) ListIssues(context.Context, string) ([]TrackedIssue, error) { + var out []TrackedIssue + nums := make([]int, 0, len(f.issues)) + for n := range f.issues { + nums = append(nums, n) + } + sort.Ints(nums) + for _, n := range nums { + is := f.issues[n] + m, ok := ParseMarker(is.body) + if !ok { + continue + } + out = append(out, TrackedIssue{Number: n, Open: is.open, Body: is.body, Marker: m}) + } + return out, nil +} + +func (f *fakeForge) CreateIssue(_ context.Context, _, title, body string, labels []string) (int, error) { + f.writes++ + f.next++ + f.issues[f.next] = &fakeIssue{title: title, body: body, labels: labels, open: true} + return f.next, nil +} + +func (f *fakeForge) EditIssueBody(_ context.Context, _ string, n int, body string) error { + f.writes++ + f.issues[n].body = body + return nil +} + +func (f *fakeForge) CloseIssue(_ context.Context, _ string, n int, comment, reason string) error { + f.writes++ + is := f.issues[n] + is.open, is.closeComment, is.closeReason = false, comment, reason + return nil +} + +func (f *fakeForge) FileAt(_ context.Context, repo, path, ref string) (string, bool, error) { + c, ok := f.files[repo+"@"+ref+"/"+path] + return c, ok, nil +} + +func (f *fakeForge) Upstream(context.Context, string) (string, error) { return f.upstream, nil } + +func (f *fakeForge) LastCommit(context.Context, string, string) (string, error) { + return f.lastCommit, nil +} + +func (f *fakeForge) openIssues() []*fakeIssue { + var out []*fakeIssue + for _, is := range f.issues { + if is.open { + out = append(out, is) + } + } + return out +} + +func run(t *testing.T, f *fakeForge, o Options) Status { + t.Helper() + if o.Repo == "" { + o.Repo = "example/exult" + } + if o.Now.IsZero() { + o.Now = time.Date(2026, 11, 7, 12, 0, 0, 0, time.UTC) + } + st, err := Run(context.Background(), f, o) + if err != nil { + t.Fatalf("Run: %v", err) + } + return st +} + +func qualifying(alerts []Alert, p Policy) []Alert { + var out []Alert + for _, a := range alerts { + if p.Judge(a) == Qualifies { + out = append(out, a) + } + } + return out +} + +func TestLevelMapsBothSeverityFields(t *testing.T) { + cases := []struct { + sec, sev string + want Level + }{ + {"critical", "warning", LevelCritical}, + {"high", "error", LevelHigh}, + {"medium", "error", LevelMedium}, + {"low", "error", LevelLow}, + {"", "error", LevelMedium}, + {"", "warning", LevelLow}, + {"", "note", LevelNote}, + {"", "", LevelNone}, + } + for _, c := range cases { + a := Alert{Rule: Rule{SecuritySeverityLevel: c.sec, Severity: c.sev}} + if got := a.Level(); got != c.want { + t.Errorf("security=%q severity=%q: level %s, want %s", c.sec, c.sev, got, c.want) + } + } + for in, want := range map[string]Level{"high": LevelHigh, "Critical": LevelCritical, "error": LevelMedium, "warning": LevelLow, "note": LevelNote} { + if got, ok := ParseLevel(in); !ok || got != want { + t.Errorf("ParseLevel(%q) = %s, %v; want %s", in, got, ok, want) + } + } + if _, ok := ParseLevel("severe"); ok { + t.Error("ParseLevel accepted an unknown level") + } +} + +// The real Danathar/exult mix (2026-11-05): 84 high/critical alerts over 13 +// rules; SARIF errors, warnings and notes without a security level stay out. +func TestExultHighSelectsTheSecurityAlertsAndGroupsThemSmall(t *testing.T) { + alerts := loadAlerts(t, "exult-open-alerts.json") + q := qualifying(alerts, Policy{}) + rules := map[string]bool{} + for _, a := range q { + rules[a.Rule.ID] = true + } + if len(q) != 84 || len(rules) != 13 { + t.Fatalf("min_severity high selected %d alerts over %d rules, want 84 over 13", len(q), len(rules)) + } + groups := Cluster(q) + covered := map[int]int{} + for _, g := range groups { + if len(g.Paths) > MaxFilesPerIssue { + t.Errorf("group %s spans %d files, max %d", Title(g), len(g.Paths), MaxFilesPerIssue) + } + if len(g.Rules) != 1 { + t.Errorf("code group %s mixes rules %v", Title(g), g.Rules) + } + for _, a := range g.Alerts { + covered[a.Number]++ + } + } + for _, a := range q { + if covered[a.Number] != 1 { + t.Errorf("alert #%d is in %d groups, want 1", a.Number, covered[a.Number]) + } + } + if groups[0].Level() != LevelCritical { + t.Errorf("first group is %s, want the critical ones first", groups[0].Level()) + } + if len(groups) < 13 || len(groups) > 30 { + t.Errorf("%d groups for 84 alerts; want one or a few per rule", len(groups)) + } +} + +func TestClusterSplitsByDirectoryAndKeepsDirectoriesTogether(t *testing.T) { + mk := func(n int, p string) Alert { + return Alert{Number: n, Tool: Tool{Name: "CodeQL"}, Rule: Rule{ID: "r", SecuritySeverityLevel: "high"}, Instance: Instance{Location: Location{Path: p, StartLine: 1}}} + } + var as []Alert + for i, p := range []string{"a/1.c", "a/2.c", "b/1.c", "b/2.c", "b/3.c", "b/4.c", "c/1.c"} { + as = append(as, mk(i+1, p)) + } + got := Cluster(as) + var paths []string + for _, g := range got { + paths = append(paths, strings.Join(g.Paths, " ")) + } + want := []string{"a/1.c a/2.c", "b/1.c b/2.c b/3.c b/4.c c/1.c"} + if strings.Join(paths, "|") != strings.Join(want, "|") { + t.Fatalf("clusters = %q, want %q", paths, want) + } + // A single directory over the limit splits into runs in path order. + as = nil + for i := 0; i < 7; i++ { + as = append(as, mk(i+1, ".github/workflows/w"+string(rune('a'+i))+".yml")) + } + got = Cluster(as) + if len(got) != 2 || len(got[0].Paths) != 5 || len(got[1].Paths) != 2 { + t.Fatalf("7 files in one directory: %d groups (%v)", len(got), got) + } +} + +func TestRunFilesAtMostTheCapAndDedupesAcrossRuns(t *testing.T) { + alerts := loadAlerts(t, "exult-open-alerts.json") + f := newFakeForge(alerts) + want := len(Cluster(qualifying(alerts, Policy{}))) + total := 0 + for pass := 1; pass <= 20; pass++ { + st := run(t, f, Options{}) + if st.Filed > DefaultMaxNewIssues { + t.Fatalf("pass %d filed %d issues, cap %d", pass, st.Filed, DefaultMaxNewIssues) + } + total += st.Filed + if st.Filed == 0 { + if st.Untracked != 0 || st.Tracked != 84 { + t.Fatalf("settled with untracked=%d tracked=%d, want 0 and 84", st.Untracked, st.Tracked) + } + break + } + if st.Updated != 0 || st.Closed != 0 { + t.Fatalf("pass %d updated %d / closed %d issues with no alert change", pass, st.Updated, st.Closed) + } + } + if total != want || len(f.issues) != want { + t.Fatalf("filed %d issues (%d stored), want %d grouped issues", total, len(f.issues), want) + } + seen := map[int]int{} + for _, is := range f.issues { + m, _ := ParseMarker(is.body) + for _, n := range m.Alerts { + seen[n]++ + } + if !strings.Contains(is.body, "may be false positives") || !strings.Contains(is.body, "## Acceptance criteria") { + t.Fatalf("issue body lacks the false-positive warning or acceptance criteria:\n%s", is.body) + } + } + for n, c := range seen { + if c != 1 { + t.Errorf("alert #%d is on %d issues", n, c) + } + } + // A restart rebuilds the same state from the markers: nothing new. + before := f.writes + if st := run(t, f, Options{}); st.Filed != 0 || f.writes != before { + t.Fatalf("re-scan wrote %d times (filed %d)", f.writes-before, st.Filed) + } +} + +func TestRunWithNoQualifyingAlertsFilesNothing(t *testing.T) { + var low []Alert + for _, a := range loadAlerts(t, "exult-open-alerts.json") { + if a.Level() < LevelHigh { + low = append(low, a) + } + } + f := newFakeForge(low) + st := run(t, f, Options{}) + if f.writes != 0 || st.Filed != 0 || st.Qualifying != 0 || st.OpenAlerts != len(low) { + t.Fatalf("writes=%d filed=%d qualifying=%d open=%d", f.writes, st.Filed, st.Qualifying, st.OpenAlerts) + } + if st.BelowThreshold != len(low) { + t.Fatalf("below threshold %d, want %d", st.BelowThreshold, len(low)) + } +} + +func onlyRule(alerts []Alert, rule string) []Alert { + var out []Alert + for _, a := range alerts { + if a.Rule.ID == rule { + out = append(out, a) + } + } + return out +} + +func TestRunClosesFixedAndDismissedIssuesAndNeverRefiles(t *testing.T) { + alerts := loadAlerts(t, "exult-open-alerts.json") + use := onlyRule(alerts, "cpp/use-after-free") // 1 alert + scanf := onlyRule(alerts, "cpp/missing-check-scanf") // 8 alerts, 3 files + f := newFakeForge(append(append([]Alert(nil), use...), scanf...)) + if st := run(t, f, Options{}); st.Filed != 2 { + t.Fatalf("filed %d, want 2", st.Filed) + } + // use-after-free fixed; scanf alerts dismissed as false positives. + f.open = nil + f.dismissed = scanf + st := run(t, f, Options{}) + if st.Closed != 2 || len(f.openIssues()) != 0 { + t.Fatalf("closed %d, open %d; want both closed", st.Closed, len(f.openIssues())) + } + for _, is := range f.issues { + switch { + case strings.Contains(is.title, "use-after-free"): + if is.closeReason != "completed" || !strings.Contains(is.closeComment, "fixed: #") { + t.Errorf("fixed issue closed %q with %q", is.closeReason, is.closeComment) + } + default: + if is.closeReason != "not_planned" || !strings.Contains(is.closeComment, "dismissed by a maintainer") { + t.Errorf("dismissed issue closed %q with %q", is.closeReason, is.closeComment) + } + } + } + // A dismissed alert reopened on GitHub is not filed again, and its + // closed issue is not reopened. + f.open, f.dismissed = scanf, nil + before := f.writes + st = run(t, f, Options{}) + if f.writes != before || st.Filed != 0 || st.TrackedClosed != len(scanf) { + t.Fatalf("reappearing alerts: writes=%d filed=%d tracked_closed=%d", f.writes-before, st.Filed, st.TrackedClosed) + } +} + +func TestRunUpdatesIssueWhenAlertsAreAddedOrFixed(t *testing.T) { + scanf := onlyRule(loadAlerts(t, "exult-open-alerts.json"), "cpp/missing-check-scanf") + sort.Slice(scanf, func(i, j int) bool { return scanf[i].Number < scanf[j].Number }) + // The newest alert in a file the issue already covers arrives later. + var late Alert + rest := scanf[:0:0] + for _, a := range scanf { + if late.Number == 0 && a.Path() == scanf[0].Path() && a.Number != scanf[0].Number { + late = a + continue + } + rest = append(rest, a) + } + f := newFakeForge(rest) + run(t, f, Options{}) + if len(f.issues) != 1 { + t.Fatalf("%d issues, want 1", len(f.issues)) + } + var num int + for n := range f.issues { + num = n + } + f.open = append(append([]Alert(nil), rest...), late) + st := run(t, f, Options{}) + if st.Filed != 0 || st.Updated != 1 { + t.Fatalf("new alert in a covered file: filed %d updated %d, want 0 and 1", st.Filed, st.Updated) + } + m, _ := ParseMarker(f.issues[num].body) + if !containsInt(m.Alerts, late.Number) { + t.Fatalf("marker %v lacks the added alert #%d", m.Alerts, late.Number) + } + // One alert fixed: its row says so, the issue stays open. + f.open = f.open[1:] + if st := run(t, f, Options{}); st.Updated != 1 || st.Closed != 0 { + t.Fatalf("partial fix: updated %d closed %d", st.Updated, st.Closed) + } + if !strings.Contains(f.issues[num].body, "| fixed |") || !strings.Contains(f.issues[num].body, "## Wanted behaviour") { + t.Fatalf("updated body lost the fixed row or the filed text:\n%s", f.issues[num].body) + } + if st := run(t, f, Options{}); st.Updated != 0 { + t.Fatal("an unchanged pass edited the issue again") + } +} + +func TestRunWithTruncatedListingNeverCloses(t *testing.T) { + use := onlyRule(loadAlerts(t, "exult-open-alerts.json"), "cpp/use-after-free") + f := newFakeForge(use) + run(t, f, Options{}) + f.open = nil + f.pageLimit = 1 + f.open = make([]Alert, 2) // more than the bound: incomplete, and #use missing + f.open[0] = Alert{Number: 9001, Rule: Rule{Severity: "note"}} + f.open[1] = Alert{Number: 9002, Rule: Rule{Severity: "note"}} + st := run(t, f, Options{}) + if st.Closed != 0 || !st.Truncated || len(f.openIssues()) != 1 { + t.Fatalf("truncated listing closed %d issues (truncated=%v)", st.Closed, st.Truncated) + } +} + +func TestRunReportsMissingPermissionWithoutWriting(t *testing.T) { + f := newFakeForge(nil) + f.listErr = ErrNoAccess + st, err := Run(context.Background(), f, Options{Repo: "example/exult"}) + if err == nil || st.NoticeKind != NoticeMissingPermission || !strings.Contains(st.Notice, "Code scanning alerts") || f.writes != 0 { + t.Fatalf("err=%v notice=%q kind=%q writes=%d", err, st.Notice, st.NoticeKind, f.writes) + } + f.listErr = ErrNotEnabled + st, _ = Run(context.Background(), f, Options{Repo: "example/exult"}) + if st.NoticeKind != NoticeNotEnabled { + t.Fatalf("not-enabled notice kind %q", st.NoticeKind) + } +} + +// The projectbluefin mix (2026-11-07): OSSF Scorecard repo-posture checks, +// TokenPermissions on many workflows, and Trivy CVEs in built binaries. +func TestScorecardPostureChecksFileNothingAndFixableOnesGroup(t *testing.T) { + actions := loadAlerts(t, "scorecard-actions.json") + f := newFakeForge(actions) + st := run(t, f, Options{Repo: "example/actions", WorkflowsLane: "scanner", WorkflowsLaneLabel: "hive/workflows-lane"}) + for _, is := range f.issues { + for _, posture := range []string{"BranchProtectionID", "CodeReviewID", "MaintainedID", "SASTID", "FuzzingID", "CIIBestPracticesID", "VulnerabilitiesID", "SecurityPolicyID"} { + if strings.Contains(is.title, posture) { + t.Fatalf("posture check %s was filed: %s", posture, is.title) + } + } + if !strings.Contains(is.title, "TokenPermissionsID") { + t.Fatalf("unexpected issue %q", is.title) + } + if !strings.Contains(is.body, "GitHub Actions workflow files") || !containsString(is.labels, "hive/workflows-lane") { + t.Fatalf("workflow issue lacks the workflows note or routing label: labels=%v", is.labels) + } + } + tokenFiles := distinctPaths(onlyRule(actions, "TokenPermissionsID")) + wantGroups := (len(tokenFiles) + MaxFilesPerIssue - 1) / MaxFilesPerIssue + if st.Filed != wantGroups || st.Excluded == 0 { + t.Fatalf("filed %d (want %d TokenPermissions groups over %d workflows), excluded %d", st.Filed, wantGroups, len(tokenFiles), st.Excluded) + } + + // No lane can push workflows: no label, and the body says to park. + f = newFakeForge(onlyRule(actions, "TokenPermissionsID")) + run(t, f, Options{Repo: "example/actions", WorkflowsLaneLabel: "hive/workflows-lane"}) + for _, is := range f.issues { + if containsString(is.labels, "hive/workflows-lane") || !strings.Contains(is.body, "park the issue with the workflows blocker") { + t.Fatalf("no workflows lane: labels=%v body lacks the park advice", is.labels) + } + } + + common := loadAlerts(t, "scorecard-trivy-common.json") + f = newFakeForge(common) + st = run(t, f, Options{Repo: "example/common"}) + // High only: the two Trivy packages with a high CVE; Pinned-Dependencies + // (medium) and the posture checks stay out. + if st.Filed != 2 { + t.Fatalf("common filed %d, want 2 Trivy package issues", st.Filed) + } + var titles []string + for _, is := range f.issues { + titles = append(titles, is.title) + if !strings.Contains(is.body, "Containerfile") || !strings.Contains(is.title, "known vulnerabilit") { + t.Fatalf("Trivy issue %q does not point at the package source", is.title) + } + } + sort.Strings(titles) + if !strings.Contains(titles[0], "golang.org/x/net") || !strings.Contains(titles[1], "stdlib") { + t.Fatalf("titles %q", titles) + } + + // With min_severity medium, both x/net CVEs share one issue and + // Pinned-Dependencies files one workflow issue. + f = newFakeForge(common) + st = run(t, f, Options{Repo: "example/common", Policy: Policy{MinLevel: LevelMedium}}) + if st.Filed != 3 { + t.Fatalf("medium filed %d, want 3", st.Filed) + } + for _, is := range f.issues { + if strings.Contains(is.title, "golang.org/x/net") && !strings.Contains(is.title, "2 known vulnerabilities") { + t.Fatalf("x/net CVEs not grouped: %q", is.title) + } + } +} + +func TestExcludeRulesAddsAndBangReincludes(t *testing.T) { + sast := Alert{Tool: Tool{Name: "Scorecard"}, Rule: Rule{ID: "SASTID", SecuritySeverityLevel: "high"}} + goto_ := Alert{Tool: Tool{Name: "CodeQL"}, Rule: Rule{ID: "cpp/path-injection", SecuritySeverityLevel: "high"}} + if (Policy{}).Judge(sast) != Excluded { + t.Fatal("SASTID not excluded by default") + } + if (Policy{ExcludeRules: []string{"!sastid"}}).Judge(sast) != Qualifies { + t.Fatal("!SASTID did not re-include it") + } + if (Policy{ExcludeRules: []string{"cpp/*"}}).Judge(goto_) != Excluded { + t.Fatal("cpp/* did not exclude a CodeQL cpp rule") + } + if (Policy{IncludeTools: []string{"scorecard"}}).Judge(goto_) != Excluded { + t.Fatal("include_tools did not leave CodeQL out") + } + if err := ValidateRulePatterns([]string{"cpp/[", "x"}); err == nil { + t.Fatal("bad pattern accepted") + } +} + +func TestMarkerRoundTrips(t *testing.T) { + m := Marker{Tool: "CodeQL", Rules: []string{"cpp/path-injection"}, Paths: []string{"a b/c,d.cc", "x-->y.c"}, Alerts: []int{3, 12}} + body := "intro\n" + m.String() + "\nrest" + got, ok := ParseMarker(body) + if !ok || got.Tool != m.Tool || strings.Join(got.Paths, "|") != strings.Join(m.Paths, "|") || len(got.Alerts) != 2 { + t.Fatalf("round trip: %+v (ok=%v) from %q", got, ok, m.String()) + } + if strings.Count(m.String(), "-->") != 1 { + t.Fatalf("a path ended the comment early: %q", m.String()) + } +} + +func TestRunOnForkSaysWhetherUpstreamChangedTheCode(t *testing.T) { + use := onlyRule(loadAlerts(t, "exult-open-alerts.json"), "cpp/use-after-free") + a := use[0] + lines := make([]string, a.Instance.Location.StartLine+5) + for i := range lines { + lines[i] = "int filler_" + string(rune('a'+i%26)) + "();" + } + lines[a.Instance.Location.StartLine-1] = "\tdelete shape; use(shape->frames);" + src := strings.Join(lines, "\n") + + f := newFakeForge(use) + f.files["example/exult@"+a.Instance.CommitSHA+"/"+a.Path()] = src + f.upstream = "upstream/exult" + f.files["upstream/exult@/"+a.Path()] = strings.Replace(src, "use(shape->frames)", "shape = nullptr", 1) + f.lastCommit = "0123456789abcdef0123456789abcdef01234567" + run(t, f, Options{}) + if len(f.issues) != 1 { + t.Fatalf("%d issues filed, want 1", len(f.issues)) + } + for _, is := range f.issues { + if !strings.Contains(is.body, "port upstream 0123456789ab") || !strings.Contains(is.body, "> ") { + t.Fatalf("fork issue lacks the upstream port note or excerpt:\n%s", is.body) + } + } + + f = newFakeForge(use) + f.files["example/exult@"+a.Instance.CommitSHA+"/"+a.Path()] = src + f.upstream = "upstream/exult" + f.files["upstream/exult@/"+a.Path()] = src + run(t, f, Options{}) + for _, is := range f.issues { + if !strings.Contains(is.body, "Upstream HEAD still has the flagged code") { + t.Fatalf("fork issue does not say upstream is unchanged:\n%s", is.body) + } + } +} diff --git a/src/pkg/codescanning/testdata/exult-open-alerts.json b/src/pkg/codescanning/testdata/exult-open-alerts.json new file mode 100644 index 0000000000..5a4c703d56 --- /dev/null +++ b/src/pkg/codescanning/testdata/exult-open-alerts.json @@ -0,0 +1,3105 @@ +[ + { + "number": 1, + "html_url": "https://github.com/example/exult/security/code-scanning/1", + "state": "open", + "rule": { + "id": "cpp/use-after-free", + "name": "cpp/use-after-free", + "severity": "warning", + "security_severity_level": "critical", + "description": "Potential use after free", + "tags": [ + "external/cwe/cwe-416", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Memory may have been previously freed by delete.\nMemory may have been previously freed by delete." + }, + "location": { + "path": "shapes/items.h", + "start_line": 267, + "end_line": 267 + } + } + }, + { + "number": 2, + "html_url": "https://github.com/example/exult/security/code-scanning/2", + "state": "open", + "rule": { + "id": "cpp/overflowing-snprintf", + "name": "cpp/overflowing-snprintf", + "severity": "warning", + "security_severity_level": "high", + "description": "Potentially overflowing call to snprintf", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-253", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "The size argument of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow." + }, + "location": { + "path": "shapes/u7drag.cc", + "start_line": 209, + "end_line": 209 + } + } + }, + { + "number": 3, + "html_url": "https://github.com/example/exult/security/code-scanning/3", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'unsigned long'." + }, + "location": { + "path": "gamemap.cc", + "start_line": 1726, + "end_line": 1726 + } + } + }, + { + "number": 4, + "html_url": "https://github.com/example/exult/security/code-scanning/4", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'unsigned long'." + }, + "location": { + "path": "gamemap.cc", + "start_line": 1727, + "end_line": 1727 + } + } + }, + { + "number": 5, + "html_url": "https://github.com/example/exult/security/code-scanning/5", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'unsigned long'." + }, + "location": { + "path": "gamemap.cc", + "start_line": 1728, + "end_line": 1728 + } + } + }, + { + "number": 6, + "html_url": "https://github.com/example/exult/security/code-scanning/6", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'unsigned long'." + }, + "location": { + "path": "npcnear.cc", + "start_line": 74, + "end_line": 74 + } + } + }, + { + "number": 7, + "html_url": "https://github.com/example/exult/security/code-scanning/7", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'size_t'." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 236, + "end_line": 236 + } + } + }, + { + "number": 8, + "html_url": "https://github.com/example/exult/security/code-scanning/8", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'size_t'." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 322, + "end_line": 322 + } + } + }, + { + "number": 9, + "html_url": "https://github.com/example/exult/security/code-scanning/9", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'size_t'." + }, + "location": { + "path": "tools/gimp_plugin/u7shp.cc", + "start_line": 554, + "end_line": 554 + } + } + }, + { + "number": 10, + "html_url": "https://github.com/example/exult/security/code-scanning/10", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'size_t'." + }, + "location": { + "path": "tools/gimp_plugin/u7shp.cc", + "start_line": 464, + "end_line": 464 + } + } + }, + { + "number": 11, + "html_url": "https://github.com/example/exult/security/code-scanning/11", + "state": "open", + "rule": { + "id": "cpp/integer-multiplication-cast-to-long", + "name": "cpp/integer-multiplication-cast-to-long", + "severity": "warning", + "security_severity_level": "high", + "description": "Multiplication result converted to larger type", + "tags": [ + "correctness", + "external/cwe/cwe-190", + "external/cwe/cwe-192", + "external/cwe/cwe-197", + "external/cwe/cwe-681", + "reliability", + "security", + "types" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiplication result may overflow 'int' before it is converted to 'long'." + }, + "location": { + "path": "usecode/intrinsics.cc", + "start_line": 136, + "end_line": 136 + } + } + }, + { + "number": 12, + "html_url": "https://github.com/example/exult/security/code-scanning/12", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 1." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 925, + "end_line": 925 + } + } + }, + { + "number": 13, + "html_url": "https://github.com/example/exult/security/code-scanning/13", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 2." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 925, + "end_line": 925 + } + } + }, + { + "number": 14, + "html_url": "https://github.com/example/exult/security/code-scanning/14", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 3." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 925, + "end_line": 925 + } + } + }, + { + "number": 15, + "html_url": "https://github.com/example/exult/security/code-scanning/15", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 1." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 932, + "end_line": 932 + } + } + }, + { + "number": 16, + "html_url": "https://github.com/example/exult/security/code-scanning/16", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 2." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 932, + "end_line": 932 + } + } + }, + { + "number": 17, + "html_url": "https://github.com/example/exult/security/code-scanning/17", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 1." + }, + "location": { + "path": "gumps/Notebook_gump.cc", + "start_line": 943, + "end_line": 943 + } + } + }, + { + "number": 18, + "html_url": "https://github.com/example/exult/security/code-scanning/18", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 1.\nThis variable is read, but may not have been written. It should be guarded by a check that the call to sscanf returns at least 1." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 125, + "end_line": 125 + } + } + }, + { + "number": 19, + "html_url": "https://github.com/example/exult/security/code-scanning/19", + "state": "open", + "rule": { + "id": "cpp/missing-check-scanf", + "name": "cpp/missing-check-scanf", + "severity": "warning", + "security_severity_level": "high", + "description": "Missing return-value check for a 'scanf'-like function", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-253", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This variable is read, but may not have been written. It should be guarded by a check that the call to fscanf returns at least 2." + }, + "location": { + "path": "tools/mockup/main.c", + "start_line": 154, + "end_line": 154 + } + } + }, + { + "number": 20, + "html_url": "https://github.com/example/exult/security/code-scanning/20", + "state": "open", + "rule": { + "id": "cpp/incorrect-not-operator-usage", + "name": "cpp/incorrect-not-operator-usage", + "severity": "warning", + "security_severity_level": "high", + "description": "Incorrect 'not' operator usage", + "tags": [ + "external/cwe/cwe-480", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Usage of a logical not (!) expression as a bitwise operator." + }, + "location": { + "path": "shapes/shapeinf.h", + "start_line": 759, + "end_line": 759 + } + } + }, + { + "number": 21, + "html_url": "https://github.com/example/exult/security/code-scanning/21", + "state": "open", + "rule": { + "id": "cpp/incorrect-not-operator-usage", + "name": "cpp/incorrect-not-operator-usage", + "severity": "warning", + "security_severity_level": "high", + "description": "Incorrect 'not' operator usage", + "tags": [ + "external/cwe/cwe-480", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Usage of a logical not (!) expression as a bitwise operator." + }, + "location": { + "path": "shapes/shapeinf.h", + "start_line": 755, + "end_line": 755 + } + } + }, + { + "number": 22, + "html_url": "https://github.com/example/exult/security/code-scanning/22", + "state": "open", + "rule": { + "id": "cpp/unsafe-strcat", + "name": "cpp/unsafe-strcat", + "severity": "warning", + "security_severity_level": "critical", + "description": "Potentially unsafe use of strcat", + "tags": [ + "correctness", + "external/cwe/cwe-120", + "external/cwe/cwe-251", + "external/cwe/cwe-676", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Always check the size of the source buffer when using strcat." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_common.cpp", + "start_line": 155, + "end_line": 155 + } + } + }, + { + "number": 23, + "html_url": "https://github.com/example/exult/security/code-scanning/23", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "files/zip/zip.cc", + "start_line": 282, + "end_line": 282 + } + } + }, + { + "number": 24, + "html_url": "https://github.com/example/exult/security/code-scanning/24", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "shapes/pngio.cc", + "start_line": 427, + "end_line": 427 + } + } + }, + { + "number": 25, + "html_url": "https://github.com/example/exult/security/code-scanning/25", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "shapes/pngio.cc", + "start_line": 234, + "end_line": 234 + } + } + }, + { + "number": 26, + "html_url": "https://github.com/example/exult/security/code-scanning/26", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 97, + "end_line": 97 + } + } + }, + { + "number": 27, + "html_url": "https://github.com/example/exult/security/code-scanning/27", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 134, + "end_line": 134 + } + } + }, + { + "number": 28, + "html_url": "https://github.com/example/exult/security/code-scanning/28", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 24, + "end_line": 24 + } + } + }, + { + "number": 29, + "html_url": "https://github.com/example/exult/security/code-scanning/29", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 409, + "end_line": 409 + } + } + }, + { + "number": 30, + "html_url": "https://github.com/example/exult/security/code-scanning/30", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 208, + "end_line": 208 + } + } + }, + { + "number": 31, + "html_url": "https://github.com/example/exult/security/code-scanning/31", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 147, + "end_line": 147 + } + } + }, + { + "number": 32, + "html_url": "https://github.com/example/exult/security/code-scanning/32", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 168, + "end_line": 168 + } + } + }, + { + "number": 33, + "html_url": "https://github.com/example/exult/security/code-scanning/33", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/mockup/main.c", + "start_line": 195, + "end_line": 195 + } + } + }, + { + "number": 34, + "html_url": "https://github.com/example/exult/security/code-scanning/34", + "state": "open", + "rule": { + "id": "cpp/world-writable-file-creation", + "name": "cpp/world-writable-file-creation", + "severity": "warning", + "security_severity_level": "high", + "description": "File created without restricting permissions", + "tags": [ + "external/cwe/cwe-732", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "A file may be created here with mode 0666, which would make it world-writable." + }, + "location": { + "path": "tools/wuc.cc", + "start_line": 201, + "end_line": 201 + } + } + }, + { + "number": 35, + "html_url": "https://github.com/example/exult/security/code-scanning/35", + "state": "open", + "rule": { + "id": "cpp/uncontrolled-process-operation", + "name": "cpp/uncontrolled-process-operation", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled process operation", + "tags": [ + "external/cwe/cwe-073", + "external/cwe/cwe-078", + "external/cwe/cwe-114", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "The value of this argument may come from string read by fgets and is being passed to dlopen.\nThe value of this argument may come from a command-line argument and is being passed to dlopen." + }, + "location": { + "path": "tools/smooth/plugin.c", + "start_line": 44, + "end_line": 44 + } + } + }, + { + "number": 36, + "html_url": "https://github.com/example/exult/security/code-scanning/36", + "state": "open", + "rule": { + "id": "cpp/uncontrolled-allocation-size", + "name": "cpp/uncontrolled-allocation-size", + "severity": "error", + "security_severity_level": "high", + "description": "Uncontrolled allocation size", + "tags": [ + "external/cwe/cwe-190", + "external/cwe/cwe-789", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation size is derived from user input (string read by fread) and could allocate arbitrary amounts of memory." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_filter.cpp", + "start_line": 206, + "end_line": 206 + } + } + }, + { + "number": 37, + "html_url": "https://github.com/example/exult/security/code-scanning/37", + "state": "open", + "rule": { + "id": "cpp/uncontrolled-allocation-size", + "name": "cpp/uncontrolled-allocation-size", + "severity": "error", + "security_severity_level": "high", + "description": "Uncontrolled allocation size", + "tags": [ + "external/cwe/cwe-190", + "external/cwe/cwe-789", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation size is derived from user input (string read by fread) and could allocate arbitrary amounts of memory." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_instrum.cpp", + "start_line": 242, + "end_line": 242 + } + } + }, + { + "number": 38, + "html_url": "https://github.com/example/exult/security/code-scanning/38", + "state": "open", + "rule": { + "id": "cpp/uncontrolled-allocation-size", + "name": "cpp/uncontrolled-allocation-size", + "severity": "error", + "security_severity_level": "high", + "description": "Uncontrolled allocation size", + "tags": [ + "external/cwe/cwe-190", + "external/cwe/cwe-789", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation size is derived from user input (string read by fread) and could allocate arbitrary amounts of memory." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_instrum.cpp", + "start_line": 414, + "end_line": 414 + } + } + }, + { + "number": 39, + "html_url": "https://github.com/example/exult/security/code-scanning/39", + "state": "open", + "rule": { + "id": "cpp/uncontrolled-allocation-size", + "name": "cpp/uncontrolled-allocation-size", + "severity": "error", + "security_severity_level": "high", + "description": "Uncontrolled allocation size", + "tags": [ + "external/cwe/cwe-190", + "external/cwe/cwe-789", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation size is derived from user input (string read by fread) and could allocate arbitrary amounts of memory." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_instrum.cpp", + "start_line": 430, + "end_line": 430 + } + } + }, + { + "number": 40, + "html_url": "https://github.com/example/exult/security/code-scanning/40", + "state": "open", + "rule": { + "id": "cpp/potentially-dangerous-function", + "name": "cpp/potentially-dangerous-function", + "severity": "warning", + "security_severity_level": "critical", + "description": "Use of potentially dangerous function", + "tags": [ + "external/cwe/cwe-676", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Call to 'localtime' is potentially dangerous." + }, + "location": { + "path": "gamedat.cc", + "start_line": 483, + "end_line": 483 + } + } + }, + { + "number": 41, + "html_url": "https://github.com/example/exult/security/code-scanning/41", + "state": "open", + "rule": { + "id": "cpp/potentially-dangerous-function", + "name": "cpp/potentially-dangerous-function", + "severity": "warning", + "security_severity_level": "critical", + "description": "Use of potentially dangerous function", + "tags": [ + "external/cwe/cwe-676", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Call to 'localtime' is potentially dangerous." + }, + "location": { + "path": "gumps/Newfile_gump.cc", + "start_line": 1068, + "end_line": 1068 + } + } + }, + { + "number": 42, + "html_url": "https://github.com/example/exult/security/code-scanning/42", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fgets) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (an environment variable) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename)." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_common.cpp", + "start_line": 127, + "end_line": 127 + } + } + }, + { + "number": 43, + "html_url": "https://github.com/example/exult/security/code-scanning/43", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fgets) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (an environment variable) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Timidity_Pentagram::try_to_open(name), which calls fopen(__filename)." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_common.cpp", + "start_line": 157, + "end_line": 157 + } + } + }, + { + "number": 44, + "html_url": "https://github.com/example/exult/security/code-scanning/44", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (an environment variable) and then passed to fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "exult.cc", + "start_line": 2829, + "end_line": 2829 + } + } + }, + { + "number": 45, + "html_url": "https://github.com/example/exult/security/code-scanning/45", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (an environment variable) and then passed to zipOpen(pathname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to zipOpen(pathname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to zipOpen(pathname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to zipOpen(pathname), which calls fopen(__filename)." + }, + "location": { + "path": "gamedat.cc", + "start_line": 1194, + "end_line": 1194 + } + } + }, + { + "number": 46, + "html_url": "https://github.com/example/exult/security/code-scanning/46", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (an environment variable) and then passed to Shape_chooser::export_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename)." + }, + "location": { + "path": "mapedit/shapelst.cc", + "start_line": 878, + "end_line": 878 + } + } + }, + { + "number": 47, + "html_url": "https://github.com/example/exult/security/code-scanning/47", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (an environment variable) and then passed to Shape_chooser::export_tiled_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_tiled_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_tiled_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Shape_chooser::export_tiled_png(fname), which calls Shape_chooser::export_png(fname), which calls Export_png8(pngname), which calls fopen(__filename)." + }, + "location": { + "path": "mapedit/shapelst.cc", + "start_line": 891, + "end_line": 891 + } + } + }, + { + "number": 48, + "html_url": "https://github.com/example/exult/security/code-scanning/48", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/aseprite_plugin/exult_shp.cc", + "start_line": 381, + "end_line": 381 + } + } + }, + { + "number": 49, + "html_url": "https://github.com/example/exult/security/code-scanning/49", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/aseprite_plugin/exult_shp.cc", + "start_line": 443, + "end_line": 443 + } + } + }, + { + "number": 50, + "html_url": "https://github.com/example/exult/security/code-scanning/50", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to open(__file)." + }, + "location": { + "path": "tools/aseprite_plugin/exult_shp.cc", + "start_line": 336, + "end_line": 336 + } + } + }, + { + "number": 51, + "html_url": "https://github.com/example/exult/security/code-scanning/51", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to open(__file)." + }, + "location": { + "path": "tools/aseprite_plugin/exult_shp.cc", + "start_line": 138, + "end_line": 138 + } + } + }, + { + "number": 52, + "html_url": "https://github.com/example/exult/security/code-scanning/52", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fread) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/compiler/uclex.cc", + "start_line": 1051, + "end_line": 1051 + } + } + }, + { + "number": 53, + "html_url": "https://github.com/example/exult/security/code-scanning/53", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (an environment variable) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/compiler/uclex.cc", + "start_line": 1058, + "end_line": 1058 + } + } + }, + { + "number": 54, + "html_url": "https://github.com/example/exult/security/code-scanning/54", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fread) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s).\nThis argument to a file access function is derived from user input (string read by fread) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s).\nThis argument to a file access function is derived from user input (string read by fread) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s), which calls std::basic_filebuf>::open(__s).\nThis argument to a file access function is derived from user input (an environment variable) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s).\nThis argument to a file access function is derived from user input (an environment variable) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s).\nThis argument to a file access function is derived from user input (an environment variable) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/compiler/uclex.cc", + "start_line": 1075, + "end_line": 1075 + } + } + }, + { + "number": 55, + "html_url": "https://github.com/example/exult/security/code-scanning/55", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::basic_ofstream(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::basic_ofstream(__s), which calls std::basic_ofstream>::open(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::basic_ofstream(__s), which calls std::basic_ofstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/compiler/ucmain.cc", + "start_line": 285, + "end_line": 285 + } + } + }, + { + "number": 56, + "html_url": "https://github.com/example/exult/security/code-scanning/56", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/compiler/ucmain.cc", + "start_line": 226, + "end_line": 226 + } + } + }, + { + "number": 57, + "html_url": "https://github.com/example/exult/security/code-scanning/57", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to Uc_location::register_source(path), which calls std::basic_ifstream>::basic_ifstream(__s), which calls std::basic_ifstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/compiler/ucmain.cc", + "start_line": 250, + "end_line": 250 + } + } + }, + { + "number": 58, + "html_url": "https://github.com/example/exult/security/code-scanning/58", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fread) and then passed to fopen(__filename).\nThis argument to a file access function is derived from user input (string read by fread) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 134, + "end_line": 134 + } + } + }, + { + "number": 59, + "html_url": "https://github.com/example/exult/security/code-scanning/59", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fread) and then passed to fopen(__filename).\nThis argument to a file access function is derived from user input (string read by fread) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 159, + "end_line": 159 + } + } + }, + { + "number": 60, + "html_url": "https://github.com/example/exult/security/code-scanning/60", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (string read by fgets) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 39, + "end_line": 39 + } + } + }, + { + "number": 61, + "html_url": "https://github.com/example/exult/security/code-scanning/61", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to load_shape(filename), which calls fopen(__filename)." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 463, + "end_line": 463 + } + } + }, + { + "number": 62, + "html_url": "https://github.com/example/exult/security/code-scanning/62", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to load_palette(filename), which calls fopen(__filename)." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 467, + "end_line": 467 + } + } + }, + { + "number": 63, + "html_url": "https://github.com/example/exult/security/code-scanning/63", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to save_image(filename), which calls fopen(__filename)." + }, + "location": { + "path": "tools/shp2pcx.cc", + "start_line": 477, + "end_line": 477 + } + } + }, + { + "number": 64, + "html_url": "https://github.com/example/exult/security/code-scanning/64", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to open_config(configfile), which calls fopen(__filename)." + }, + "location": { + "path": "tools/smooth/smooth.c", + "start_line": 94, + "end_line": 94 + } + } + }, + { + "number": 65, + "html_url": "https://github.com/example/exult/security/code-scanning/65", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to merge_frames(shapefile), which calls fopen(__filename)." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 303, + "end_line": 303 + } + } + }, + { + "number": 66, + "html_url": "https://github.com/example/exult/security/code-scanning/66", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to split_shape(filename), which calls fopen(__filename)." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 305, + "end_line": 305 + } + } + }, + { + "number": 67, + "html_url": "https://github.com/example/exult/security/code-scanning/67", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/mockup/main.c", + "start_line": 124, + "end_line": 124 + } + } + }, + { + "number": 68, + "html_url": "https://github.com/example/exult/security/code-scanning/68", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/ucxt/head2data.cc", + "start_line": 88, + "end_line": 88 + } + } + }, + { + "number": 69, + "html_url": "https://github.com/example/exult/security/code-scanning/69", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/ucxt/head2data.cc", + "start_line": 65, + "end_line": 65 + } + } + }, + { + "number": 70, + "html_url": "https://github.com/example/exult/security/code-scanning/70", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s).\nThis argument to a file access function is derived from user input (a command-line argument) and then passed to std::basic_ofstream>::open(__s), which calls std::basic_filebuf>::open(__s)." + }, + "location": { + "path": "tools/ucxt/head2data.cc", + "start_line": 44, + "end_line": 44 + } + } + }, + { + "number": 71, + "html_url": "https://github.com/example/exult/security/code-scanning/71", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to (unnamed namespace)::Write_thumbnail(filename), which calls Export_png32(pngname), which calls fopen(__filename)." + }, + "location": { + "path": "tools/exult_shp_thumbnailer.cc", + "start_line": 250, + "end_line": 250 + } + } + }, + { + "number": 72, + "html_url": "https://github.com/example/exult/security/code-scanning/72", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to (unnamed namespace)::Write_thumbnail(filename), which calls Export_png32(pngname), which calls fopen(__filename)." + }, + "location": { + "path": "tools/exult_shp_thumbnailer.cc", + "start_line": 260, + "end_line": 260 + } + } + }, + { + "number": 73, + "html_url": "https://github.com/example/exult/security/code-scanning/73", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/wuc.cc", + "start_line": 197, + "end_line": 197 + } + } + }, + { + "number": 74, + "html_url": "https://github.com/example/exult/security/code-scanning/74", + "state": "open", + "rule": { + "id": "cpp/path-injection", + "name": "cpp/path-injection", + "severity": "warning", + "security_severity_level": "high", + "description": "Uncontrolled data used in path expression", + "tags": [ + "external/cwe/cwe-022", + "external/cwe/cwe-023", + "external/cwe/cwe-036", + "external/cwe/cwe-073", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This argument to a file access function is derived from user input (a command-line argument) and then passed to fopen(__filename)." + }, + "location": { + "path": "tools/wuc.cc", + "start_line": 201, + "end_line": 201 + } + } + }, + { + "number": 75, + "html_url": "https://github.com/example/exult/security/code-scanning/75", + "state": "open", + "rule": { + "id": "cpp/incorrect-allocation-error-handling", + "name": "cpp/incorrect-allocation-error-handling", + "severity": "warning", + "security_severity_level": "high", + "description": "Incorrect allocation-error handling", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-570", + "external/cwe/cwe-755", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation cannot return null. This check is unnecessary." + }, + "location": { + "path": "files/zip/zip.cc", + "start_line": 138, + "end_line": 138 + } + } + }, + { + "number": 76, + "html_url": "https://github.com/example/exult/security/code-scanning/76", + "state": "open", + "rule": { + "id": "cpp/incorrect-allocation-error-handling", + "name": "cpp/incorrect-allocation-error-handling", + "severity": "warning", + "security_severity_level": "high", + "description": "Incorrect allocation-error handling", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-570", + "external/cwe/cwe-755", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation cannot return null. This check is unnecessary." + }, + "location": { + "path": "tools/compiler/ucparse.cc", + "start_line": 8304, + "end_line": 8304 + } + } + }, + { + "number": 77, + "html_url": "https://github.com/example/exult/security/code-scanning/77", + "state": "open", + "rule": { + "id": "cpp/incorrect-allocation-error-handling", + "name": "cpp/incorrect-allocation-error-handling", + "severity": "warning", + "security_severity_level": "high", + "description": "Incorrect allocation-error handling", + "tags": [ + "correctness", + "external/cwe/cwe-252", + "external/cwe/cwe-570", + "external/cwe/cwe-755", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This allocation cannot return null. This check is unnecessary." + }, + "location": { + "path": "tools/compiler/ucparse.cc", + "start_line": 8315, + "end_line": 8315 + } + } + }, + { + "number": 78, + "html_url": "https://github.com/example/exult/security/code-scanning/78", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcpy' with input from string read by fgets may overflow the destination.\nThis 'call to strcpy' with input from an environment variable may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_common.cpp", + "start_line": 226, + "end_line": 226 + } + } + }, + { + "number": 79, + "html_url": "https://github.com/example/exult/security/code-scanning/79", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcat' with input from string read by fgets may overflow the destination.\nThis 'call to strcat' with input from an environment variable may overflow the destination.\nThis 'call to strcat' with input from a command-line argument may overflow the destination.\nThis 'call to strcat' with input from a command-line argument may overflow the destination.\nThis 'call to strcat' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_common.cpp", + "start_line": 155, + "end_line": 155 + } + } + }, + { + "number": 80, + "html_url": "https://github.com/example/exult/security/code-scanning/80", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcpy' with input from string read by fgets may overflow the destination.\nThis 'call to strcpy' with input from an environment variable may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity_instrum.cpp", + "start_line": 189, + "end_line": 189 + } + } + }, + { + "number": 81, + "html_url": "https://github.com/example/exult/security/code-scanning/81", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcpy' with input from string read by fgets may overflow the destination.\nThis 'call to strcpy' with input from an environment variable may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination.\nThis 'call to strcpy' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "audio/midi_drivers/timidity/timidity.cpp", + "start_line": 183, + "end_line": 183 + } + } + }, + { + "number": 82, + "html_url": "https://github.com/example/exult/security/code-scanning/82", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcpy' with input from string read by fread may overflow the destination." + }, + "location": { + "path": "tools/rip.cc", + "start_line": 127, + "end_line": 127 + } + } + }, + { + "number": 83, + "html_url": "https://github.com/example/exult/security/code-scanning/83", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'call to strcpy' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "tools/splitshp.cc", + "start_line": 122, + "end_line": 122 + } + } + }, + { + "number": 84, + "html_url": "https://github.com/example/exult/security/code-scanning/84", + "state": "open", + "rule": { + "id": "cpp/unbounded-write", + "name": "cpp/unbounded-write", + "severity": "error", + "security_severity_level": "critical", + "description": "Unbounded write", + "tags": [ + "external/cwe/cwe-120", + "external/cwe/cwe-787", + "external/cwe/cwe-805", + "reliability", + "security" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "This 'fscanf string argument' with input from a command-line argument may overflow the destination." + }, + "location": { + "path": "tools/mockup/main.c", + "start_line": 151, + "end_line": 151 + } + } + }, + { + "number": 232, + "html_url": "https://github.com/example/exult/security/code-scanning/232", + "state": "open", + "rule": { + "id": "cpp/redefined-default-parameter", + "name": "cpp/redefined-default-parameter", + "severity": "error", + "description": "Redefined default parameter", + "tags": [ + "external/jsf", + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Parameter ammo_shape redefines its default value to 0 from the inherited default value -1 (in Game_object).\nThe default value will be resolved statically, not by dispatch, so this can cause confusion." + }, + "location": { + "path": "actors.h", + "start_line": 522, + "end_line": 522 + } + } + }, + { + "number": 233, + "html_url": "https://github.com/example/exult/security/code-scanning/233", + "state": "open", + "rule": { + "id": "cpp/redefined-default-parameter", + "name": "cpp/redefined-default-parameter", + "severity": "error", + "description": "Redefined default parameter", + "tags": [ + "external/jsf", + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Parameter weapon_shape redefines its default value to 0 from the inherited default value -1 (in Game_object).\nThe default value will be resolved statically, not by dispatch, so this can cause confusion." + }, + "location": { + "path": "actors.h", + "start_line": 960, + "end_line": 960 + } + } + }, + { + "number": 234, + "html_url": "https://github.com/example/exult/security/code-scanning/234", + "state": "open", + "rule": { + "id": "cpp/redefined-default-parameter", + "name": "cpp/redefined-default-parameter", + "severity": "error", + "description": "Redefined default parameter", + "tags": [ + "external/jsf", + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Parameter ammo_shape redefines its default value to 0 from the inherited default value -1 (in Game_object).\nThe default value will be resolved statically, not by dispatch, so this can cause confusion." + }, + "location": { + "path": "actors.h", + "start_line": 960, + "end_line": 960 + } + } + }, + { + "number": 658, + "html_url": "https://github.com/example/exult/security/code-scanning/658", + "state": "open", + "rule": { + "id": "cpp/rule-of-two", + "name": "cpp/rule-of-two", + "severity": "warning", + "description": "Inconsistent definition of copy constructor and assignment ('Rule of Two')", + "tags": [ + "correctness", + "language-features", + "quality", + "reliability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "No matching copy assignment operator in class Combo. It is good practice to match a copy constructor with a copy assignment operator." + }, + "location": { + "path": "mapedit/combo.cc", + "start_line": 271, + "end_line": 271 + } + } + }, + { + "number": 659, + "html_url": "https://github.com/example/exult/security/code-scanning/659", + "state": "open", + "rule": { + "id": "cpp/rule-of-two", + "name": "cpp/rule-of-two", + "severity": "warning", + "description": "Inconsistent definition of copy constructor and assignment ('Rule of Two')", + "tags": [ + "correctness", + "language-features", + "quality", + "reliability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "No matching copy assignment operator in class Shape_spec. It is good practice to match a copy constructor with a copy assignment operator." + }, + "location": { + "path": "tools/ipack.cc", + "start_line": 77, + "end_line": 77 + } + } + }, + { + "number": 694, + "html_url": "https://github.com/example/exult/security/code-scanning/694", + "state": "open", + "rule": { + "id": "cpp/long-switch", + "name": "cpp/long-switch", + "severity": "note", + "description": "Long switch case", + "tags": [ + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Switch has at least one case that is too long: 5 (42 lines)." + }, + "location": { + "path": "usecode/ucdisasm.cc", + "start_line": 228, + "end_line": 272 + } + } + }, + { + "number": 695, + "html_url": "https://github.com/example/exult/security/code-scanning/695", + "state": "open", + "rule": { + "id": "cpp/long-switch", + "name": "cpp/long-switch", + "severity": "note", + "description": "Long switch case", + "tags": [ + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Switch has at least one case that is too long: repeat2 (34 lines).\nSwitch has at least one case that is too long: usecode (41 lines)." + }, + "location": { + "path": "usecode/ucsched.cc", + "start_line": 371, + "end_line": 715 + } + } + }, + { + "number": 696, + "html_url": "https://github.com/example/exult/security/code-scanning/696", + "state": "open", + "rule": { + "id": "cpp/long-switch", + "name": "cpp/long-switch", + "severity": "note", + "description": "Long switch case", + "tags": [ + "maintainability", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Switch has at least one case that is too long: UC_AIDXTHV (61 lines).\nSwitch has at least one case that is too long: UC_LOOPTOPTHV32 (164 lines).\nSwitch has at least one case that is too long: UC_POPFVAR (59 lines).\nSwitch has at least one case that is too long: UC_POPARRTHV (53 lines).\nSwitch has at least one case that is too long: UC_DBGFUNC32 (79 lines)." + }, + "location": { + "path": "usecode/ucinternal.cc", + "start_line": 2106, + "end_line": 3121 + } + } + }, + { + "number": 697, + "html_url": "https://github.com/example/exult/security/code-scanning/697", + "state": "open", + "rule": { + "id": "cpp/use-of-goto", + "name": "cpp/use-of-goto", + "severity": "warning", + "description": "Use of goto", + "tags": [ + "complexity", + "language-features", + "maintainability", + "quality", + "readability" + ] + }, + "tool": { + "name": "CodeQL" + }, + "most_recent_instance": { + "ref": "refs/heads/master", + "commit_sha": "3254511f2d05a8052a0659004b8dc325469e74ef", + "message": { + "text": "Multiple forward and backward goto statements may make function yyparse hard to understand." + }, + "location": { + "path": "tools/compiler/ucparse.cc", + "start_line": 3879, + "end_line": 3879 + } + } + } +] diff --git a/src/pkg/codescanning/testdata/scorecard-actions.json b/src/pkg/codescanning/testdata/scorecard-actions.json new file mode 100644 index 0000000000..90a33bb828 --- /dev/null +++ b/src/pkg/codescanning/testdata/scorecard-actions.json @@ -0,0 +1,1126 @@ +[ + { + "number": 142, + "html_url": "https://github.com/example/actions/security/code-scanning/142", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/reusable-issue-policy-preview.yml", + "start_line": 71, + "end_line": 71 + } + } + }, + { + "number": 141, + "html_url": "https://github.com/example/actions/security/code-scanning/141", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/actionlint.yml", + "start_line": 38, + "end_line": 38 + } + } + }, + { + "number": 138, + "html_url": "https://github.com/example/actions/security/code-scanning/138", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/update-v1-tag.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/update-v1-tag.yml", + "start_line": 22, + "end_line": 22 + } + } + }, + { + "number": 137, + "html_url": "https://github.com/example/actions/security/code-scanning/137", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-release.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-release.yml", + "start_line": 288, + "end_line": 288 + } + } + }, + { + "number": 103, + "html_url": "https://github.com/example/actions/security/code-scanning/103", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'checks' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/actionlint.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/actionlint.yml", + "start_line": 27, + "end_line": 27 + } + } + }, + { + "number": 100, + "html_url": "https://github.com/example/actions/security/code-scanning/100", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'statuses' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-promote-squash.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-promote-squash.yml", + "start_line": 572, + "end_line": 572 + } + } + }, + { + "number": 99, + "html_url": "https://github.com/example/actions/security/code-scanning/99", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-promote-squash.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-promote-squash.yml", + "start_line": 570, + "end_line": 570 + } + } + }, + { + "number": 98, + "html_url": "https://github.com/example/actions/security/code-scanning/98", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-promote-squash.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-promote-squash.yml", + "start_line": 171, + "end_line": 171 + } + } + }, + { + "number": 91, + "html_url": "https://github.com/example/actions/security/code-scanning/91", + "state": "open", + "rule": { + "id": "BranchProtectionID", + "name": "Branch-Protection", + "severity": "error", + "security_severity_level": "high", + "description": "Branch-Protection", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#branch-protection", + "tags": [ + "code-reviews", + "security", + "source-code", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 4: branch protection is not maximal on development and all release branches:\nWarn: 'branch protection settings apply to administrators' is disabled on branch 'main'\nWarn: required approving review count is 1 on branch 'main'\nWarn: 'last push approval' is disabled on branch 'main'\nWarn: 'up-to-date branches' is disabled on branch 'main'\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 89, + "html_url": "https://github.com/example/actions/security/code-scanning/89", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/renovate-automerge.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/renovate-automerge.yml", + "start_line": 28, + "end_line": 28 + } + } + }, + { + "number": 64, + "html_url": "https://github.com/example/actions/security/code-scanning/64", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/vendor-chunka-files.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/vendor-chunka-files.yml", + "start_line": 35, + "end_line": 35 + } + } + }, + { + "number": 63, + "html_url": "https://github.com/example/actions/security/code-scanning/63", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-release.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-release.yml", + "start_line": 448, + "end_line": 448 + } + } + }, + { + "number": 62, + "html_url": "https://github.com/example/actions/security/code-scanning/62", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-sync-branches.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-sync-branches.yml", + "start_line": 40, + "end_line": 40 + } + } + }, + { + "number": 61, + "html_url": "https://github.com/example/actions/security/code-scanning/61", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-execute-release.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-execute-release.yml", + "start_line": 193, + "end_line": 193 + } + } + }, + { + "number": 60, + "html_url": "https://github.com/example/actions/security/code-scanning/60", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-execute-release.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-execute-release.yml", + "start_line": 191, + "end_line": 191 + } + } + }, + { + "number": 59, + "html_url": "https://github.com/example/actions/security/code-scanning/59", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-execute-release.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-execute-release.yml", + "start_line": 172, + "end_line": 172 + } + } + }, + { + "number": 48, + "html_url": "https://github.com/example/actions/security/code-scanning/48", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: npmCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/unit-tests.yml", + "start_line": 95, + "end_line": 95 + } + } + }, + { + "number": 47, + "html_url": "https://github.com/example/actions/security/code-scanning/47", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-promote-squash.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-promote-squash.yml", + "start_line": 134, + "end_line": 134 + } + } + }, + { + "number": 46, + "html_url": "https://github.com/example/actions/security/code-scanning/46", + "state": "open", + "rule": { + "id": "SASTID", + "name": "SAST", + "severity": "error", + "security_severity_level": "medium", + "description": "SAST", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#sast", + "tags": [ + "security", + "supply-chain", + "testing" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: SAST tool is not run on all commits -- score normalized to 0:\nWarn: 0 commits out of 30 are checked with a SAST tool\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 45, + "html_url": "https://github.com/example/actions/security/code-scanning/45", + "state": "open", + "rule": { + "id": "FuzzingID", + "name": "Fuzzing", + "severity": "error", + "security_severity_level": "medium", + "description": "Fuzzing", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#fuzzing", + "tags": [ + "security", + "supply-chain", + "testing" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: project is not fuzzed:\nWarn: no fuzzer integrations found\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 44, + "html_url": "https://github.com/example/actions/security/code-scanning/44", + "state": "open", + "rule": { + "id": "VulnerabilitiesID", + "name": "Vulnerabilities", + "severity": "error", + "security_severity_level": "high", + "description": "Vulnerabilities", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#vulnerabilities", + "tags": [ + "security", + "supply-chain", + "vulnerabilities" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 9: 1 existing vulnerabilities detected:\nWarn: Project is vulnerable to: https://osv.dev/PYSEC-2026-1845\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 43, + "html_url": "https://github.com/example/actions/security/code-scanning/43", + "state": "open", + "rule": { + "id": "CIIBestPracticesID", + "name": "CII-Best-Practices", + "severity": "error", + "security_severity_level": "low", + "description": "CII-Best-Practices", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#cii-best-practices", + "tags": [ + "security", + "security-awareness", + "security-training" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: no effort to earn an OpenSSF best practices badge detected\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 42, + "html_url": "https://github.com/example/actions/security/code-scanning/42", + "state": "open", + "rule": { + "id": "CodeReviewID", + "name": "Code-Review", + "severity": "error", + "security_severity_level": "high", + "description": "Code-Review", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#code-review", + "tags": [ + "code-reviews", + "security", + "source-code", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: Found 12/15 approved changesets -- score normalized to 8\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 40, + "html_url": "https://github.com/example/actions/security/code-scanning/40", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/unit-tests.yml", + "start_line": 59, + "end_line": 59 + } + } + }, + { + "number": 39, + "html_url": "https://github.com/example/actions/security/code-scanning/39", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 8: npmCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/reusable-validate-renovate.yml", + "start_line": 29, + "end_line": 29 + } + } + }, + { + "number": 24, + "html_url": "https://github.com/example/actions/security/code-scanning/24", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'security-events' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-vulnerability-scan.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-vulnerability-scan.yml", + "start_line": 37, + "end_line": 37 + } + } + }, + { + "number": 22, + "html_url": "https://github.com/example/actions/security/code-scanning/22", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-renovate-automerge.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-renovate-automerge.yml", + "start_line": 88, + "end_line": 88 + } + } + }, + { + "number": 20, + "html_url": "https://github.com/example/actions/security/code-scanning/20", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/migration-test.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/migration-test.yml", + "start_line": 95, + "end_line": 95 + } + } + }, + { + "number": 18, + "html_url": "https://github.com/example/actions/security/code-scanning/18", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: topLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/ghcr-cleanup.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/ghcr-cleanup.yml", + "start_line": 9, + "end_line": 9 + } + } + }, + { + "number": 14, + "html_url": "https://github.com/example/actions/security/code-scanning/14", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/upgrade-test.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/upgrade-test.yml", + "start_line": 90, + "end_line": 90 + } + } + }, + { + "number": 7, + "html_url": "https://github.com/example/actions/security/code-scanning/7", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'security-events' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-build.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-build.yml", + "start_line": 104, + "end_line": 104 + } + } + }, + { + "number": 6, + "html_url": "https://github.com/example/actions/security/code-scanning/6", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/reusable-build.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/reusable-build.yml", + "start_line": 101, + "end_line": 101 + } + } + }, + { + "number": 5, + "html_url": "https://github.com/example/actions/security/code-scanning/5", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'contents' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/prune-merged-branches.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/prune-merged-branches.yml", + "start_line": 15, + "end_line": 15 + } + } + }, + { + "number": 2, + "html_url": "https://github.com/example/actions/security/code-scanning/2", + "state": "open", + "rule": { + "id": "TokenPermissionsID", + "name": "Token-Permissions", + "severity": "error", + "security_severity_level": "high", + "description": "Token-Permissions", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#token-permissions", + "tags": [ + "infrastructure", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "460aab74615e911b69d2c1dc86bfb08442b15188", + "message": { + "text": "score is 0: jobLevel 'packages' permission set to 'write'\nRemediation tip: Visit [https://app.stepsecurity.io/secureworkflow](https://app.stepsecurity.io/secureworkflow/github.com/example/actions/migration-test.yml/main?enable=permissions).\nTick the 'Restrict permissions for GITHUB_TOKEN'\nUntick other options\nNOTE: If you want to resolve multiple issues at once, you can visit [https://app.stepsecurity.io/securerepo](https://app.stepsecurity.io/securerepo) instead.\nClick Remediation section below for further remediation help" + }, + "location": { + "path": ".github/workflows/migration-test.yml", + "start_line": 105, + "end_line": 105 + } + } + } +] diff --git a/src/pkg/codescanning/testdata/scorecard-trivy-common.json b/src/pkg/codescanning/testdata/scorecard-trivy-common.json new file mode 100644 index 0000000000..c4455932d1 --- /dev/null +++ b/src/pkg/codescanning/testdata/scorecard-trivy-common.json @@ -0,0 +1,400 @@ +[ + { + "number": 149, + "html_url": "https://github.com/example/common/security/code-scanning/149", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/unit-tests.yml", + "start_line": 39, + "end_line": 39 + } + } + }, + { + "number": 148, + "html_url": "https://github.com/example/common/security/code-scanning/148", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/bazaar-featured-refresh.yml", + "start_line": 33, + "end_line": 33 + } + } + }, + { + "number": 145, + "html_url": "https://github.com/example/common/security/code-scanning/145", + "state": "open", + "rule": { + "id": "CVE-2026-97045", + "name": "LanguageSpecificPackageVulnerability", + "severity": "warning", + "security_severity_level": "medium", + "description": "golang.org/x/net/html: golang.org/x/net/html: Cross-Site Scripting via improper namespace handling during HTML rendering", + "help_uri": "https://avd.aquasec.com/nvd/cve-2026-97045", + "tags": [ + "MEDIUM", + "security", + "vulnerability" + ] + }, + "tool": { + "name": "Trivy" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "Package: golang.org/x/net\nInstalled Version: v0.61.0\nVulnerability CVE-2026-97045\nSeverity: UNKNOWN\nFixed Version: 0.62.0\nLink: [CVE-2026-97045](https://avd.aquasec.com/nvd/cve-2026-97045)" + }, + "location": { + "path": "system_files/shared/usr/bin/uwelcome", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 144, + "html_url": "https://github.com/example/common/security/code-scanning/144", + "state": "open", + "rule": { + "id": "CVE-2026-78661", + "name": "LanguageSpecificPackageVulnerability", + "severity": "error", + "security_severity_level": "high", + "description": "golang.org/x/net/html: golang.org/x/net/html: Denial of Service via crafted HTML input", + "help_uri": "https://avd.aquasec.com/nvd/cve-2026-78661", + "tags": [ + "HIGH", + "security", + "vulnerability" + ] + }, + "tool": { + "name": "Trivy" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "Package: golang.org/x/net\nInstalled Version: v0.61.0\nVulnerability CVE-2026-78661\nSeverity: UNKNOWN\nFixed Version: 0.62.0\nLink: [CVE-2026-78661](https://avd.aquasec.com/nvd/cve-2026-78661)" + }, + "location": { + "path": "system_files/shared/usr/bin/uwelcome", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 139, + "html_url": "https://github.com/example/common/security/code-scanning/139", + "state": "open", + "rule": { + "id": "CVE-2026-111943", + "name": "LanguageSpecificPackageVulnerability", + "severity": "error", + "security_severity_level": "high", + "description": "crypto/x509: golang: crypto/x509: Man-in-the-middle attacks via untrusted intermediate certificates", + "help_uri": "https://avd.aquasec.com/nvd/cve-2026-111943", + "tags": [ + "HIGH", + "security", + "vulnerability" + ] + }, + "tool": { + "name": "Trivy" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "Package: stdlib\nInstalled Version: v1.26.9\nVulnerability CVE-2026-111943\nSeverity: HIGH\nFixed Version: 1.26.10, 1.27.3\nLink: [CVE-2026-111943](https://avd.aquasec.com/nvd/cve-2026-111943)" + }, + "location": { + "path": "system_files/shared/usr/bin/chairlift-helper", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 64, + "html_url": "https://github.com/example/common/security/code-scanning/64", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/validate-chairlift-config.yaml", + "start_line": 40, + "end_line": 40 + } + } + }, + { + "number": 61, + "html_url": "https://github.com/example/common/security/code-scanning/61", + "state": "open", + "rule": { + "id": "PinnedDependenciesID", + "name": "Pinned-Dependencies", + "severity": "error", + "security_severity_level": "medium", + "description": "Pinned-Dependencies", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#pinned-dependencies", + "tags": [ + "dependencies", + "security", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 8: pipCommand not pinned by hash\nClick Remediation section below to solve this issue" + }, + "location": { + "path": ".github/workflows/validate.yml", + "start_line": 149, + "end_line": 149 + } + } + }, + { + "number": 22, + "html_url": "https://github.com/example/common/security/code-scanning/22", + "state": "open", + "rule": { + "id": "FuzzingID", + "name": "Fuzzing", + "severity": "error", + "security_severity_level": "medium", + "description": "Fuzzing", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#fuzzing", + "tags": [ + "security", + "supply-chain", + "testing" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 0: project is not fuzzed:\nWarn: no fuzzer integrations found\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 21, + "html_url": "https://github.com/example/common/security/code-scanning/21", + "state": "open", + "rule": { + "id": "SASTID", + "name": "SAST", + "severity": "error", + "security_severity_level": "medium", + "description": "SAST", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#sast", + "tags": [ + "security", + "supply-chain", + "testing" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 9: SAST tool is not run on all commits -- score normalized to 9:\nWarn: 27 commits out of 29 are checked with a SAST tool\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 20, + "html_url": "https://github.com/example/common/security/code-scanning/20", + "state": "open", + "rule": { + "id": "CIIBestPracticesID", + "name": "CII-Best-Practices", + "severity": "error", + "security_severity_level": "low", + "description": "CII-Best-Practices", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#cii-best-practices", + "tags": [ + "security", + "security-awareness", + "security-training" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 0: no effort to earn an OpenSSF best practices badge detected\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 19, + "html_url": "https://github.com/example/common/security/code-scanning/19", + "state": "open", + "rule": { + "id": "CodeReviewID", + "name": "Code-Review", + "severity": "error", + "security_severity_level": "high", + "description": "Code-Review", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#code-review", + "tags": [ + "code-reviews", + "security", + "source-code", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 9: Found 26/27 approved changesets -- score normalized to 9\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + }, + { + "number": 1, + "html_url": "https://github.com/example/common/security/code-scanning/1", + "state": "open", + "rule": { + "id": "BranchProtectionID", + "name": "Branch-Protection", + "severity": "error", + "security_severity_level": "high", + "description": "Branch-Protection", + "help_uri": "https://github.com/ossf/scorecard/blob/61e84743356275f6ffca23b1b2f2cb945e19eb96/docs/checks.md#branch-protection", + "tags": [ + "code-reviews", + "security", + "source-code", + "supply-chain" + ] + }, + "tool": { + "name": "Scorecard" + }, + "most_recent_instance": { + "ref": "refs/heads/main", + "commit_sha": "69acadb2cfa2b440dad43e33323b16169a654e0a", + "message": { + "text": "score is 4: branch protection is not maximal on development and all release branches:\nWarn: 'branch protection settings apply to administrators' is disabled on branch 'main'\nWarn: 'stale review dismissal' is disabled on branch 'main'\nWarn: codeowners review is not required on branch 'main'\nWarn: 'last push approval' is disabled on branch 'main'\nWarn: 'up-to-date branches' is disabled on branch 'main'\nClick Remediation section below to solve this issue" + }, + "location": { + "path": "no file associated with this alert", + "start_line": 1, + "end_line": 1 + } + } + } +] diff --git a/src/pkg/config/code_scanning.go b/src/pkg/config/code_scanning.go new file mode 100644 index 0000000000..ca27ee3b7b --- /dev/null +++ b/src/pkg/config/code_scanning.go @@ -0,0 +1,159 @@ +package config + +import ( + "fmt" + "sort" + "strings" + "time" + + "github.com/hivecommons/hive/pkg/codescanning" +) + +// DefaultCodeScanningInterval is how often the code scanning sweep runs. +// Alerts change when an analysis runs (a push or a weekly schedule), so an +// hourly pass is prompt enough, and its listings are ETag-cached reads that +// cost nothing when nothing changed. +const DefaultCodeScanningInterval = time.Hour + +// minCodeScanningInterval keeps an operator from turning the sweep into a +// rate-limit problem. +const minCodeScanningInterval = 10 * time.Minute + +// CodeScanningConfig (top-level `code_scanning:`) turns a repository's open +// GitHub code scanning alerts into grouped hive issues the lanes can work +// (src/docs/code-scanning.md). Off by default, and per repo: the top-level +// keys are the defaults, and repos. turns a repo on or off and +// overrides any of them. +type CodeScanningConfig struct { + // Enabled is the default for every repo in project.repos. + Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"` + // Interval between passes. Zero means DefaultCodeScanningInterval. + Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty"` + // MinSeverity is the lowest level filed: critical, high (default), + // medium, low or note; error and warning are read as medium and low. + MinSeverity string `yaml:"min_severity,omitempty" json:"min_severity,omitempty"` + // IncludeTools files only alerts from these tools (CodeQL, Scorecard, + // Trivy, …). Empty means every tool. + IncludeTools []string `yaml:"include_tools,omitempty" json:"include_tools,omitempty"` + // ExcludeRules are rule-ID patterns left out on top of the default + // list (OSSF Scorecard's repo-posture checks); "!" takes one of + // the defaults back out. + ExcludeRules []string `yaml:"exclude_rules,omitempty" json:"exclude_rules,omitempty"` + // MaxNewIssuesPerRun caps new issues per repo per pass. Zero means 5. + MaxNewIssuesPerRun int `yaml:"max_new_issues_per_run,omitempty" json:"max_new_issues_per_run,omitempty"` + // Repos holds per-repo overrides keyed by owner/repo or bare repo name. + Repos map[string]CodeScanningRepoConfig `yaml:"repos,omitempty" json:"repos,omitempty"` +} + +// CodeScanningRepoConfig is code_scanning.repos.: every field left +// empty inherits the top-level value. +type CodeScanningRepoConfig struct { + Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"` + MinSeverity string `yaml:"min_severity,omitempty" json:"min_severity,omitempty"` + IncludeTools []string `yaml:"include_tools,omitempty" json:"include_tools,omitempty"` + ExcludeRules []string `yaml:"exclude_rules,omitempty" json:"exclude_rules,omitempty"` + MaxNewIssuesPerRun int `yaml:"max_new_issues_per_run,omitempty" json:"max_new_issues_per_run,omitempty"` +} + +// IntervalOrDefault resolves the sweep cadence. +func (c CodeScanningConfig) IntervalOrDefault() time.Duration { + if c.Interval > 0 { + return c.Interval + } + return DefaultCodeScanningInterval +} + +// repoOverride finds repo's override, matching owner/repo or bare names +// against project.org. +func (c CodeScanningConfig) repoOverride(org, repo string) (CodeScanningRepoConfig, bool) { + want := codeScanningRepoKey(org, repo) + for k, v := range c.Repos { + if codeScanningRepoKey(org, k) == want { + return v, true + } + } + return CodeScanningRepoConfig{}, false +} + +func codeScanningRepoKey(org, repo string) string { + bare, _ := NormalizeRepoForOrg(org, repo) + return strings.ToLower(strings.TrimSpace(bare)) +} + +// For returns repo's effective policy and whether the sweep runs there. +func (c CodeScanningConfig) For(org, repo string) (codescanning.Policy, bool) { + on := c.Enabled + sev, tools, excl, maxNew := c.MinSeverity, c.IncludeTools, c.ExcludeRules, c.MaxNewIssuesPerRun + if ov, ok := c.repoOverride(org, repo); ok { + if ov.Enabled != nil { + on = *ov.Enabled + } + if ov.MinSeverity != "" { + sev = ov.MinSeverity + } + if len(ov.IncludeTools) > 0 { + tools = ov.IncludeTools + } + if len(ov.ExcludeRules) > 0 { + excl = ov.ExcludeRules + } + if ov.MaxNewIssuesPerRun > 0 { + maxNew = ov.MaxNewIssuesPerRun + } + } + level, _ := codescanning.ParseLevel(sev) + return codescanning.Policy{MinLevel: level, IncludeTools: tools, ExcludeRules: excl, MaxNewIssues: maxNew}, on +} + +// AnyEnabled reports whether the sweep runs on at least one of repos. +func (c CodeScanningConfig) AnyEnabled(repos []string, org string) bool { + for _, r := range repos { + if _, on := c.For(org, r); on { + return true + } + } + return false +} + +func (c *Config) validateCodeScanning() error { + cs := c.CodeScanning + if cs.Interval < 0 || (cs.Interval > 0 && cs.Interval < minCodeScanningInterval) { + return fmt.Errorf("code_scanning.interval: must be at least %s, got %s", minCodeScanningInterval, cs.Interval) + } + check := func(where, sev string, maxNew int, excl []string) error { + if sev != "" { + if _, ok := codescanning.ParseLevel(sev); !ok { + return fmt.Errorf("%s.min_severity: %q is not one of critical, high, medium, low, note (or error, warning)", where, sev) + } + } + if maxNew < 0 { + return fmt.Errorf("%s.max_new_issues_per_run: must not be negative, got %d", where, maxNew) + } + if err := codescanning.ValidateRulePatterns(excl); err != nil { + return fmt.Errorf("%s.exclude_rules: %w", where, err) + } + return nil + } + if err := check("code_scanning", cs.MinSeverity, cs.MaxNewIssuesPerRun, cs.ExcludeRules); err != nil { + return err + } + known := map[string]bool{} + for _, r := range c.Project.Repos { + known[codeScanningRepoKey(c.Project.Org, r)] = true + } + keys := make([]string, 0, len(cs.Repos)) + for k := range cs.Repos { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { + if !known[codeScanningRepoKey(c.Project.Org, k)] { + return fmt.Errorf("code_scanning.repos: %q is not listed in project.repos", k) + } + r := cs.Repos[k] + if err := check("code_scanning.repos["+k+"]", r.MinSeverity, r.MaxNewIssuesPerRun, r.ExcludeRules); err != nil { + return err + } + } + return nil +} diff --git a/src/pkg/config/code_scanning_test.go b/src/pkg/config/code_scanning_test.go new file mode 100644 index 0000000000..5ee0f22223 --- /dev/null +++ b/src/pkg/config/code_scanning_test.go @@ -0,0 +1,87 @@ +package config + +import ( + "strings" + "testing" + "time" + + "gopkg.in/yaml.v3" + + "github.com/hivecommons/hive/pkg/codescanning" +) + +func TestCodeScanningIsOffByDefault(t *testing.T) { + var c Config + if _, on := c.CodeScanning.For("acme", "acme/widget"); on || c.CodeScanning.AnyEnabled([]string{"widget"}, "acme") { + t.Fatal("code scanning sweep is on with no config") + } + if got := c.CodeScanning.IntervalOrDefault(); got != time.Hour { + t.Fatalf("default interval %s, want 1h", got) + } +} + +func TestCodeScanningPerRepoOverride(t *testing.T) { + var c Config + src := ` +code_scanning: + min_severity: critical + exclude_rules: [cpp/commented-out-code] + repos: + acme/widget: + enabled: true + min_severity: medium + max_new_issues_per_run: 2 + gadget: + enabled: true +` + if err := yaml.Unmarshal([]byte(src), &c); err != nil { + t.Fatal(err) + } + c.Project.Org = "acme" + c.Project.Repos = []string{"widget", "gadget", "other"} + if err := c.validateCodeScanning(); err != nil { + t.Fatalf("valid block rejected: %v", err) + } + p, on := c.CodeScanning.For("acme", "widget") + if !on || p.MinLevel != codescanning.LevelMedium || p.MaxNewIssues != 2 || len(p.ExcludeRules) != 1 { + t.Fatalf("widget policy %+v on=%v", p, on) + } + p, on = c.CodeScanning.For("acme", "acme/gadget") + if !on || p.MinLevel != codescanning.LevelCritical || p.MaxNewIssues != 0 { + t.Fatalf("gadget inherits the top-level policy: %+v on=%v", p, on) + } + if _, on := c.CodeScanning.For("acme", "other"); on { + t.Fatal("a repo with no override follows code_scanning.enabled (off)") + } + c.CodeScanning.Enabled = true + off := false + c.CodeScanning.Repos["other"] = CodeScanningRepoConfig{Enabled: &off} + if _, on := c.CodeScanning.For("acme", "other"); on { + t.Fatal("per-repo enabled: false did not turn it off") + } +} + +func TestCodeScanningValidation(t *testing.T) { + base := func() Config { + var c Config + c.Project.Org = "acme" + c.Project.Repos = []string{"widget"} + return c + } + for name, mutate := range map[string]func(*Config){ + "bad severity": func(c *Config) { c.CodeScanning.MinSeverity = "severe" }, + "negative cap": func(c *Config) { c.CodeScanning.MaxNewIssuesPerRun = -1 }, + "bad interval": func(c *Config) { c.CodeScanning.Interval = time.Minute }, + "bad pattern": func(c *Config) { c.CodeScanning.ExcludeRules = []string{"cpp/["} }, + "unknown repo": func(c *Config) { c.CodeScanning.Repos = map[string]CodeScanningRepoConfig{"nope": {}} }, + "repo severity": func(c *Config) { + c.CodeScanning.Repos = map[string]CodeScanningRepoConfig{"widget": {MinSeverity: "x"}} + }, + } { + c := base() + mutate(&c) + if err := c.validateCodeScanning(); err == nil || !strings.Contains(err.Error(), "code_scanning") { + t.Errorf("%s: err %v", name, err) + } + } +} diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index b96232b21b..768955a7fd 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -169,6 +169,9 @@ type Config struct { // UpstreamWatch declares per-repo upstreams and filters for the fork // upstream watch (hivecommons/hive#9966). Default off. UpstreamWatch UpstreamWatchConfig `yaml:"upstream_watch,omitempty" json:"upstream_watch,omitempty"` + // CodeScanning turns open GitHub code scanning alerts into grouped hive + // issues (src/docs/code-scanning.md). Default off, opt-in per repo. + CodeScanning CodeScanningConfig `yaml:"code_scanning,omitempty" json:"code_scanning,omitempty"` // Convergence toggles the convergence-driven admission surfaces // (kubestellar/hive#3845 follow-ons). Default off → zero behaviour change. Convergence ConvergenceConfig `yaml:"convergence,omitempty" json:"convergence,omitempty"` diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index f333b819ee..7ef79d2692 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -787,6 +787,7 @@ "search": {}, "scanner": {}, "upstream_watch": {}, + "code_scanning": {}, "convergence": {}, "integration_orchestration": { "mode": "", diff --git a/src/pkg/config/validate.go b/src/pkg/config/validate.go index 47abec30f8..4189a24e3b 100644 --- a/src/pkg/config/validate.go +++ b/src/pkg/config/validate.go @@ -242,6 +242,9 @@ func (c *Config) ValidateWithOptions(opts ValidateOptions) error { if err := c.validateUpstreamWatch(); err != nil { return err } + if err := c.validateCodeScanning(); err != nil { + return err + } if err := c.ValidateRecheckDiscovery(); err != nil { return err } diff --git a/src/pkg/dashboard/code_scanning_status_test.go b/src/pkg/dashboard/code_scanning_status_test.go new file mode 100644 index 0000000000..f6dc029216 --- /dev/null +++ b/src/pkg/dashboard/code_scanning_status_test.go @@ -0,0 +1,108 @@ +package dashboard + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/codescanning" + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" +) + +// /api/status code_scanning carries per-repo alert counts by severity, how +// many open alerts hive issues track, the Security-tab link, and a notice +// for a repo whose alerts the App cannot read. +func TestStatusCodeScanning(t *testing.T) { + tracked := codescanning.Marker{Tool: "CodeQL", Rules: []string{"cpp/use-after-free"}, Paths: []string{"a.cc"}, Alerts: []int{7}} + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/repos/o/ok/code-scanning/alerts": + _, _ = w.Write([]byte(`[ + {"number":7,"state":"open","rule":{"id":"cpp/use-after-free","severity":"warning","security_severity_level":"critical"},"tool":{"name":"CodeQL"},"most_recent_instance":{"location":{"path":"a.cc","start_line":4}}}, + {"number":8,"state":"open","rule":{"id":"cpp/commented-out-code","severity":"note"},"tool":{"name":"CodeQL"},"most_recent_instance":{"location":{"path":"b.cc","start_line":9}}}]`)) + case "/repos/o/ok/issues": + _ = json.NewEncoder(w).Encode([]map[string]any{{"number": 3, "state": "open", "title": "x", "body": tracked.String(), "user": map[string]any{"login": "hive-app[bot]"}}}) + case "/repos/o/denied/code-scanning/alerts": + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte(`{"message":"Resource not accessible by integration"}`)) + default: + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"message":"Not Found"}`)) + } + })) + defer srv.Close() + s := newTestServer() + gh := github.NewClientForTest(srv.URL, "o", []string{"ok", "denied"}, s.logger) + gh.SetAppBotLogin("hive-app[bot]") + cfg := &config.Config{} + cfg.Project.Org, cfg.Project.Repos = "o", []string{"ok", "denied"} + cfg.CodeScanning.Enabled = true + gh.RunCodeScanningSweep(context.Background(), cfg, time.Now()) + s.deps = &Dependencies{GHClient: gh} + s.UpdateStatus(minimalPayload()) + + rec := httptest.NewRecorder() + s.handleStatus(rec, httptest.NewRequest(http.MethodGet, "/api/status?fields=code_scanning", nil)) + var payload map[string]json.RawMessage + if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { + t.Fatalf("decode: %v: %s", err, rec.Body.String()) + } + raw, ok := payload["code_scanning"] + if !ok { + t.Fatalf("code_scanning missing: %s", rec.Body.String()) + } + var got github.CodeScanningStatusBlock + if err := json.Unmarshal(raw, &got); err != nil || !got.Enabled || len(got.Repos) != 2 { + t.Fatalf("code_scanning=%s err=%v", raw, err) + } + denied, okRepo := got.Repos[0], got.Repos[1] + if okRepo.Repo != "o/ok" || okRepo.BySeverity["critical"] != 1 || okRepo.BySeverity["note"] != 1 || okRepo.Tracked != 1 || okRepo.OpenIssues != 1 { + t.Fatalf("o/ok status %+v", okRepo) + } + if okRepo.SecurityURL != "https://github.com/o/ok/security/code-scanning" { + t.Fatalf("security link %q", okRepo.SecurityURL) + } + if denied.NoticeKind != codescanning.NoticeMissingPermission || len(got.Notices) != 1 || !strings.Contains(got.Notices[0], "Code scanning alerts") { + t.Fatalf("missing-permission notice: %+v / %v", denied, got.Notices) + } +} + +// A hive with the sweep off carries no code_scanning block. +func TestStatusCodeScanningAbsentWhenOff(t *testing.T) { + s := newTestServer() + s.deps = &Dependencies{GHClient: github.NewClient("fake", "org", []string{"repo"}, s.logger, "")} + s.UpdateStatus(minimalPayload()) + rec := httptest.NewRecorder() + s.handleStatus(rec, httptest.NewRequest(http.MethodGet, "/api/status", nil)) + if strings.Contains(rec.Body.String(), `"code_scanning"`) { + t.Fatal("code_scanning present with the sweep off") + } +} + +// The notices reach the operator as a pinned banner with a Security-tab link. +func TestCodeScanningBannerWired(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + `id="code-scanning-banner" class="gh-app-install-banner perm-issue" hidden`, + `id="code-scanning-banner-list"`, + "renderCodeScanningBanner(data);", + "data.code_scanning.repos", + "r.security_url", + } { + if !strings.Contains(html, want) { + t.Fatalf("code scanning banner is missing %q", want) + } + } + notices := strings.Index(html, `
`) + banner := strings.Index(html, `id="code-scanning-banner"`) + firstSection := strings.Index(html, `data-dashboard-section="overview-section"`) + if notices < 0 || banner < notices || banner > firstSection { + t.Fatal("code scanning banner must sit in the pinned dashboard notices") + } +} diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 20c165bb9d..aa7923fcfe 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -4083,6 +4083,9 @@ func (s *Server) handleStatus(w http.ResponseWriter, r *http.Request) { payload.Config = s.configHealthStatus() if s.deps != nil { payload.WorkflowApprovals = s.deps.GHClient.WorkflowApprovalsStatus() + if cs := s.deps.GHClient.CodeScanningStatus(); cs.Enabled || len(cs.Repos) > 0 { + payload.CodeScanning = &cs + } } statusJSONResponse(w, r, filterStatusPayload(&payload, r.URL.Query().Get("fields"), r.URL.Query().Get("omit"))) } @@ -4117,6 +4120,11 @@ type statusWithWebhooks struct { // WorkflowApprovals counts the hive's approvals of GitHub-gated // workflow runs (hivecommons/hive#16603). WorkflowApprovals github.WorkflowApprovalsStatus `json:"workflow_approvals"` + // CodeScanning is the code scanning sweep's per-repo picture: open + // alerts by severity, how many hive issues track, the Security-tab + // link, and a notice for a repo whose alerts the App cannot read. + // Absent while the sweep is off everywhere. + CodeScanning *github.CodeScanningStatusBlock `json:"code_scanning,omitempty"` *EvalLoopStatus // MatrixEnabled reports whether the Matrix block is active (enabled with // at least one repo, see config.DashboardMatrixConfig.Active) so the header shows diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index 9b4b81f83e..3f1c107b7e 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -182,6 +182,17 @@ chat.grounded_answers.model # TODO #14412 classification.review_bots.logins[] # TODO #11854 classification.review_bots.max_attempts_per_thread # TODO #11854 classification.review_bots.resolve_after_fix # TODO #11854 +code_scanning.enabled # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.exclude_rules[] # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.include_tools[] # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.interval # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.max_new_issues_per_run # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.min_severity # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.repos..enabled # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.repos..exclude_rules[] # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.repos..include_tools[] # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.repos..max_new_issues_per_run # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md +code_scanning.repos..min_severity # opt-in code scanning sweep; yaml-only, see docs/code-scanning.md compliance.frameworks[] # TODO #11854 data.nous_dir # TODO #11854 contribute.token_idle_max # TODO #11854 diff --git a/src/pkg/dashboard/static-src/html/root-notices.html b/src/pkg/dashboard/static-src/html/root-notices.html index 412a495aeb..89d9b4b446 100644 --- a/src/pkg/dashboard/static-src/html/root-notices.html +++ b/src/pkg/dashboard/static-src/html/root-notices.html @@ -61,6 +61,13 @@
+
GitHub API authentication failed. Check GitHub App key or token configuration.
diff --git a/src/pkg/dashboard/static-src/js/banners.js b/src/pkg/dashboard/static-src/js/banners.js index 1ab3d40b0e..60a7f578d3 100644 --- a/src/pkg/dashboard/static-src/js/banners.js +++ b/src/pkg/dashboard/static-src/js/banners.js @@ -479,6 +479,32 @@ renderIssuesDisabledBanner({ issuesDisabledRepos: _lastIssuesDisabledRepos }); } + // The code scanning sweep's notices (/api/status code_scanning): a repo + // whose alerts the GitHub App cannot read (it lacks "Code scanning + // alerts: Read") or that has no code scanning analysis. The sweep backs + // off from such a repo; the row links to the repo's Security tab. + function renderCodeScanningBanner(data) { + var banner = document.getElementById('code-scanning-banner'); + if (!banner) return; + var repos = (data && data.code_scanning && data.code_scanning.repos) || []; + var shown = repos.filter(function(r) { return r && r.repo && r.notice; }); + var list = document.getElementById('code-scanning-banner-list'); + if (!shown.length || !list) { + banner.setAttribute('hidden', ''); + banner.style.display = 'none'; + if (list) list.innerHTML = ''; + return; + } + list.innerHTML = shown.map(function(r) { + return '
' + + '' + escapeHtml(r.repo) + ': ' + escapeHtml(r.notice) + + ' Security tab' + + '
'; + }).join(''); + banner.removeAttribute('hidden'); + banner.style.cssText = 'display:flex !important'; + } + var _hubBannerColorMap = { /* banner copy stays neutral (--text); the semantic color lives in the tint/border */ green: {bg: 'rgba(22,163,74,0.12)', border: 'rgba(22,163,74,0.3)', color: 'var(--text)'}, diff --git a/src/pkg/dashboard/static-src/js/refresh.js b/src/pkg/dashboard/static-src/js/refresh.js index 63be5f3573..e34ce97128 100644 --- a/src/pkg/dashboard/static-src/js/refresh.js +++ b/src/pkg/dashboard/static-src/js/refresh.js @@ -534,6 +534,7 @@ renderRepoTargetBanner(data); renderOnboardingGuideChip(data); renderIssuesDisabledBanner(data); + renderCodeScanningBanner(data); refreshWelcomeAutoChecks(data); renderHubBanner(data.hubBanner); maybePlanningIntro(data); diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 10e5f7ec3c..231c7a2c5f 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -8064,6 +8064,13 @@
Required Permissions (Organization)
+
GitHub API authentication failed. Check GitHub App key or token configuration.
@@ -30713,6 +30720,32 @@

All labels

renderIssuesDisabledBanner({ issuesDisabledRepos: _lastIssuesDisabledRepos }); } + // The code scanning sweep's notices (/api/status code_scanning): a repo + // whose alerts the GitHub App cannot read (it lacks "Code scanning + // alerts: Read") or that has no code scanning analysis. The sweep backs + // off from such a repo; the row links to the repo's Security tab. + function renderCodeScanningBanner(data) { + var banner = document.getElementById('code-scanning-banner'); + if (!banner) return; + var repos = (data && data.code_scanning && data.code_scanning.repos) || []; + var shown = repos.filter(function(r) { return r && r.repo && r.notice; }); + var list = document.getElementById('code-scanning-banner-list'); + if (!shown.length || !list) { + banner.setAttribute('hidden', ''); + banner.style.display = 'none'; + if (list) list.innerHTML = ''; + return; + } + list.innerHTML = shown.map(function(r) { + return '
' + + '' + escapeHtml(r.repo) + ': ' + escapeHtml(r.notice) + + ' Security tab' + + '
'; + }).join(''); + banner.removeAttribute('hidden'); + banner.style.cssText = 'display:flex !important'; + } + var _hubBannerColorMap = { /* banner copy stays neutral (--text); the semantic color lives in the tint/border */ green: {bg: 'rgba(22,163,74,0.12)', border: 'rgba(22,163,74,0.3)', color: 'var(--text)'}, @@ -48462,6 +48495,7 @@ renderRepoTargetBanner(data); renderOnboardingGuideChip(data); renderIssuesDisabledBanner(data); + renderCodeScanningBanner(data); refreshWelcomeAutoChecks(data); renderHubBanner(data.hubBanner); maybePlanningIntro(data); diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index f8dfc030d5..3a2ec75d05 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -178,6 +178,7 @@ type Client struct { mergeAlertIDsByRepo map[string]map[string]*mergeAlertEntry mergeAlertLastRevalidate time.Time logger *slog.Logger + codeScanning codeScanningState workflowApprovals workflowApprovalLedger heldRunApprovals HeldRunApprovals installationPerms installationPermissionCache diff --git a/src/pkg/github/code_scanning.go b/src/pkg/github/code_scanning.go new file mode 100644 index 0000000000..955787dbc9 --- /dev/null +++ b/src/pkg/github/code_scanning.go @@ -0,0 +1,412 @@ +package github + +import ( + "context" + "errors" + "fmt" + "net/http" + "sort" + "strings" + "sync" + "time" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/crux/logscrub" + "github.com/hivecommons/hive/pkg/advisory" + "github.com/hivecommons/hive/pkg/codescanning" + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/issueshape" + "github.com/hivecommons/hive/pkg/writeback" +) + +// CodeScanningLabel marks the issues the code scanning sweep files. It is +// how the sweep lists its own issues (with the hidden marker and the App +// author); it is not a gate. +const CodeScanningLabel = "hive/code-scanning" + +// codeScanningPerPage is the alert page size (GitHub's maximum); a var so a +// test can page a small fixture. +var codeScanningPerPage = 100 + +// codeScanningIssuePages bounds the listing of the sweep's own issues +// (open and closed, 100 a page). +const codeScanningIssuePages = 5 + +// codeScanningNoAccessBackoff is how long a repo whose alerts GitHub +// refused (missing App permission, or no analysis) is left alone before the +// sweep asks again. +const codeScanningNoAccessBackoff = 6 * time.Hour + +// codeScanningMaxFileBytes bounds a file read for an excerpt or the fork +// check. +const codeScanningMaxFileBytes = 512 << 10 + +type codeScanningState struct { + mu sync.Mutex + enabled bool + status map[string]codescanning.Status + backoff map[string]time.Time + // logged is the notice kind last logged per repo, so a refusal is + // logged once rather than every pass. + logged map[string]string +} + +// CodeScanningSweepResult summarises one pass over every enabled repo. +type CodeScanningSweepResult struct { + Repos int + Filed int + Updated int + Closed int + Errors int + // BudgetSkipped is true when the GitHub API budget was not normal, so + // the pass made no calls. + BudgetSkipped bool +} + +// CodeScanningStatusBlock is /api/status code_scanning. +type CodeScanningStatusBlock struct { + // Enabled is true when the sweep runs on at least one repo. + Enabled bool `json:"enabled"` + Repos []codescanning.Status `json:"repos"` + // Notices are the operator-facing problems, one per repo (a missing + // App permission, code scanning not set up). + Notices []string `json:"notices"` +} + +// CodeScanningStatus returns the last pass's per-repo picture. +func (c *Client) CodeScanningStatus() CodeScanningStatusBlock { + out := CodeScanningStatusBlock{Repos: []codescanning.Status{}, Notices: []string{}} + if c == nil { + return out + } + s := &c.codeScanning + s.mu.Lock() + defer s.mu.Unlock() + out.Enabled = s.enabled + for _, st := range s.status { + cp := st + cp.BySeverity = make(map[string]int, len(st.BySeverity)) + for k, v := range st.BySeverity { + cp.BySeverity[k] = v + } + out.Repos = append(out.Repos, cp) + } + sort.Slice(out.Repos, func(i, j int) bool { return out.Repos[i].Repo < out.Repos[j].Repo }) + for _, st := range out.Repos { + if st.Notice != "" { + out.Notices = append(out.Notices, st.Notice) + } + } + return out +} + +// RunCodeScanningSweep makes one pass of the opt-in code scanning sweep +// (code_scanning in hive.yaml, src/docs/code-scanning.md) over every repo +// it is enabled on. It makes no GitHub call while the API budget is not +// normal, and leaves a repo whose alerts GitHub refused alone for +// codeScanningNoAccessBackoff, keeping the notice on the dashboard. +func (c *Client) RunCodeScanningSweep(ctx context.Context, cfg *config.Config, now time.Time) CodeScanningSweepResult { + var res CodeScanningSweepResult + if c == nil || c.client == nil || cfg == nil { + return res + } + var repos []string + for _, r := range c.activeRepos() { + if _, on := cfg.CodeScanning.For(cfg.Project.Org, r); on { + repos = append(repos, r) + } + } + s := &c.codeScanning + s.mu.Lock() + s.enabled = len(repos) > 0 + if s.status == nil { + s.status, s.backoff, s.logged = map[string]codescanning.Status{}, map[string]time.Time{}, map[string]string{} + } + keep := map[string]bool{} + for _, r := range repos { + keep[c.fullRepoName(r)] = true + } + for r := range s.status { + if !keep[r] { + delete(s.status, r) + } + } + s.mu.Unlock() + f := codeScanningForge{c: c} + for _, repo := range repos { + if ctx.Err() != nil { + return res + } + if mode, _ := c.APIBudgetMode(); mode != APIBudgetNormal { + res.BudgetSkipped = true + return res + } + full := c.fullRepoName(repo) + s.mu.Lock() + until := s.backoff[full] + s.mu.Unlock() + if now.Before(until) { + continue + } + policy, _ := cfg.CodeScanning.For(cfg.Project.Org, repo) + lane := cfg.WorkflowsCapableLane(repo) + st, err := codescanning.Run(ctx, f, codescanning.Options{ + Repo: full, + Policy: policy, + Labels: []string{config.OriginLabel(config.OriginSourceGovernor), CodeScanningLabel}, + WorkflowsLane: lane, + WorkflowsLaneLabel: WorkflowsLaneLabel, + Now: now, + }) + res.Repos++ + res.Filed += st.Filed + res.Updated += st.Updated + res.Closed += st.Closed + if err != nil && st.NoticeKind == "" { + res.Errors++ + st.Error = err.Error() + if c.logger != nil { + c.logger.Warn("code scanning sweep: repo pass failed", "repo", full, "filed", st.Filed, "error", err) + } + } + s.mu.Lock() + if st.NoticeKind != "" { + s.backoff[full] = now.Add(codeScanningNoAccessBackoff) + if s.logged[full] != st.NoticeKind && c.logger != nil { + c.logger.Warn("code scanning sweep: cannot read alerts; backing off", "repo", full, "notice", st.NoticeKind, "retry_after", codeScanningNoAccessBackoff, "detail", st.Notice) + } + } else { + delete(s.backoff, full) + } + s.logged[full] = st.NoticeKind + s.status[full] = st + s.mu.Unlock() + if c.logger != nil && (st.Filed > 0 || st.Updated > 0 || st.Closed > 0) { + c.logger.Info("code scanning sweep", "repo", full, "open_alerts", st.OpenAlerts, "qualifying", st.Qualifying, + "filed", st.Filed, "updated", st.Updated, "closed", st.Closed, "untracked", st.Untracked, "truncated", st.Truncated) + } + } + return res +} + +func (c *Client) fullRepoName(repo string) string { + owner, name := c.splitRepo(repo) + return owner + "/" + name +} + +// codeScanningForge is codescanning.Forge over the App client. Reads go +// through the shared ETag cache (stable URLs, no since= filter); every write +// asks the write-back gate as an issue_file write on the hive's own issue. +type codeScanningForge struct{ c *Client } + +func (f codeScanningForge) ListAlerts(ctx context.Context, repo, state string, maxPages int) ([]codescanning.Alert, bool, error) { + owner, name := f.c.splitRepo(repo) + var out []codescanning.Alert + for page := 1; page <= maxPages; page++ { + u := fmt.Sprintf("repos/%s/%s/code-scanning/alerts?state=%s&per_page=%d&page=%d", owner, name, state, codeScanningPerPage, page) + req, err := f.c.client.NewRequest(http.MethodGet, u, nil) + if err != nil { + return nil, false, err + } + var batch []codescanning.Alert + resp, err := f.c.client.Do(ctx, req, &batch) + if err != nil { + return nil, false, classifyCodeScanningError(err) + } + out = append(out, batch...) + if resp == nil || resp.NextPage == 0 { + return out, true, nil + } + } + return out, false, nil +} + +// classifyCodeScanningError maps GitHub's refusals onto the notice errors. +// "Advanced Security must be enabled" (a private repo without it) and "no +// analysis found" mean nothing to read; any other 403 or 404 means the App +// cannot read alerts (no security_events grant, or no access to the repo). +func classifyCodeScanningError(err error) error { + var ghErr *gh.ErrorResponse + if !errors.As(err, &ghErr) || ghErr.Response == nil { + return err + } + msg := strings.ToLower(ghErr.Message) + switch ghErr.Response.StatusCode { + case http.StatusForbidden, http.StatusNotFound: + if strings.Contains(msg, "no analysis found") || strings.Contains(msg, "must be enabled") || strings.Contains(msg, "not enabled") { + return fmt.Errorf("%w: %s", codescanning.ErrNotEnabled, ghErr.Message) + } + return fmt.Errorf("%w: %d %s", codescanning.ErrNoAccess, ghErr.Response.StatusCode, ghErr.Message) + } + return err +} + +func (f codeScanningForge) ListIssues(ctx context.Context, repo string) ([]codescanning.TrackedIssue, error) { + owner, name := f.c.splitRepo(repo) + own := f.c.knowsOwnAccounts() + opts := &gh.IssueListByRepoOptions{State: "all", Labels: []string{CodeScanningLabel}, Sort: "created", Direction: "asc", ListOptions: gh.ListOptions{PerPage: 100}} + var out []codescanning.TrackedIssue + for page := 0; page < codeScanningIssuePages; page++ { + issues, resp, err := f.c.client.Issues.ListByRepo(ctx, owner, name, opts) + if err != nil { + return nil, err + } + for _, is := range issues { + if is == nil || is.IsPullRequest() { + continue + } + // Only the hive's own issues count, so a squatted marker + // cannot suppress a filing. + if own && !f.c.isHiveAccount(is.GetUser()) && !f.c.IsHiveAuthorLogin(safeGetLogin(is.GetUser())) { + continue + } + m, ok := codescanning.ParseMarker(is.GetBody()) + if !ok { + continue + } + out = append(out, codescanning.TrackedIssue{Number: is.GetNumber(), Open: is.GetState() != "closed", Body: is.GetBody(), Marker: m}) + } + if resp == nil || resp.NextPage == 0 { + return out, nil + } + opts.ListOptions.Page = resp.NextPage + } + // Past the bound the dedupe state would be partial: file nothing. + return nil, fmt.Errorf("more than %d pages of %s issues in %s", codeScanningIssuePages, CodeScanningLabel, repo) +} + +// prepare runs the checks every hive-authored text gets before it is +// posted: the canary scan, log scrubbing and @-mention neutralising (alert +// messages are analyser text and may quote handles). +func (f codeScanningForge) prepare(repo, text string) (string, error) { + if leak, ok := f.c.scanCanaryText(text, "hive-code-scanning:"+repo); ok && f.c.canaryFailClosed { + return "", fmt.Errorf("ioscan canary leak detected: agent=%s source=%s", leak.Agent, leak.Source) + } + return logscrub.ScrubString(advisory.NeutralizeMentions(text)), nil +} + +func (f codeScanningForge) gate(repo string, number int, preview string) error { + if d := f.c.WritebackAllowed(repo, writeback.Item{Number: number, HiveAuthored: true}, writeback.KindIssueFile, preview); !d.Allowed { + return fmt.Errorf("code scanning %s: %w: %s %s", repo, writeback.ErrSuppressed, d.Reason, d.Detail) + } + return nil +} + +func (f codeScanningForge) CreateIssue(ctx context.Context, repo, title, body string, labels []string) (int, error) { + title = issueshape.AgentIssueTitle(config.OriginSourceGovernor, title) + body, err := f.prepare(repo, title+"\n"+body) + if err != nil { + return 0, err + } + title, body, _ = strings.Cut(body, "\n") + if err := f.gate(repo, 0, title); err != nil { + return 0, err + } + for _, l := range labels { + if err := f.c.EnsureIssueLabel(ctx, repo, l, codeScanningLabelColor(l), codeScanningLabelDescription(l)); err != nil { + return 0, fmt.Errorf("ensuring label %s: %w", l, err) + } + } + owner, name := f.c.splitRepo(repo) + ls := append([]string(nil), labels...) + created, resp, err := f.c.client.Issues.Create(ctx, owner, name, &gh.IssueRequest{Title: gh.Ptr(title), Body: gh.Ptr(body), Labels: &ls}) // writeback:gated — WritebackAllowed consulted above + f.c.noteWritebackOutcome(repo, resp, err) + if err != nil { + return 0, err + } + return created.GetNumber(), nil +} + +func codeScanningLabelColor(label string) string { + if label == CodeScanningLabel { + return "b60205" + } + return "" +} + +func codeScanningLabelDescription(label string) string { + if label == CodeScanningLabel { + return "Filed by the hive from GitHub code scanning alerts" + } + return "" +} + +func (f codeScanningForge) EditIssueBody(ctx context.Context, repo string, number int, body string) error { + body, err := f.prepare(repo, body) + if err != nil { + return err + } + if err := f.gate(repo, number, "code scanning alert table"); err != nil { + return err + } + owner, name := f.c.splitRepo(repo) + _, resp, err := f.c.client.Issues.Edit(ctx, owner, name, number, &gh.IssueRequest{Body: gh.Ptr(body)}) // writeback:gated — WritebackAllowed consulted above + f.c.noteWritebackOutcome(repo, resp, err) + return err +} + +func (f codeScanningForge) CloseIssue(ctx context.Context, repo string, number int, comment, stateReason string) error { + comment, err := f.prepare(repo, comment) + if err != nil { + return err + } + if err := f.gate(repo, number, comment); err != nil { + return err + } + // The closing note carries codescanning.CloseMarker: when an earlier + // pass posted it and the close itself failed, close without a second note. + owner, name := f.c.splitRepo(repo) + if _, posted, err := f.c.findOwnMarkerComment(ctx, owner, name, number, codescanning.CloseMarker); err != nil { + return err + } else if !posted { + if err := f.c.CreateIssueComment(ctx, repo, number, comment); err != nil { // writeback:gated — WritebackAllowed consulted above + return err + } + } + return f.c.CloseIssue(ctx, repo, number, IssueCloseOptions{StateReason: stateReason}) // writeback:gated — WritebackAllowed consulted above +} + +func (f codeScanningForge) FileAt(ctx context.Context, repo, path, ref string) (string, bool, error) { + owner, name := f.c.splitRepo(repo) + var opts *gh.RepositoryContentGetOptions + if ref != "" { + opts = &gh.RepositoryContentGetOptions{Ref: ref} + } + file, _, _, err := f.c.client.Repositories.GetContents(ctx, owner, name, path, opts) + if err != nil { + if githubStatusError(err, http.StatusNotFound) { + return "", false, nil + } + return "", false, err + } + if file == nil || file.GetSize() > codeScanningMaxFileBytes { + return "", false, nil + } + content, err := file.GetContent() + if err != nil { + return "", false, err + } + return content, true, nil +} + +func (f codeScanningForge) Upstream(ctx context.Context, repo string) (string, error) { + owner, name := f.c.splitRepo(repo) + r, _, err := f.c.client.Repositories.Get(ctx, owner, name) + if err != nil { + return "", err + } + if !r.GetFork() || r.GetParent() == nil { + return "", nil + } + return r.GetParent().GetFullName(), nil +} + +func (f codeScanningForge) LastCommit(ctx context.Context, repo, path string) (string, error) { + owner, name := f.c.splitRepo(repo) + commits, _, err := f.c.client.Repositories.ListCommits(ctx, owner, name, &gh.CommitsListOptions{Path: path, ListOptions: gh.ListOptions{PerPage: 1}}) + if err != nil || len(commits) == 0 { + return "", err + } + return commits[0].GetSHA(), nil +} diff --git a/src/pkg/github/code_scanning_test.go b/src/pkg/github/code_scanning_test.go new file mode 100644 index 0000000000..c4c3618e5f --- /dev/null +++ b/src/pkg/github/code_scanning_test.go @@ -0,0 +1,333 @@ +package github + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "strconv" + "strings" + "sync" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/codescanning" + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/writeback" +) + +// codeScanningServer is a GitHub stand-in for one repo, o/r: code scanning +// alerts, issues and labels. +type codeScanningServer struct { + mu sync.Mutex + alerts []map[string]any + alertsErr int // status for the alerts listing; 0 = 200 + alertsMsg string // error message with alertsErr + issues []map[string]any + creates []map[string]any + edits int + comments int + posted map[int][]string // comment bodies by issue number + requests int + alertGets int + labels map[string]bool +} + +func (s *codeScanningServer) start(t *testing.T) *httptest.Server { + t.Helper() + if s.labels == nil { + s.labels = map[string]bool{} + } + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + s.mu.Lock() + defer s.mu.Unlock() + s.requests++ + w.Header().Set("Content-Type", "application/json") + var in map[string]any + _ = json.NewDecoder(r.Body).Decode(&in) + p := r.URL.Path + switch { + case p == "/repos/o/r/code-scanning/alerts": + s.alertGets++ + if s.alertsErr != 0 { + w.WriteHeader(s.alertsErr) + _ = json.NewEncoder(w).Encode(map[string]any{"message": s.alertsMsg}) + return + } + if r.URL.Query().Get("state") != "open" { + _, _ = w.Write([]byte("[]")) + return + } + page, _ := strconv.Atoi(r.URL.Query().Get("page")) + if page < 1 { + page = 1 + } + per, _ := strconv.Atoi(r.URL.Query().Get("per_page")) + lo, hi := (page-1)*per, page*per + if lo > len(s.alerts) { + lo = len(s.alerts) + } + if hi >= len(s.alerts) { + hi = len(s.alerts) + } else { + w.Header().Set("Link", `; rel="next"`) + } + _ = json.NewEncoder(w).Encode(s.alerts[lo:hi]) + case p == "/repos/o/r" && r.Method == http.MethodGet: + _ = json.NewEncoder(w).Encode(map[string]any{"full_name": "o/r", "fork": false}) + case strings.HasPrefix(p, "/repos/o/r/labels/"): + name := strings.TrimPrefix(p, "/repos/o/r/labels/") + if s.labels[name] { + _ = json.NewEncoder(w).Encode(map[string]any{"name": name, "color": "8250df"}) + return + } + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"message":"Not Found"}`)) + case p == "/repos/o/r/labels" && r.Method == http.MethodPost: + s.labels[in["name"].(string)] = true + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(in) + case p == "/repos/o/r/issues" && r.Method == http.MethodGet: + _ = json.NewEncoder(w).Encode(s.issues) + case p == "/repos/o/r/issues" && r.Method == http.MethodPost: + n := 500 + len(s.creates) + var labels []any + for _, l := range in["labels"].([]any) { + labels = append(labels, map[string]any{"name": l}) + } + is := map[string]any{"number": n, "state": "open", "title": in["title"], "body": in["body"], "labels": labels, "user": map[string]any{"login": "hive-app[bot]", "type": "Bot"}} + s.creates = append(s.creates, in) + s.issues = append(s.issues, is) + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(is) + case strings.HasPrefix(p, "/repos/o/r/issues/") && strings.HasSuffix(p, "/comments") && r.Method == http.MethodPost: + s.comments++ + n, _ := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(p, "/repos/o/r/issues/"), "/comments")) + if s.posted == nil { + s.posted = map[int][]string{} + } + body, _ := in["body"].(string) + s.posted[n] = append(s.posted[n], body) + w.WriteHeader(http.StatusCreated) + _, _ = w.Write([]byte(`{"id":1}`)) + case strings.HasPrefix(p, "/repos/o/r/issues/") && strings.HasSuffix(p, "/comments") && r.Method == http.MethodGet: + n, _ := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(p, "/repos/o/r/issues/"), "/comments")) + out := []map[string]any{} + for i, b := range s.posted[n] { + out = append(out, map[string]any{"id": i + 1, "body": b, "user": map[string]any{"login": "hive-app[bot]", "type": "Bot"}}) + } + _ = json.NewEncoder(w).Encode(out) + case strings.HasPrefix(p, "/repos/o/r/issues/"): + n, _ := strconv.Atoi(strings.TrimPrefix(p, "/repos/o/r/issues/")) + for _, is := range s.issues { + if is["number"] == n { + if r.Method == http.MethodPatch { + s.edits++ + for k, v := range in { + is[k] = v + } + } + _ = json.NewEncoder(w).Encode(is) + return + } + } + w.WriteHeader(http.StatusNotFound) + default: + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"message":"Not Found"}`)) + } + })) + t.Cleanup(srv.Close) + return srv +} + +func codeScanningFixture(t *testing.T) []map[string]any { + t.Helper() + data, err := os.ReadFile("../codescanning/testdata/exult-open-alerts.json") + if err != nil { + t.Fatal(err) + } + var out []map[string]any + if err := json.Unmarshal(data, &out); err != nil { + t.Fatal(err) + } + return out +} + +func codeScanningConfig() *config.Config { + cfg := &config.Config{} + cfg.Project.Org = "o" + cfg.Project.Repos = []string{"r"} + cfg.CodeScanning.Enabled = true + return cfg +} + +func newCodeScanningClient(t *testing.T, srv *httptest.Server) *Client { + t.Helper() + c := NewClientForTest(srv.URL, "o", []string{"r"}, testLogger()) + c.SetAppBotLogin("hive-app[bot]") + return c +} + +func TestCodeScanningSweepFilesGroupedIssuesThroughTheGateAndDedupes(t *testing.T) { + resetRESTAccountingForTest(t, time.Now()) + s := &codeScanningServer{alerts: codeScanningFixture(t)} + c := newCodeScanningClient(t, s.start(t)) + cfg := codeScanningConfig() + now := time.Now() + + res := c.RunCodeScanningSweep(context.Background(), cfg, now) + if res.Filed != codescanning.DefaultMaxNewIssues || len(s.creates) != codescanning.DefaultMaxNewIssues { + t.Fatalf("first pass filed %d (%d creates), want the cap %d", res.Filed, len(s.creates), codescanning.DefaultMaxNewIssues) + } + first := s.creates[0] + if !strings.HasPrefix(first["title"].(string), "[governor] Code scanning: ") { + t.Fatalf("title %q lacks the filer tag", first["title"]) + } + labels := first["labels"].([]any) + if len(labels) != 2 || labels[0] != "origin/governor" || labels[1] != CodeScanningLabel { + t.Fatalf("labels %v", labels) + } + if !strings.Contains(first["body"].(string), codescanning.MarkerPrefix) { + t.Fatal("body lacks the dedupe marker") + } + st := c.CodeScanningStatus() + if len(st.Repos) != 1 || st.Repos[0].Repo != "o/r" || st.Repos[0].BySeverity["critical"] != 11 || st.Repos[0].BySeverity["high"] != 73 { + t.Fatalf("status %+v", st) + } + if st.Repos[0].SecurityURL != "https://github.com/o/r/security/code-scanning" || st.Repos[0].Tracked == 0 || st.Repos[0].Untracked == 0 { + t.Fatalf("status counts %+v", st.Repos[0]) + } + + // Later passes (a restart reads the same markers back) never file a + // duplicate, and settle at every qualifying alert tracked. + for pass := 0; pass < 10 && res.Filed > 0; pass++ { + res = c.RunCodeScanningSweep(context.Background(), cfg, now.Add(time.Duration(pass+1)*time.Hour)) + } + seen := map[int]bool{} + for _, is := range s.issues { + m, _ := codescanning.ParseMarker(is["body"].(string)) + for _, n := range m.Alerts { + if seen[n] { + t.Fatalf("alert #%d filed twice", n) + } + seen[n] = true + } + } + if len(seen) != 84 || c.CodeScanningStatus().Repos[0].Untracked != 0 { + t.Fatalf("tracked %d alerts, untracked %d; want 84 and 0", len(seen), c.CodeScanningStatus().Repos[0].Untracked) + } + + // The write-back gate stops every write when the repo is off. + s.alerts = append(s.alerts, map[string]any{"number": 9001, "state": "open", "rule": map[string]any{"id": "cpp/new-rule", "security_severity_level": "critical"}, "tool": map[string]any{"name": "CodeQL"}, "most_recent_instance": map[string]any{"location": map[string]any{"path": "new.cc", "start_line": 3}}}) + c.SetWritebackGate(writeback.New(writeback.Config{PerRepo: map[string]writeback.RepoOverride{"o/r": {Mode: writeback.RepoModeOff}}}, writeback.Deps{}, "")) + before := len(s.creates) + res = c.RunCodeScanningSweep(context.Background(), cfg, now.Add(20*time.Hour)) + if len(s.creates) != before || res.Filed != 0 { + t.Fatalf("a refused gate still filed %d issues", len(s.creates)-before) + } +} + +func TestCodeScanningSweepReportsMissingPermissionOnceAndBacksOff(t *testing.T) { + resetRESTAccountingForTest(t, time.Now()) + s := &codeScanningServer{alertsErr: http.StatusForbidden, alertsMsg: "Resource not accessible by integration"} + c := newCodeScanningClient(t, s.start(t)) + cfg := codeScanningConfig() + now := time.Now() + c.RunCodeScanningSweep(context.Background(), cfg, now) + st := c.CodeScanningStatus() + if len(st.Repos) != 1 || st.Repos[0].NoticeKind != codescanning.NoticeMissingPermission || !strings.Contains(st.Repos[0].Notice, "security_events") { + t.Fatalf("status %+v", st) + } + if len(st.Notices) != 1 { + t.Fatalf("notices %v, want one", st.Notices) + } + gets := s.alertGets + c.RunCodeScanningSweep(context.Background(), cfg, now.Add(time.Hour)) + if s.alertGets != gets { + t.Fatalf("the sweep retried a refused repo inside the back-off (%d extra reads)", s.alertGets-gets) + } + if len(s.creates) != 0 { + t.Fatal("filed an issue without reading alerts") + } + c.RunCodeScanningSweep(context.Background(), cfg, now.Add(codeScanningNoAccessBackoff+time.Minute)) + if s.alertGets == gets { + t.Fatal("the sweep never retried after the back-off") + } + + // GitHub's 404 for "no analysis" is a different notice. + s2 := &codeScanningServer{alertsErr: http.StatusNotFound, alertsMsg: "no analysis found"} + c2 := newCodeScanningClient(t, s2.start(t)) + c2.RunCodeScanningSweep(context.Background(), cfg, now) + if k := c2.CodeScanningStatus().Repos[0].NoticeKind; k != codescanning.NoticeNotEnabled { + t.Fatalf("no-analysis notice kind %q", k) + } +} + +func TestCodeScanningSweepMakesNoCallsWhenOffOrOutsideNormalBudget(t *testing.T) { + resetRESTAccountingForTest(t, time.Now()) + s := &codeScanningServer{alerts: codeScanningFixture(t)} + c := newCodeScanningClient(t, s.start(t)) + c.RunCodeScanningSweep(context.Background(), &config.Config{Project: config.ProjectConfig{Org: "o", Repos: []string{"r"}}}, time.Now()) + if s.requests != 0 { + t.Fatalf("disabled sweep made %d requests", s.requests) + } + c.SetAPIBudgetThresholds(800, 250) + c.rateLimits.mu.Lock() + c.rateLimits.windows = map[string]rateLimitWindow{githubCoreRateLimitResource: { + limit: 7000, remaining: 600, reset: time.Now().Add(30 * time.Minute), observedAt: time.Now(), + }} + c.rateLimits.mu.Unlock() + res := c.RunCodeScanningSweep(context.Background(), codeScanningConfig(), time.Now()) + if s.requests != 0 || !res.BudgetSkipped { + t.Fatalf("conserve budget: %d requests, skipped=%v", s.requests, res.BudgetSkipped) + } +} + +func TestCodeScanningAlertListingIsBounded(t *testing.T) { + resetRESTAccountingForTest(t, time.Now()) + s := &codeScanningServer{alerts: codeScanningFixture(t)} + c := newCodeScanningClient(t, s.start(t)) + old := codeScanningPerPage + codeScanningPerPage = 50 + t.Cleanup(func() { codeScanningPerPage = old }) + f := codeScanningForge{c: c} + alerts, complete, err := f.ListAlerts(context.Background(), "o/r", "open", 1) + if err != nil || complete || len(alerts) != codeScanningPerPage { + t.Fatalf("one page of %d: got %d alerts complete=%v err=%v", len(s.alerts), len(alerts), complete, err) + } + alerts, complete, err = f.ListAlerts(context.Background(), "o/r", "open", 10) + if err != nil || !complete || len(alerts) != len(s.alerts) { + t.Fatalf("full listing: %d alerts complete=%v err=%v", len(alerts), complete, err) + } +} + +// A closing note carries codescanning.CloseMarker. When an earlier pass +// posted it and the close itself failed, the retry closes without posting +// the note a second time. +func TestCodeScanningCloseNotePostedOnceAcrossRetries(t *testing.T) { + srv := &codeScanningServer{issues: []map[string]any{{"number": 7, "state": "open", "title": "t", "body": "b", "user": map[string]any{"login": "hive-app[bot]", "type": "Bot"}}}} + c := newCodeScanningClient(t, srv.start(t)) + f := codeScanningForge{c: c} + note := codescanning.CloseComment(map[int]codescanning.AlertStatus{12: codescanning.StatusFixed}) + if !strings.Contains(note, codescanning.CloseMarker) { + t.Fatalf("close note lacks its marker: %q", note) + } + ctx := context.Background() + if err := f.CloseIssue(ctx, "o/r", 7, note, "completed"); err != nil { + t.Fatal(err) + } + // A retry (as after a refused close) must not post the note again. + if err := f.CloseIssue(ctx, "o/r", 7, note, "completed"); err != nil { + t.Fatal(err) + } + srv.mu.Lock() + defer srv.mu.Unlock() + if got := len(srv.posted[7]); got != 1 { + t.Fatalf("closing note posted %d times, want 1", got) + } + if srv.issues[0]["state"] != "closed" { + t.Fatalf("issue state = %v, want closed", srv.issues[0]["state"]) + } +} diff --git a/src/pkg/github/notification_write_sites.go b/src/pkg/github/notification_write_sites.go index 5e40455ccf..4741b72156 100644 --- a/src/pkg/github/notification_write_sites.go +++ b/src/pkg/github/notification_write_sites.go @@ -48,6 +48,7 @@ var notificationWriteSites = map[string]NotificationWriteSite{ "dashboard.(*Server).handleReviewQueueSupersededClose": {Class: NotificationClassStatus}, "dashboard.(*Server).mirrorPlanWith": {Class: NotificationClassStatus}, "github.(*Client).CloseIssueForConfiguredLinePR": {Class: NotificationClassStatus}, + "github.codeScanningForge.CloseIssue": {Class: NotificationClassStatus}, "github.(*Client).ApproveIssueRelease": {Class: NotificationClassStatus}, "github.(*Client).PostFleetReportCleared": {Class: NotificationClassStatus}, "github.(*Client).PostFleetReportRecovery": {Class: NotificationClassStatus},