OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
refactor(artifacts): derive historical union types from their members (#2459)
Michael D'Angelodb1c7fb74667
diff --git a/plugins/codex-security/mcp-app/scripts/canonical-schemas.mts b/plugins/codex-security/mcp-app/scripts/canonical-schemas.mtsindex 150e2284e..0350551d3 100644--- a/plugins/codex-security/mcp-app/scripts/canonical-schemas.mts+++ b/plugins/codex-security/mcp-app/scripts/canonical-schemas.mts@@ -9,8 +9,8 @@ import { findingDetailSchemas } from "../src/finding-detail-schemas.ts";// Generator-only definitions: canonical runtime validation uses the selected// plugin's exported JSON Schemas in AJV and Python, including legacy type arrays.-function typeArray<T extends z.ZodType>(schema: T, types: string[]): T {- z.globalRegistry.add(schema, { ...schema.meta(), type: types });+function typeArray<T extends z.ZodType>(schema: T): T {+ z.globalRegistry.add(schema, { ...schema.meta(), legacyTypeArray: true });return schema;}function pattern(source: string) {@@ -50,15 +50,11 @@ const validation = findingValidation.extend({evidence_refs: textList.optional(),});for (const schema of [findingAssessment, textOrSummary, findingReachability])- typeArray(schema, ["string", "object"]);+ typeArray(schema);for (const field of ["status", "disposition", "result"] as const)- typeArray(validation.shape[field].unwrap(), ["string", "null"]);-typeArray(validation.shape.evidence.unwrap(), ["string", "array"]);-const assessment = typeArray(findingAttackPath.shape.impact.unwrap(), [- "string",- "object",- "null",-]);+ typeArray(validation.shape[field].unwrap());+typeArray(validation.shape.evidence.unwrap());+const assessment = typeArray(findingAttackPath.shape.impact.unwrap());const attackPath = findingAttackPath.extend({dataFlow: textOrSummary.optional(),data_flow: textOrSummary.optional(),@@ -95,14 +91,8 @@ const finding = z.looseObject({}).optional(),codeEvidence: z.array(codeEvidence).optional(),- code_evidence: typeArray(z.array(legacyCodeEvidence).nullable(), [- "array",- "null",- ]).optional(),- rootCause: typeArray(z.union([rootCause, z.string()]), [- "object",- "string",- ]).optional(),+ code_evidence: typeArray(z.array(legacyCodeEvidence).nullable()).optional(),+ rootCause: typeArray(z.union([rootCause, z.string()])).optional(),root_cause: typeArray(z.union([z.looseObject({@@ -115,11 +105,10 @@ const finding = z.looseObject({z.string(),z.null(),]),- ["object", "string", "null"],).optional(),remediation: text,- validation: typeArray(validation.nullable(), ["object", "null"]).optional(),- attackPath: typeArray(attackPath.nullable(), ["object", "null"]).optional(),+ validation: typeArray(validation.nullable()).optional(),+ attackPath: typeArray(attackPath.nullable()).optional(),remediationTests: textList.optional(),preventiveControls: textList.optional(),provenance: z.looseObject({ source: text }),diff --git a/plugins/codex-security/mcp-app/scripts/generate-artifact-schemas.mjs b/plugins/codex-security/mcp-app/scripts/generate-artifact-schemas.mjsindex 95cbf0a60..0b3ec471e 100644--- a/plugins/codex-security/mcp-app/scripts/generate-artifact-schemas.mjs+++ b/plugins/codex-security/mcp-app/scripts/generate-artifact-schemas.mjs@@ -123,13 +123,18 @@ for (const [path, { title, schema, definitions = {} }] of Object.entries(// Run after Zod resolves reused branches. Only explicitly marked canonical// unions use this historical representation; other anyOf schemas stay intact.function legacyTypeArrays(_key, schema) {- if (!Array.isArray(schema?.type) || !schema.anyOf) return schema;- const { anyOf, ...rest } = schema;- return Object.assign(- {},- ...anyOf.map((part) => legacyTypeArrays("", part)),- rest,- );+ if (schema?.legacyTypeArray !== true) return schema;+ const { legacyTypeArray, anyOf, ...rest } = schema;+ const parts = anyOf?.map((part) => legacyTypeArrays("", part)) ?? [];+ const types = parts.flatMap((part) => part.type);+ if (+ types.length === 0 ||+ types.some((type) => typeof type !== "string") ||+ new Set(types).size !== types.length+ ) {+ throw new Error("Cannot publish this union as a JSON Schema type array.");+ }+ return Object.assign({}, ...parts, { ...rest, type: types });}async function save(path, schema, replacer) {const contents = await format(JSON.stringify(schema, replacer), {