@openai/codex-security 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +200 -23
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/scan-contract.md +10 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +27 -78
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -8
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
- package/_bundled_plugin/scripts/rank_preview.py +12 -1
- package/_bundled_plugin/scripts/report_projection.py +8 -14
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +5 -15
- package/_bundled_plugin/scripts/workbench_cli.py +14 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +41 -18
- package/_bundled_plugin/scripts/workbench_db.py +127 -541
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +31 -13
- package/_bundled_plugin/scripts/workbench_findings.py +8 -3
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
- package/_bundled_plugin/scripts/workbench_publication.py +520 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +298 -90
- package/_bundled_plugin/scripts/workbench_scan_history.py +375 -68
- package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
- package/_bundled_plugin/scripts/workbench_schema.py +49 -21
- package/_bundled_plugin/scripts/workbench_target.py +96 -17
- package/_bundled_plugin/scripts/workbench_validation.py +1 -5
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
- package/dist/api.d.ts +18 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +350 -28
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +35 -3
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +118 -35
- package/dist/cli.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +4 -2
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +21 -6
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +46 -2
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts +1 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +23 -11
- package/dist/cost.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +2 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +3 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +122 -36
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -3
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -9
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +46 -24
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +186 -23
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/scan.d.ts +9 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-progress.d.ts +21 -0
- package/dist/deep-progress.d.ts.map +1 -0
- package/dist/deep-progress.js +108 -0
- package/dist/deep-progress.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mock-scan.d.ts +4 -0
- package/dist/mock-scan.d.ts.map +1 -0
- package/dist/mock-scan.js +210 -0
- package/dist/mock-scan.js.map +1 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +2 -2
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +54 -14
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +12 -2
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +11 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +237 -39
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +70 -3
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +21 -0
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/server/api.d.ts +6 -0
- package/dist/server/api.d.ts.map +1 -0
- package/dist/server/api.js +4 -0
- package/dist/server/api.js.map +1 -0
- package/dist/server/dashboard/app.css +1 -1
- package/dist/server/embeddings.d.ts +2 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +8 -3
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/index.js +2 -28
- package/dist/server/index.js.map +1 -1
- package/dist/server/serve.d.ts +2 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +28 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +3 -5
- package/dist/targets.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +10 -5
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { execFile as execFileCallback, execFileSync, spawn, } from "node:child_p
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { accessSync, constants, createReadStream, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
5
5
|
import { chmod, lstat, mkdir, mkdtemp, open, readFile, realpath, rm, writeFile, } from "node:fs/promises";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
6
|
+
import { homedir, tmpdir } from "node:os";
|
|
7
7
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep, win32, } from "node:path";
|
|
8
8
|
import { cwd } from "node:process";
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
@@ -13,7 +13,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
13
13
|
import { promisify, stripVTControlCharacters } from "node:util";
|
|
14
14
|
import { Cli, z } from "incur";
|
|
15
15
|
import { parse as parseToml } from "smol-toml";
|
|
16
|
-
import { classifyConnectionFailure, createSecurityInternal, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
|
|
16
|
+
import { classifyConnectionFailure, createSecurityInternal, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
|
|
17
17
|
import { accountStatus } from "./auth.js";
|
|
18
18
|
import { publishScanToCustom } from "./custom-publish.js";
|
|
19
19
|
import { deduplicateScanInternal } from "./deduplication/scan.js";
|
|
@@ -29,8 +29,8 @@ import { runMultiscan } from "./multiscan.js";
|
|
|
29
29
|
import { componentPlanSchema } from "./component-plan.js";
|
|
30
30
|
import { runComponentScans } from "./component-scan.js";
|
|
31
31
|
import { checkScanPublication, forceTerminatePublicationProcesses as terminatePublishers, publishScan, } from "./publish.js";
|
|
32
|
-
import { bundledPluginRoot, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, expandHome, prepareCodexSecurityCredentialHome, pythonUtf8Environment, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
33
|
-
import { matchScanFindingsInternal, } from "./scan-comparison.js";
|
|
32
|
+
import { bundledPluginRoot, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome, pythonUtf8Environment, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
33
|
+
import { comparisonFindingGroups, matchScanFindingsInternal, unionFindingGroups, } from "./scan-comparison.js";
|
|
34
34
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
35
35
|
import { CODEX_SECURITY_THREAD_SOURCES, } from "./thread-source.js";
|
|
36
36
|
import { readScanLogs } from "./scan-logs.js";
|
|
@@ -79,6 +79,7 @@ const EXPORT_DEFAULT_OUTPUTS = {
|
|
|
79
79
|
sarif: "results.sarif",
|
|
80
80
|
};
|
|
81
81
|
const VALUE_OPTIONS = new Set([
|
|
82
|
+
"--port",
|
|
82
83
|
"--workflow-id",
|
|
83
84
|
"--auth",
|
|
84
85
|
"--safety-identifier",
|
|
@@ -814,7 +815,9 @@ const DEFAULT_DEPENDENCIES = {
|
|
|
814
815
|
matchFindings: (input, options) => matchScanFindingsInternal(input, options, { surface: "cli" }),
|
|
815
816
|
};
|
|
816
817
|
export async function runCodexSkillCommand(args, output, command = resolveCodexCommand(), processEnvironment = process.env, input) {
|
|
817
|
-
const configuredHome =
|
|
818
|
+
const configuredHome = process.platform === "win32"
|
|
819
|
+
? environmentValue(processEnvironment, "CODEX_HOME")
|
|
820
|
+
: processEnvironment["CODEX_HOME"];
|
|
818
821
|
const environment = { ...processEnvironment };
|
|
819
822
|
for (const name of Object.keys(environment)) {
|
|
820
823
|
if (name.toUpperCase() === "CODEX_HOME")
|
|
@@ -823,7 +826,7 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
823
826
|
if (configuredHome?.trim()) {
|
|
824
827
|
environment["CODEX_HOME"] = resolve(expandHome(configuredHome, processEnvironment));
|
|
825
828
|
}
|
|
826
|
-
const invocation = spawn(command.command, [...args], {
|
|
829
|
+
const invocation = spawn(executablePathForSpawn(command.command), [...args], {
|
|
827
830
|
env: environment,
|
|
828
831
|
cwd: output?.appServer?.directory ?? parse(process.execPath).root,
|
|
829
832
|
stdio: output === undefined
|
|
@@ -2081,7 +2084,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2081
2084
|
.number()
|
|
2082
2085
|
.positive()
|
|
2083
2086
|
.optional()
|
|
2084
|
-
.describe("Stop
|
|
2087
|
+
.describe("Stop above AMOUNT in estimated USD; the dashboard offers increases near the limit."),
|
|
2085
2088
|
headless: z
|
|
2086
2089
|
.boolean()
|
|
2087
2090
|
.default(false)
|
|
@@ -2090,6 +2093,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2090
2093
|
.boolean()
|
|
2091
2094
|
.default(false)
|
|
2092
2095
|
.describe("Validate local scan inputs without starting a scan."),
|
|
2096
|
+
mock: z
|
|
2097
|
+
.boolean()
|
|
2098
|
+
.default(false)
|
|
2099
|
+
.describe("Save synthetic Standard scan findings without calling an LLM."),
|
|
2093
2100
|
})
|
|
2094
2101
|
.refine((options) => Number(options.path.length > 0) +
|
|
2095
2102
|
Number(options.diff !== undefined) +
|
|
@@ -2110,6 +2117,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2110
2117
|
})
|
|
2111
2118
|
.refine((options) => !options.patch || !options.dryRun, {
|
|
2112
2119
|
message: "--patch cannot be combined with --dry-run.",
|
|
2120
|
+
})
|
|
2121
|
+
.refine((options) => !options.mock || (!options.dryRun && !options.patch), {
|
|
2122
|
+
message: "--mock cannot be combined with --dry-run or --patch.",
|
|
2113
2123
|
})
|
|
2114
2124
|
.refine((options) => options.mode === "deep" ||
|
|
2115
2125
|
(options.workers === undefined &&
|
|
@@ -2178,6 +2188,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2178
2188
|
maxCostUsd: options.maxCost,
|
|
2179
2189
|
headless: options.headless,
|
|
2180
2190
|
dryRun: options.dryRun,
|
|
2191
|
+
mock: options.mock,
|
|
2181
2192
|
}, errorOutput, dependencies, format !== "json" && format !== "jsonl");
|
|
2182
2193
|
exitCode = outcome.exitCode;
|
|
2183
2194
|
if (outcome.error !== undefined) {
|
|
@@ -3125,6 +3136,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3125
3136
|
const credentialHome = dependencies.prepareAuthenticationHome !== undefined
|
|
3126
3137
|
? await dependencies.prepareAuthenticationHome(dependencies.environment)
|
|
3127
3138
|
: await prepareCodexSecurityCredentialHome(dependencies.environment);
|
|
3139
|
+
if (args.action === "status" && existsSync(credentialHome)) {
|
|
3140
|
+
const ambientHome = environmentValue(dependencies.environment, "CODEX_HOME") ??
|
|
3141
|
+
join(homedir(), ".codex");
|
|
3142
|
+
await initialCredentialsAvailable(dependencies.environment, ambientHome, credentialHome);
|
|
3143
|
+
}
|
|
3128
3144
|
const authenticationEnvironment = {
|
|
3129
3145
|
...dependencies.environment,
|
|
3130
3146
|
CODEX_HOME: credentialHome,
|
|
@@ -3147,7 +3163,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3147
3163
|
(exitCode === 0 || exitCode === 1)) {
|
|
3148
3164
|
exitCode = 0;
|
|
3149
3165
|
errorOutput.write(`Effective scan authentication: API key from ${authentication.source}.\n`);
|
|
3150
|
-
errorOutput.write(
|
|
3166
|
+
errorOutput.write(`To use a ChatGPT sign-in, ${formatEnvironmentVariableRemovalGuidance(["OPENAI_API_KEY", "CODEX_API_KEY"])}.\n`);
|
|
3151
3167
|
}
|
|
3152
3168
|
}
|
|
3153
3169
|
else if (exitCode === 0 && !options.withApiKey) {
|
|
@@ -3166,8 +3182,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3166
3182
|
? "your stored credentials"
|
|
3167
3183
|
: "your ChatGPT sign-in";
|
|
3168
3184
|
errorOutput.write(loginWarning +
|
|
3169
|
-
`To use ${storedCredentials}, pass '--auth chatgpt' or
|
|
3170
|
-
|
|
3185
|
+
`To use ${storedCredentials}, pass '--auth chatgpt' or ` +
|
|
3186
|
+
`${formatEnvironmentVariableRemovalGuidance(configuredApiKeyVariables)}.\n`);
|
|
3171
3187
|
}
|
|
3172
3188
|
}
|
|
3173
3189
|
},
|
|
@@ -3190,6 +3206,32 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3190
3206
|
await setCodexSecurityCredentialLogout(credentialHome, true);
|
|
3191
3207
|
}
|
|
3192
3208
|
},
|
|
3209
|
+
})
|
|
3210
|
+
.command("serve", {
|
|
3211
|
+
description: "Start the findings HTTP service (HOST=127.0.0.1, PORT=3000). CODEX_SECURITY_EMBEDDINGS_URL overrides the embeddings endpoint (default: https://api.openai.com/v1/embeddings).",
|
|
3212
|
+
destructive: true,
|
|
3213
|
+
mcp: false,
|
|
3214
|
+
options: z.object({
|
|
3215
|
+
port: z
|
|
3216
|
+
.number()
|
|
3217
|
+
.int()
|
|
3218
|
+
.min(0)
|
|
3219
|
+
.max(65535)
|
|
3220
|
+
.optional()
|
|
3221
|
+
.describe("Listen port (default: PORT or 3000; 0 picks a free port)."),
|
|
3222
|
+
}),
|
|
3223
|
+
async run({ options }) {
|
|
3224
|
+
try {
|
|
3225
|
+
const { serveFindings } = await import("./server/serve.js");
|
|
3226
|
+
await serveFindings(options.port === undefined
|
|
3227
|
+
? dependencies.environment
|
|
3228
|
+
: { ...dependencies.environment, PORT: String(options.port) }, output);
|
|
3229
|
+
}
|
|
3230
|
+
catch (error) {
|
|
3231
|
+
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
3232
|
+
exitCode = 1;
|
|
3233
|
+
}
|
|
3234
|
+
},
|
|
3193
3235
|
})
|
|
3194
3236
|
.command("info", {
|
|
3195
3237
|
description: "Show read-only SDK and bundled-plugin metadata.",
|
|
@@ -3381,6 +3423,7 @@ function scanArgumentsFromRecipe(recipe, parentScanId, validationPromptFile) {
|
|
|
3381
3423
|
maxCostUsd,
|
|
3382
3424
|
dryRun: false,
|
|
3383
3425
|
parentScanId,
|
|
3426
|
+
...(recipe["mock"] === true ? { mock: true } : {}),
|
|
3384
3427
|
expectedPluginVersion: typeof recipe["pluginVersion"] === "string"
|
|
3385
3428
|
? recipe["pluginVersion"]
|
|
3386
3429
|
: undefined,
|
|
@@ -3404,6 +3447,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
3404
3447
|
"patch",
|
|
3405
3448
|
"login",
|
|
3406
3449
|
"logout",
|
|
3450
|
+
"serve",
|
|
3407
3451
|
"info",
|
|
3408
3452
|
].includes(value));
|
|
3409
3453
|
if (commandIndex < 0)
|
|
@@ -3418,7 +3462,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
3418
3462
|
argv[index + 1] === "json" ||
|
|
3419
3463
|
argv[index + 1] === "jsonl")));
|
|
3420
3464
|
if (structuredOutput &&
|
|
3421
|
-
["validate", "login", "logout"].includes(command) &&
|
|
3465
|
+
["validate", "login", "logout", "serve"].includes(command) &&
|
|
3422
3466
|
!argv.includes("--schema")) {
|
|
3423
3467
|
return `${command} does not support noninteractive JSON output; run it without --json, --format json, or --format jsonl.`;
|
|
3424
3468
|
}
|
|
@@ -3501,7 +3545,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
3501
3545
|
command !== "verify-fix" &&
|
|
3502
3546
|
command !== "patch" &&
|
|
3503
3547
|
positionals.length >
|
|
3504
|
-
(command === "logout" || command === "info"
|
|
3548
|
+
(command === "logout" || command === "info" || command === "serve"
|
|
3505
3549
|
? 0
|
|
3506
3550
|
: subcommand === "compare" || subcommand === "match"
|
|
3507
3551
|
? 2
|
|
@@ -3519,11 +3563,23 @@ async function matchAllScans(dependencies, force) {
|
|
|
3519
3563
|
const { repository, scanCount, unavailableScans, skippedPairs, batches } = result;
|
|
3520
3564
|
let matchedPairs = 0;
|
|
3521
3565
|
let findingMatches = 0;
|
|
3522
|
-
|
|
3566
|
+
const newlyMatchedGroups = [];
|
|
3567
|
+
for (const { afterScanId, afterFindings, beforeScans, knownFindingGroups = [], } of batches) {
|
|
3523
3568
|
const before = beforeScans.flatMap(({ findings }) => findings);
|
|
3569
|
+
const knownGroups = unionFindingGroups([
|
|
3570
|
+
...knownFindingGroups,
|
|
3571
|
+
...newlyMatchedGroups,
|
|
3572
|
+
]);
|
|
3573
|
+
const input = {
|
|
3574
|
+
before,
|
|
3575
|
+
after: afterFindings,
|
|
3576
|
+
...(knownGroups.length === 0 ? {} : { knownFindingGroups: knownGroups }),
|
|
3577
|
+
};
|
|
3524
3578
|
const matching = before.length === 0 || afterFindings.length === 0
|
|
3525
3579
|
? { matches: [], uncertain: [] }
|
|
3526
|
-
: await dependencies.matchFindings(
|
|
3580
|
+
: await dependencies.matchFindings(input, {
|
|
3581
|
+
allowHistoricalUncertainty: true,
|
|
3582
|
+
});
|
|
3527
3583
|
const comparisons = beforeScans.map(({ scanId, findings }) => {
|
|
3528
3584
|
const beforeIds = new Set(findings.map(({ occurrenceId }) => occurrenceId));
|
|
3529
3585
|
const matches = matching.matches.flatMap((match) => {
|
|
@@ -3533,13 +3589,14 @@ async function matchAllScans(dependencies, force) {
|
|
|
3533
3589
|
: [{ ...match, beforeOccurrenceIds }];
|
|
3534
3590
|
});
|
|
3535
3591
|
const uncertain = matching.uncertain.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
|
|
3592
|
+
const related = matching.related?.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
|
|
3536
3593
|
const matchedAfter = new Set(matches.flatMap(({ afterOccurrenceIds }) => afterOccurrenceIds));
|
|
3537
3594
|
if (uncertain.some(({ afterOccurrenceId }) => matchedAfter.has(afterOccurrenceId))) {
|
|
3538
3595
|
throw new CodexSecurityError("Scan matching returned conflicting confirmed and uncertain findings.");
|
|
3539
3596
|
}
|
|
3540
|
-
return { scanId, matches, uncertain };
|
|
3597
|
+
return { scanId, matches, uncertain, related };
|
|
3541
3598
|
});
|
|
3542
|
-
for (const { scanId, matches, uncertain } of comparisons) {
|
|
3599
|
+
for (const { scanId, matches, uncertain, related } of comparisons) {
|
|
3543
3600
|
await dependencies.runWorkbench([
|
|
3544
3601
|
"save-scan-comparison",
|
|
3545
3602
|
"--before-scan-id",
|
|
@@ -3547,10 +3604,11 @@ async function matchAllScans(dependencies, force) {
|
|
|
3547
3604
|
"--after-scan-id",
|
|
3548
3605
|
afterScanId,
|
|
3549
3606
|
"--matches-json-stdin",
|
|
3550
|
-
], JSON.stringify({ matches, uncertain }));
|
|
3607
|
+
], JSON.stringify({ matches, uncertain, related }));
|
|
3551
3608
|
matchedPairs += 1;
|
|
3552
3609
|
findingMatches += matches.reduce((count, { beforeOccurrenceIds, afterOccurrenceIds }) => count + beforeOccurrenceIds.length * afterOccurrenceIds.length, 0);
|
|
3553
3610
|
}
|
|
3611
|
+
newlyMatchedGroups.push(...comparisonFindingGroups(input, matching));
|
|
3554
3612
|
}
|
|
3555
3613
|
return {
|
|
3556
3614
|
repository,
|
|
@@ -4567,6 +4625,7 @@ async function withTerminalErrorsHandled(errorOutput, operation) {
|
|
|
4567
4625
|
}
|
|
4568
4626
|
async function executeScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
4569
4627
|
let scanDir = null;
|
|
4628
|
+
const scanInput = dependencies.scanInput ?? process.stdin;
|
|
4570
4629
|
let requestedSignal = null;
|
|
4571
4630
|
let firstSignalAt = 0;
|
|
4572
4631
|
let progress = null;
|
|
@@ -4576,6 +4635,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4576
4635
|
let workerCapacity = null;
|
|
4577
4636
|
let fileProgress = null;
|
|
4578
4637
|
let runningCost = null;
|
|
4638
|
+
let maxCostUsd = arguments_.maxCostUsd;
|
|
4579
4639
|
let phase = null;
|
|
4580
4640
|
const targetWarnings = [];
|
|
4581
4641
|
const configuredLogLevel = dependencies.environment["CODEX_SECURITY_LOG_LEVEL"]?.trim() ||
|
|
@@ -4675,7 +4735,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4675
4735
|
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
4676
4736
|
scanModelConfiguration(effectiveConfiguration));
|
|
4677
4737
|
const provider = scanModelProvider(effectiveConfiguration);
|
|
4678
|
-
const auth = !arguments_.dryRun && interactive
|
|
4738
|
+
const auth = !arguments_.dryRun && !arguments_.mock && interactive
|
|
4679
4739
|
? await chooseInteractiveAuthentication({
|
|
4680
4740
|
auth: arguments_.auth,
|
|
4681
4741
|
provider,
|
|
@@ -4689,7 +4749,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4689
4749
|
providerConfiguration: effectiveConfiguration["model_providers"]?.[provider],
|
|
4690
4750
|
};
|
|
4691
4751
|
}
|
|
4692
|
-
selectedAuthentication =
|
|
4752
|
+
selectedAuthentication = arguments_.mock
|
|
4753
|
+
? null
|
|
4754
|
+
: scanAuthentication(dependencies.environment, auth, provider);
|
|
4693
4755
|
diagnostic("scan.configuration", {
|
|
4694
4756
|
cli_version: VERSION,
|
|
4695
4757
|
bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
|
|
@@ -4706,6 +4768,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4706
4768
|
: "repository",
|
|
4707
4769
|
requested_auth: auth ?? "auto",
|
|
4708
4770
|
dry_run: arguments_.dryRun,
|
|
4771
|
+
mock: arguments_.mock,
|
|
4709
4772
|
profile: typeof selectedProfileName === "string"
|
|
4710
4773
|
? selectedProfileName
|
|
4711
4774
|
: undefined,
|
|
@@ -4727,7 +4790,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4727
4790
|
clock: dependencies,
|
|
4728
4791
|
color: dependencies.environment["NO_COLOR"] === undefined,
|
|
4729
4792
|
sanitize: safeErrorMessage,
|
|
4730
|
-
input:
|
|
4793
|
+
input: scanInput,
|
|
4731
4794
|
onInterrupt,
|
|
4732
4795
|
});
|
|
4733
4796
|
}
|
|
@@ -4771,7 +4834,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4771
4834
|
}
|
|
4772
4835
|
}
|
|
4773
4836
|
security = dependencies.createSecurity(config);
|
|
4837
|
+
if (arguments_.mock) {
|
|
4838
|
+
errorOutput.write("codex-security: Mock scan: generating synthetic findings; no security analysis or LLM calls.\n");
|
|
4839
|
+
}
|
|
4774
4840
|
const options = {
|
|
4841
|
+
...(arguments_.mock ? { mock: true } : {}),
|
|
4775
4842
|
...(arguments_.workflowId === undefined
|
|
4776
4843
|
? {}
|
|
4777
4844
|
: { workflowId: arguments_.workflowId }),
|
|
@@ -4792,7 +4859,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4792
4859
|
expectedPluginVersion: arguments_.expectedPluginVersion,
|
|
4793
4860
|
failureSeverity: arguments_.failOnSeverity,
|
|
4794
4861
|
maxCostUsd: arguments_.maxCostUsd,
|
|
4795
|
-
onCost: (cost) => {
|
|
4862
|
+
onCost: (cost, limit = maxCostUsd) => {
|
|
4863
|
+
if (limit !== maxCostUsd && limit !== undefined) {
|
|
4864
|
+
dashboard?.note(`Total cost limit increased to ${formatUsd(limit)}.`);
|
|
4865
|
+
}
|
|
4866
|
+
maxCostUsd = limit;
|
|
4796
4867
|
diagnostic("cost.updated", {
|
|
4797
4868
|
model: cost.model,
|
|
4798
4869
|
estimated_usd: cost.estimatedUsd,
|
|
@@ -4800,15 +4871,15 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4800
4871
|
cached_input_tokens: cost.cachedInputTokens,
|
|
4801
4872
|
cache_write_input_tokens: cost.cacheWriteInputTokens,
|
|
4802
4873
|
output_tokens: cost.outputTokens,
|
|
4803
|
-
max_cost_usd:
|
|
4874
|
+
max_cost_usd: maxCostUsd,
|
|
4804
4875
|
});
|
|
4805
4876
|
runningCost = cost;
|
|
4806
4877
|
if (dashboard !== null) {
|
|
4807
|
-
dashboard.setCost(cost);
|
|
4878
|
+
dashboard.setCost(cost, maxCostUsd);
|
|
4808
4879
|
return;
|
|
4809
4880
|
}
|
|
4810
4881
|
progress?.stopTimer();
|
|
4811
|
-
if (
|
|
4882
|
+
if (maxCostUsd === undefined) {
|
|
4812
4883
|
const tokens = formatTokenUsage({
|
|
4813
4884
|
input_tokens: cost.inputTokens,
|
|
4814
4885
|
cached_input_tokens: cost.cachedInputTokens,
|
|
@@ -4817,13 +4888,15 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4817
4888
|
progress?.stage(`${tokens === null ? "" : `Tokens: ${tokens}. `}Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
|
|
4818
4889
|
}
|
|
4819
4890
|
else {
|
|
4820
|
-
progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(
|
|
4891
|
+
progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(maxCostUsd)} limit`);
|
|
4821
4892
|
}
|
|
4822
|
-
if (
|
|
4823
|
-
cost.estimatedUsd <= arguments_.maxCostUsd) {
|
|
4893
|
+
if (maxCostUsd === undefined || cost.estimatedUsd <= maxCostUsd) {
|
|
4824
4894
|
progress?.startTimer(runningMessage());
|
|
4825
4895
|
}
|
|
4826
4896
|
},
|
|
4897
|
+
onBudgetApproaching: scanInput.isTTY === true
|
|
4898
|
+
? dashboard?.requestBudgetIncrease.bind(dashboard)
|
|
4899
|
+
: undefined,
|
|
4827
4900
|
onOutputArchived: (archiveDir) => {
|
|
4828
4901
|
diagnostic("scan.output_archived", { archive_dir: archiveDir });
|
|
4829
4902
|
if (dashboard !== null) {
|
|
@@ -4843,9 +4916,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4843
4916
|
diagnostic("authentication.selected", {
|
|
4844
4917
|
requested: auth ?? "auto",
|
|
4845
4918
|
method: authentication.method,
|
|
4846
|
-
source: authentication.
|
|
4847
|
-
? authentication.source
|
|
4848
|
-
: undefined,
|
|
4919
|
+
source: "source" in authentication ? authentication.source : undefined,
|
|
4849
4920
|
verified: authentication.verified,
|
|
4850
4921
|
});
|
|
4851
4922
|
if (dashboard !== null) {
|
|
@@ -4853,7 +4924,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4853
4924
|
? `Using API key from ${authentication.source}`
|
|
4854
4925
|
: authentication.method === "aws_credentials"
|
|
4855
4926
|
? `Using AWS credentials from ${authentication.source}`
|
|
4856
|
-
:
|
|
4927
|
+
: authentication.method === "command"
|
|
4928
|
+
? "Using native Codex command authentication"
|
|
4929
|
+
: "Using stored Codex credentials");
|
|
4857
4930
|
return;
|
|
4858
4931
|
}
|
|
4859
4932
|
progress?.stopTimer();
|
|
@@ -4864,6 +4937,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4864
4937
|
else if (authentication.method === "aws_credentials") {
|
|
4865
4938
|
progress?.stage(`Authentication: AWS credentials from ${authentication.source}.`);
|
|
4866
4939
|
}
|
|
4940
|
+
else if (authentication.method === "command") {
|
|
4941
|
+
progress?.stage("Authentication: native Codex command.");
|
|
4942
|
+
}
|
|
4867
4943
|
else {
|
|
4868
4944
|
progress?.stage("Authentication: stored Codex credentials.");
|
|
4869
4945
|
}
|
|
@@ -4917,7 +4993,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4917
4993
|
dashboard.setStage("inspecting repository files");
|
|
4918
4994
|
}
|
|
4919
4995
|
},
|
|
4920
|
-
onSessionEvent:
|
|
4996
|
+
onSessionEvent: scanInput.isTTY === true
|
|
4921
4997
|
? dashboard?.recordDetails.bind(dashboard)
|
|
4922
4998
|
: undefined,
|
|
4923
4999
|
onProgress: (update) => {
|
|
@@ -5080,7 +5156,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
5080
5156
|
model: effectivePreflight.model,
|
|
5081
5157
|
reasoning_effort: effectivePreflight.reasoningEffort,
|
|
5082
5158
|
method: effectivePreflight.authentication.method,
|
|
5083
|
-
source: effectivePreflight.authentication
|
|
5159
|
+
source: "source" in effectivePreflight.authentication
|
|
5084
5160
|
? effectivePreflight.authentication.source
|
|
5085
5161
|
: undefined,
|
|
5086
5162
|
verified: effectivePreflight.authentication.verified,
|
|
@@ -5105,7 +5181,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
5105
5181
|
const incomplete = result.coverage.completeness !== "complete";
|
|
5106
5182
|
let deepScanStop;
|
|
5107
5183
|
if (arguments_.mode === "deep") {
|
|
5108
|
-
deepScanStop = (await readDeepScanStop(result,
|
|
5184
|
+
deepScanStop = (await readDeepScanStop(result, maxCostUsd, dependencies.runWorkbench).catch(() => undefined)) ?? {
|
|
5109
5185
|
reason: "Stop reason unavailable. See the report for details.",
|
|
5110
5186
|
};
|
|
5111
5187
|
}
|
|
@@ -5138,7 +5214,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
5138
5214
|
? arguments_.patchSeverity ?? "low"
|
|
5139
5215
|
: undefined;
|
|
5140
5216
|
let patchSelection = null;
|
|
5141
|
-
if (
|
|
5217
|
+
if (!arguments_.mock &&
|
|
5218
|
+
actionableFindings.length > 0 &&
|
|
5142
5219
|
arguments_.patchSeverity === undefined &&
|
|
5143
5220
|
progress?.interactive === true &&
|
|
5144
5221
|
(dependencies.patchEditor !== undefined || process.stdin.isTTY === true)) {
|
|
@@ -5272,6 +5349,9 @@ function scanFailureMessage(error, authentication) {
|
|
|
5272
5349
|
}
|
|
5273
5350
|
switch (classifyConnectionFailure(error)) {
|
|
5274
5351
|
case "unauthorized":
|
|
5352
|
+
if (authentication?.method === "command") {
|
|
5353
|
+
return "Native Codex command authentication failed. Check the configured provider auth command.";
|
|
5354
|
+
}
|
|
5275
5355
|
if (authentication?.method === "aws_credentials") {
|
|
5276
5356
|
return (`Authentication failed using AWS credentials from ${authentication.source}. ` +
|
|
5277
5357
|
"Check your Amazon Bedrock bearer token or AWS credential chain.");
|
|
@@ -5282,6 +5362,9 @@ function scanFailureMessage(error, authentication) {
|
|
|
5282
5362
|
: "Authentication failed using stored ChatGPT credentials. " +
|
|
5283
5363
|
"Sign in again with 'codex-security login' or provide a valid API key.";
|
|
5284
5364
|
case "forbidden":
|
|
5365
|
+
if (authentication?.method === "command") {
|
|
5366
|
+
return "The configured Codex provider denied access. Check the command credentials and provider permissions.";
|
|
5367
|
+
}
|
|
5285
5368
|
if (authentication?.method === "aws_credentials") {
|
|
5286
5369
|
return (`The AWS credentials from ${authentication.source} cannot access the configured Amazon Bedrock model. ` +
|
|
5287
5370
|
"Check your AWS identity and Bedrock model permissions.");
|