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(cli): resume deep scans after clearing their instructions (#2049)

Michael D'Angelo17826aa594bd
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index a800ab741..f8e83575f 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -2611,7 +2611,7 @@ export async function main(
}
scanArguments = await prepareScanArgumentsFromRecipe(
saved["recipe"],
- saved["scanId"],
+ "resume",
{
scanPrompt:
typeof saved["userContext"] === "string"
@@ -2632,7 +2632,6 @@ export async function main(
(saved["recipe"] as JsonObject)["scanInputs"],
);
}
- scanArguments.parentScanId = undefined;
// Resume uses the installed engine with the saved recipe and checkpoints.
scanArguments.expectedPluginVersion = undefined;
scanArguments.verbose = options.verbose;
@@ -2762,7 +2761,7 @@ export async function main(
}
scanArguments = await prepareScanArgumentsFromRecipe(
recipe,
- parentScanId,
+ "rerun",
{
scanPromptFile:
options.scanPromptFile === undefined
@@ -2783,6 +2782,7 @@ export async function main(
);
scanArguments.verbose = options.verbose;
scanArguments.showCost = options.showCost;
+ scanArguments.parentScanId = parentScanId;
scanArguments.rerunInputIdentity = isJsonObject(recipe)
? (recipe["scanInputs"] ?? null)
: null;
@@ -5443,7 +5443,7 @@ export async function main(
}
const recipe = await prepareScanArgumentsFromRecipe(
saved["recipe"],
- scan.scanId,
+ "resume",
{
scanPrompt:
typeof saved["userContext"] === "string"
@@ -7167,7 +7167,7 @@ async function runScanImport(
async function prepareScanArgumentsFromRecipe(
recipe: JsonValue | undefined,
- parentScanId: string,
+ operation: "resume" | "rerun",
{
scanPrompt,
scanPromptFile,
@@ -7183,11 +7183,9 @@ async function prepareScanArgumentsFromRecipe(
"This scan does not have a saved launch recipe.",
);
}
- if (
- recipe["requiresScanPrompt"] === true &&
- scanPrompt === undefined &&
- scanPromptFile === undefined
- ) {
+ const requiresRerunPrompt =
+ operation === "rerun" && recipe["requiresScanPrompt"] === true;
+ if (requiresRerunPrompt && scanPromptFile === undefined) {
throw new CodexSecurityError(
"This scan used additional instructions. Supply --scan-prompt-file to rerun it.",
);
@@ -7351,7 +7349,7 @@ async function prepareScanArgumentsFromRecipe(
repository,
directory,
);
- if (recipe["requiresScanPrompt"] === true && !prompts.scanPrompt?.trim()) {
+ if (requiresRerunPrompt && !prompts.scanPrompt?.trim()) {
throw new CodexSecurityError(
"This scan used additional instructions. The --scan-prompt-file must not be empty.",
);
@@ -7390,7 +7388,6 @@ async function prepareScanArgumentsFromRecipe(
maxCostUsd,
maxTimeMinutes: maxTimeMinutes.data,
dryRun: false,
- parentScanId,
...(recipe["mock"] === true ? { mock: true } : {}),
expectedPluginVersion:
typeof recipe["pluginVersion"] === "string"
diff --git a/sdk/typescript/tests-ts/scan-resume.test.ts b/sdk/typescript/tests-ts/scan-resume.test.ts
index 5c34ede0f..5647f3c3e 100644
--- a/sdk/typescript/tests-ts/scan-resume.test.ts
+++ b/sdk/typescript/tests-ts/scan-resume.test.ts
@@ -702,9 +702,20 @@ test.each([
[false, true],
[true, true],
])(
- "resumed CLI seals the original scan (coordinator finished: %p, bulk: %p)",
+ "resumed CLI seals the original scan after its instructions are cleared (coordinator finished: %p, bulk: %p)",
async (alreadyFinished, bulk) => {
const f = await interruptedScan("deep", bulk);
+ await f.command(
+ [
+ "update-scan-context",
+ "--scan-id",
+ f.scanId,
+ "--thread-id",
+ f.threadId,
+ "--user-context-stdin",
+ ],
+ "",
+ );
if (alreadyFinished) await finishDiscovery(f);
await appendFile(
f.sessionPath,
@@ -730,7 +741,10 @@ test.each([
expect(threadId).toBe(f.threadId);
return {
id: threadId,
- async runStreamed() {
+ async runStreamed(prompt) {
+ expect(prompt).not.toContain(
+ "Keep the original scan instructions.",
+ );
if (!alreadyFinished) await finishDiscovery(f);
return { events: completedEvents(threadId) };
},