@openai/codex-security 0.1.5 → 0.1.6
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 +79 -8
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +8 -1
- package/_bundled_plugin/mcp/mcp-app.html.br +0 -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/preflight/capability-profiles.toml +0 -57
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/final-report.md +15 -7
- package/_bundled_plugin/references/scan-artifacts.md +11 -9
- package/_bundled_plugin/references/scan-contract.md +3 -1
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +42 -0
- package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +100 -0
- package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +181 -0
- package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +166 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +120 -0
- package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +83 -0
- package/_bundled_plugin/schemas/tools/review-items.schema.json +80 -0
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +572 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +18 -0
- package/_bundled_plugin/scripts/deep_scan_config.py +11 -3
- package/_bundled_plugin/scripts/deep_scan_workbench.py +153 -133
- package/_bundled_plugin/scripts/finalize_scan_contract.py +21 -0
- package/_bundled_plugin/scripts/generate_in_scope_files.py +134 -0
- package/_bundled_plugin/scripts/workbench_cli.py +33 -1
- package/_bundled_plugin/scripts/workbench_db.py +127 -117
- package/_bundled_plugin/scripts/workbench_feedback.py +2 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +5 -49
- package/_bundled_plugin/scripts/workbench_progress.py +86 -3
- package/_bundled_plugin/scripts/workbench_remediation.py +19 -1
- package/_bundled_plugin/scripts/workbench_scan_history.py +7 -1
- package/_bundled_plugin/scripts/workbench_scan_start.py +11 -5
- package/_bundled_plugin/scripts/workbench_scan_usage.py +557 -0
- package/_bundled_plugin/scripts/workbench_schema.py +501 -0
- package/_bundled_plugin/scripts/workbench_validation.py +117 -13
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -4
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +34 -28
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +1 -1
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +11 -8
- package/_bundled_plugin/skills/security-scan/SKILL.md +16 -9
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +26 -14
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +1 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/_bundled_plugin/skills/validation/SKILL.md +5 -5
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +145 -227
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +53 -68
- package/dist/api.d.ts +29 -7
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +323 -47
- package/dist/api.js.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +3 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +458 -40
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +39 -2
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts +7 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +345 -17
- package/dist/cost.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +3 -0
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +540 -25
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.d.ts +13 -0
- package/dist/scan-activity.d.ts.map +1 -0
- package/dist/scan-activity.js +319 -0
- package/dist/scan-activity.js.map +1 -0
- package/dist/scan-dashboard.d.ts +47 -0
- package/dist/scan-dashboard.d.ts.map +1 -0
- package/dist/scan-dashboard.js +444 -0
- package/dist/scan-dashboard.js.map +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +4 -1
- package/dist/scan-history-renderer.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/dist/worker-progress.d.ts +7 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +68 -0
- package/dist/worker-progress.js.map +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -12,13 +12,14 @@ import { parse as parseToml } from "smol-toml";
|
|
|
12
12
|
import { classifyConnectionFailure, CodexSecurity, scanAuthentication, } from "./api.js";
|
|
13
13
|
import { accountStatus } from "./auth.js";
|
|
14
14
|
import { createBulkScanDiscoveryDependencies, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
15
|
-
import { DEFAULT_CODEX_CONFIG, mergedCodexConfig, scanModelConfiguration, } from "./config.js";
|
|
15
|
+
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergedCodexConfig, scanModelConfiguration, } from "./config.js";
|
|
16
16
|
import { formatUsd } from "./cost.js";
|
|
17
|
-
import { CodexSecurityError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, redactedErrorMessage, ScanInterruptedError, } from "./errors.js";
|
|
17
|
+
import { CodexSecurityError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, redactedErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
18
18
|
import { runMultiscan } from "./multiscan.js";
|
|
19
19
|
import { bundledPluginRoot, codexSecurityCredentialHome, codexSecurityStateDirectory, expandHome, prepareCodexSecurityCredentialHome, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
20
20
|
import { matchScanFindings, } from "./scan-comparison.js";
|
|
21
21
|
import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
22
|
+
import { ScanDashboard } from "./scan-dashboard.js";
|
|
22
23
|
import { DiffTarget } from "./targets.js";
|
|
23
24
|
import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
|
|
24
25
|
const PROGRESS_REFRESH_MILLISECONDS = 1_000;
|
|
@@ -72,6 +73,7 @@ const VALUE_OPTIONS = new Set([
|
|
|
72
73
|
"--mode",
|
|
73
74
|
"--model",
|
|
74
75
|
"--effort",
|
|
76
|
+
"--provider",
|
|
75
77
|
"--output-dir",
|
|
76
78
|
"--plugin-path",
|
|
77
79
|
"--python",
|
|
@@ -79,6 +81,9 @@ const VALUE_OPTIONS = new Set([
|
|
|
79
81
|
"--fail-on-severity",
|
|
80
82
|
"--max-cost",
|
|
81
83
|
"--workers",
|
|
84
|
+
"--subagents",
|
|
85
|
+
"--stop-after-no-new",
|
|
86
|
+
"--max-discovery-runs",
|
|
82
87
|
"--max-attempts",
|
|
83
88
|
"--export-format",
|
|
84
89
|
"--output",
|
|
@@ -90,6 +95,10 @@ const VALUE_OPTIONS = new Set([
|
|
|
90
95
|
"--scan-root",
|
|
91
96
|
"--reason",
|
|
92
97
|
]);
|
|
98
|
+
const PROVIDER_OPTION = z
|
|
99
|
+
.enum(["openai", "openrouter", "fireworks"])
|
|
100
|
+
.default("openai")
|
|
101
|
+
.describe("Inference provider for scans.");
|
|
93
102
|
function optionValue(flag) {
|
|
94
103
|
return z.string().min(1, `${flag} must not be empty.`);
|
|
95
104
|
}
|
|
@@ -101,6 +110,32 @@ function effortOption() {
|
|
|
101
110
|
.optional()
|
|
102
111
|
.describe(`Model reasoning effort (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort}).`);
|
|
103
112
|
}
|
|
113
|
+
const DEEP_SCAN_OPTION_SCHEMAS = {
|
|
114
|
+
workers: z
|
|
115
|
+
.number()
|
|
116
|
+
.int()
|
|
117
|
+
.positive()
|
|
118
|
+
.optional()
|
|
119
|
+
.describe("Maximum concurrent deep-scan discovery workers."),
|
|
120
|
+
subagents: z
|
|
121
|
+
.number()
|
|
122
|
+
.int()
|
|
123
|
+
.nonnegative()
|
|
124
|
+
.optional()
|
|
125
|
+
.describe("Subagents available to each deep-scan worker."),
|
|
126
|
+
stopAfterNoNew: z
|
|
127
|
+
.number()
|
|
128
|
+
.int()
|
|
129
|
+
.positive()
|
|
130
|
+
.optional()
|
|
131
|
+
.describe("Stop after this many runs find no new issues."),
|
|
132
|
+
maxDiscoveryRuns: z
|
|
133
|
+
.number()
|
|
134
|
+
.int()
|
|
135
|
+
.positive()
|
|
136
|
+
.optional()
|
|
137
|
+
.describe("Maximum deep-scan discovery runs."),
|
|
138
|
+
};
|
|
104
139
|
const DEFAULT_DEPENDENCIES = {
|
|
105
140
|
createSecurity: (config) => new CodexSecurity(config),
|
|
106
141
|
environment: process.env,
|
|
@@ -562,8 +597,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
562
597
|
args: z.object({
|
|
563
598
|
scanId: z.string().min(1).describe("Saved scan identifier."),
|
|
564
599
|
}),
|
|
600
|
+
options: z.object({
|
|
601
|
+
verbose: z
|
|
602
|
+
.boolean()
|
|
603
|
+
.default(false)
|
|
604
|
+
.describe("Print scan diagnostics to stderr."),
|
|
605
|
+
}),
|
|
565
606
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
566
|
-
async run({ args, error: incurError }) {
|
|
607
|
+
async run({ args, error: incurError, options }) {
|
|
567
608
|
let scanArguments;
|
|
568
609
|
try {
|
|
569
610
|
const { recipe } = await dependencies.runWorkbench([
|
|
@@ -572,6 +613,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
572
613
|
args.scanId,
|
|
573
614
|
]);
|
|
574
615
|
scanArguments = scanArgumentsFromRecipe(recipe, args.scanId);
|
|
616
|
+
scanArguments.verbose = options.verbose;
|
|
575
617
|
}
|
|
576
618
|
catch (error) {
|
|
577
619
|
const message = redactedErrorMessage(error);
|
|
@@ -673,6 +715,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
673
715
|
.enum(["auto", "chatgpt", "api-key"])
|
|
674
716
|
.default("auto")
|
|
675
717
|
.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication."),
|
|
718
|
+
verbose: z
|
|
719
|
+
.boolean()
|
|
720
|
+
.default(false)
|
|
721
|
+
.describe("Print redacted scan diagnostics to stderr."),
|
|
676
722
|
path: z
|
|
677
723
|
.array(optionValue("--path"))
|
|
678
724
|
.default([])
|
|
@@ -698,10 +744,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
698
744
|
.enum(["standard", "deep"])
|
|
699
745
|
.default("standard")
|
|
700
746
|
.describe("Scan mode; deep supports repository and path targets."),
|
|
747
|
+
...DEEP_SCAN_OPTION_SCHEMAS,
|
|
701
748
|
model: optionValue("--model")
|
|
702
749
|
.optional()
|
|
703
750
|
.describe(`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
704
751
|
effort: effortOption(),
|
|
752
|
+
provider: PROVIDER_OPTION,
|
|
705
753
|
outputDir: optionValue("--output-dir")
|
|
706
754
|
.optional()
|
|
707
755
|
.describe("Artifact directory outside the repository (default: Codex Security state; CODEX_SECURITY_STATE_DIR)."),
|
|
@@ -728,6 +776,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
728
776
|
.positive()
|
|
729
777
|
.optional()
|
|
730
778
|
.describe("Stop the scan if estimated USD cost exceeds AMOUNT."),
|
|
779
|
+
headless: z
|
|
780
|
+
.boolean()
|
|
781
|
+
.default(false)
|
|
782
|
+
.describe("Use plain text progress instead of the interactive dashboard."),
|
|
731
783
|
dryRun: z
|
|
732
784
|
.boolean()
|
|
733
785
|
.default(false)
|
|
@@ -743,7 +795,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
743
795
|
.refine((options) => options.base === undefined || options.workingTree, {
|
|
744
796
|
message: "--base requires --working-tree.",
|
|
745
797
|
})
|
|
746
|
-
.refine((options) => !options.archiveExisting || options.outputDir !== undefined, { message: "--archive-existing requires --output-dir." })
|
|
798
|
+
.refine((options) => !options.archiveExisting || options.outputDir !== undefined, { message: "--archive-existing requires --output-dir." })
|
|
799
|
+
.refine((options) => options.mode === "deep" ||
|
|
800
|
+
(options.workers === undefined &&
|
|
801
|
+
options.subagents === undefined &&
|
|
802
|
+
options.stopAfterNoNew === undefined &&
|
|
803
|
+
options.maxDiscoveryRuns === undefined), { message: "Deep scan settings require --mode deep." }),
|
|
747
804
|
examples: [
|
|
748
805
|
{ args: { repository: "." } },
|
|
749
806
|
{ args: { repository: "." }, options: { model: "gpt-5.6-terra" } },
|
|
@@ -771,6 +828,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
771
828
|
}
|
|
772
829
|
const outcome = await runScan({
|
|
773
830
|
auth: options.auth,
|
|
831
|
+
verbose: options.verbose,
|
|
774
832
|
repository: args.repository,
|
|
775
833
|
paths: options.path,
|
|
776
834
|
knowledgeBasePaths: options.knowledgeBase,
|
|
@@ -779,8 +837,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
779
837
|
head: options.head,
|
|
780
838
|
base: options.base,
|
|
781
839
|
mode: options.mode,
|
|
840
|
+
workers: options.workers,
|
|
841
|
+
subagents: options.subagents,
|
|
842
|
+
stopAfterNoNew: options.stopAfterNoNew,
|
|
843
|
+
maxDiscoveryRuns: options.maxDiscoveryRuns,
|
|
782
844
|
model: options.model,
|
|
783
845
|
effort: options.effort,
|
|
846
|
+
provider: options.provider,
|
|
784
847
|
outputDir: options.outputDir,
|
|
785
848
|
archiveExisting: options.archiveExisting,
|
|
786
849
|
pluginPath: options.pluginPath,
|
|
@@ -788,6 +851,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
788
851
|
codex: options.codex,
|
|
789
852
|
failOnSeverity: options.failOnSeverity,
|
|
790
853
|
maxCostUsd: options.maxCost,
|
|
854
|
+
headless: options.headless,
|
|
791
855
|
dryRun: options.dryRun,
|
|
792
856
|
}, errorOutput, dependencies, format !== "json" && format !== "jsonl");
|
|
793
857
|
exitCode = outcome.exitCode;
|
|
@@ -890,6 +954,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
890
954
|
.min(1, "--output-dir must not be empty.")
|
|
891
955
|
.optional()
|
|
892
956
|
.describe("Resumable results directory; required with a repository CSV."),
|
|
957
|
+
knowledgeBase: z
|
|
958
|
+
.array(optionValue("--knowledge-base"))
|
|
959
|
+
.default([])
|
|
960
|
+
.describe("Read shared security docs for every repository."),
|
|
893
961
|
workers: z
|
|
894
962
|
.number()
|
|
895
963
|
.int()
|
|
@@ -904,6 +972,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
904
972
|
.optional()
|
|
905
973
|
.describe(`OpenAI model for each repository (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
906
974
|
effort: effortOption(),
|
|
975
|
+
provider: PROVIDER_OPTION,
|
|
907
976
|
maxAttempts: z
|
|
908
977
|
.number()
|
|
909
978
|
.int()
|
|
@@ -954,12 +1023,16 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
954
1023
|
const argument = argv[optionIndex];
|
|
955
1024
|
if (argument === "--model" ||
|
|
956
1025
|
argument === "--effort" ||
|
|
957
|
-
argument === "--
|
|
1026
|
+
argument === "--provider" ||
|
|
1027
|
+
argument === "--codex" ||
|
|
1028
|
+
argument === "--knowledge-base") {
|
|
958
1029
|
optionIndex += 2;
|
|
959
1030
|
}
|
|
960
1031
|
else if (argument.startsWith("--model=") ||
|
|
961
1032
|
argument.startsWith("--effort=") ||
|
|
962
|
-
argument.startsWith("--
|
|
1033
|
+
argument.startsWith("--provider=") ||
|
|
1034
|
+
argument.startsWith("--codex=") ||
|
|
1035
|
+
argument.startsWith("--knowledge-base=")) {
|
|
963
1036
|
optionIndex += 1;
|
|
964
1037
|
}
|
|
965
1038
|
else {
|
|
@@ -967,7 +1040,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
967
1040
|
}
|
|
968
1041
|
}
|
|
969
1042
|
if (argv[0] !== "bulk-scan" || optionIndex !== argv.length) {
|
|
970
|
-
throw new Error("Run 'codex-security bulk-scan [--model MODEL] [--effort EFFORT] [--codex KEY=VALUE]' to discover repositories, or provide a CSV and --output-dir.");
|
|
1043
|
+
throw new Error("Run 'codex-security bulk-scan [--provider PROVIDER] [--model MODEL] [--effort EFFORT] [--codex KEY=VALUE] [--knowledge-base PATH]' to discover repositories, or provide a CSV and --output-dir.");
|
|
971
1044
|
}
|
|
972
1045
|
const wizard = await runBulkScanWizard(dependencies.bulkScan ??
|
|
973
1046
|
createBulkScanDiscoveryDependencies({
|
|
@@ -995,10 +1068,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
995
1068
|
workers: options.workers,
|
|
996
1069
|
mode: options.mode,
|
|
997
1070
|
maxAttempts: options.maxAttempts,
|
|
1071
|
+
knowledgeBasePaths: options.knowledgeBase,
|
|
998
1072
|
config: {
|
|
999
1073
|
pluginPath: options.pluginPath,
|
|
1000
1074
|
pythonPath: options.python,
|
|
1001
|
-
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort),
|
|
1075
|
+
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider),
|
|
1002
1076
|
},
|
|
1003
1077
|
createSecurity: dependencies.createSecurity,
|
|
1004
1078
|
signal: controller.signal,
|
|
@@ -1361,6 +1435,18 @@ function scanArgumentsFromRecipe(recipe, parentScanId) {
|
|
|
1361
1435
|
maxCostUsd <= 0)) {
|
|
1362
1436
|
throw new CodexSecurityError("The saved scan recipe contains an invalid cost limit.");
|
|
1363
1437
|
}
|
|
1438
|
+
const deepScan = z
|
|
1439
|
+
.object(DEEP_SCAN_OPTION_SCHEMAS)
|
|
1440
|
+
.optional()
|
|
1441
|
+
.safeParse(recipe["deepScan"]);
|
|
1442
|
+
if (!deepScan.success) {
|
|
1443
|
+
throw new CodexSecurityError("The saved scan recipe contains invalid deep scan settings.");
|
|
1444
|
+
}
|
|
1445
|
+
if (mode !== "deep" &&
|
|
1446
|
+
deepScan.data !== undefined &&
|
|
1447
|
+
Object.keys(deepScan.data).length > 0) {
|
|
1448
|
+
throw new CodexSecurityError("The saved scan recipe contains deep scan settings for a standard scan.");
|
|
1449
|
+
}
|
|
1364
1450
|
return {
|
|
1365
1451
|
repository,
|
|
1366
1452
|
paths,
|
|
@@ -1370,6 +1456,7 @@ function scanArgumentsFromRecipe(recipe, parentScanId) {
|
|
|
1370
1456
|
head: kind === "refs" ? head ?? "HEAD" : undefined,
|
|
1371
1457
|
base: kind === "working_tree" ? reference : undefined,
|
|
1372
1458
|
mode,
|
|
1459
|
+
...deepScan.data,
|
|
1373
1460
|
archiveExisting: false,
|
|
1374
1461
|
codex: [],
|
|
1375
1462
|
codexOverrides: config,
|
|
@@ -1865,13 +1952,47 @@ async function runExport(arguments_, output, errorOutput, dependencies) {
|
|
|
1865
1952
|
return 2;
|
|
1866
1953
|
}
|
|
1867
1954
|
}
|
|
1955
|
+
function sanitizeDiagnosticValue(value) {
|
|
1956
|
+
return redactedErrorMessage(value)
|
|
1957
|
+
.replaceAll(/(\b(?:tenant(?:[_-]?id)?|org(?:anization)?(?:[_-]?id)?|project(?:[_-]?id)?|(?:x[_-]?)?(?:request|trace|correlation)[_-]?id)\b(?:\\*["'])?\s*[:=]\s*)(?!\[redacted\])(?:(\\*)(['"])(?:(?!(?<!\\)\2\3)(?:\\.|[^\\]))*(?:(?<!\\)\2\3|$)|[^\s"',;&}\]]+)/giu, "$1$2$3[redacted]$2$3")
|
|
1958
|
+
.replaceAll(/[\u0000-\u001F\u007F\u0085\u2028\u2029]/gu, " ");
|
|
1959
|
+
}
|
|
1868
1960
|
async function runScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
1869
1961
|
let scanDir = null;
|
|
1870
1962
|
let requestedSignal = null;
|
|
1871
1963
|
let firstSignalAt = 0;
|
|
1872
1964
|
let progress = null;
|
|
1965
|
+
let dashboard = null;
|
|
1873
1966
|
let lastWorkerUpdate = "";
|
|
1967
|
+
let lastProgressUpdate = "";
|
|
1968
|
+
let workerCapacity = null;
|
|
1969
|
+
let fileProgress = null;
|
|
1970
|
+
let runningCost = null;
|
|
1874
1971
|
let phase = null;
|
|
1972
|
+
const targetWarnings = [];
|
|
1973
|
+
const configuredLogLevel = dependencies.environment["CODEX_SECURITY_LOG_LEVEL"]?.trim() ||
|
|
1974
|
+
dependencies.environment["LOG_LEVEL"]?.trim();
|
|
1975
|
+
const verbose = arguments_.verbose === true ||
|
|
1976
|
+
configuredLogLevel?.toLowerCase() === "debug";
|
|
1977
|
+
const writeAboveProgress = (write) => {
|
|
1978
|
+
if (progress === null) {
|
|
1979
|
+
write();
|
|
1980
|
+
return;
|
|
1981
|
+
}
|
|
1982
|
+
progress.writeAboveTimer(write);
|
|
1983
|
+
};
|
|
1984
|
+
const diagnostic = (event, fields = {}) => {
|
|
1985
|
+
if (!verbose)
|
|
1986
|
+
return;
|
|
1987
|
+
const attributes = Object.entries(fields).flatMap(([name, value]) => value === undefined
|
|
1988
|
+
? []
|
|
1989
|
+
: [
|
|
1990
|
+
`${name}=${JSON.stringify(typeof value === "string" ? sanitizeDiagnosticValue(value) : value)}`,
|
|
1991
|
+
]);
|
|
1992
|
+
writeAboveProgress(() => {
|
|
1993
|
+
errorOutput.write(`codex-security: debug: ${event}${attributes.length === 0 ? "" : ` ${attributes.join(" ")}`}\n`);
|
|
1994
|
+
});
|
|
1995
|
+
};
|
|
1875
1996
|
const preparationAbortController = new AbortController();
|
|
1876
1997
|
const signalListener = (signal) => () => {
|
|
1877
1998
|
if (requestedSignal !== null) {
|
|
@@ -1882,6 +2003,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1882
2003
|
return;
|
|
1883
2004
|
}
|
|
1884
2005
|
requestedSignal = signal;
|
|
2006
|
+
dashboard?.stop();
|
|
1885
2007
|
progress?.stopTimer();
|
|
1886
2008
|
if (progress?.interactive === true) {
|
|
1887
2009
|
try {
|
|
@@ -1910,6 +2032,8 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1910
2032
|
let security = null;
|
|
1911
2033
|
let result = null;
|
|
1912
2034
|
let preflight = null;
|
|
2035
|
+
let effectiveModel = DEFAULT_SCAN_MODEL_CONFIGURATION.model;
|
|
2036
|
+
let effectiveReasoningEffort = DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort;
|
|
1913
2037
|
let selectedAuthentication = null;
|
|
1914
2038
|
let failed = false;
|
|
1915
2039
|
let failure;
|
|
@@ -1920,11 +2044,19 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1920
2044
|
pluginPath: arguments_.pluginPath,
|
|
1921
2045
|
pythonPath: arguments_.pythonPath,
|
|
1922
2046
|
codexOverrides: arguments_.codexOverrides ??
|
|
1923
|
-
parseCodexOverrides(arguments_.codex, arguments_.model, arguments_.effort),
|
|
2047
|
+
parseCodexOverrides(arguments_.codex, arguments_.model, arguments_.effort, arguments_.provider),
|
|
1924
2048
|
};
|
|
2049
|
+
const selectedProfileName = config.codexOverrides?.["profile"];
|
|
2050
|
+
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
2051
|
+
scanModelConfiguration({
|
|
2052
|
+
...DEFAULT_CODEX_CONFIG,
|
|
2053
|
+
...config.codexOverrides,
|
|
2054
|
+
}));
|
|
1925
2055
|
let auth = arguments_.auth;
|
|
1926
|
-
|
|
1927
|
-
|
|
2056
|
+
const provider = config.codexOverrides?.["model_provider"];
|
|
2057
|
+
selectedAuthentication = scanAuthentication(dependencies.environment, auth, provider);
|
|
2058
|
+
if (!isExternalModelProvider(provider) &&
|
|
2059
|
+
(auth === undefined || auth === "auto") &&
|
|
1928
2060
|
!arguments_.dryRun &&
|
|
1929
2061
|
interactive &&
|
|
1930
2062
|
errorOutput.isTTY === true &&
|
|
@@ -1943,23 +2075,91 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1943
2075
|
{ label: "ChatGPT subscription", value: "chatgpt" },
|
|
1944
2076
|
{ label: `API key from ${source}`, value: "api-key" },
|
|
1945
2077
|
]);
|
|
1946
|
-
selectedAuthentication = scanAuthentication(dependencies.environment, auth);
|
|
2078
|
+
selectedAuthentication = scanAuthentication(dependencies.environment, auth, provider);
|
|
1947
2079
|
}
|
|
1948
2080
|
}
|
|
1949
|
-
|
|
2081
|
+
diagnostic("scan.configuration", {
|
|
2082
|
+
cli_version: VERSION,
|
|
2083
|
+
bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
|
|
2084
|
+
codex_version: CODEX_EXECUTABLE_VERSION,
|
|
2085
|
+
codex_sdk_version: CODEX_SDK_VERSION,
|
|
2086
|
+
mode: arguments_.mode,
|
|
2087
|
+
max_cost_usd: arguments_.maxCostUsd,
|
|
2088
|
+
target: arguments_.paths.length > 0
|
|
2089
|
+
? "paths"
|
|
2090
|
+
: arguments_.diff !== undefined
|
|
2091
|
+
? "diff"
|
|
2092
|
+
: arguments_.workingTree
|
|
2093
|
+
? "working_tree"
|
|
2094
|
+
: "repository",
|
|
2095
|
+
requested_auth: auth ?? "auto",
|
|
2096
|
+
dry_run: arguments_.dryRun,
|
|
2097
|
+
profile: typeof selectedProfileName === "string"
|
|
2098
|
+
? selectedProfileName
|
|
2099
|
+
: undefined,
|
|
2100
|
+
model: effectiveModel,
|
|
2101
|
+
reasoning_effort: effectiveReasoningEffort,
|
|
2102
|
+
});
|
|
2103
|
+
progress = new Progress(errorOutput, dependencies, interactive &&
|
|
2104
|
+
!arguments_.headless &&
|
|
2105
|
+
dependencies.environment["CI"] === undefined &&
|
|
2106
|
+
dependencies.environment["TERM"] !== "dumb");
|
|
2107
|
+
if (progress.interactive && !arguments_.dryRun && !verbose) {
|
|
2108
|
+
dashboard = new ScanDashboard(errorOutput, {
|
|
2109
|
+
repository,
|
|
2110
|
+
model: scanModelConfiguration(await mergedCodexConfig(config)),
|
|
2111
|
+
...(arguments_.maxCostUsd === undefined
|
|
2112
|
+
? {}
|
|
2113
|
+
: { maxCostUsd: arguments_.maxCostUsd }),
|
|
2114
|
+
clock: dependencies,
|
|
2115
|
+
color: dependencies.environment["NO_COLOR"] === undefined,
|
|
2116
|
+
sanitize: redactedErrorMessage,
|
|
2117
|
+
input: process.stdin,
|
|
2118
|
+
onInterrupt,
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
1950
2121
|
const scope = scanScope(arguments_);
|
|
1951
|
-
const runningMessage = () =>
|
|
1952
|
-
|
|
1953
|
-
?
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
2122
|
+
const runningMessage = () => {
|
|
2123
|
+
const stage = phase === null
|
|
2124
|
+
? scope === null
|
|
2125
|
+
? "Running scan"
|
|
2126
|
+
: `Running scan: ${scope}`
|
|
2127
|
+
: `Running scan: ${phase}${scope === null ? "" : ` (${scope})`}`;
|
|
2128
|
+
const details = [];
|
|
2129
|
+
if (workerCapacity !== null) {
|
|
2130
|
+
details.push(`Workers: ${workerCapacity.started}/${workerCapacity.planned}`);
|
|
2131
|
+
}
|
|
2132
|
+
if (fileProgress !== null && fileProgress.filesTotal > 0) {
|
|
2133
|
+
details.push(`Files: ${fileProgress.filesCompleted.toLocaleString("en-US")}/${fileProgress.filesTotal.toLocaleString("en-US")}`);
|
|
2134
|
+
}
|
|
2135
|
+
if (runningCost !== null) {
|
|
2136
|
+
const tokens = formatTokenUsage({
|
|
2137
|
+
input_tokens: runningCost.inputTokens,
|
|
2138
|
+
cached_input_tokens: runningCost.cachedInputTokens,
|
|
2139
|
+
output_tokens: runningCost.outputTokens,
|
|
2140
|
+
});
|
|
2141
|
+
if (tokens !== null)
|
|
2142
|
+
details.push(`Tokens: ${tokens}`);
|
|
2143
|
+
details.push(`Cost: ${formatUsd(runningCost.estimatedUsd)}`);
|
|
2144
|
+
}
|
|
2145
|
+
return details.length === 0 ? stage : `${stage} | ${details.join(" | ")}`;
|
|
2146
|
+
};
|
|
2147
|
+
if (dashboard === null) {
|
|
2148
|
+
progress.startTimer(arguments_.dryRun ? "Validating scan inputs" : "Preparing scan");
|
|
2149
|
+
}
|
|
2150
|
+
else {
|
|
2151
|
+
dashboard.start();
|
|
2152
|
+
}
|
|
1957
2153
|
security = dependencies.createSecurity(config);
|
|
1958
2154
|
const options = {
|
|
1959
2155
|
auth,
|
|
1960
2156
|
target,
|
|
1961
2157
|
knowledgeBasePaths: arguments_.knowledgeBasePaths,
|
|
1962
2158
|
mode: arguments_.mode,
|
|
2159
|
+
workers: arguments_.workers,
|
|
2160
|
+
subagents: arguments_.subagents,
|
|
2161
|
+
stopAfterNoNew: arguments_.stopAfterNoNew,
|
|
2162
|
+
maxDiscoveryRuns: arguments_.maxDiscoveryRuns,
|
|
1963
2163
|
outputDir: arguments_.outputDir,
|
|
1964
2164
|
archiveExisting: arguments_.archiveExisting,
|
|
1965
2165
|
parentScanId: arguments_.parentScanId,
|
|
@@ -1967,24 +2167,67 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1967
2167
|
failureSeverity: arguments_.failOnSeverity,
|
|
1968
2168
|
maxCostUsd: arguments_.maxCostUsd,
|
|
1969
2169
|
onCost: (cost) => {
|
|
1970
|
-
|
|
2170
|
+
diagnostic("cost.updated", {
|
|
2171
|
+
model: cost.model,
|
|
2172
|
+
estimated_usd: cost.estimatedUsd,
|
|
2173
|
+
input_tokens: cost.inputTokens,
|
|
2174
|
+
cached_input_tokens: cost.cachedInputTokens,
|
|
2175
|
+
cache_write_input_tokens: cost.cacheWriteInputTokens,
|
|
2176
|
+
output_tokens: cost.outputTokens,
|
|
2177
|
+
max_cost_usd: arguments_.maxCostUsd,
|
|
2178
|
+
});
|
|
2179
|
+
runningCost = cost;
|
|
2180
|
+
if (dashboard !== null) {
|
|
2181
|
+
dashboard.setCost(cost);
|
|
1971
2182
|
return;
|
|
2183
|
+
}
|
|
1972
2184
|
progress?.stopTimer();
|
|
1973
|
-
|
|
1974
|
-
|
|
2185
|
+
if (arguments_.maxCostUsd === undefined) {
|
|
2186
|
+
const tokens = formatTokenUsage({
|
|
2187
|
+
input_tokens: cost.inputTokens,
|
|
2188
|
+
cached_input_tokens: cost.cachedInputTokens,
|
|
2189
|
+
output_tokens: cost.outputTokens,
|
|
2190
|
+
});
|
|
2191
|
+
progress?.stage(`${tokens === null ? "" : `Tokens: ${tokens}. `}Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
|
|
2192
|
+
}
|
|
2193
|
+
else {
|
|
2194
|
+
progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(arguments_.maxCostUsd)} limit`);
|
|
2195
|
+
}
|
|
2196
|
+
if (arguments_.maxCostUsd === undefined ||
|
|
2197
|
+
cost.estimatedUsd <= arguments_.maxCostUsd) {
|
|
1975
2198
|
progress?.startTimer(runningMessage());
|
|
1976
2199
|
}
|
|
1977
2200
|
},
|
|
1978
2201
|
onOutputArchived: (archiveDir) => {
|
|
2202
|
+
diagnostic("scan.output_archived", { archive_dir: archiveDir });
|
|
2203
|
+
if (dashboard !== null) {
|
|
2204
|
+
dashboard.note(`Moved existing results to: ${redactedErrorMessage(archiveDir)}`);
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
1979
2207
|
progress?.stopTimer();
|
|
1980
2208
|
errorOutput.write(`Moved existing results to: ${redactedErrorMessage(archiveDir)}\n`);
|
|
1981
2209
|
},
|
|
1982
2210
|
signal: preparationAbortController.signal,
|
|
1983
2211
|
onOutputDirReady: (path) => {
|
|
1984
2212
|
scanDir = path;
|
|
2213
|
+
diagnostic("scan.output_ready", { scan_dir: path });
|
|
1985
2214
|
},
|
|
1986
2215
|
onAuthentication: (authentication) => {
|
|
1987
2216
|
selectedAuthentication = authentication;
|
|
2217
|
+
diagnostic("authentication.selected", {
|
|
2218
|
+
requested: auth ?? "auto",
|
|
2219
|
+
method: authentication.method,
|
|
2220
|
+
source: authentication.method === "api_key"
|
|
2221
|
+
? authentication.source
|
|
2222
|
+
: undefined,
|
|
2223
|
+
verified: authentication.verified,
|
|
2224
|
+
});
|
|
2225
|
+
if (dashboard !== null) {
|
|
2226
|
+
dashboard.note(authentication.method === "api_key"
|
|
2227
|
+
? `Using API key from ${authentication.source}`
|
|
2228
|
+
: "Using stored Codex credentials");
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
1988
2231
|
progress?.stopTimer();
|
|
1989
2232
|
if (authentication.method === "api_key") {
|
|
1990
2233
|
progress?.stage(`Authentication: API key from ${authentication.source}.`);
|
|
@@ -1995,11 +2238,27 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1995
2238
|
}
|
|
1996
2239
|
progress?.startTimer("Preparing scan");
|
|
1997
2240
|
},
|
|
2241
|
+
onTrustedAccessStatus: (status) => {
|
|
2242
|
+
if (status === "granted") {
|
|
2243
|
+
errorOutput.write("codex-security: ✓ Your account has Trusted Access for Cyber.\n");
|
|
2244
|
+
}
|
|
2245
|
+
},
|
|
1998
2246
|
onScanStarted: () => {
|
|
2247
|
+
diagnostic("scan.started");
|
|
2248
|
+
if (dashboard !== null) {
|
|
2249
|
+
dashboard.setStage(phase ?? "Scanning repository");
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
1999
2252
|
progress?.stopTimer();
|
|
2000
2253
|
progress?.startTimer(runningMessage());
|
|
2001
2254
|
},
|
|
2002
2255
|
onReconnect: (attempt, maxAttempts, details) => {
|
|
2256
|
+
diagnostic("connection.retry", {
|
|
2257
|
+
reason: details?.reason ?? "unknown",
|
|
2258
|
+
attempt,
|
|
2259
|
+
max_attempts: maxAttempts,
|
|
2260
|
+
retry_after_seconds: details?.retryAfterSeconds,
|
|
2261
|
+
});
|
|
2003
2262
|
progress?.stopTimer();
|
|
2004
2263
|
const message = details?.reason === "rate_limit"
|
|
2005
2264
|
? `Rate limit reached; retrying${details.retryAfterSeconds === undefined
|
|
@@ -2012,9 +2271,42 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2012
2271
|
: details?.reason === "authorization"
|
|
2013
2272
|
? `Model access interrupted; retrying (${attempt}/${maxAttempts}).`
|
|
2014
2273
|
: `Codex connection interrupted; retrying (${attempt}/${maxAttempts})`;
|
|
2274
|
+
if (dashboard !== null) {
|
|
2275
|
+
dashboard.note(message);
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2015
2278
|
progress?.stage(message);
|
|
2016
2279
|
progress?.startTimer(runningMessage());
|
|
2017
2280
|
},
|
|
2281
|
+
onActivity: (activity) => {
|
|
2282
|
+
if (dashboard === null)
|
|
2283
|
+
return;
|
|
2284
|
+
dashboard.record(activity);
|
|
2285
|
+
if (activity.paths.length > 0 && phase === "preflight") {
|
|
2286
|
+
dashboard.setStage("inspecting repository files");
|
|
2287
|
+
}
|
|
2288
|
+
},
|
|
2289
|
+
onProgress: (update) => {
|
|
2290
|
+
const key = `${update.phase}:${update.filesCompleted}:${update.filesTotal}`;
|
|
2291
|
+
if (key === lastProgressUpdate)
|
|
2292
|
+
return;
|
|
2293
|
+
lastProgressUpdate = key;
|
|
2294
|
+
fileProgress = update;
|
|
2295
|
+
const previousPhase = phase;
|
|
2296
|
+
phase = scanPhase(update.phase);
|
|
2297
|
+
if (dashboard !== null) {
|
|
2298
|
+
dashboard.setFiles(update);
|
|
2299
|
+
dashboard.setStage(phase);
|
|
2300
|
+
if (previousPhase !== phase)
|
|
2301
|
+
dashboard.note(`Started ${phase}`);
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
if (progress === null)
|
|
2305
|
+
return;
|
|
2306
|
+
progress.stopTimer();
|
|
2307
|
+
progress.stage(`Scan phase: ${phase}${update.filesTotal === 0 ? "" : ` (${update.filesCompleted.toLocaleString("en-US")}/${update.filesTotal.toLocaleString("en-US")} files)`}.`);
|
|
2308
|
+
progress.startTimer(runningMessage());
|
|
2309
|
+
},
|
|
2018
2310
|
onWorkerStatus: (status) => {
|
|
2019
2311
|
const update = status.kind === "preflight"
|
|
2020
2312
|
? `preflight:${status.delegation}:${status.configuredSlots}`
|
|
@@ -2022,20 +2314,60 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2022
2314
|
if (update === lastWorkerUpdate)
|
|
2023
2315
|
return;
|
|
2024
2316
|
lastWorkerUpdate = update;
|
|
2025
|
-
if (status.kind === "
|
|
2317
|
+
if (status.kind === "preflight") {
|
|
2318
|
+
diagnostic("worker.preflight", {
|
|
2319
|
+
delegation: status.delegation,
|
|
2320
|
+
configured_slots: status.configuredSlots,
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
else {
|
|
2324
|
+
diagnostic("worker.phase", {
|
|
2325
|
+
phase: status.phase,
|
|
2326
|
+
planned: status.planned,
|
|
2327
|
+
started: status.started,
|
|
2328
|
+
});
|
|
2329
|
+
workerCapacity = { planned: status.planned, started: status.started };
|
|
2026
2330
|
phase = scanPhase(status.phase);
|
|
2331
|
+
}
|
|
2027
2332
|
const message = workerStatusMessage(status);
|
|
2333
|
+
if (dashboard !== null) {
|
|
2334
|
+
if (status.kind === "dispatch") {
|
|
2335
|
+
dashboard.setStage(scanPhase(status.phase));
|
|
2336
|
+
}
|
|
2337
|
+
if (message !== null)
|
|
2338
|
+
dashboard.note(message);
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2028
2341
|
if (message === null || progress === null)
|
|
2029
2342
|
return;
|
|
2030
2343
|
progress.stopTimer();
|
|
2031
2344
|
progress.stage(message);
|
|
2032
2345
|
progress.startTimer(runningMessage());
|
|
2033
2346
|
},
|
|
2034
|
-
onWarning: (warning) => {
|
|
2035
|
-
|
|
2347
|
+
onWarning: (warning, details) => {
|
|
2348
|
+
const message = sanitizeDiagnosticValue(warning);
|
|
2349
|
+
if (details?.kind === "target_changed") {
|
|
2350
|
+
targetWarnings.push(message);
|
|
2351
|
+
}
|
|
2352
|
+
writeAboveProgress(() => {
|
|
2353
|
+
diagnostic("scan.warning", { message });
|
|
2354
|
+
errorOutput.write(`codex-security: warning: ${message}\n`);
|
|
2355
|
+
});
|
|
2036
2356
|
},
|
|
2037
2357
|
onObserverError: (observer, error) => {
|
|
2038
|
-
|
|
2358
|
+
diagnostic("scan.observer_failed", {
|
|
2359
|
+
observer,
|
|
2360
|
+
classification: classifyConnectionFailure(error),
|
|
2361
|
+
});
|
|
2362
|
+
const warning = `${observer} observer failed: ${sanitizeDiagnosticValue(error)}`;
|
|
2363
|
+
if (dashboard === null) {
|
|
2364
|
+
writeAboveProgress(() => {
|
|
2365
|
+
errorOutput.write(`codex-security: warning: ${warning}\n`);
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
else {
|
|
2369
|
+
dashboard.note(`Warning: ${warning}`);
|
|
2370
|
+
}
|
|
2039
2371
|
},
|
|
2040
2372
|
};
|
|
2041
2373
|
if (arguments_.dryRun) {
|
|
@@ -2045,23 +2377,33 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2045
2377
|
result = await security.run(repository, options);
|
|
2046
2378
|
scanDir = result.scanDir;
|
|
2047
2379
|
}
|
|
2048
|
-
progress.stopTimer();
|
|
2049
2380
|
}
|
|
2050
2381
|
catch (error) {
|
|
2051
2382
|
failed = true;
|
|
2052
2383
|
failure = error;
|
|
2053
2384
|
}
|
|
2054
2385
|
finally {
|
|
2386
|
+
dashboard?.stop();
|
|
2055
2387
|
progress?.stopTimer();
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2388
|
+
if (security !== null) {
|
|
2389
|
+
diagnostic("runtime.cleanup.started");
|
|
2390
|
+
await security.close().then(() => diagnostic("runtime.cleanup.completed"), (error) => {
|
|
2391
|
+
diagnostic("runtime.cleanup.failed", {
|
|
2392
|
+
classification: classifyConnectionFailure(error),
|
|
2393
|
+
});
|
|
2394
|
+
if (!failed) {
|
|
2395
|
+
failed = true;
|
|
2396
|
+
failure = error;
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2062
2400
|
removeSignalListeners();
|
|
2063
2401
|
}
|
|
2064
2402
|
if (requestedSignal !== null) {
|
|
2403
|
+
diagnostic("scan.interrupted", {
|
|
2404
|
+
signal: requestedSignal,
|
|
2405
|
+
partial_output: scanDir !== null,
|
|
2406
|
+
});
|
|
2065
2407
|
return {
|
|
2066
2408
|
exitCode: interruptedExit(requestedSignal, scanDir, errorOutput),
|
|
2067
2409
|
error: requestedSignal === "SIGINT"
|
|
@@ -2070,9 +2412,20 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2070
2412
|
};
|
|
2071
2413
|
}
|
|
2072
2414
|
if (failed) {
|
|
2415
|
+
const costLimitFailure = failure instanceof ScanCostLimitExceededError ? failure : undefined;
|
|
2073
2416
|
const message = failure instanceof OutputInsideProtectedRootError
|
|
2074
2417
|
? redactedErrorMessage(protectedRootErrorMessage(failure))
|
|
2075
2418
|
: scanFailureMessage(failure, selectedAuthentication);
|
|
2419
|
+
diagnostic("scan.failed", {
|
|
2420
|
+
classification: costLimitFailure !== undefined
|
|
2421
|
+
? "cost_limit_exceeded"
|
|
2422
|
+
: isLocalScanFailure(failure)
|
|
2423
|
+
? "local"
|
|
2424
|
+
: classifyConnectionFailure(failure),
|
|
2425
|
+
partial_output: scanDir !== null,
|
|
2426
|
+
max_cost_usd: costLimitFailure?.maxCostUsd,
|
|
2427
|
+
estimated_usd: costLimitFailure?.cost.estimatedUsd,
|
|
2428
|
+
});
|
|
2076
2429
|
errorOutput.write(`${message}\n`);
|
|
2077
2430
|
if (failure instanceof ScanInterruptedError) {
|
|
2078
2431
|
return { exitCode: 2, error: message };
|
|
@@ -2083,10 +2436,28 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2083
2436
|
return { exitCode: 2, error: message };
|
|
2084
2437
|
}
|
|
2085
2438
|
if (preflight !== null) {
|
|
2439
|
+
const effectivePreflight = {
|
|
2440
|
+
...preflight,
|
|
2441
|
+
model: effectiveModel,
|
|
2442
|
+
reasoningEffort: effectiveReasoningEffort,
|
|
2443
|
+
};
|
|
2086
2444
|
progress?.stage("Preflight complete");
|
|
2087
|
-
|
|
2445
|
+
diagnostic("scan.preflight.completed", {
|
|
2446
|
+
model: effectivePreflight.model,
|
|
2447
|
+
reasoning_effort: effectivePreflight.reasoningEffort,
|
|
2448
|
+
method: effectivePreflight.authentication.method,
|
|
2449
|
+
source: effectivePreflight.authentication.method === "api_key"
|
|
2450
|
+
? effectivePreflight.authentication.source
|
|
2451
|
+
: undefined,
|
|
2452
|
+
verified: effectivePreflight.authentication.verified,
|
|
2453
|
+
});
|
|
2454
|
+
return { exitCode: 0, data: { dryRun: true, ...effectivePreflight } };
|
|
2088
2455
|
}
|
|
2089
2456
|
if (result === null) {
|
|
2457
|
+
diagnostic("scan.failed", {
|
|
2458
|
+
classification: "unknown",
|
|
2459
|
+
message: "Scan completed without a result.",
|
|
2460
|
+
});
|
|
2090
2461
|
errorOutput.write("scan completed without a result\n");
|
|
2091
2462
|
return { exitCode: 2, error: "Scan completed without a result." };
|
|
2092
2463
|
}
|
|
@@ -2095,18 +2466,32 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2095
2466
|
? []
|
|
2096
2467
|
: REPORTABLE_SEVERITIES.slice(0, REPORTABLE_SEVERITIES.indexOf(threshold) + 1));
|
|
2097
2468
|
const blockingCount = result.findings.findings.filter(({ severity }) => blockingSeverities.has(severity.level)).length;
|
|
2469
|
+
const scanData = targetWarnings.length === 0
|
|
2470
|
+
? result.toJSON()
|
|
2471
|
+
: { ...result.toJSON(), warnings: targetWarnings };
|
|
2098
2472
|
const incomplete = result.coverage.completeness !== "complete";
|
|
2099
|
-
progress?.stage(
|
|
2473
|
+
progress?.stage(`Scan complete · ${result.manifest.scan.id.slice(0, 8)}`);
|
|
2100
2474
|
printScanSummary(result, progress, errorOutput, progress?.interactive === true &&
|
|
2101
2475
|
dependencies.environment["NO_COLOR"] === undefined &&
|
|
2102
2476
|
dependencies.environment["TERM"] !== "dumb");
|
|
2477
|
+
diagnostic("scan.completed", {
|
|
2478
|
+
coverage: result.coverage.completeness,
|
|
2479
|
+
findings: result.findings.findings.length,
|
|
2480
|
+
scan_id: result.manifest.scan.id,
|
|
2481
|
+
estimated_usd: result.cost?.estimatedUsd,
|
|
2482
|
+
exit_code: targetWarnings.length > 0 || incomplete ? 2 : blockingCount > 0 ? 1 : 0,
|
|
2483
|
+
});
|
|
2484
|
+
if (targetWarnings.length > 0) {
|
|
2485
|
+
errorOutput.write("codex-security: Scan target changed during execution; results do not represent the current checkout.\n");
|
|
2486
|
+
return { exitCode: 2, data: scanData };
|
|
2487
|
+
}
|
|
2103
2488
|
if (incomplete) {
|
|
2104
2489
|
errorOutput.write(threshold === undefined
|
|
2105
2490
|
? `codex-security: Scan coverage is ${result.coverage.completeness}; results may be incomplete.\n`
|
|
2106
2491
|
: `codex-security: Cannot evaluate the failure policy: coverage is ${result.coverage.completeness}.\n`);
|
|
2107
|
-
return { exitCode: 2, data:
|
|
2492
|
+
return { exitCode: 2, data: scanData };
|
|
2108
2493
|
}
|
|
2109
|
-
return { exitCode: blockingCount > 0 ? 1 : 0, data:
|
|
2494
|
+
return { exitCode: blockingCount > 0 ? 1 : 0, data: scanData };
|
|
2110
2495
|
}
|
|
2111
2496
|
// Filesystem and OS syscall failures cannot originate from the model transport,
|
|
2112
2497
|
// so they must never be rewritten as connectivity or credential advice. Network
|
|
@@ -2154,7 +2539,7 @@ function scanFailureMessage(error, authentication) {
|
|
|
2154
2539
|
// errors can name the organization or project, which must not reach stderr or
|
|
2155
2540
|
// the JSON error field.
|
|
2156
2541
|
if (isLocalScanFailure(error))
|
|
2157
|
-
return
|
|
2542
|
+
return sanitizeDiagnosticValue(error);
|
|
2158
2543
|
switch (classifyConnectionFailure(error)) {
|
|
2159
2544
|
case "unauthorized":
|
|
2160
2545
|
return authentication?.method === "api_key"
|
|
@@ -2174,7 +2559,7 @@ function scanFailureMessage(error, authentication) {
|
|
|
2174
2559
|
case "network_error":
|
|
2175
2560
|
case "timeout":
|
|
2176
2561
|
case "unknown":
|
|
2177
|
-
return
|
|
2562
|
+
return sanitizeDiagnosticValue(error);
|
|
2178
2563
|
}
|
|
2179
2564
|
}
|
|
2180
2565
|
function scanScope(arguments_) {
|
|
@@ -2198,10 +2583,14 @@ function scanScope(arguments_) {
|
|
|
2198
2583
|
}
|
|
2199
2584
|
function scanPhase(value) {
|
|
2200
2585
|
return {
|
|
2586
|
+
preflight: "preflight",
|
|
2587
|
+
threat_model: "building threat model",
|
|
2588
|
+
discovery: "reviewing files",
|
|
2201
2589
|
ranking: "ranking scan targets",
|
|
2202
2590
|
file_review: "reviewing files",
|
|
2203
2591
|
validation: "validating findings",
|
|
2204
2592
|
attack_path: "analyzing attack paths",
|
|
2593
|
+
reporting: "writing report",
|
|
2205
2594
|
}[value];
|
|
2206
2595
|
}
|
|
2207
2596
|
function printScanSummary(result, progress, errorOutput, color) {
|
|
@@ -2341,12 +2730,18 @@ function targetFromArguments(arguments_) {
|
|
|
2341
2730
|
}
|
|
2342
2731
|
return "repository";
|
|
2343
2732
|
}
|
|
2344
|
-
export function parseCodexOverrides(values, model, effort) {
|
|
2733
|
+
export function parseCodexOverrides(values, model, effort, provider) {
|
|
2345
2734
|
const result = Object.create(null);
|
|
2346
2735
|
if (model !== undefined)
|
|
2347
2736
|
result["model"] = model;
|
|
2348
2737
|
if (effort !== undefined)
|
|
2349
2738
|
result["model_reasoning_effort"] = effort;
|
|
2739
|
+
if (isExternalModelProvider(provider)) {
|
|
2740
|
+
result["model_provider"] = provider;
|
|
2741
|
+
result["model_providers"] = {
|
|
2742
|
+
[provider]: { ...EXTERNAL_CODEX_PROVIDERS[provider] },
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2350
2745
|
for (const value of values) {
|
|
2351
2746
|
const separator = value.indexOf("=");
|
|
2352
2747
|
const key = separator < 0 ? "" : value.slice(0, separator);
|
|
@@ -2396,10 +2791,16 @@ export function parseCodexOverrides(values, model, effort) {
|
|
|
2396
2791
|
if (effort !== undefined && key === "model_reasoning_effort") {
|
|
2397
2792
|
throw new CodexSecurityError("--effort conflicts with --codex model_reasoning_effort");
|
|
2398
2793
|
}
|
|
2794
|
+
if (isExternalModelProvider(provider) && key === "model_provider") {
|
|
2795
|
+
throw new CodexSecurityError("--provider conflicts with --codex model_provider");
|
|
2796
|
+
}
|
|
2399
2797
|
throw new CodexSecurityError("Duplicate --codex key");
|
|
2400
2798
|
}
|
|
2401
2799
|
cursor[final] = parsed;
|
|
2402
2800
|
}
|
|
2801
|
+
if (isExternalModelProvider(provider) && !("model" in result)) {
|
|
2802
|
+
throw new CodexSecurityError(`--model is required when using --provider ${provider}`);
|
|
2803
|
+
}
|
|
2403
2804
|
return result;
|
|
2404
2805
|
}
|
|
2405
2806
|
function workerStatusMessage(status) {
|
|
@@ -2429,6 +2830,7 @@ export class Progress {
|
|
|
2429
2830
|
#startedAt;
|
|
2430
2831
|
#interactive;
|
|
2431
2832
|
#timer = null;
|
|
2833
|
+
#timerMessage = null;
|
|
2432
2834
|
#timerLineActive = false;
|
|
2433
2835
|
#cursorHidden = false;
|
|
2434
2836
|
constructor(stream = process.stderr, dependencies = DEFAULT_DEPENDENCIES, interactive = true) {
|
|
@@ -2455,12 +2857,14 @@ export class Progress {
|
|
|
2455
2857
|
this.#cursorHidden = true;
|
|
2456
2858
|
this.#renderTimer(message);
|
|
2457
2859
|
this.#timer = this.#dependencies.setInterval(() => this.#renderTimer(message), PROGRESS_REFRESH_MILLISECONDS);
|
|
2860
|
+
this.#timerMessage = message;
|
|
2458
2861
|
}
|
|
2459
2862
|
stopTimer() {
|
|
2460
2863
|
if (this.#timer !== null) {
|
|
2461
2864
|
this.#dependencies.clearInterval(this.#timer);
|
|
2462
2865
|
this.#timer = null;
|
|
2463
2866
|
}
|
|
2867
|
+
this.#timerMessage = null;
|
|
2464
2868
|
if (this.#timerLineActive) {
|
|
2465
2869
|
this.#stream.write("\n");
|
|
2466
2870
|
this.#timerLineActive = false;
|
|
@@ -2470,6 +2874,20 @@ export class Progress {
|
|
|
2470
2874
|
this.#cursorHidden = false;
|
|
2471
2875
|
}
|
|
2472
2876
|
}
|
|
2877
|
+
writeAboveTimer(write) {
|
|
2878
|
+
const message = this.#timerMessage;
|
|
2879
|
+
if (message === null) {
|
|
2880
|
+
write();
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
this.stopTimer();
|
|
2884
|
+
try {
|
|
2885
|
+
write();
|
|
2886
|
+
}
|
|
2887
|
+
finally {
|
|
2888
|
+
this.startTimer(message);
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2473
2891
|
#line(message) {
|
|
2474
2892
|
const elapsedSeconds = this.elapsedSeconds;
|
|
2475
2893
|
const minutes = Math.floor(elapsedSeconds / 60);
|