Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(action): show highest-severity findings first (#2160)

andy-tang-oaieeb969e87b46
diff --git a/github-action/README.md b/github-action/README.md
index 5fd942ae5..b8dceeec4 100644
--- a/github-action/README.md
+++ b/github-action/README.md
@@ -343,7 +343,8 @@ room for finalization within your job timeout.
## Reports
-The Action writes a job summary and source annotations. Set
+The Action lists the highest-severity findings first in the job summary and
+source annotations, preserving scan order within each severity level. Set
`upload-artifacts: 'true'` for downloadable reports, retained for seven days by
default. Reports can contain source code and vulnerability details.
diff --git a/github-action/dist/index.cjs b/github-action/dist/index.cjs
index aae63d0f9..971618588 100644
--- a/github-action/dist/index.cjs
+++ b/github-action/dist/index.cjs
@@ -99460,6 +99460,7 @@ function emitAnnotations(result) {
}
// src/main.ts
+var SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3, informational: 4 };
var OUTPUT_NAMES = [
"sarif-path",
"json-path",
@@ -99645,8 +99646,12 @@ async function runAction(actionRoot, overrides = {}) {
info(`Findings: ${result.counts ? Object.entries(result.counts).map(([level, count]) => `${level}: ${count}`).join(", ") : "unavailable"}.`);
info(`Estimated cost: ${result.estimatedCost === void 0 ? "unavailable" : `$${result.estimatedCost.toFixed(4)}`}.`);
for (const error2 of result.errors) log2(`Report diagnostic: ${error2}`);
- finalSummary = resultSummary(result, inputs, target);
- if (inputs.annotations) emitAnnotations(result);
+ const displayResult = {
+ ...result,
+ findings: [...result.findings].sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity])
+ };
+ finalSummary = resultSummary(displayResult, inputs, target);
+ if (inputs.annotations) emitAnnotations(displayResult);
success = result.reportStatus !== "failed" && result.scanStatus === "completed" && result.policyStatus === "passed";
finalTitle = resultTitle(result, inputs);
}
diff --git a/github-action/src/main.ts b/github-action/src/main.ts
index aeb27b5fe..4fcc5db6b 100644
--- a/github-action/src/main.ts
+++ b/github-action/src/main.ts
@@ -4,10 +4,12 @@ import { parseInputs, scanArguments, type Inputs } from './inputs.js';
import { resolveTarget, type EventContext, type Target } from './targets.js';
import { SUPPORTED_CLI_VERSION, setupRuntime, cleanupRuntime, runtimeEnvironment, scanCredentials, API_KEY_ENVIRONMENT_VARIABLES, type Runtime } from './runtime.js';
import { runProcess, safeLogLines } from './process.js';
-import { analyzeResults, type ScanResults } from './results.js';
+import { analyzeResults, type ScanResults, type Severity } from './results.js';
import { collectReports, uploadReports } from './artifacts.js';
import { resultSummary, emitAnnotations, plain, resultTitle } from './reporting.js';
+const SEVERITY_RANK: Record<Severity, number> = { critical: 0, high: 1, medium: 2, low: 3, informational: 4 };
+
export const OUTPUT_NAMES = [
'sarif-path', 'json-path', 'manifest-path', 'coverage-path', 'results-directory', 'scan-status', 'skip-reason',
'policy-status', 'report-status', 'exit-code', 'scanned-sha', 'analysis-ref', 'sarif-upload-ready',
@@ -160,8 +162,12 @@ export async function runAction(actionRoot: string, overrides: Partial<Dependenc
core.info(`Findings: ${result.counts ? Object.entries(result.counts).map(([level, count]) => `${level}: ${count}`).join(', ') : 'unavailable'}.`);
core.info(`Estimated cost: ${result.estimatedCost === undefined ? 'unavailable' : `$${result.estimatedCost.toFixed(4)}`}.`);
for (const error of result.errors) log(`Report diagnostic: ${error}`);
- finalSummary = resultSummary(result, inputs, target);
- if (inputs.annotations) emitAnnotations(result);
+ const displayResult = {
+ ...result,
+ findings: [...result.findings].sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity]),
+ };
+ finalSummary = resultSummary(displayResult, inputs, target);
+ if (inputs.annotations) emitAnnotations(displayResult);
success = result.reportStatus !== 'failed' && result.scanStatus === 'completed' && result.policyStatus === 'passed';
finalTitle = resultTitle(result, inputs);
}
diff --git a/github-action/tests/main.test.ts b/github-action/tests/main.test.ts
index 8b0cb125f..508883343 100644
--- a/github-action/tests/main.test.ts
+++ b/github-action/tests/main.test.ts
@@ -197,6 +197,29 @@ test('PR severity failure retains SARIF outputs despite unrelated scope notes',
assert.match(annotation[2], /filesystem write without containment validation/);
});
+test('a Critical finding after 50 Low findings leads the PR summary and annotations', async (t) => {
+ const app = await harness(t, 'pr');
+ app.setInput('fail-on-severity', 'high');
+ app.setInput('annotations', 'true');
+ app.configure({ scanResult: value => {
+ const [finding] = value.findings.findings;
+ const lowFindings = Array.from({ length: 50 }, (_, i) => ({
+ ...finding, title: `Low finding ${i + 1}`, severity: { level: 'low' },
+ }));
+ value.findings.findings = [...lowFindings, { ...finding, title: 'Blocking finding', severity: { level: 'critical' } }];
+ }});
+
+ const result = await app.run();
+ assert.equal(result.outputs['policy-status'], 'failed');
+ const headings = [...result.summary.matchAll(/<h3>([^<]+)<\/h3>/g)].map(match => match[1]);
+ const annotations = result.logs.split(/\r?\n/).filter(line => line.startsWith('::warning '));
+ assert.equal(headings.length, 30);
+ assert.equal(annotations.length, 50);
+ assert.deepEqual(headings.slice(0, 2), ['CRITICAL: Blocking finding', 'LOW: Low finding 1']);
+ assert.match(annotations[0], /title=CRITICAL%3A Blocking finding/);
+ assert.match(annotations[1], /title=LOW%3A Low finding 1/);
+});
+
test('scheduled complete report-only scan succeeds', async (t) => {
const app = await harness(t);
process.env.INPUT_FOO = 'unrelated workflow value';