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): isolate artifact upload failures (#1719)

Michael D'Angeloe10e28113fa8
diff --git a/github-action/dist/index.cjs b/github-action/dist/index.cjs
index c64705a23..70cd64d7b 100644
--- a/github-action/dist/index.cjs
+++ b/github-action/dist/index.cjs
@@ -99196,8 +99196,8 @@ async function collectReports(result) {
async function uploadReports(reports, inputs, tempRoot) {
if (!reports.size) throw new Error("Artifact upload requested, but no validated reports are available.");
const staging = await (0, import_promises9.mkdtemp)((0, import_node_path6.join)(tempRoot, "codex-security-upload-"));
- await (0, import_promises9.chmod)(staging, 448);
try {
+ await (0, import_promises9.chmod)(staging, 448);
const files = [];
for (const [name, bytes] of reports) {
const dest = (0, import_node_path6.join)(staging, name === "exports/results.sarif" ? "results.sarif" : name);
diff --git a/github-action/src/artifacts.ts b/github-action/src/artifacts.ts
index 39b1dc2f6..b02b197fc 100644
--- a/github-action/src/artifacts.ts
+++ b/github-action/src/artifacts.ts
@@ -19,8 +19,8 @@ export async function collectReports(result: ScanResults): Promise<Map<string, B
export async function uploadReports(reports: Map<string, Buffer>, inputs: Inputs, tempRoot: string): Promise<void> {
if (!reports.size) throw new Error('Artifact upload requested, but no validated reports are available.');
const staging = await mkdtemp(join(tempRoot, 'codex-security-upload-'));
- await chmod(staging, 0o700);
try {
+ await chmod(staging, 0o700);
const files: string[] = [];
for (const [name, bytes] of reports) {
const dest = join(staging, name === 'exports/results.sarif' ? 'results.sarif' : name);
diff --git a/github-action/tests/main.test.ts b/github-action/tests/main.test.ts
index dcd74df3f..8e2e250d3 100644
--- a/github-action/tests/main.test.ts
+++ b/github-action/tests/main.test.ts
@@ -1,11 +1,14 @@
import { test, type TestContext } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
+import { chmod, mkdir, mkdtemp, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
+import { once } from 'node:events';
+import { createServer } from 'node:http';
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import { execFileSync } from 'node:child_process';
import * as core from '@actions/core';
import { DefaultArtifactClient } from '@actions/artifact';
+import { BlobClient } from '@azure/storage-blob';
import { runAction } from '../src/main.js';
import { INPUT_NAMES } from '../src/inputs.js';
import { gitEnvironment } from '../src/targets.js';
@@ -618,6 +621,62 @@ test('requested artifact upload failure remains fatal without SARIF', async (t)
assert.match(result.summary, /Synthetic artifact upload failure/);
});
+test('archive read failure preserves scan reports, summary and cleanup', {
+ skip: process.platform === 'win32' || process.getuid?.() === 0,
+}, async t => {
+ const app = await harness(t);
+ app.setInput('upload-artifacts', 'true');
+ const requests: string[] = [];
+ const server = createServer(async (request, response) => {
+ for await (const _chunk of request) { /* Read the artifact creation request. */ }
+ requests.push(request.url ?? '');
+ response.writeHead(200, {'Content-Type': 'application/json'});
+ response.end(JSON.stringify({ok: true, signed_upload_url: 'https://example.invalid/artifact'}));
+ });
+ server.listen(0, '127.0.0.1');
+ await once(server, 'listening');
+ t.after(() => new Promise<void>((resolve, reject) => server.close(error => error ? reject(error) : resolve())));
+ const address = server.address();
+ assert.ok(address && typeof address !== 'string');
+ const payload = Buffer.from(JSON.stringify({scp: 'Actions.Results:synthetic-run:synthetic-job'})).toString('base64url');
+ Object.assign(process.env, {
+ ACTIONS_RESULTS_URL: `http://127.0.0.1:${address.port}`,
+ ACTIONS_RUNTIME_TOKEN: `e30.${payload}.synthetic-signature`,
+ });
+ let signal: AbortSignal | undefined;
+ t.mock.method(BlobClient.prototype, 'getBlockBlobClient', () => ({
+ uploadStream: async (input: AsyncIterable<Buffer>, _bufferSize: number, _concurrency: number, options: {abortSignal: AbortSignal}) => {
+ signal = options.abortSignal;
+ for await (const _chunk of input) { /* Consume the real archive stream. */ }
+ },
+ }));
+ let staging = '';
+ let unreadable = '';
+ const uploadArtifact = DefaultArtifactClient.prototype.uploadArtifact;
+ t.mock.method(DefaultArtifactClient.prototype, 'uploadArtifact', async function (this: DefaultArtifactClient, ...args: Parameters<typeof uploadArtifact>) {
+ staging = args[2];
+ unreadable = args[1][0];
+ // Fail the archive's actual file read without altering the saved scan report.
+ await chmod(unreadable, 0);
+ return uploadArtifact.apply(this, args);
+ });
+ const result = await app.run();
+ assert.equal(result.exitCode, 1); assert.equal(result.cleanups, 1);
+ assert.equal(result.outputs['scan-status'], 'completed');
+ assert.equal(result.outputs['policy-status'], 'passed');
+ assert.equal(result.outputs['report-status'], 'failed');
+ assert.equal(result.outputs['sarif-upload-ready'], 'false');
+ for (const name of ['json-path', 'coverage-path', 'sarif-path']) {
+ assert.ok((await readFile(result.outputs[name])).length);
+ }
+ assert.match(result.summary, /EACCES/);
+ assert.ok(result.summary.includes(unreadable));
+ assert.match(result.logs, /::error::Scan completed, but required reporting failed\./);
+ assert.deepEqual(requests, ['/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact']);
+ assert.equal(signal?.aborted, true);
+ await assert.rejects(stat(staging), {code: 'ENOENT'});
+});
+
test('CLI authentication failure leaves findings unavailable instead of reporting a threshold failure', async (t) => {
const app = await harness(t); app.configure({exitCode: 2, cliFailure: true});
const result = await app.run();