@openai/codex-security 0.1.5 → 0.1.7
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 +89 -8
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +24 -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 +33 -7
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +361 -48
- 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 +477 -40
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +47 -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 +349 -18
- 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, scanModelProvider, } 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", "amazon-bedrock"])
|
|
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,20 @@ 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
|
+
const effectiveConfiguration = {
|
|
2051
|
+
...DEFAULT_CODEX_CONFIG,
|
|
2052
|
+
...config.codexOverrides,
|
|
2053
|
+
};
|
|
2054
|
+
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
2055
|
+
scanModelConfiguration(effectiveConfiguration));
|
|
1925
2056
|
let auth = arguments_.auth;
|
|
1926
|
-
|
|
1927
|
-
|
|
2057
|
+
const provider = scanModelProvider(effectiveConfiguration);
|
|
2058
|
+
selectedAuthentication = scanAuthentication(dependencies.environment, auth, provider);
|
|
2059
|
+
if (!isExternalModelProvider(provider) &&
|
|
2060
|
+
(auth === undefined || auth === "auto") &&
|
|
1928
2061
|
!arguments_.dryRun &&
|
|
1929
2062
|
interactive &&
|
|
1930
2063
|
errorOutput.isTTY === true &&
|
|
@@ -1943,23 +2076,91 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1943
2076
|
{ label: "ChatGPT subscription", value: "chatgpt" },
|
|
1944
2077
|
{ label: `API key from ${source}`, value: "api-key" },
|
|
1945
2078
|
]);
|
|
1946
|
-
selectedAuthentication = scanAuthentication(dependencies.environment, auth);
|
|
2079
|
+
selectedAuthentication = scanAuthentication(dependencies.environment, auth, provider);
|
|
1947
2080
|
}
|
|
1948
2081
|
}
|
|
1949
|
-
|
|
2082
|
+
diagnostic("scan.configuration", {
|
|
2083
|
+
cli_version: VERSION,
|
|
2084
|
+
bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
|
|
2085
|
+
codex_version: CODEX_EXECUTABLE_VERSION,
|
|
2086
|
+
codex_sdk_version: CODEX_SDK_VERSION,
|
|
2087
|
+
mode: arguments_.mode,
|
|
2088
|
+
max_cost_usd: arguments_.maxCostUsd,
|
|
2089
|
+
target: arguments_.paths.length > 0
|
|
2090
|
+
? "paths"
|
|
2091
|
+
: arguments_.diff !== undefined
|
|
2092
|
+
? "diff"
|
|
2093
|
+
: arguments_.workingTree
|
|
2094
|
+
? "working_tree"
|
|
2095
|
+
: "repository",
|
|
2096
|
+
requested_auth: auth ?? "auto",
|
|
2097
|
+
dry_run: arguments_.dryRun,
|
|
2098
|
+
profile: typeof selectedProfileName === "string"
|
|
2099
|
+
? selectedProfileName
|
|
2100
|
+
: undefined,
|
|
2101
|
+
model: effectiveModel,
|
|
2102
|
+
reasoning_effort: effectiveReasoningEffort,
|
|
2103
|
+
});
|
|
2104
|
+
progress = new Progress(errorOutput, dependencies, interactive &&
|
|
2105
|
+
!arguments_.headless &&
|
|
2106
|
+
dependencies.environment["CI"] === undefined &&
|
|
2107
|
+
dependencies.environment["TERM"] !== "dumb");
|
|
2108
|
+
if (progress.interactive && !arguments_.dryRun && !verbose) {
|
|
2109
|
+
dashboard = new ScanDashboard(errorOutput, {
|
|
2110
|
+
repository,
|
|
2111
|
+
model: scanModelConfiguration(await mergedCodexConfig(config)),
|
|
2112
|
+
...(arguments_.maxCostUsd === undefined
|
|
2113
|
+
? {}
|
|
2114
|
+
: { maxCostUsd: arguments_.maxCostUsd }),
|
|
2115
|
+
clock: dependencies,
|
|
2116
|
+
color: dependencies.environment["NO_COLOR"] === undefined,
|
|
2117
|
+
sanitize: redactedErrorMessage,
|
|
2118
|
+
input: process.stdin,
|
|
2119
|
+
onInterrupt,
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
1950
2122
|
const scope = scanScope(arguments_);
|
|
1951
|
-
const runningMessage = () =>
|
|
1952
|
-
|
|
1953
|
-
?
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
2123
|
+
const runningMessage = () => {
|
|
2124
|
+
const stage = phase === null
|
|
2125
|
+
? scope === null
|
|
2126
|
+
? "Running scan"
|
|
2127
|
+
: `Running scan: ${scope}`
|
|
2128
|
+
: `Running scan: ${phase}${scope === null ? "" : ` (${scope})`}`;
|
|
2129
|
+
const details = [];
|
|
2130
|
+
if (workerCapacity !== null) {
|
|
2131
|
+
details.push(`Workers: ${workerCapacity.started}/${workerCapacity.planned}`);
|
|
2132
|
+
}
|
|
2133
|
+
if (fileProgress !== null && fileProgress.filesTotal > 0) {
|
|
2134
|
+
details.push(`Files: ${fileProgress.filesCompleted.toLocaleString("en-US")}/${fileProgress.filesTotal.toLocaleString("en-US")}`);
|
|
2135
|
+
}
|
|
2136
|
+
if (runningCost !== null) {
|
|
2137
|
+
const tokens = formatTokenUsage({
|
|
2138
|
+
input_tokens: runningCost.inputTokens,
|
|
2139
|
+
cached_input_tokens: runningCost.cachedInputTokens,
|
|
2140
|
+
output_tokens: runningCost.outputTokens,
|
|
2141
|
+
});
|
|
2142
|
+
if (tokens !== null)
|
|
2143
|
+
details.push(`Tokens: ${tokens}`);
|
|
2144
|
+
details.push(`Cost: ${formatUsd(runningCost.estimatedUsd)}`);
|
|
2145
|
+
}
|
|
2146
|
+
return details.length === 0 ? stage : `${stage} | ${details.join(" | ")}`;
|
|
2147
|
+
};
|
|
2148
|
+
if (dashboard === null) {
|
|
2149
|
+
progress.startTimer(arguments_.dryRun ? "Validating scan inputs" : "Preparing scan");
|
|
2150
|
+
}
|
|
2151
|
+
else {
|
|
2152
|
+
dashboard.start();
|
|
2153
|
+
}
|
|
1957
2154
|
security = dependencies.createSecurity(config);
|
|
1958
2155
|
const options = {
|
|
1959
2156
|
auth,
|
|
1960
2157
|
target,
|
|
1961
2158
|
knowledgeBasePaths: arguments_.knowledgeBasePaths,
|
|
1962
2159
|
mode: arguments_.mode,
|
|
2160
|
+
workers: arguments_.workers,
|
|
2161
|
+
subagents: arguments_.subagents,
|
|
2162
|
+
stopAfterNoNew: arguments_.stopAfterNoNew,
|
|
2163
|
+
maxDiscoveryRuns: arguments_.maxDiscoveryRuns,
|
|
1963
2164
|
outputDir: arguments_.outputDir,
|
|
1964
2165
|
archiveExisting: arguments_.archiveExisting,
|
|
1965
2166
|
parentScanId: arguments_.parentScanId,
|
|
@@ -1967,39 +2168,103 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1967
2168
|
failureSeverity: arguments_.failOnSeverity,
|
|
1968
2169
|
maxCostUsd: arguments_.maxCostUsd,
|
|
1969
2170
|
onCost: (cost) => {
|
|
1970
|
-
|
|
2171
|
+
diagnostic("cost.updated", {
|
|
2172
|
+
model: cost.model,
|
|
2173
|
+
estimated_usd: cost.estimatedUsd,
|
|
2174
|
+
input_tokens: cost.inputTokens,
|
|
2175
|
+
cached_input_tokens: cost.cachedInputTokens,
|
|
2176
|
+
cache_write_input_tokens: cost.cacheWriteInputTokens,
|
|
2177
|
+
output_tokens: cost.outputTokens,
|
|
2178
|
+
max_cost_usd: arguments_.maxCostUsd,
|
|
2179
|
+
});
|
|
2180
|
+
runningCost = cost;
|
|
2181
|
+
if (dashboard !== null) {
|
|
2182
|
+
dashboard.setCost(cost);
|
|
1971
2183
|
return;
|
|
2184
|
+
}
|
|
1972
2185
|
progress?.stopTimer();
|
|
1973
|
-
|
|
1974
|
-
|
|
2186
|
+
if (arguments_.maxCostUsd === undefined) {
|
|
2187
|
+
const tokens = formatTokenUsage({
|
|
2188
|
+
input_tokens: cost.inputTokens,
|
|
2189
|
+
cached_input_tokens: cost.cachedInputTokens,
|
|
2190
|
+
output_tokens: cost.outputTokens,
|
|
2191
|
+
});
|
|
2192
|
+
progress?.stage(`${tokens === null ? "" : `Tokens: ${tokens}. `}Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
|
|
2193
|
+
}
|
|
2194
|
+
else {
|
|
2195
|
+
progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(arguments_.maxCostUsd)} limit`);
|
|
2196
|
+
}
|
|
2197
|
+
if (arguments_.maxCostUsd === undefined ||
|
|
2198
|
+
cost.estimatedUsd <= arguments_.maxCostUsd) {
|
|
1975
2199
|
progress?.startTimer(runningMessage());
|
|
1976
2200
|
}
|
|
1977
2201
|
},
|
|
1978
2202
|
onOutputArchived: (archiveDir) => {
|
|
2203
|
+
diagnostic("scan.output_archived", { archive_dir: archiveDir });
|
|
2204
|
+
if (dashboard !== null) {
|
|
2205
|
+
dashboard.note(`Moved existing results to: ${redactedErrorMessage(archiveDir)}`);
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
1979
2208
|
progress?.stopTimer();
|
|
1980
2209
|
errorOutput.write(`Moved existing results to: ${redactedErrorMessage(archiveDir)}\n`);
|
|
1981
2210
|
},
|
|
1982
2211
|
signal: preparationAbortController.signal,
|
|
1983
2212
|
onOutputDirReady: (path) => {
|
|
1984
2213
|
scanDir = path;
|
|
2214
|
+
diagnostic("scan.output_ready", { scan_dir: path });
|
|
1985
2215
|
},
|
|
1986
2216
|
onAuthentication: (authentication) => {
|
|
1987
2217
|
selectedAuthentication = authentication;
|
|
2218
|
+
diagnostic("authentication.selected", {
|
|
2219
|
+
requested: auth ?? "auto",
|
|
2220
|
+
method: authentication.method,
|
|
2221
|
+
source: authentication.method !== "stored_credentials"
|
|
2222
|
+
? authentication.source
|
|
2223
|
+
: undefined,
|
|
2224
|
+
verified: authentication.verified,
|
|
2225
|
+
});
|
|
2226
|
+
if (dashboard !== null) {
|
|
2227
|
+
dashboard.note(authentication.method === "api_key"
|
|
2228
|
+
? `Using API key from ${authentication.source}`
|
|
2229
|
+
: authentication.method === "aws_credentials"
|
|
2230
|
+
? `Using AWS credentials from ${authentication.source}`
|
|
2231
|
+
: "Using stored Codex credentials");
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
1988
2234
|
progress?.stopTimer();
|
|
1989
2235
|
if (authentication.method === "api_key") {
|
|
1990
2236
|
progress?.stage(`Authentication: API key from ${authentication.source}.`);
|
|
1991
2237
|
progress?.stage("To use your ChatGPT sign-in, retry with --auth chatgpt.");
|
|
1992
2238
|
}
|
|
2239
|
+
else if (authentication.method === "aws_credentials") {
|
|
2240
|
+
progress?.stage(`Authentication: AWS credentials from ${authentication.source}.`);
|
|
2241
|
+
}
|
|
1993
2242
|
else {
|
|
1994
2243
|
progress?.stage("Authentication: stored Codex credentials.");
|
|
1995
2244
|
}
|
|
1996
2245
|
progress?.startTimer("Preparing scan");
|
|
1997
2246
|
},
|
|
2247
|
+
onTrustedAccessStatus: (status) => {
|
|
2248
|
+
if (status === "granted") {
|
|
2249
|
+
errorOutput.write("codex-security: ✓ Your account has Trusted Access for Cyber.\n");
|
|
2250
|
+
}
|
|
2251
|
+
},
|
|
1998
2252
|
onScanStarted: () => {
|
|
2253
|
+
diagnostic("scan.started");
|
|
2254
|
+
if (dashboard !== null) {
|
|
2255
|
+
dashboard.setStage(phase ?? "Scanning repository");
|
|
2256
|
+
return;
|
|
2257
|
+
}
|
|
1999
2258
|
progress?.stopTimer();
|
|
2000
2259
|
progress?.startTimer(runningMessage());
|
|
2001
2260
|
},
|
|
2002
2261
|
onReconnect: (attempt, maxAttempts, details) => {
|
|
2262
|
+
diagnostic("connection.retry", {
|
|
2263
|
+
reason: details?.reason ?? "unknown",
|
|
2264
|
+
attempt,
|
|
2265
|
+
max_attempts: maxAttempts,
|
|
2266
|
+
retry_after_seconds: details?.retryAfterSeconds,
|
|
2267
|
+
});
|
|
2003
2268
|
progress?.stopTimer();
|
|
2004
2269
|
const message = details?.reason === "rate_limit"
|
|
2005
2270
|
? `Rate limit reached; retrying${details.retryAfterSeconds === undefined
|
|
@@ -2012,9 +2277,42 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2012
2277
|
: details?.reason === "authorization"
|
|
2013
2278
|
? `Model access interrupted; retrying (${attempt}/${maxAttempts}).`
|
|
2014
2279
|
: `Codex connection interrupted; retrying (${attempt}/${maxAttempts})`;
|
|
2280
|
+
if (dashboard !== null) {
|
|
2281
|
+
dashboard.note(message);
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2015
2284
|
progress?.stage(message);
|
|
2016
2285
|
progress?.startTimer(runningMessage());
|
|
2017
2286
|
},
|
|
2287
|
+
onActivity: (activity) => {
|
|
2288
|
+
if (dashboard === null)
|
|
2289
|
+
return;
|
|
2290
|
+
dashboard.record(activity);
|
|
2291
|
+
if (activity.paths.length > 0 && phase === "preflight") {
|
|
2292
|
+
dashboard.setStage("inspecting repository files");
|
|
2293
|
+
}
|
|
2294
|
+
},
|
|
2295
|
+
onProgress: (update) => {
|
|
2296
|
+
const key = `${update.phase}:${update.filesCompleted}:${update.filesTotal}`;
|
|
2297
|
+
if (key === lastProgressUpdate)
|
|
2298
|
+
return;
|
|
2299
|
+
lastProgressUpdate = key;
|
|
2300
|
+
fileProgress = update;
|
|
2301
|
+
const previousPhase = phase;
|
|
2302
|
+
phase = scanPhase(update.phase);
|
|
2303
|
+
if (dashboard !== null) {
|
|
2304
|
+
dashboard.setFiles(update);
|
|
2305
|
+
dashboard.setStage(phase);
|
|
2306
|
+
if (previousPhase !== phase)
|
|
2307
|
+
dashboard.note(`Started ${phase}`);
|
|
2308
|
+
return;
|
|
2309
|
+
}
|
|
2310
|
+
if (progress === null)
|
|
2311
|
+
return;
|
|
2312
|
+
progress.stopTimer();
|
|
2313
|
+
progress.stage(`Scan phase: ${phase}${update.filesTotal === 0 ? "" : ` (${update.filesCompleted.toLocaleString("en-US")}/${update.filesTotal.toLocaleString("en-US")} files)`}.`);
|
|
2314
|
+
progress.startTimer(runningMessage());
|
|
2315
|
+
},
|
|
2018
2316
|
onWorkerStatus: (status) => {
|
|
2019
2317
|
const update = status.kind === "preflight"
|
|
2020
2318
|
? `preflight:${status.delegation}:${status.configuredSlots}`
|
|
@@ -2022,20 +2320,60 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2022
2320
|
if (update === lastWorkerUpdate)
|
|
2023
2321
|
return;
|
|
2024
2322
|
lastWorkerUpdate = update;
|
|
2025
|
-
if (status.kind === "
|
|
2323
|
+
if (status.kind === "preflight") {
|
|
2324
|
+
diagnostic("worker.preflight", {
|
|
2325
|
+
delegation: status.delegation,
|
|
2326
|
+
configured_slots: status.configuredSlots,
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
else {
|
|
2330
|
+
diagnostic("worker.phase", {
|
|
2331
|
+
phase: status.phase,
|
|
2332
|
+
planned: status.planned,
|
|
2333
|
+
started: status.started,
|
|
2334
|
+
});
|
|
2335
|
+
workerCapacity = { planned: status.planned, started: status.started };
|
|
2026
2336
|
phase = scanPhase(status.phase);
|
|
2337
|
+
}
|
|
2027
2338
|
const message = workerStatusMessage(status);
|
|
2339
|
+
if (dashboard !== null) {
|
|
2340
|
+
if (status.kind === "dispatch") {
|
|
2341
|
+
dashboard.setStage(scanPhase(status.phase));
|
|
2342
|
+
}
|
|
2343
|
+
if (message !== null)
|
|
2344
|
+
dashboard.note(message);
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2028
2347
|
if (message === null || progress === null)
|
|
2029
2348
|
return;
|
|
2030
2349
|
progress.stopTimer();
|
|
2031
2350
|
progress.stage(message);
|
|
2032
2351
|
progress.startTimer(runningMessage());
|
|
2033
2352
|
},
|
|
2034
|
-
onWarning: (warning) => {
|
|
2035
|
-
|
|
2353
|
+
onWarning: (warning, details) => {
|
|
2354
|
+
const message = sanitizeDiagnosticValue(warning);
|
|
2355
|
+
if (details?.kind === "target_changed") {
|
|
2356
|
+
targetWarnings.push(message);
|
|
2357
|
+
}
|
|
2358
|
+
writeAboveProgress(() => {
|
|
2359
|
+
diagnostic("scan.warning", { message });
|
|
2360
|
+
errorOutput.write(`codex-security: warning: ${message}\n`);
|
|
2361
|
+
});
|
|
2036
2362
|
},
|
|
2037
2363
|
onObserverError: (observer, error) => {
|
|
2038
|
-
|
|
2364
|
+
diagnostic("scan.observer_failed", {
|
|
2365
|
+
observer,
|
|
2366
|
+
classification: classifyConnectionFailure(error),
|
|
2367
|
+
});
|
|
2368
|
+
const warning = `${observer} observer failed: ${sanitizeDiagnosticValue(error)}`;
|
|
2369
|
+
if (dashboard === null) {
|
|
2370
|
+
writeAboveProgress(() => {
|
|
2371
|
+
errorOutput.write(`codex-security: warning: ${warning}\n`);
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
else {
|
|
2375
|
+
dashboard.note(`Warning: ${warning}`);
|
|
2376
|
+
}
|
|
2039
2377
|
},
|
|
2040
2378
|
};
|
|
2041
2379
|
if (arguments_.dryRun) {
|
|
@@ -2045,23 +2383,33 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2045
2383
|
result = await security.run(repository, options);
|
|
2046
2384
|
scanDir = result.scanDir;
|
|
2047
2385
|
}
|
|
2048
|
-
progress.stopTimer();
|
|
2049
2386
|
}
|
|
2050
2387
|
catch (error) {
|
|
2051
2388
|
failed = true;
|
|
2052
2389
|
failure = error;
|
|
2053
2390
|
}
|
|
2054
2391
|
finally {
|
|
2392
|
+
dashboard?.stop();
|
|
2055
2393
|
progress?.stopTimer();
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2394
|
+
if (security !== null) {
|
|
2395
|
+
diagnostic("runtime.cleanup.started");
|
|
2396
|
+
await security.close().then(() => diagnostic("runtime.cleanup.completed"), (error) => {
|
|
2397
|
+
diagnostic("runtime.cleanup.failed", {
|
|
2398
|
+
classification: classifyConnectionFailure(error),
|
|
2399
|
+
});
|
|
2400
|
+
if (!failed) {
|
|
2401
|
+
failed = true;
|
|
2402
|
+
failure = error;
|
|
2403
|
+
}
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2062
2406
|
removeSignalListeners();
|
|
2063
2407
|
}
|
|
2064
2408
|
if (requestedSignal !== null) {
|
|
2409
|
+
diagnostic("scan.interrupted", {
|
|
2410
|
+
signal: requestedSignal,
|
|
2411
|
+
partial_output: scanDir !== null,
|
|
2412
|
+
});
|
|
2065
2413
|
return {
|
|
2066
2414
|
exitCode: interruptedExit(requestedSignal, scanDir, errorOutput),
|
|
2067
2415
|
error: requestedSignal === "SIGINT"
|
|
@@ -2070,9 +2418,20 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2070
2418
|
};
|
|
2071
2419
|
}
|
|
2072
2420
|
if (failed) {
|
|
2421
|
+
const costLimitFailure = failure instanceof ScanCostLimitExceededError ? failure : undefined;
|
|
2073
2422
|
const message = failure instanceof OutputInsideProtectedRootError
|
|
2074
2423
|
? redactedErrorMessage(protectedRootErrorMessage(failure))
|
|
2075
2424
|
: scanFailureMessage(failure, selectedAuthentication);
|
|
2425
|
+
diagnostic("scan.failed", {
|
|
2426
|
+
classification: costLimitFailure !== undefined
|
|
2427
|
+
? "cost_limit_exceeded"
|
|
2428
|
+
: isLocalScanFailure(failure)
|
|
2429
|
+
? "local"
|
|
2430
|
+
: classifyConnectionFailure(failure),
|
|
2431
|
+
partial_output: scanDir !== null,
|
|
2432
|
+
max_cost_usd: costLimitFailure?.maxCostUsd,
|
|
2433
|
+
estimated_usd: costLimitFailure?.cost.estimatedUsd,
|
|
2434
|
+
});
|
|
2076
2435
|
errorOutput.write(`${message}\n`);
|
|
2077
2436
|
if (failure instanceof ScanInterruptedError) {
|
|
2078
2437
|
return { exitCode: 2, error: message };
|
|
@@ -2083,10 +2442,28 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2083
2442
|
return { exitCode: 2, error: message };
|
|
2084
2443
|
}
|
|
2085
2444
|
if (preflight !== null) {
|
|
2445
|
+
const effectivePreflight = {
|
|
2446
|
+
...preflight,
|
|
2447
|
+
model: effectiveModel,
|
|
2448
|
+
reasoningEffort: effectiveReasoningEffort,
|
|
2449
|
+
};
|
|
2086
2450
|
progress?.stage("Preflight complete");
|
|
2087
|
-
|
|
2451
|
+
diagnostic("scan.preflight.completed", {
|
|
2452
|
+
model: effectivePreflight.model,
|
|
2453
|
+
reasoning_effort: effectivePreflight.reasoningEffort,
|
|
2454
|
+
method: effectivePreflight.authentication.method,
|
|
2455
|
+
source: effectivePreflight.authentication.method !== "stored_credentials"
|
|
2456
|
+
? effectivePreflight.authentication.source
|
|
2457
|
+
: undefined,
|
|
2458
|
+
verified: effectivePreflight.authentication.verified,
|
|
2459
|
+
});
|
|
2460
|
+
return { exitCode: 0, data: { dryRun: true, ...effectivePreflight } };
|
|
2088
2461
|
}
|
|
2089
2462
|
if (result === null) {
|
|
2463
|
+
diagnostic("scan.failed", {
|
|
2464
|
+
classification: "unknown",
|
|
2465
|
+
message: "Scan completed without a result.",
|
|
2466
|
+
});
|
|
2090
2467
|
errorOutput.write("scan completed without a result\n");
|
|
2091
2468
|
return { exitCode: 2, error: "Scan completed without a result." };
|
|
2092
2469
|
}
|
|
@@ -2095,18 +2472,32 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2095
2472
|
? []
|
|
2096
2473
|
: REPORTABLE_SEVERITIES.slice(0, REPORTABLE_SEVERITIES.indexOf(threshold) + 1));
|
|
2097
2474
|
const blockingCount = result.findings.findings.filter(({ severity }) => blockingSeverities.has(severity.level)).length;
|
|
2475
|
+
const scanData = targetWarnings.length === 0
|
|
2476
|
+
? result.toJSON()
|
|
2477
|
+
: { ...result.toJSON(), warnings: targetWarnings };
|
|
2098
2478
|
const incomplete = result.coverage.completeness !== "complete";
|
|
2099
|
-
progress?.stage(
|
|
2479
|
+
progress?.stage(`Scan complete · ${result.manifest.scan.id.slice(0, 8)}`);
|
|
2100
2480
|
printScanSummary(result, progress, errorOutput, progress?.interactive === true &&
|
|
2101
2481
|
dependencies.environment["NO_COLOR"] === undefined &&
|
|
2102
2482
|
dependencies.environment["TERM"] !== "dumb");
|
|
2483
|
+
diagnostic("scan.completed", {
|
|
2484
|
+
coverage: result.coverage.completeness,
|
|
2485
|
+
findings: result.findings.findings.length,
|
|
2486
|
+
scan_id: result.manifest.scan.id,
|
|
2487
|
+
estimated_usd: result.cost?.estimatedUsd,
|
|
2488
|
+
exit_code: targetWarnings.length > 0 || incomplete ? 2 : blockingCount > 0 ? 1 : 0,
|
|
2489
|
+
});
|
|
2490
|
+
if (targetWarnings.length > 0) {
|
|
2491
|
+
errorOutput.write("codex-security: Scan target changed during execution; results do not represent the current checkout.\n");
|
|
2492
|
+
return { exitCode: 2, data: scanData };
|
|
2493
|
+
}
|
|
2103
2494
|
if (incomplete) {
|
|
2104
2495
|
errorOutput.write(threshold === undefined
|
|
2105
2496
|
? `codex-security: Scan coverage is ${result.coverage.completeness}; results may be incomplete.\n`
|
|
2106
2497
|
: `codex-security: Cannot evaluate the failure policy: coverage is ${result.coverage.completeness}.\n`);
|
|
2107
|
-
return { exitCode: 2, data:
|
|
2498
|
+
return { exitCode: 2, data: scanData };
|
|
2108
2499
|
}
|
|
2109
|
-
return { exitCode: blockingCount > 0 ? 1 : 0, data:
|
|
2500
|
+
return { exitCode: blockingCount > 0 ? 1 : 0, data: scanData };
|
|
2110
2501
|
}
|
|
2111
2502
|
// Filesystem and OS syscall failures cannot originate from the model transport,
|
|
2112
2503
|
// so they must never be rewritten as connectivity or credential advice. Network
|
|
@@ -2154,9 +2545,13 @@ function scanFailureMessage(error, authentication) {
|
|
|
2154
2545
|
// errors can name the organization or project, which must not reach stderr or
|
|
2155
2546
|
// the JSON error field.
|
|
2156
2547
|
if (isLocalScanFailure(error))
|
|
2157
|
-
return
|
|
2548
|
+
return sanitizeDiagnosticValue(error);
|
|
2158
2549
|
switch (classifyConnectionFailure(error)) {
|
|
2159
2550
|
case "unauthorized":
|
|
2551
|
+
if (authentication?.method === "aws_credentials") {
|
|
2552
|
+
return (`Authentication failed using AWS credentials from ${authentication.source}. ` +
|
|
2553
|
+
"Check your Amazon Bedrock bearer token or AWS credential chain.");
|
|
2554
|
+
}
|
|
2160
2555
|
return authentication?.method === "api_key"
|
|
2161
2556
|
? `Authentication failed using ${authentication.source}. ` +
|
|
2162
2557
|
"Your ChatGPT sign-in was not used. " +
|
|
@@ -2164,6 +2559,10 @@ function scanFailureMessage(error, authentication) {
|
|
|
2164
2559
|
: "Authentication failed using stored ChatGPT credentials. " +
|
|
2165
2560
|
"Sign in again with 'codex-security login' or provide a valid API key.";
|
|
2166
2561
|
case "forbidden":
|
|
2562
|
+
if (authentication?.method === "aws_credentials") {
|
|
2563
|
+
return (`The AWS credentials from ${authentication.source} cannot access the configured Amazon Bedrock model. ` +
|
|
2564
|
+
"Check your AWS identity and Bedrock model permissions.");
|
|
2565
|
+
}
|
|
2167
2566
|
return authentication?.method === "api_key"
|
|
2168
2567
|
? `The API key from ${authentication.source} cannot access the configured model. ` +
|
|
2169
2568
|
"Retry with '--auth chatgpt' or use an API key with model access."
|
|
@@ -2174,7 +2573,7 @@ function scanFailureMessage(error, authentication) {
|
|
|
2174
2573
|
case "network_error":
|
|
2175
2574
|
case "timeout":
|
|
2176
2575
|
case "unknown":
|
|
2177
|
-
return
|
|
2576
|
+
return sanitizeDiagnosticValue(error);
|
|
2178
2577
|
}
|
|
2179
2578
|
}
|
|
2180
2579
|
function scanScope(arguments_) {
|
|
@@ -2198,10 +2597,14 @@ function scanScope(arguments_) {
|
|
|
2198
2597
|
}
|
|
2199
2598
|
function scanPhase(value) {
|
|
2200
2599
|
return {
|
|
2600
|
+
preflight: "preflight",
|
|
2601
|
+
threat_model: "building threat model",
|
|
2602
|
+
discovery: "reviewing files",
|
|
2201
2603
|
ranking: "ranking scan targets",
|
|
2202
2604
|
file_review: "reviewing files",
|
|
2203
2605
|
validation: "validating findings",
|
|
2204
2606
|
attack_path: "analyzing attack paths",
|
|
2607
|
+
reporting: "writing report",
|
|
2205
2608
|
}[value];
|
|
2206
2609
|
}
|
|
2207
2610
|
function printScanSummary(result, progress, errorOutput, color) {
|
|
@@ -2341,12 +2744,21 @@ function targetFromArguments(arguments_) {
|
|
|
2341
2744
|
}
|
|
2342
2745
|
return "repository";
|
|
2343
2746
|
}
|
|
2344
|
-
export function parseCodexOverrides(values, model, effort) {
|
|
2747
|
+
export function parseCodexOverrides(values, model, effort, provider) {
|
|
2345
2748
|
const result = Object.create(null);
|
|
2346
2749
|
if (model !== undefined)
|
|
2347
2750
|
result["model"] = model;
|
|
2348
2751
|
if (effort !== undefined)
|
|
2349
2752
|
result["model_reasoning_effort"] = effort;
|
|
2753
|
+
if (isExternalModelProvider(provider)) {
|
|
2754
|
+
result["model_provider"] = provider;
|
|
2755
|
+
result["model_providers"] = {
|
|
2756
|
+
[provider]: { ...EXTERNAL_CODEX_PROVIDERS[provider] },
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
else if (provider === "amazon-bedrock") {
|
|
2760
|
+
result["model_provider"] = provider;
|
|
2761
|
+
}
|
|
2350
2762
|
for (const value of values) {
|
|
2351
2763
|
const separator = value.indexOf("=");
|
|
2352
2764
|
const key = separator < 0 ? "" : value.slice(0, separator);
|
|
@@ -2396,10 +2808,18 @@ export function parseCodexOverrides(values, model, effort) {
|
|
|
2396
2808
|
if (effort !== undefined && key === "model_reasoning_effort") {
|
|
2397
2809
|
throw new CodexSecurityError("--effort conflicts with --codex model_reasoning_effort");
|
|
2398
2810
|
}
|
|
2811
|
+
if ((isExternalModelProvider(provider) || provider === "amazon-bedrock") &&
|
|
2812
|
+
key === "model_provider") {
|
|
2813
|
+
throw new CodexSecurityError("--provider conflicts with --codex model_provider");
|
|
2814
|
+
}
|
|
2399
2815
|
throw new CodexSecurityError("Duplicate --codex key");
|
|
2400
2816
|
}
|
|
2401
2817
|
cursor[final] = parsed;
|
|
2402
2818
|
}
|
|
2819
|
+
if ((isExternalModelProvider(provider) || provider === "amazon-bedrock") &&
|
|
2820
|
+
!("model" in result)) {
|
|
2821
|
+
throw new CodexSecurityError(`--model is required when using --provider ${provider}`);
|
|
2822
|
+
}
|
|
2403
2823
|
return result;
|
|
2404
2824
|
}
|
|
2405
2825
|
function workerStatusMessage(status) {
|
|
@@ -2429,6 +2849,7 @@ export class Progress {
|
|
|
2429
2849
|
#startedAt;
|
|
2430
2850
|
#interactive;
|
|
2431
2851
|
#timer = null;
|
|
2852
|
+
#timerMessage = null;
|
|
2432
2853
|
#timerLineActive = false;
|
|
2433
2854
|
#cursorHidden = false;
|
|
2434
2855
|
constructor(stream = process.stderr, dependencies = DEFAULT_DEPENDENCIES, interactive = true) {
|
|
@@ -2455,12 +2876,14 @@ export class Progress {
|
|
|
2455
2876
|
this.#cursorHidden = true;
|
|
2456
2877
|
this.#renderTimer(message);
|
|
2457
2878
|
this.#timer = this.#dependencies.setInterval(() => this.#renderTimer(message), PROGRESS_REFRESH_MILLISECONDS);
|
|
2879
|
+
this.#timerMessage = message;
|
|
2458
2880
|
}
|
|
2459
2881
|
stopTimer() {
|
|
2460
2882
|
if (this.#timer !== null) {
|
|
2461
2883
|
this.#dependencies.clearInterval(this.#timer);
|
|
2462
2884
|
this.#timer = null;
|
|
2463
2885
|
}
|
|
2886
|
+
this.#timerMessage = null;
|
|
2464
2887
|
if (this.#timerLineActive) {
|
|
2465
2888
|
this.#stream.write("\n");
|
|
2466
2889
|
this.#timerLineActive = false;
|
|
@@ -2470,6 +2893,20 @@ export class Progress {
|
|
|
2470
2893
|
this.#cursorHidden = false;
|
|
2471
2894
|
}
|
|
2472
2895
|
}
|
|
2896
|
+
writeAboveTimer(write) {
|
|
2897
|
+
const message = this.#timerMessage;
|
|
2898
|
+
if (message === null) {
|
|
2899
|
+
write();
|
|
2900
|
+
return;
|
|
2901
|
+
}
|
|
2902
|
+
this.stopTimer();
|
|
2903
|
+
try {
|
|
2904
|
+
write();
|
|
2905
|
+
}
|
|
2906
|
+
finally {
|
|
2907
|
+
this.startTimer(message);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2473
2910
|
#line(message) {
|
|
2474
2911
|
const elapsedSeconds = this.elapsedSeconds;
|
|
2475
2912
|
const minutes = Math.floor(elapsedSeconds / 60);
|