Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/src/content/docs/lint-rules/audit-rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,42 @@ Bump the reference to a patched ref/commit named by the advisory.

Authority: [OSSF Scorecard — Vulnerabilities](https://github.com/ossf/scorecard/blob/main/docs/checks.md#vulnerabilities)

### GHA063

**Dependency setup action without caching enabled** — report-only · guidance

Enable the setup action's `cache:` option or add an actions/cache step.

### GHA064

**Expensive runner without justification** — report-only · guidance

Confirm the job needs that OS, or move it to a Linux runner.

### GHA065

**Unbounded matrix fan-out** — report-only · guidance

Trim the matrix with include/exclude, or cap it with max-parallel.

### GHA066

**Unbounded artifact retention** — report-only · guidance

Set a retention-days sized to how long the artifact is actually needed.

### GHA067

**Unconditional heavy step with no path filter** — report-only · guidance

Scope the trigger's paths, or add an if: guard to the step.

### GHA068

**Pull-request workflow missing a concurrency group** — report-only · guidance

Add a concurrency group with cancel-in-progress: true.

## GitLab CI (WGL)

### WGL010
Expand Down Expand Up @@ -634,6 +670,18 @@ Authority: [OSSF Scorecard — Pinned-Dependencies](https://github.com/ossf/scor

Add a `workflow:name` for clearer pipeline naming.

### WGL049

**Dependency install without a cache** — report-only · guidance

Add a `cache:` covering the dependency directory.

### WGL050

**Merge-request job missing interruptible** — report-only · guidance

Add `interruptible: true` so a superseded pipeline can be cancelled.

## Forgejo (WFJ)

### WFJ010
Expand Down
9 changes: 9 additions & 0 deletions lexicons/github/src/lint/audit-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ export const githubAuditCatalog: Record<string, RuleMeta> = {
GHA060: auditRule("GHA060", "merge-worthy", "guidance", "Over-scoped generated token", "Narrow the GitHub App token's permission-* inputs to the scopes its consuming steps actually use, or remove the unused ones.", { authority: [SCORECARD_TOKEN, GH_TOKEN] }),
GHA061: auditRule("GHA061", "merge-worthy", "guidance", "Action reference outside the configured usage policy", "Replace the reference with one from the approved allowlist, or get it added if it should be trusted.", { category: "security" }),
GHA062: auditRule("GHA062", "merge-worthy", "guidance", "Pinned reference matches a known-vulnerability advisory", "Bump the reference to a patched ref/commit named by the advisory.", { authority: [SCORECARD_VULN] }),

// Efficiency (#444) — waste, not a safety/correctness issue. Always
// report-only: none of these warrant a merge on their own.
GHA063: auditRule("GHA063", "report-only", "guidance", "Dependency setup action without caching enabled", "Enable the setup action's `cache:` option or add an actions/cache step.", { category: "efficiency" }),
GHA064: auditRule("GHA064", "report-only", "guidance", "Expensive runner without justification", "Confirm the job needs that OS, or move it to a Linux runner.", { category: "efficiency" }),
GHA065: auditRule("GHA065", "report-only", "guidance", "Unbounded matrix fan-out", "Trim the matrix with include/exclude, or cap it with max-parallel.", { category: "efficiency" }),
GHA066: auditRule("GHA066", "report-only", "guidance", "Unbounded artifact retention", "Set a retention-days sized to how long the artifact is actually needed.", { category: "efficiency" }),
GHA067: auditRule("GHA067", "report-only", "guidance", "Unconditional heavy step with no path filter", "Scope the trigger's paths, or add an if: guard to the step.", { category: "efficiency" }),
GHA068: auditRule("GHA068", "report-only", "guidance", "Pull-request workflow missing a concurrency group", "Add a concurrency group with cancel-in-progress: true.", { category: "efficiency" }),
};
86 changes: 86 additions & 0 deletions lexicons/github/src/lint/post-synth/gha063.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, test, expect } from "vitest";
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
import { gha063 } from "./gha063";

function makeCtx(yaml: string): PostSynthContext {
return {
outputs: new Map([["github", yaml]]),
entities: new Map(),
buildResult: { outputs: new Map([["github", yaml]]), entities: new Map(), warnings: [], errors: [], sourceFileCount: 1 },
};
}

describe("GHA063: dependency setup without caching", () => {
test("flags setup-node with no cache option and no cache step", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
`;
const diags = gha063.check(makeCtx(yaml));
expect(diags).toHaveLength(1);
expect(diags[0].checkId).toBe("GHA063");
expect(diags[0].entity).toBe("build");
});

test("does not flag setup-node with cache enabled", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- run: npm ci
`;
expect(gha063.check(makeCtx(yaml))).toHaveLength(0);
});

test("does not flag setup-node when a separate actions/cache step covers it", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-\${{ hashFiles('package-lock.json') }}
- run: npm ci
`;
expect(gha063.check(makeCtx(yaml))).toHaveLength(0);
});

test("does not flag a job with no setup action at all", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make build
`;
expect(gha063.check(makeCtx(yaml))).toHaveLength(0);
});
});
60 changes: 60 additions & 0 deletions lexicons/github/src/lint/post-synth/gha063.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* GHA063: Dependency Setup Without Caching
*
* Flags a `actions/setup-{node,python,java,ruby,dotnet}` step that leaves its
* built-in `cache:` option unset, with no adjacent `actions/cache` step to
* cover the gap. Every run re-downloads the same dependencies from the
* registry from a cold cache — pure wasted time and bandwidth, not a
* correctness or security issue (efficiency, #444).
*/

import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
import { getPrimaryOutput, jobEntries, parseActionUses } from "./yaml-helpers";

/** Setup actions whose `with.cache` option enables built-in dependency caching. */
const CACHEABLE_SETUP_ACTIONS = new Set(["actions/setup-node", "actions/setup-python", "actions/setup-java", "actions/setup-ruby", "actions/setup-dotnet"]);

function cacheEnabled(withBlock: unknown): boolean {
if (!withBlock || typeof withBlock !== "object") return false;
const cache = (withBlock as Record<string, unknown>).cache;
if (typeof cache === "boolean") return cache;
if (typeof cache === "string") return cache.trim().length > 0 && cache.trim() !== "false";
return false;
}

export const gha063: PostSynthCheck = {
id: "GHA063",
description: "Dependency setup action without caching enabled",

check(ctx: PostSynthContext): PostSynthDiagnostic[] {
const diagnostics: PostSynthDiagnostic[] = [];

for (const [, output] of ctx.outputs) {
const yaml = getPrimaryOutput(output);

for (const [jobName, jobObj] of jobEntries(yaml)) {
const steps = Array.isArray(jobObj.steps) ? (jobObj.steps as Array<Record<string, unknown>>) : [];
const hasGenericCacheStep = steps.some((s) => parseActionUses(String(s.uses ?? ""))?.slug === "actions/cache");
if (hasGenericCacheStep) continue;

for (const step of steps) {
const uses = typeof step.uses === "string" ? step.uses : undefined;
if (!uses) continue;
const parsed = parseActionUses(uses);
if (!parsed || !CACHEABLE_SETUP_ACTIONS.has(parsed.slug)) continue;
if (cacheEnabled(step.with)) continue;

diagnostics.push({
checkId: "GHA063",
severity: "info",
message: `Job "${jobName}" uses ${parsed.slug} without enabling its \`cache:\` option, and no separate actions/cache step covers it — dependencies are re-fetched from a cold cache on every run. Set \`with.cache\` (e.g. \`cache: npm\`) or add an actions/cache step.`,
entity: jobName,
lexicon: "github",
});
}
}
}

return diagnostics;
},
};
73 changes: 73 additions & 0 deletions lexicons/github/src/lint/post-synth/gha064.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { describe, test, expect } from "vitest";
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
import { gha064 } from "./gha064";

function makeCtx(yaml: string): PostSynthContext {
return {
outputs: new Map([["github", yaml]]),
entities: new Map(),
buildResult: { outputs: new Map([["github", yaml]]), entities: new Map(), warnings: [], errors: [], sourceFileCount: 1 },
};
}

describe("GHA064: expensive runner without justification", () => {
test("flags a macOS runner with no macOS-specific step", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: npm test
`;
const diags = gha064.check(makeCtx(yaml));
expect(diags).toHaveLength(1);
expect(diags[0].checkId).toBe("GHA064");
expect(diags[0].entity).toBe("build");
});

test("does not flag macOS when a step is Xcode-specific", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: xcodebuild -scheme App build
`;
expect(gha064.check(makeCtx(yaml))).toHaveLength(0);
});

test("does not flag runs-on driven by a matrix expression", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: \${{ matrix.os }}
steps:
- run: npm test
`;
expect(gha064.check(makeCtx(yaml))).toHaveLength(0);
});

test("does not flag a Linux runner", () => {
const yaml = `name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: npm test
`;
expect(gha064.check(makeCtx(yaml))).toHaveLength(0);
});
});
55 changes: 55 additions & 0 deletions lexicons/github/src/lint/post-synth/gha064.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* GHA064: Expensive Runner Without Justification
*
* Flags a job hardcoded onto a pricier macOS/Windows runner (billed at a
* multiple of Linux minutes) when none of its `run:` steps show any sign the
* job actually needs that OS. A matrix-driven `runs-on: ${{ matrix.os }}`
* (intentional cross-platform testing) is never flagged — only a literal,
* hardcoded label. Efficiency (#444), not a correctness/security issue.
*/

import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
import { getPrimaryOutput, extractRunsOnByJob, extractRunBlocks } from "./yaml-helpers";

const OS_JUSTIFICATION: Array<{ prefix: string; label: string; keywords: RegExp }> = [
{ prefix: "macos-", label: "macOS", keywords: /xcodebuild|xcode-select|\.xcodeproj|\.xcworkspace|carthage|fastlane|cocoapods|pod install|swiftpm|codesign|notarize/i },
{ prefix: "windows-", label: "Windows", keywords: /msbuild|\.sln\b|\.ps1\b|vcvarsall|nuget\s|choco\s|Set-ItemProperty|Get-ChildItem/i },
];

export const gha064: PostSynthCheck = {
id: "GHA064",
description: "Job hardcoded onto an expensive runner with no sign it needs that OS",

check(ctx: PostSynthContext): PostSynthDiagnostic[] {
const diagnostics: PostSynthDiagnostic[] = [];

for (const [, output] of ctx.outputs) {
const yaml = getPrimaryOutput(output);
const runsOnByJob = extractRunsOnByJob(yaml);
const runBlocks = extractRunBlocks(yaml);

for (const [jobName, labels] of runsOnByJob) {
if (labels.some((l) => l.includes("${{"))) continue; // matrix/expression-driven — intentional

for (const { prefix, label, keywords } of OS_JUSTIFICATION) {
const matched = labels.find((l) => l.toLowerCase().startsWith(prefix));
if (!matched) continue;

const justified = runBlocks.some((r) => r.job === jobName && keywords.test(r.run));
if (justified) break;

diagnostics.push({
checkId: "GHA064",
severity: "info",
message: `Job "${jobName}" runs on "${matched}" (a pricier ${label} runner) but no step looks ${label}-specific. Confirm it needs ${label}, or move it to a Linux runner.`,
entity: jobName,
lexicon: "github",
});
break;
}
}
}

return diagnostics;
},
};
Loading
Loading