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
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion docs/tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
12 changes: 9 additions & 3 deletions lib/scanners.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <image> AS <name>`. A later `FROM <name>` 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];
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 5 additions & 3 deletions secgate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 26 additions & 2 deletions test/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
});
});

Expand Down
Loading