@openai/codex-security 0.1.21 → 0.1.23
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 +529 -0
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +2 -30
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/finding-detail-fields.md +5 -10
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/scripts/config_preflight.py +2 -8
- package/_bundled_plugin/scripts/finalize_scan_contract.py +114 -24
- package/_bundled_plugin/scripts/finding_preview.py +22 -4
- package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +101 -7
- package/_bundled_plugin/scripts/workbench_cli.py +21 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +115 -0
- package/_bundled_plugin/scripts/workbench_db.py +29 -2
- package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +190 -0
- package/_bundled_plugin/scripts/workbench_findings.py +216 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +30 -5
- package/_bundled_plugin/scripts/workbench_schema.py +263 -58
- package/_bundled_plugin/scripts/workbench_target.py +22 -3
- package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +115 -27
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +124 -58
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +5 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -1
- package/dist/custom-publish.d.ts +22 -0
- package/dist/custom-publish.d.ts.map +1 -0
- package/dist/custom-publish.js +47 -0
- package/dist/custom-publish.js.map +1 -0
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +16 -0
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -0
- package/dist/deduplication/checkpointed-review.js +76 -0
- package/dist/deduplication/checkpointed-review.js.map +1 -0
- package/dist/deduplication/codex-review.d.ts +21 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -0
- package/dist/deduplication/codex-review.js +252 -0
- package/dist/deduplication/codex-review.js.map +1 -0
- package/dist/deduplication/deduplication-prompts.d.ts +8 -0
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -0
- package/dist/deduplication/deduplication-prompts.js +35 -0
- package/dist/deduplication/deduplication-prompts.js.map +1 -0
- package/dist/deduplication/deduplication-reviewer.d.ts +46 -0
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -0
- package/dist/deduplication/deduplication-reviewer.js +105 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -0
- package/dist/deduplication/deduplication.d.ts +6 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -0
- package/dist/deduplication/deduplication.js +85 -0
- package/dist/deduplication/deduplication.js.map +1 -0
- package/dist/deduplication/scan.d.ts +16 -0
- package/dist/deduplication/scan.d.ts.map +1 -0
- package/dist/deduplication/scan.js +101 -0
- package/dist/deduplication/scan.js.map +1 -0
- package/dist/finding-dedupe-groups.d.ts +7 -0
- package/dist/finding-dedupe-groups.d.ts.map +1 -0
- package/dist/finding-dedupe-groups.js +2 -0
- package/dist/finding-dedupe-groups.js.map +1 -0
- package/dist/finding-retrieval.d.ts +13 -0
- package/dist/finding-retrieval.d.ts.map +1 -0
- package/dist/finding-retrieval.js +2 -0
- package/dist/finding-retrieval.js.map +1 -0
- package/dist/finding-workflow.d.ts +53 -0
- package/dist/finding-workflow.d.ts.map +1 -0
- package/dist/finding-workflow.js +117 -0
- package/dist/finding-workflow.js.map +1 -0
- package/dist/findings-client.d.ts +15 -0
- package/dist/findings-client.d.ts.map +1 -0
- package/dist/findings-client.js +60 -0
- package/dist/findings-client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.js +28 -40
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +113 -12
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts +15 -0
- package/dist/saved-scan.d.ts.map +1 -0
- package/dist/saved-scan.js +68 -0
- package/dist/saved-scan.js.map +1 -0
- package/dist/scan-comparison.d.ts +3 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +1 -1
- package/dist/scan-comparison.js.map +1 -1
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +276 -0
- package/dist/server/dashboard/app.css +2 -0
- package/dist/server/dashboard/app.js +66 -0
- package/dist/server/dashboard/index.html +18 -0
- package/dist/server/dashboard-types.d.ts +45 -0
- package/dist/server/dashboard-types.d.ts.map +1 -0
- package/dist/server/dashboard-types.js +2 -0
- package/dist/server/dashboard-types.js.map +1 -0
- package/dist/server/dashboard.d.ts +6 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js +45 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/embeddings.d.ts +16 -0
- package/dist/server/embeddings.d.ts.map +1 -0
- package/dist/server/embeddings.js +114 -0
- package/dist/server/embeddings.js.map +1 -0
- package/dist/server/errors.d.ts +5 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +8 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/findings-service.d.ts +20 -0
- package/dist/server/findings-service.d.ts.map +1 -0
- package/dist/server/findings-service.js +31 -0
- package/dist/server/findings-service.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +32 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes.d.ts +6 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/routes.js +86 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/sqlite-store.d.ts +22 -0
- package/dist/server/sqlite-store.d.ts.map +1 -0
- package/dist/server/sqlite-store.js +82 -0
- package/dist/server/sqlite-store.js.map +1 -0
- package/dist/server/storage.d.ts +32 -0
- package/dist/server/storage.d.ts.map +1 -0
- package/dist/server/storage.js +2 -0
- package/dist/server/storage.js.map +1 -0
- package/dist/server/validation.d.ts +17 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +53 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +2 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +17 -5
package/dist/api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
-
import { chmod, lstat, mkdir, readFile, realpath,
|
|
2
|
+
import { chmod, lstat, mkdir, readFile, realpath, rm, writeFile, } from "node:fs/promises";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
|
-
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
6
6
|
import { Codex, } from "@openai/codex-sdk";
|
|
7
7
|
import { parse as parseToml, stringify as stringifyToml, } from "smol-toml";
|
|
8
8
|
import { z } from "incur";
|
|
@@ -10,18 +10,19 @@ import { accountStatus, CodexLoginHandle, loginApiKey as persistApiKey, logout a
|
|
|
10
10
|
import { jsonForPrompt, pluginPythonCommand, shellEnvironmentReference, } from "./codex-prompt.js";
|
|
11
11
|
import { EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergedCodexConfig, scanApprovalPolicy, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
12
12
|
import { estimateScanCost, ScanCostTracker, sumTokenUsage, } from "./cost.js";
|
|
13
|
-
import { loadContract, requireScanFile, } from "./contract.js";
|
|
13
|
+
import { loadContract, readScanFile, requireScanFile, } from "./contract.js";
|
|
14
14
|
import { runCustomValidation, writeCustomValidationStatus, } from "./custom-validation.js";
|
|
15
15
|
import { customDiscoveryPrompt, customValidationConfig, } from "./custom-validation-prompt.js";
|
|
16
16
|
import { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, IncompleteScanError, OutputDirectoryError, errorMessage, safeErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
17
17
|
import { prepareKnowledgeBase, } from "./knowledge-base.js";
|
|
18
|
+
import { FindingWorkflow, workflowDigest } from "./finding-workflow.js";
|
|
18
19
|
import { ScanResult, } from "./result.js";
|
|
19
20
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
20
21
|
import { matchCompletedScan, matchScanFindingsInternal, } from "./scan-comparison.js";
|
|
21
22
|
import { scanProgressUpdatesFromEvent, workerStatusFromEvent, } from "./worker-progress.js";
|
|
22
23
|
import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
|
|
23
24
|
import { CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION } from "./version.js";
|
|
24
|
-
import { acquireCodexSecurityCredentialHomeLock, bootstrapPlugin, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, createIsolatedHome, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, planOutputArchive, prepareOutputDir, preparePersistentOutputRoot, requireModelSafeOutputDir, requireOutputOutsideRepository, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
|
|
25
|
+
import { acquireCodexSecurityCredentialHomeLock, bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, createIsolatedHome, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, planOutputArchive, prepareScanArtifactRestorer, prepareOutputDir, preparePersistentOutputRoot, requireModelSafeOutputDir, requireOutputOutsideRepository, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
|
|
25
26
|
import { enclosingGitWorktreeRoot, normalizeRepository, normalizeTarget, repositoryRevision, resolveRepositoryPath, validatedGitEnvironment, validateCommittedDiffCheckout, validateMode, } from "./targets.js";
|
|
26
27
|
const DEEP_SCAN_CONFIG_PATH_ENVIRONMENT = "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH";
|
|
27
28
|
const VALIDATION_DISPOSITIONS = [
|
|
@@ -76,7 +77,94 @@ export class CodexSecurity {
|
|
|
76
77
|
this.#surface = runtimeOptions.surface;
|
|
77
78
|
}
|
|
78
79
|
async run(repository, options = {}) {
|
|
79
|
-
return await this.#trackOperation(() =>
|
|
80
|
+
return await this.#trackOperation(() => options.workflowId === undefined
|
|
81
|
+
? this.#run(repository, { ...options })
|
|
82
|
+
: this.#runWorkflow(repository, { ...options }, options.workflowId));
|
|
83
|
+
}
|
|
84
|
+
async #runWorkflow(repository, options, workflowId) {
|
|
85
|
+
this.#requireOpen();
|
|
86
|
+
const signal = AbortSignal.any([
|
|
87
|
+
this.#abortController.signal,
|
|
88
|
+
...(options.signal ? [options.signal] : []),
|
|
89
|
+
]);
|
|
90
|
+
const local = await this.#validateLocalInputs(repository, { ...options, outputDir: undefined, archiveExisting: false }, signal);
|
|
91
|
+
const workflow = new FindingWorkflow(workflowId, this.#dependencies.environment, this.#dependencies.runWorkbench, this.config.pythonPath);
|
|
92
|
+
if (options.outputDir !== undefined)
|
|
93
|
+
await workflow.protectArtifacts(options.outputDir);
|
|
94
|
+
const state = await workflow.bind({
|
|
95
|
+
repositoryPath: local.repository,
|
|
96
|
+
scanRequestDigest: workflowDigest({
|
|
97
|
+
config: this.config,
|
|
98
|
+
options: {
|
|
99
|
+
...options,
|
|
100
|
+
target: options.target ?? "repository",
|
|
101
|
+
mode: options.mode ?? "standard",
|
|
102
|
+
outputDir: options.outputDir === undefined
|
|
103
|
+
? undefined
|
|
104
|
+
: resolve(expandHome(options.outputDir)),
|
|
105
|
+
workflowId: undefined,
|
|
106
|
+
signal: undefined,
|
|
107
|
+
auth: undefined,
|
|
108
|
+
archiveExisting: undefined,
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
if (state.scanId && state.scanDir) {
|
|
113
|
+
await workflow.protectArtifacts(state.scanDir);
|
|
114
|
+
let metadata = state.stages.scan.result;
|
|
115
|
+
let completed = state.stages.scan.status === "completed";
|
|
116
|
+
if (!completed) {
|
|
117
|
+
const scan = await workflow.registeredScan(state.scanId);
|
|
118
|
+
completed =
|
|
119
|
+
scan["progress"]?.["status"] ===
|
|
120
|
+
"complete";
|
|
121
|
+
if (completed)
|
|
122
|
+
metadata = {
|
|
123
|
+
threadId: scan["continuationThreadId"] ?? "",
|
|
124
|
+
turnResult: { status: "completed" },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (completed) {
|
|
128
|
+
const contract = await loadContract(state.scanDir, {
|
|
129
|
+
pluginRoot: await bundledPluginRoot(),
|
|
130
|
+
expectedScanId: state.scanId,
|
|
131
|
+
signal,
|
|
132
|
+
});
|
|
133
|
+
await workflow.bind({ artifactDigest: workflowDigest(contract) });
|
|
134
|
+
metadata ??= { threadId: "", turnResult: { status: "completed" } };
|
|
135
|
+
await workflow.complete("scan", metadata);
|
|
136
|
+
return new ScanResult({
|
|
137
|
+
...contract,
|
|
138
|
+
scanDir: state.scanDir,
|
|
139
|
+
...metadata,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
await workflow.begin("scan");
|
|
144
|
+
try {
|
|
145
|
+
const result = await this.#run(repository, options);
|
|
146
|
+
await workflow.protectArtifacts(result.scanDir);
|
|
147
|
+
await workflow.bind({
|
|
148
|
+
scanId: result.manifest.scan.id,
|
|
149
|
+
scanDir: result.scanDir,
|
|
150
|
+
artifactDigest: workflowDigest({
|
|
151
|
+
manifest: result.manifest,
|
|
152
|
+
findings: result.findings,
|
|
153
|
+
coverage: result.coverage,
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
await workflow.complete("scan", {
|
|
157
|
+
threadId: result.threadId,
|
|
158
|
+
turnResult: result.turnResult,
|
|
159
|
+
sarifPath: result.sarifPath,
|
|
160
|
+
repositoryFindings: result.repositoryFindings,
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
await workflow.fail("scan", error);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
80
168
|
}
|
|
81
169
|
async validate(options) {
|
|
82
170
|
return await this.#trackOperation(() => this.#validate(options));
|
|
@@ -218,6 +306,8 @@ export class CodexSecurity {
|
|
|
218
306
|
let preparedTargetWarnings = [];
|
|
219
307
|
let runPostScan = null;
|
|
220
308
|
let activeScan = null;
|
|
309
|
+
const prepareArtifactRestorer = this.#dependencies.prepareScanArtifactRestorer ??
|
|
310
|
+
prepareScanArtifactRestorer;
|
|
221
311
|
const workbench = this.#dependencies.runWorkbench ?? runWorkbench;
|
|
222
312
|
try {
|
|
223
313
|
const checkOpen = () => {
|
|
@@ -374,7 +464,13 @@ export class CodexSecurity {
|
|
|
374
464
|
...(options.parentScanId === undefined
|
|
375
465
|
? []
|
|
376
466
|
: ["--parent-scan-id", options.parentScanId]),
|
|
377
|
-
], JSON.stringify({
|
|
467
|
+
], JSON.stringify({
|
|
468
|
+
recipe,
|
|
469
|
+
userContext: options.scanPrompt,
|
|
470
|
+
...(options.workflowId === undefined
|
|
471
|
+
? {}
|
|
472
|
+
: { workflowId: options.workflowId }),
|
|
473
|
+
}));
|
|
378
474
|
const scanId = registration["scanId"];
|
|
379
475
|
const targetId = registration["targetId"];
|
|
380
476
|
const contract = registration["contract"];
|
|
@@ -699,9 +795,11 @@ export class CodexSecurity {
|
|
|
699
795
|
]),
|
|
700
796
|
].map(async (name) => ({
|
|
701
797
|
name,
|
|
702
|
-
contents: await
|
|
798
|
+
contents: await readScanFile(scanDir, name, name, signal),
|
|
703
799
|
})));
|
|
800
|
+
let artifactRestorer = null;
|
|
704
801
|
try {
|
|
802
|
+
artifactRestorer = await prepareArtifactRestorer(workbenchOptions, scanDir);
|
|
705
803
|
await runScanEvents({
|
|
706
804
|
thread,
|
|
707
805
|
events: (await followUp()).events,
|
|
@@ -719,26 +817,16 @@ export class CodexSecurity {
|
|
|
719
817
|
catch (error) {
|
|
720
818
|
if (signal.aborted || this.#closed)
|
|
721
819
|
throw error;
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
try {
|
|
733
|
-
await writeFile(temporary, artifact.contents, {
|
|
734
|
-
flag: "wx",
|
|
735
|
-
mode: 0o600,
|
|
736
|
-
signal,
|
|
737
|
-
});
|
|
738
|
-
await rename(temporary, path);
|
|
739
|
-
}
|
|
740
|
-
finally {
|
|
741
|
-
await rm(temporary, { force: true });
|
|
820
|
+
if (artifactRestorer !== null) {
|
|
821
|
+
for (const artifact of completedArtifacts) {
|
|
822
|
+
try {
|
|
823
|
+
await artifactRestorer.restore(artifact.name, artifact.contents);
|
|
824
|
+
}
|
|
825
|
+
catch (cause) {
|
|
826
|
+
if (signal.aborted || this.#closed)
|
|
827
|
+
throw cause;
|
|
828
|
+
throw new OutputDirectoryError("Cannot restore an artifact outside the scan directory.", { cause });
|
|
829
|
+
}
|
|
742
830
|
}
|
|
743
831
|
}
|
|
744
832
|
await collectResult(result.turnResult, result.threadId, scanDir, runtime.plugin.installedRoot, expectation, signal, true);
|