diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0f6d0..049b805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,21 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) + [Semantic Ver ## [Unreleased] +## [0.3.2] - 2026-11-15 + +### Fixed +- **osv-scanner that scans nothing is `skipped`, not `clean`.** When + osv-scanner finds no lockfile or manifest it can read (exit 128, "No package + sources found"), SecGate reported it as `clean` and scored it 100. It is now + `skipped` with the reason `no package sources found` and is not scored. Like + `no package.json in target` for npm audit, this is not a coverage gap, + because there was nothing for it to scan. +- **A Dockerfile stage name is not scanned as an image.** In a multi-stage + Dockerfile, `FROM base AS production` builds on an earlier stage named + `base`. SecGate ran `trivy image base`, which failed, so the image scan + ended `error` and Trivy counted as not run. A `FROM` that names an earlier + stage of the same Dockerfile is no longer scanned as an image. + ## [0.3.1] - 2026-11-15 ### Fixed @@ -439,7 +454,8 @@ Initial public release to npm as `@stelnyx/secgate`. - npm publish with provenance (`--provenance`). - Risk scoring and exit code semantics: exit `0` = clean or low/medium only; exit `1` = CRITICAL or HIGH findings present. -[Unreleased]: https://github.com/Stelnyx/secgate/compare/v0.3.1...HEAD +[Unreleased]: https://github.com/Stelnyx/secgate/compare/v0.3.2...HEAD +[0.3.2]: https://github.com/Stelnyx/secgate/compare/v0.3.1...v0.3.2 [0.3.1]: https://github.com/Stelnyx/secgate/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/Stelnyx/secgate/compare/v0.2.13...v0.3.0 [0.2.13]: https://github.com/Stelnyx/SecGate/compare/v0.2.12...v0.2.13 diff --git a/README.md b/README.md index 1e48ba4..9b5d1f6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ One command. One report. One exit code. **Honest positioning.** SecGate is a **triage accelerator**, not a defect oracle. Dogfooded against a 2,628-file production codebase: **1,858 → 46 actionable findings — 98% noise demoted**. The wrapped scanners are each noisy in isolation (industry estimate: ~70% of raw SAST/SCA output is signal-less). SecGate's job is to surface what's actionable and demote the rest — see [What we demote (and why)](#what-we-demote-and-why). -**Status.** Early release (`v0.3.1`). From `v0.3.0` on, the tag-triggered release workflow publishes to npm with provenance and creates the signed GitHub Release; `v0.2.14` was published to npm without provenance and without a GitHub Release. Report vulnerabilities via [SECURITY.md](SECURITY.md). +**Status.** Early release (`v0.3.2`). From `v0.3.0` on, the tag-triggered release workflow publishes to npm with provenance and creates the signed GitHub Release; `v0.2.14` was published to npm without provenance and without a GitHub Release. Report vulnerabilities via [SECURITY.md](SECURITY.md). **Accuracy contract.** SecGate's aggregation pipeline is deterministic — same inputs produce JSON-byte-identical findings, score, and gate status across every run. Report files embed a timestamp, so they are byte-identical only when the inputs, the scanner versions and the timestamp are the same: set `SECGATE_TIMESTAMP` (ISO 8601, e.g. `2026-01-01T00:00:00Z`) or, if it is unset, `SOURCE_DATE_EPOCH` (Unix seconds). Both pin `timestamp` in the JSON report and the audit log; an unparsable value exits 2. Without them the timestamp is the wall-clock time. Scanner versions and rule databases are not pinned by SecGate. Two test suites lock the contract: diff --git a/docs/tuning.md b/docs/tuning.md index 5bb3aed..eff1c5b 100644 --- a/docs/tuning.md +++ b/docs/tuning.md @@ -4,7 +4,7 @@ # Tuning SecGate -How to adjust severity thresholds, baseline noisy findings, suppress rules, toggle scanners, and tune CI vs local defaults. This document reflects the `v0.3.1` CLI. +How to adjust severity thresholds, baseline noisy findings, suppress rules, toggle scanners, and tune CI vs local defaults. This document reflects the `v0.3.2` CLI. --- diff --git a/lib/scanners.mjs b/lib/scanners.mjs index 66d19b0..2ee245b 100644 --- a/lib/scanners.mjs +++ b/lib/scanners.mjs @@ -95,11 +95,15 @@ function extractBaseImages(dockerfilePath, maxFileSizeBytes) { let content; try { content = fs.readFileSync(dockerfilePath, "utf-8"); } catch { return []; } const images = new Set(); + // Names given with `FROM AS `. A later `FROM ` builds + // on that stage, so it is not an image to pull. + const stages = new Set(); for (const line of content.split("\n")) { - const m = line.match(/^FROM\s+(?:--platform=\S+\s+)?([^\s]+)(?:\s+AS\s+\S+)?$/i); + const m = line.match(/^FROM\s+(?:--platform=\S+\s+)?([^\s]+)(?:\s+AS\s+(\S+))?$/i); if (m) { const ref = m[1]; - if (ref.toLowerCase() !== "scratch") images.add(ref); + if (ref.toLowerCase() !== "scratch" && !stages.has(ref.toLowerCase())) images.add(ref); + if (m[2]) stages.add(m[2].toLowerCase()); } } return [...images]; @@ -392,8 +396,10 @@ export async function runOsvScanner(target, config, addFinding, debugFn) { if (debugFn) debugFn("osv-scanner", out); const exitCode = exitCodeOf(toolResult); + // Exit 128: osv-scanner found no lockfile or manifest it can read, so it + // scanned nothing. That is not a clean result. if (exitCode === 128 || /No package sources found/i.test(out)) { - return { status: "clean" }; + return { status: "skipped", skipReason: "no package sources found" }; } if (!out.trim()) { return exitCode === 0 diff --git a/package-lock.json b/package-lock.json index af292bb..3a3d80e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@stelnyx/secgate", - "version": "0.3.1", + "version": "0.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@stelnyx/secgate", - "version": "0.3.1", + "version": "0.3.2", "license": "MIT", "dependencies": { "@stelnyx/report-theme": "^0.1.4" diff --git a/package.json b/package.json index 075e428..63c418b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stelnyx/secgate", - "version": "0.3.1", + "version": "0.3.2", "description": "Tiny security gate for CI/CD — orchestrates Semgrep, Gitleaks, osv-scanner, Trivy, and npm audit with a premium HTML report.", "type": "module", "bin": { diff --git a/secgate.js b/secgate.js index c7c0b2f..f2cf9f7 100755 --- a/secgate.js +++ b/secgate.js @@ -502,9 +502,11 @@ const noScannersRan = coverage.ran.length === 0; const missingRequired = requiredScanners.filter(t => !coverage.ran.includes(t)); const coverageExit2 = noScannersRan || missingRequired.length > 0; // Skips that are not a coverage gap: the user turned the scanner off, or there -// is nothing for it to scan. Any other skip (not installed, error, timeout, -// no lockfile) means a scanner that should have run did not. -const NOT_A_GAP = new Set(["disabled in config", "no package.json in target"]); +// is nothing for it to scan (no package.json for npm audit, no lockfile or +// manifest osv-scanner can read). Any other skip (not installed, error, +// timeout, a package.json without a lockfile) means a scanner that should +// have run did not. +const NOT_A_GAP = new Set(["disabled in config", "no package.json in target", "no package sources found"]); const skipReasonOf = t => coverageSkipReason(t, toolStatus, toolSkipReason); const coverageGaps = coverage.skipped.filter(t => !NOT_A_GAP.has(skipReasonOf(t))); const configDisabled = disabledByConfig(toolSkipReason); diff --git a/test/smoke.mjs b/test/smoke.mjs index 31b3eb0..6e52bae 100644 --- a/test/smoke.mjs +++ b/test/smoke.mjs @@ -410,6 +410,28 @@ test("trivy fs exit 1 with valid JSON → error, not clean (#82)", () => { assertEq(r.code, 2, "exit"); }); +test("a Dockerfile stage name (FROM base AS production) is not scanned as an image", () => { + // `base` names the first stage; `trivy image base` would try to pull an + // image called base and fail. + const failOnBase = `for a in "$@"; do if [ "$a" = "base" ]; then echo 'FATAL unable to pull image base' >&2; exit 1; fi; done\n${TRIVY_CLEAN}`; + const binDir = makeBinDir({ trivy: trivyStub({ image: failOnBase }) }); + const target = makeTrivyTarget({ dockerfile: false }); + fs.writeFileSync( + path.join(target, "Dockerfile"), + 'FROM node:20-slim AS base\nRUN echo build\nFROM base AS production\nCMD ["node"]\n' + ); + try { + const r = runIsolated(binDir, target); + if (!r.rep) throw new Error("report not written"); + assertEq(r.rep.tools.trivyImage, "clean", "image scan status"); + assertEq(r.rep.status, "PASS", "status"); + assertEq(r.code, 0, "exit"); + } finally { + fs.rmSync(binDir, { recursive: true, force: true }); + fs.rmSync(target, { recursive: true, force: true }); + } +}); + test("trivy image exit 1 with valid JSON → image error, not clean (#82)", () => { const r = runTrivyCase(trivyStub({ image: `${TRIVY_CLEAN}; exit 1` })); assertEq(r.rep.tools.trivyImage, "error", "image status"); @@ -511,11 +533,13 @@ test("semgrep: a fatal error in its JSON is an error; a file it could not parse } }); -test("osv-scanner exit 128 (no package sources found) stays clean (#82)", () => { +test("osv-scanner exit 128 (no package sources found) is skipped with the reason, never clean", () => { const stub = "echo 'No package sources found, --help for usage information.' >&2; exit 128"; withStubs({ "osv-scanner": stub }, r => { if (!r.rep) throw new Error("report not written"); - assertEq(r.rep.tools.osv, "clean", "osv status"); + assertEq(r.rep.tools.osv, "skipped", "osv status"); + assertEq(r.rep.toolSkipReason.osv, "no package sources found", "osv reason"); + assertEq(r.rep.toolScores.osv, null, "osv is not scored"); }); });