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

refactor(cli): simplify export and progress delegation (#1478)

mldangelo-oaiae1d9b2c2f43
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 3ffea9edb..339c601f7 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -689,11 +689,7 @@ class PublicationProgressPresenter {
try {
dashboard.start();
this.#dashboard = dashboard;
- } catch {
- try {
- dashboard.stop();
- } catch {}
- }
+ } catch {}
}
public stop(): void {
@@ -857,11 +853,7 @@ class FindingProgressPresenter {
dashboard.start();
this.#dashboard = dashboard;
return;
- } catch {
- try {
- dashboard.stop();
- } catch {}
- }
+ } catch {}
}
this.#write(
@@ -1064,8 +1056,6 @@ function scanOutputSchema(...codes: [string, ...string[]]) {
.optional();
}
-type ExportArguments = ArtifactExportArguments;
-
type MatchingPlan = JsonObject & {
repository: string;
scanCount: number;
@@ -1215,7 +1205,7 @@ interface CliDependencies {
terminatePublishers?(): void;
forceExit(signal: SignalName): void;
exportFindings(
- arguments_: ExportArguments,
+ arguments_: ArtifactExportArguments,
output?: Writable,
): Promise<string | Uint8Array | undefined>;
runCodex(
@@ -4355,11 +4345,7 @@ export async function main(
try {
candidate.start();
dashboard = candidate;
- } catch {
- try {
- candidate.stop();
- } catch {}
- }
+ } catch {}
}
const result = await runComponentScans({
surface: "cli",
@@ -4856,28 +4842,46 @@ export async function main(
),
);
}
- exitCode = await runExport(
- {
- scanDir: resolveCliPath(currentDirectory, scanDir),
- artifact: options.artifact,
- format,
- output:
- options.output === "-"
- ? "-"
- : resolveCliPath(
- currentDirectory,
- options.output ?? EXPORT_DEFAULT_OUTPUTS[format],
- ),
- sourceRoot:
- options.sourceRoot === undefined
- ? undefined
- : resolveCliPath(currentDirectory, options.sourceRoot),
- pythonPath: options.python,
- },
- output,
- errorOutput,
- dependencies,
- );
+ const arguments_: ArtifactExportArguments = {
+ scanDir: resolveCliPath(currentDirectory, scanDir),
+ artifact: options.artifact,
+ format,
+ output:
+ options.output === "-"
+ ? "-"
+ : resolveCliPath(
+ currentDirectory,
+ options.output ?? EXPORT_DEFAULT_OUTPUTS[format],
+ ),
+ sourceRoot:
+ options.sourceRoot === undefined
+ ? undefined
+ : resolveCliPath(currentDirectory, options.sourceRoot),
+ pythonPath: options.python,
+ };
+ try {
+ const prepared = await resolveArtifactExportOutput(
+ arguments_,
+ dependencies.currentDirectory(),
+ );
+ const contents = await dependencies.exportFindings(
+ prepared,
+ output,
+ );
+ if (arguments_.output === "-") {
+ if (contents !== undefined) {
+ await writeCliOutput(output, Buffer.from(contents));
+ }
+ } else {
+ errorOutput.write(
+ `${arguments_.format.toUpperCase()}: ${arguments_.output}\n`,
+ );
+ }
+ exitCode = 0;
+ } catch (error) {
+ errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
+ exitCode = 2;
+ }
} catch (error) {
if (exitCode !== 2) {
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
@@ -8113,34 +8117,6 @@ function incurErrorMessage(output: string): string {
return typeof parsed === "string" ? parsed : message;
}
-async function runExport(
- arguments_: ExportArguments,
- output: Writable,
- errorOutput: Writable,
- dependencies: CliDependencies,
-): Promise<number> {
- try {
- const prepared = await resolveArtifactExportOutput(
- arguments_,
- dependencies.currentDirectory(),
- );
- const contents = await dependencies.exportFindings(prepared, output);
- if (arguments_.output === "-") {
- if (contents !== undefined) {
- await writeCliOutput(output, Buffer.from(contents));
- }
- } else {
- errorOutput.write(
- `${arguments_.format.toUpperCase()}: ${arguments_.output}\n`,
- );
- }
- return 0;
- } catch (error) {
- errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
- return 2;
- }
-}
-
type VerboseDiagnosticValue = string | number | boolean | null | undefined;
function diagnosticValue(value: unknown): string {
diff --git a/sdk/typescript/src/publication-events.ts b/sdk/typescript/src/publication-events.ts
index fd39130ac..251e973ea 100644
--- a/sdk/typescript/src/publication-events.ts
+++ b/sdk/typescript/src/publication-events.ts
@@ -280,20 +280,8 @@ function isCanonicalUuid(value: string): boolean {
function linearIssueReferenceFromUrl(
value: string,
): { id: string; workspace: string } | undefined {
- let url: URL;
- try {
- url = new URL(value);
- } catch {
- return undefined;
- }
// Recognize every scheme linearIssueReference parses, so a plain HTTP URL
// still resolves to the issue it names instead of an unrecognized claim.
- if (
- (url.protocol !== "https:" && url.protocol !== "http:") ||
- url.hostname !== "linear.app"
- ) {
- return undefined;
- }
try {
const reference = linearIssueReference(value);
return reference.workspace === undefined