@openai/codex-security 0.1.30 → 0.2.0
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 +386 -37
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +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/references/artifact-storage.md +4 -4
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -2
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +2 -2
- package/_bundled_plugin/references/scan-contract.md +2 -2
- package/_bundled_plugin/references/threat-model.md +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +22 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +19 -4
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
- package/_bundled_plugin/scripts/config_preflight.py +4 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
- package/_bundled_plugin/scripts/finding_preview.py +42 -82
- package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
- package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
- package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
- package/_bundled_plugin/scripts/rank_preview.py +86 -68
- package/_bundled_plugin/scripts/report_projection.py +37 -58
- package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
- package/_bundled_plugin/scripts/workbench/storage.py +11 -0
- package/_bundled_plugin/scripts/workbench_cli.py +11 -17
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +116 -228
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
- package/_bundled_plugin/scripts/workbench_progress.py +12 -34
- package/_bundled_plugin/scripts/workbench_publication.py +47 -62
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
- package/_bundled_plugin/scripts/workbench_schema.py +86 -271
- package/_bundled_plugin/scripts/workbench_severity.py +3 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
- package/_bundled_plugin/scripts/workbench_target.py +98 -10
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +6 -20
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/dist/api.d.ts +3 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +201 -207
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +277 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +9 -4
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +2 -8
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -5
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +281 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +21 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +673 -701
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +1 -8
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +2 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +30 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +2 -6
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +1 -0
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +31 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -33
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +63 -122
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +65 -34
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -31
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +4 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +17 -16
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +10 -11
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +2 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +3 -3
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +2 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js +40 -62
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +1 -4
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +2 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +24 -6
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.js.map +1 -1
- package/dist/deduplication/scan.js +3 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +3 -19
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +0 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +22 -40
- package/dist/deep-progress.js.map +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -7
- package/dist/errors.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +22 -22
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +4 -7
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +7 -17
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +2 -3
- package/dist/github.js.map +1 -1
- package/dist/import-scan.js +2 -2
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +7 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -3
- package/dist/linear.js.map +1 -1
- package/dist/models.d.ts +24 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +36 -31
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +29 -0
- package/dist/owner-evidence.d.ts.map +1 -0
- package/dist/owner-evidence.js +192 -0
- package/dist/owner-evidence.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -4
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +15 -29
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -13
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +11 -14
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +31 -41
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- package/dist/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +10 -13
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +230 -145
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +10 -20
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +8 -22
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +4 -4
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +38 -73
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +0 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +10 -19
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +1 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +2 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +1 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +8 -6
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +8 -4
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +98 -84
- package/dist/security-policy.js.map +1 -1
- package/dist/server/dashboard/app.js +5 -5
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +1 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/routes.d.ts +3 -2
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +19 -7
- package/dist/server/routes.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +2 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +4 -14
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js +8 -15
- package/dist/severity-store.js.map +1 -1
- package/dist/suggest-owners.d.ts +37 -0
- package/dist/suggest-owners.d.ts.map +1 -0
- package/dist/suggest-owners.js +111 -0
- package/dist/suggest-owners.js.map +1 -0
- package/dist/targets.d.ts +7 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +29 -25
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.js.map +1 -1
- package/dist/trusted-executable.d.ts +5 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +22 -5
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +20 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.js.map +1 -1
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +13 -34
- package/dist/worker-progress.js.map +1 -1
- package/docs/dedupe-records.md +24 -0
- package/package.json +15 -13
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- package/dist/server/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.js.map +0 -1
package/dist/api.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
-
import {
|
|
2
|
+
import { isSafeNonNegativeInteger as safeInteger } from "./value.js";
|
|
3
3
|
import { chmod, lstat, mkdir, mkdtemp, readFile, realpath, rm, writeFile, } from "node:fs/promises";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import {
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
7
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
7
8
|
import { Codex, } from "@openai/codex-sdk";
|
|
8
9
|
import { z } from "incur";
|
|
9
|
-
import {
|
|
10
|
+
import { readThreatModelPath } from "./artifact-export.js";
|
|
11
|
+
import { isRecord } from "./record.js";
|
|
12
|
+
import { CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, accountStatus, configuredCodexHome, CodexLoginHandle, loginApiKey as persistApiKey, logout as codexLogout, withoutOpenAiApiKeys, } from "./auth.js";
|
|
10
13
|
import { jsonForPrompt, pluginPythonCommand, shellEnvironmentReference, } from "./codex-prompt.js";
|
|
11
|
-
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, inlineToml, isExternalModelProvider, hasCommandAuth, mergedCodexConfig, resolveCodexProfile, modelProviderConfigOverride, resolveCommandAuthConfig, scanApprovalPolicy, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
14
|
+
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, inlineToml, isExternalModelProvider, hasCommandAuth, mergedCodexConfig, resolveCodexProfile, modelProviderConfigOverride, resolveCommandAuthConfig, scanApprovalPolicy, scanCyberAccessConfig, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
12
15
|
import { estimateScanCost, ScanCostTracker, } from "./cost.js";
|
|
13
16
|
import { DeepScanProgressTracker, } from "./deep-progress.js";
|
|
14
17
|
import { findScanSession } from "./scan-logs.js";
|
|
@@ -19,7 +22,7 @@ export { SCAN_AUTH_MODES } from "./scan-settings.js";
|
|
|
19
22
|
import { loadContract, readScanFile, requireScanFile, } from "./contract.js";
|
|
20
23
|
import { runCustomValidation, writeCustomValidationStatus, } from "./custom-validation.js";
|
|
21
24
|
import { customDiscoveryPrompt, customValidationConfig, } from "./custom-validation-prompt.js";
|
|
22
|
-
import { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, IncompleteScanError, OutputDirectoryError, OutputDirectoryNotEmptyError, errorMessage,
|
|
25
|
+
import { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, IncompleteScanError, OutputDirectoryError, OutputDirectoryNotEmptyError, errorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
23
26
|
import { prepareKnowledgeBase, } from "./knowledge-base.js";
|
|
24
27
|
import { FindingWorkflow, workflowDigest } from "./finding-workflow.js";
|
|
25
28
|
import { ScanResult, } from "./result.js";
|
|
@@ -30,8 +33,10 @@ import { matchCompletedScan, matchScanFindingsInternal, } from "./scan-compariso
|
|
|
30
33
|
import { scanProgressUpdatesFromEvent, workerStatusFromEvent, } from "./worker-progress.js";
|
|
31
34
|
import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
|
|
32
35
|
import { CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION } from "./version.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
36
|
+
import { bundledCodexSdkEnvironment } from "./codex-sdk-environment.js";
|
|
37
|
+
import { canonicalConfigPath, acquireCodexSecurityCredentialHomeLock, bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, createIsolatedHome, executablePathForSpawn, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, environmentWithGit, pluginMetadata, planOutputArchive, prepareScanArtifactRestorer, prepareOutputDir, preparePersistentOutputRoot, probeCodexSandbox, requireModelSafeOutputDir, requireOutputOutsideRepositories, requireOutputOutsideRepository, requirePrivatePolicyOutputDirectory, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
|
|
38
|
+
import { enclosingGitWorktreeRoot, enclosingGitWorktreeRoots, normalizeRepository, normalizeTarget, gitMarkerRoot, repositoryRevision, resolveRepositoryPath, validatedGitEnvironment, validateCommittedDiffCheckout, validateMode, } from "./targets.js";
|
|
39
|
+
import { inspectTrustedExecutable, } from "./trusted-executable.js";
|
|
35
40
|
const DEEP_SCAN_CONFIG_PATH_ENVIRONMENT = "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH";
|
|
36
41
|
const VALIDATION_DISPOSITIONS = [
|
|
37
42
|
"reportable",
|
|
@@ -67,7 +72,6 @@ export class CodexSecurity {
|
|
|
67
72
|
#loginHandles = new Set();
|
|
68
73
|
#abortController = new AbortController();
|
|
69
74
|
#activeOperation = null;
|
|
70
|
-
#runtimePromise = null;
|
|
71
75
|
#runtime = null;
|
|
72
76
|
#runtimeCredentialSource = null;
|
|
73
77
|
#closed = false;
|
|
@@ -139,6 +143,11 @@ export class CodexSecurity {
|
|
|
139
143
|
...contract,
|
|
140
144
|
scanDir: state.scanDir,
|
|
141
145
|
...metadata,
|
|
146
|
+
threatModelPath: await readThreatModelPath(state.scanDir, {
|
|
147
|
+
pythonPath: this.config.pythonPath,
|
|
148
|
+
protectedRoot: local.protectedRoot,
|
|
149
|
+
signal,
|
|
150
|
+
}),
|
|
142
151
|
});
|
|
143
152
|
}
|
|
144
153
|
}
|
|
@@ -252,8 +261,7 @@ export class CodexSecurity {
|
|
|
252
261
|
}
|
|
253
262
|
async preflight(repository, options = {}) {
|
|
254
263
|
this.#requireOpen();
|
|
255
|
-
|
|
256
|
-
return await this.#preflightInputs(inputs, options);
|
|
264
|
+
return await this.#preflightInputs(await this.#prepareLocalInputs(repository, options, options.signal), options);
|
|
257
265
|
}
|
|
258
266
|
async #preflightInputs(inputs, options) {
|
|
259
267
|
requireOutputOutsideRepositories(inputs.protectedRoots, await realpath(tmpdir()), "temporary");
|
|
@@ -353,9 +361,7 @@ export class CodexSecurity {
|
|
|
353
361
|
"mcp/helpers.mjs",
|
|
354
362
|
]) {
|
|
355
363
|
const metadata = await lstat(join(runtime.plugin.pluginRoot, path)).catch(() => null);
|
|
356
|
-
if (metadata === null ||
|
|
357
|
-
!metadata.isFile() ||
|
|
358
|
-
metadata.isSymbolicLink()) {
|
|
364
|
+
if (metadata === null || !metadata.isFile()) {
|
|
359
365
|
throw new CodexSecurityError(`Installed plugin is missing policy-generation support: ${path}`);
|
|
360
366
|
}
|
|
361
367
|
}
|
|
@@ -388,7 +394,7 @@ export class CodexSecurity {
|
|
|
388
394
|
...(knowledgeBase === null
|
|
389
395
|
? {}
|
|
390
396
|
: { CODEX_SECURITY_KNOWLEDGE_BASE: knowledgeBase.path }),
|
|
391
|
-
}, options.auth, policyCodexConfig(session.sessionConfig), inputs.gitMetadataPaths.length === 0
|
|
397
|
+
}, options.auth, undefined, policyCodexConfig(session.sessionConfig), inputs.gitMetadataPaths.length === 0
|
|
392
398
|
? []
|
|
393
399
|
: [
|
|
394
400
|
// CLI override keys split on dots, so keep paths inside the TOML value.
|
|
@@ -426,7 +432,7 @@ export class CodexSecurity {
|
|
|
426
432
|
if (options.maxCostUsd !== undefined)
|
|
427
433
|
budgetController.abort(error);
|
|
428
434
|
else
|
|
429
|
-
warn(`Could not track policy-generation cost: ${
|
|
435
|
+
warn(`Could not track policy-generation cost: ${errorMessage(error)}`);
|
|
430
436
|
},
|
|
431
437
|
});
|
|
432
438
|
let stopped = false;
|
|
@@ -445,7 +451,7 @@ export class CodexSecurity {
|
|
|
445
451
|
tracker.start(event["thread_id"]);
|
|
446
452
|
}
|
|
447
453
|
},
|
|
448
|
-
onReconnect:
|
|
454
|
+
onReconnect: warn,
|
|
449
455
|
});
|
|
450
456
|
usage = turn.usage;
|
|
451
457
|
signal.throwIfAborted();
|
|
@@ -455,7 +461,7 @@ export class CodexSecurity {
|
|
|
455
461
|
const snapshot = await tracker.stop(usage).catch((error) => {
|
|
456
462
|
if (options.maxCostUsd !== undefined)
|
|
457
463
|
throw error;
|
|
458
|
-
warn(`Could not track policy-generation cost: ${
|
|
464
|
+
warn(`Could not track policy-generation cost: ${errorMessage(error)}`);
|
|
459
465
|
const cost = estimateScanCost(model.model, usage);
|
|
460
466
|
if (cost !== null)
|
|
461
467
|
reportCost(cost);
|
|
@@ -482,7 +488,7 @@ export class CodexSecurity {
|
|
|
482
488
|
if (!stopped)
|
|
483
489
|
await tracker
|
|
484
490
|
.stop(usage)
|
|
485
|
-
.catch((error) => warn(
|
|
491
|
+
.catch((error) => warn(errorMessage(error)));
|
|
486
492
|
}
|
|
487
493
|
};
|
|
488
494
|
return await runSecurityPolicyStages({
|
|
@@ -502,7 +508,10 @@ export class CodexSecurity {
|
|
|
502
508
|
revision: await (this.#dependencies.repositoryRevision ?? repositoryRevision)(target.repository, signal),
|
|
503
509
|
...model,
|
|
504
510
|
pluginVersion: runtime.plugin.version,
|
|
511
|
+
pythonPath: session.python,
|
|
512
|
+
protectedRoot: inputs.protectedRoot,
|
|
505
513
|
signal,
|
|
514
|
+
onWarning: warn,
|
|
506
515
|
onStage: (stage) => notifyObserver("onStage", options.onStage, options.onObserverError, stage),
|
|
507
516
|
answerQuestions: options.answerQuestions,
|
|
508
517
|
run,
|
|
@@ -551,6 +560,7 @@ export class CodexSecurity {
|
|
|
551
560
|
let deepProgressTracker = null;
|
|
552
561
|
let releaseCredentialHome = null;
|
|
553
562
|
let scanFailure = false;
|
|
563
|
+
let artifactRestorationFailure = null;
|
|
554
564
|
let customValidationComplete = false;
|
|
555
565
|
let completionCost = null;
|
|
556
566
|
let budgetRecovery = null;
|
|
@@ -590,13 +600,17 @@ export class CodexSecurity {
|
|
|
590
600
|
const session = await this.#prepareSession({ protectedRoot }, options, signal, temporaryRoot, mode === "deep");
|
|
591
601
|
const { runtime, runtimeHome, effectiveConfig, preflightConfig, modelProvider, authentication, approvalPolicy, python, } = session;
|
|
592
602
|
releaseCredentialHome = session.releaseCredentialHome;
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
603
|
+
let git = {
|
|
604
|
+
executable: null,
|
|
605
|
+
environment: selectedScanEnvironment(runtime.environment, options.auth, modelProvider),
|
|
606
|
+
};
|
|
607
|
+
for (const source of [repo, ...(knowledgeBase?.sources ?? [])]) {
|
|
608
|
+
git = await inspectTrustedExecutable("git", git.environment, (await gitMarkerRoot(source, signal, "outermost")) ?? source);
|
|
609
|
+
}
|
|
610
|
+
checkOpen();
|
|
611
|
+
if (deepScanConfiguration !== undefined) {
|
|
612
|
+
await writeDeepScanConfig(runtime.deepScanConfigPath ??
|
|
613
|
+
join(runtimeHome, "codex-security", "config.toml"), deepScanConfiguration);
|
|
600
614
|
}
|
|
601
615
|
checkOpen();
|
|
602
616
|
const scanOutputRoot = requestedOutput === null &&
|
|
@@ -609,10 +623,7 @@ export class CodexSecurity {
|
|
|
609
623
|
scanDir =
|
|
610
624
|
options.resumeScanId !== undefined
|
|
611
625
|
? requestedOutput
|
|
612
|
-
: await (this.#dependencies.prepareOutputDir ?? prepareOutputDir)(requestedOutput ?? undefined, basename(repo), scanOutputRoot, (path) => requireOutputOutsideRepository(protectedRoot, path), options.archiveExisting, (
|
|
613
|
-
archivedScanDir = archiveDir;
|
|
614
|
-
notifyObserver("onOutputArchived", options.onOutputArchived, options.onObserverError, archiveDir);
|
|
615
|
-
});
|
|
626
|
+
: await (this.#dependencies.prepareOutputDir ?? prepareOutputDir)(requestedOutput ?? undefined, basename(repo), scanOutputRoot, (path) => requireOutputOutsideRepository(protectedRoot, path), options.archiveExisting, archiveObserver(options, (path) => (archivedScanDir = path)));
|
|
616
627
|
requireOutputOutsideRepository(protectedRoot, scanDir);
|
|
617
628
|
requireModelSafeOutputDir(scanDir);
|
|
618
629
|
notifyObserver("onOutputDirReady", options.onOutputDirReady, options.onObserverError, scanDir);
|
|
@@ -633,10 +644,7 @@ export class CodexSecurity {
|
|
|
633
644
|
if (discoveryPrompt !== undefined)
|
|
634
645
|
session.sessionConfig = await customValidationConfig(session.sessionConfig, runtime.plugin.installedRoot);
|
|
635
646
|
const skillPath = join(shellPluginRoot, "skills", skillName, "SKILL.md");
|
|
636
|
-
|
|
637
|
-
if (skillMetadata === null ||
|
|
638
|
-
!skillMetadata.isFile() ||
|
|
639
|
-
skillMetadata.isSymbolicLink()) {
|
|
647
|
+
if (!(await lstat(skillPath).catch(() => null))?.isFile()) {
|
|
640
648
|
throw new IncompleteScanError(`Installed plugin is missing scan skill: ${skillName}`);
|
|
641
649
|
}
|
|
642
650
|
checkOpen();
|
|
@@ -653,6 +661,8 @@ export class CodexSecurity {
|
|
|
653
661
|
budgetRecovery = {
|
|
654
662
|
expectation,
|
|
655
663
|
pluginRoot: runtime.plugin.installedRoot,
|
|
664
|
+
pythonPath: session.python,
|
|
665
|
+
protectedRoot,
|
|
656
666
|
model,
|
|
657
667
|
threadId: null,
|
|
658
668
|
};
|
|
@@ -757,6 +767,7 @@ export class CodexSecurity {
|
|
|
757
767
|
maxCostUsd: options.maxCostUsd,
|
|
758
768
|
deepScan: deepScanConfiguration?.settings,
|
|
759
769
|
auth: options.auth,
|
|
770
|
+
cyberAccessProgram: options.cyberAccessProgram,
|
|
760
771
|
});
|
|
761
772
|
if (options.scanPrompt?.trim())
|
|
762
773
|
recipe["requiresScanPrompt"] = true;
|
|
@@ -770,7 +781,7 @@ export class CodexSecurity {
|
|
|
770
781
|
python,
|
|
771
782
|
pluginRoot: runtime.plugin.pluginRoot,
|
|
772
783
|
environment: {
|
|
773
|
-
...
|
|
784
|
+
...environmentWithGit(git.environment, git),
|
|
774
785
|
CODEX_SECURITY_STATE_DIR: stateDirectory,
|
|
775
786
|
},
|
|
776
787
|
signal,
|
|
@@ -907,7 +918,7 @@ export class CodexSecurity {
|
|
|
907
918
|
const basePrompt = scanPrompt(normalized, mode, skillName, scanId, runtime.configPath !== undefined, knowledgeBase !== null, options.resumeScanId !== undefined &&
|
|
908
919
|
typeof registration["userContext"] === "string"
|
|
909
920
|
? registration["userContext"]
|
|
910
|
-
: options.scanPrompt, options.maxCostUsd !== undefined, discoveryPrompt);
|
|
921
|
+
: options.scanPrompt, options.maxCostUsd !== undefined, discoveryPrompt, modelProvider);
|
|
911
922
|
checkOpen();
|
|
912
923
|
const feedback = await workbench({
|
|
913
924
|
...workbenchOptions,
|
|
@@ -983,7 +994,7 @@ export class CodexSecurity {
|
|
|
983
994
|
? {}
|
|
984
995
|
: { CODEX_SECURITY_TARGET_PATHS_FILE: targetPathsFile }),
|
|
985
996
|
};
|
|
986
|
-
const { codex, environment } = this.#createSessionCodex(session, runtimePaths, options.auth);
|
|
997
|
+
const { codex, environment } = this.#createSessionCodex(session, runtimePaths, options.auth, git);
|
|
987
998
|
const threadOptions = {
|
|
988
999
|
threadSource: CODEX_SECURITY_THREAD_SOURCES.scan,
|
|
989
1000
|
workingDirectory: scanDir,
|
|
@@ -1016,22 +1027,27 @@ export class CodexSecurity {
|
|
|
1016
1027
|
await chmod(targetPathsFile, 0o400);
|
|
1017
1028
|
}
|
|
1018
1029
|
checkOpen();
|
|
1030
|
+
const turnOptions = {
|
|
1031
|
+
signal,
|
|
1032
|
+
cyberAccessProgram: options.cyberAccessProgram,
|
|
1033
|
+
};
|
|
1019
1034
|
const postScanPrompt = options.postScanPrompt;
|
|
1020
1035
|
if (postScanPrompt?.trim()) {
|
|
1021
|
-
runPostScan = () => thread.runStreamed(postScanPrompt,
|
|
1036
|
+
runPostScan = () => thread.runStreamed(postScanPrompt, turnOptions);
|
|
1022
1037
|
}
|
|
1023
|
-
const { events } = await thread.runStreamed(prompt,
|
|
1024
|
-
signal,
|
|
1025
|
-
});
|
|
1038
|
+
const { events } = await thread.runStreamed(prompt, turnOptions);
|
|
1026
1039
|
checkOpen();
|
|
1027
|
-
|
|
1040
|
+
let result = await runScanEvents({
|
|
1028
1041
|
thread,
|
|
1029
1042
|
events,
|
|
1030
1043
|
signal,
|
|
1031
1044
|
scanDir,
|
|
1032
1045
|
pluginRoot: runtime.plugin.installedRoot,
|
|
1046
|
+
pythonPath: session.python,
|
|
1047
|
+
protectedRoot,
|
|
1033
1048
|
expectation,
|
|
1034
1049
|
authentication,
|
|
1050
|
+
modelProvider,
|
|
1035
1051
|
workbenchValidated: true,
|
|
1036
1052
|
model,
|
|
1037
1053
|
onThreadStarted: async (threadId) => {
|
|
@@ -1054,7 +1070,7 @@ export class CodexSecurity {
|
|
|
1054
1070
|
]);
|
|
1055
1071
|
}
|
|
1056
1072
|
catch (error) {
|
|
1057
|
-
notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not save scan session: ${
|
|
1073
|
+
notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not save scan session: ${errorMessage(error)}`);
|
|
1058
1074
|
}
|
|
1059
1075
|
},
|
|
1060
1076
|
onFinalize: async (usage) => {
|
|
@@ -1087,8 +1103,8 @@ export class CodexSecurity {
|
|
|
1087
1103
|
const turn = await readCodexTurn({
|
|
1088
1104
|
thread: validationThread,
|
|
1089
1105
|
events: (await validationThread.runStreamed(validationPrompt, {
|
|
1106
|
+
...turnOptions,
|
|
1090
1107
|
outputSchema,
|
|
1091
|
-
signal,
|
|
1092
1108
|
})).events,
|
|
1093
1109
|
onReconnect: (message, attempts) => notifyObserver("onReconnect", options.onReconnect, options.onObserverError, ...attempts, reconnectDetails(message)),
|
|
1094
1110
|
});
|
|
@@ -1204,6 +1220,13 @@ export class CodexSecurity {
|
|
|
1204
1220
|
"findings.json",
|
|
1205
1221
|
"coverage.json",
|
|
1206
1222
|
"report.md",
|
|
1223
|
+
...(result.threatModelPath === null
|
|
1224
|
+
? []
|
|
1225
|
+
: [
|
|
1226
|
+
relative(scanDir, result.threatModelPath)
|
|
1227
|
+
.split(sep)
|
|
1228
|
+
.join("/"),
|
|
1229
|
+
]),
|
|
1207
1230
|
...result.manifest.scan.artifacts.map((artifact) => artifact.path),
|
|
1208
1231
|
]),
|
|
1209
1232
|
].map(async (name) => ({
|
|
@@ -1213,12 +1236,14 @@ export class CodexSecurity {
|
|
|
1213
1236
|
let artifactRestorer = null;
|
|
1214
1237
|
try {
|
|
1215
1238
|
artifactRestorer = await prepareArtifactRestorer(workbenchOptions, scanDir);
|
|
1216
|
-
await runScanEvents({
|
|
1239
|
+
const followUpResult = await runScanEvents({
|
|
1217
1240
|
thread,
|
|
1218
1241
|
events: (await followUp()).events,
|
|
1219
1242
|
signal,
|
|
1220
1243
|
scanDir,
|
|
1221
1244
|
pluginRoot: runtime.plugin.installedRoot,
|
|
1245
|
+
pythonPath: session.python,
|
|
1246
|
+
protectedRoot,
|
|
1222
1247
|
expectation,
|
|
1223
1248
|
model,
|
|
1224
1249
|
onReconnect: options.onReconnect,
|
|
@@ -1226,23 +1251,28 @@ export class CodexSecurity {
|
|
|
1226
1251
|
onObserverError: options.onObserverError,
|
|
1227
1252
|
});
|
|
1228
1253
|
checkOpen();
|
|
1254
|
+
result = new ScanResult({
|
|
1255
|
+
...result,
|
|
1256
|
+
threatModelPath: isDeepStrictEqual(result.threatModel, followUpResult.threatModel)
|
|
1257
|
+
? followUpResult.threatModelPath
|
|
1258
|
+
: null,
|
|
1259
|
+
});
|
|
1229
1260
|
}
|
|
1230
1261
|
catch (error) {
|
|
1231
|
-
if (signal.aborted || this.#closed)
|
|
1232
|
-
throw error;
|
|
1233
1262
|
if (artifactRestorer !== null) {
|
|
1234
1263
|
for (const artifact of completedArtifacts) {
|
|
1235
1264
|
try {
|
|
1236
1265
|
await artifactRestorer.restore(artifact.name, artifact.contents);
|
|
1237
1266
|
}
|
|
1238
1267
|
catch (cause) {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
throw new OutputDirectoryError("Cannot restore an artifact outside the scan directory.", { cause });
|
|
1268
|
+
artifactRestorationFailure = new OutputDirectoryError("Cannot restore an artifact outside the scan directory.", { cause });
|
|
1269
|
+
throw artifactRestorationFailure;
|
|
1242
1270
|
}
|
|
1243
1271
|
}
|
|
1244
1272
|
}
|
|
1245
|
-
|
|
1273
|
+
if (signal.aborted || this.#closed)
|
|
1274
|
+
throw error;
|
|
1275
|
+
await collectResult(result.turnResult, result.threadId, scanDir, runtime.plugin.installedRoot, expectation, signal, true, session.python, protectedRoot);
|
|
1246
1276
|
notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not run post-scan instructions: ${errorMessage(error)}`);
|
|
1247
1277
|
}
|
|
1248
1278
|
}
|
|
@@ -1264,6 +1294,7 @@ export class CodexSecurity {
|
|
|
1264
1294
|
}),
|
|
1265
1295
|
environment,
|
|
1266
1296
|
model,
|
|
1297
|
+
cyberAccessProgram: options.cyberAccessProgram,
|
|
1267
1298
|
signal,
|
|
1268
1299
|
});
|
|
1269
1300
|
result.repositoryFindings = (await listRepositoryFindings(runWorkbench, targetId));
|
|
@@ -1279,6 +1310,8 @@ export class CodexSecurity {
|
|
|
1279
1310
|
// scan, and cleanup must treat all of those as a failure it is not allowed to mask.
|
|
1280
1311
|
scanFailure = true;
|
|
1281
1312
|
const snapshot = await costTracker?.stop().catch(() => null);
|
|
1313
|
+
if (artifactRestorationFailure !== null)
|
|
1314
|
+
throw artifactRestorationFailure;
|
|
1282
1315
|
let failure = signal.reason instanceof ScanCostLimitExceededError
|
|
1283
1316
|
? signal.reason
|
|
1284
1317
|
: error;
|
|
@@ -1312,7 +1345,7 @@ export class CodexSecurity {
|
|
|
1312
1345
|
}, budgetRecovery.threadId, scanDir, budgetRecovery.pluginRoot, budgetRecovery.expectation, AbortSignal.any([
|
|
1313
1346
|
this.#abortController.signal,
|
|
1314
1347
|
...(options.signal === undefined ? [] : [options.signal]),
|
|
1315
|
-
]), true);
|
|
1348
|
+
]), true, budgetRecovery.pythonPath, budgetRecovery.protectedRoot);
|
|
1316
1349
|
if (result.coverage.completeness !== "partial") {
|
|
1317
1350
|
throw new IncompleteScanError("Budget-exhausted scan recovery did not report partial coverage.");
|
|
1318
1351
|
}
|
|
@@ -1343,7 +1376,7 @@ export class CodexSecurity {
|
|
|
1343
1376
|
await writeCustomValidationStatus(scanDir, {
|
|
1344
1377
|
scanId: activeScan.id,
|
|
1345
1378
|
status: "incomplete",
|
|
1346
|
-
reason:
|
|
1379
|
+
reason: errorMessage(failure),
|
|
1347
1380
|
}).catch(() => undefined);
|
|
1348
1381
|
}
|
|
1349
1382
|
try {
|
|
@@ -1351,9 +1384,8 @@ export class CodexSecurity {
|
|
|
1351
1384
|
"fail-scan",
|
|
1352
1385
|
"--scan-id",
|
|
1353
1386
|
activeScan.id,
|
|
1354
|
-
// Scan history can be shared; never persist credential-bearing failures.
|
|
1355
1387
|
"--message",
|
|
1356
|
-
|
|
1388
|
+
errorMessage(failure).slice(0, 2400),
|
|
1357
1389
|
...(snapshot?.cost
|
|
1358
1390
|
? ["--cost-json", JSON.stringify(snapshot.cost)]
|
|
1359
1391
|
: []),
|
|
@@ -1463,10 +1495,7 @@ export class CodexSecurity {
|
|
|
1463
1495
|
const authentication = await this.#authentication();
|
|
1464
1496
|
this.#requireOpen();
|
|
1465
1497
|
await codexLogout(this.#codexCommand(), authentication.environment, this.#abortController.signal);
|
|
1466
|
-
|
|
1467
|
-
this.#runtime.persistentCredentialHome === true) {
|
|
1468
|
-
await setCodexSecurityCredentialLogout(authentication.codexHome, true);
|
|
1469
|
-
}
|
|
1498
|
+
await setCodexSecurityCredentialLogout(authentication.codexHome, true);
|
|
1470
1499
|
if (this.#runtime !== null)
|
|
1471
1500
|
this.#runtime.credentialsAvailable = false;
|
|
1472
1501
|
this.#runtimeCredentialSource = null;
|
|
@@ -1483,31 +1512,16 @@ export class CodexSecurity {
|
|
|
1483
1512
|
async #finishClose() {
|
|
1484
1513
|
const activeOperation = this.#activeOperation;
|
|
1485
1514
|
const loginHandles = [...this.#loginHandles];
|
|
1486
|
-
if (activeOperation !== null ||
|
|
1487
|
-
loginHandles.length > 0 ||
|
|
1488
|
-
(this.#runtime === null && this.#runtimePromise !== null)) {
|
|
1515
|
+
if (activeOperation !== null || loginHandles.length > 0) {
|
|
1489
1516
|
this.#abortController.abort();
|
|
1490
1517
|
}
|
|
1491
1518
|
for (const handle of loginHandles)
|
|
1492
1519
|
handle.cancel();
|
|
1493
1520
|
await Promise.allSettled([activeOperation, ...loginHandles.map((handle) => handle.wait())].filter((operation) => operation !== null));
|
|
1494
|
-
const runtime = this.#runtime
|
|
1521
|
+
const runtime = this.#runtime;
|
|
1495
1522
|
this.#runtime = null;
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
await this.#cleanupRuntime(runtime);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
async #cleanupRuntime(runtime) {
|
|
1502
|
-
const cleanupResults = await Promise.allSettled([
|
|
1503
|
-
runtime.persistentCredentialHome ? undefined : runtime.codexHome,
|
|
1504
|
-
runtime.bootstrapWorkspace,
|
|
1505
|
-
]
|
|
1506
|
-
.filter((path) => path !== undefined)
|
|
1507
|
-
.map((path) => cleanupSdkDirectory(path)));
|
|
1508
|
-
for (const result of cleanupResults) {
|
|
1509
|
-
if (result.status === "rejected")
|
|
1510
|
-
throw result.reason;
|
|
1523
|
+
if (runtime?.bootstrapWorkspace !== undefined) {
|
|
1524
|
+
await cleanupSdkDirectory(runtime.bootstrapWorkspace);
|
|
1511
1525
|
}
|
|
1512
1526
|
}
|
|
1513
1527
|
async [Symbol.asyncDispose]() {
|
|
@@ -1527,10 +1541,7 @@ export class CodexSecurity {
|
|
|
1527
1541
|
};
|
|
1528
1542
|
}
|
|
1529
1543
|
async #recordLogin(codexHome, source) {
|
|
1530
|
-
|
|
1531
|
-
this.#runtime.persistentCredentialHome === true) {
|
|
1532
|
-
await setCodexSecurityCredentialLogout(codexHome, false);
|
|
1533
|
-
}
|
|
1544
|
+
await setCodexSecurityCredentialLogout(codexHome, false);
|
|
1534
1545
|
if (this.#runtime !== null)
|
|
1535
1546
|
this.#runtime.credentialsAvailable = true;
|
|
1536
1547
|
this.#runtimeCredentialSource = source;
|
|
@@ -1551,13 +1562,13 @@ export class CodexSecurity {
|
|
|
1551
1562
|
}
|
|
1552
1563
|
}
|
|
1553
1564
|
}
|
|
1554
|
-
#createSessionCodex(session, runtimePaths, auth = "auto", config, configOverrides = []) {
|
|
1565
|
+
#createSessionCodex(session, runtimePaths, auth = "auto", git, config, configOverrides = []) {
|
|
1555
1566
|
const { runtime, python, modelProvider, externalProvider, apiKey, sessionConfig, } = session;
|
|
1556
1567
|
const commandAuth = hasCommandAuth(sessionConfig);
|
|
1557
1568
|
const environment = {
|
|
1558
|
-
...pluginExecutionEnvironment(python, withoutCodexHome(selectedScanEnvironment(commandAuth
|
|
1569
|
+
...environmentWithGit(pluginExecutionEnvironment(python, withoutCodexHome(selectedScanEnvironment(commandAuth
|
|
1559
1570
|
? withoutOpenAiApiKeys(runtime.environment)
|
|
1560
|
-
: runtime.environment, auth, modelProvider))),
|
|
1571
|
+
: runtime.environment, auth, modelProvider))), git),
|
|
1561
1572
|
...(externalProvider === null
|
|
1562
1573
|
? {}
|
|
1563
1574
|
: { [externalProvider.env_key]: apiKey }),
|
|
@@ -1643,17 +1654,32 @@ export class CodexSecurity {
|
|
|
1643
1654
|
const credentialHome = await prepareCodexSecurityCredentialHome(scanEnvironment, (path) => requireOutputOutsideRepositories(protectedRoots, path, "runtime"));
|
|
1644
1655
|
releaseCredentialHome = await acquireCodexSecurityCredentialHomeLock(credentialHome, signal);
|
|
1645
1656
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
this.#
|
|
1650
|
-
|
|
1657
|
+
this.#requireOpen();
|
|
1658
|
+
if (this.#runtime === null) {
|
|
1659
|
+
this.#runtime = await this.#prepareRuntime(signal, temporaryRoot, (path) => requireOutputOutsideRepositories(protectedRoots, path, "runtime"), options.auth, requestedConfig);
|
|
1660
|
+
this.#requireOpen();
|
|
1661
|
+
this.#runtimeCredentialSource = this.#runtime.credentialsAvailable
|
|
1662
|
+
? "stored_credentials"
|
|
1663
|
+
: null;
|
|
1664
|
+
}
|
|
1665
|
+
else if (this.#dependencies.prepareRuntime === undefined) {
|
|
1666
|
+
await this.#refreshPersistentRuntime(this.#runtime, scanEnvironment, signal, requestedConfig);
|
|
1651
1667
|
}
|
|
1652
|
-
const
|
|
1668
|
+
const runtime = this.#runtime;
|
|
1669
|
+
const effectiveConfig = scanCyberAccessConfig(requestedConfig, options.cyberAccessProgram);
|
|
1653
1670
|
const approvalPolicy = scanApprovalPolicy(effectiveConfig);
|
|
1654
1671
|
const preflightConfig = scanPreflightCodexConfig(effectiveConfig);
|
|
1655
1672
|
if (runtime.configPath !== undefined) {
|
|
1656
|
-
await writeCodexConfig(runtime.configPath,
|
|
1673
|
+
await writeCodexConfig(runtime.configPath, {
|
|
1674
|
+
...preflightConfig,
|
|
1675
|
+
...(options.cyberAccessProgram === undefined
|
|
1676
|
+
? {}
|
|
1677
|
+
: {
|
|
1678
|
+
codex_security: {
|
|
1679
|
+
cyber_access_program: options.cyberAccessProgram,
|
|
1680
|
+
},
|
|
1681
|
+
}),
|
|
1682
|
+
});
|
|
1657
1683
|
}
|
|
1658
1684
|
const runtimeHome = await realpath(runtime.codexHome);
|
|
1659
1685
|
requireOutputOutsideRepositories(protectedRoots, runtimeHome, "runtime");
|
|
@@ -1736,27 +1762,6 @@ export class CodexSecurity {
|
|
|
1736
1762
|
throw error;
|
|
1737
1763
|
}
|
|
1738
1764
|
}
|
|
1739
|
-
async #ensureRuntime(signal, temporaryRoot, validateLocation, auth = "auto", requestedConfig) {
|
|
1740
|
-
this.#requireOpen();
|
|
1741
|
-
if (this.#runtime !== null)
|
|
1742
|
-
return this.#runtime;
|
|
1743
|
-
if (this.#runtimePromise === null) {
|
|
1744
|
-
const runtimePromise = this.#prepareRuntime(signal ?? this.#abortController.signal, temporaryRoot, validateLocation, auth, requestedConfig);
|
|
1745
|
-
this.#runtimePromise = runtimePromise;
|
|
1746
|
-
void runtimePromise.catch(() => {
|
|
1747
|
-
if (this.#runtimePromise === runtimePromise) {
|
|
1748
|
-
this.#runtimePromise = null;
|
|
1749
|
-
}
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1752
|
-
const runtime = await this.#runtimePromise;
|
|
1753
|
-
this.#requireOpen();
|
|
1754
|
-
this.#runtime = runtime;
|
|
1755
|
-
this.#runtimeCredentialSource = runtime.credentialsAvailable
|
|
1756
|
-
? "stored_credentials"
|
|
1757
|
-
: null;
|
|
1758
|
-
return this.#runtime;
|
|
1759
|
-
}
|
|
1760
1765
|
#trackLoginHandle(handle) {
|
|
1761
1766
|
this.#loginHandles.add(handle);
|
|
1762
1767
|
void handle.wait().then(() => this.#loginHandles.delete(handle), () => this.#loginHandles.delete(handle));
|
|
@@ -1780,7 +1785,6 @@ export class CodexSecurity {
|
|
|
1780
1785
|
(await pluginSupportsIsolatedDeepScanConfig(runtime.plugin.pluginRoot))
|
|
1781
1786
|
? join(runtime.bootstrapWorkspace, "deep-scan-config.toml")
|
|
1782
1787
|
: undefined;
|
|
1783
|
-
runtime.effectiveConfig = mergedConfig;
|
|
1784
1788
|
}
|
|
1785
1789
|
async #validatePolicyInputs(target, options, signal) {
|
|
1786
1790
|
policyCodexConfig(await mergedCodexConfig(this.config));
|
|
@@ -1791,14 +1795,13 @@ export class CodexSecurity {
|
|
|
1791
1795
|
...sources.gitMetadataPaths,
|
|
1792
1796
|
]),
|
|
1793
1797
|
];
|
|
1794
|
-
const inputs = await this.#prepareLocalInputs(target.repository, {
|
|
1795
|
-
auth: options.auth,
|
|
1796
|
-
target: target.scope === "." ? "repository" : [dirname(target.targetPath)],
|
|
1797
|
-
outputDir: options.outputDir,
|
|
1798
|
-
maxCostUsd: options.maxCostUsd,
|
|
1799
|
-
}, signal, protectedRoots);
|
|
1800
1798
|
return {
|
|
1801
|
-
...
|
|
1799
|
+
...(await this.#prepareLocalInputs(target.repository, {
|
|
1800
|
+
auth: options.auth,
|
|
1801
|
+
target: target.scope === "." ? "repository" : [dirname(target.targetPath)],
|
|
1802
|
+
outputDir: options.outputDir,
|
|
1803
|
+
maxCostUsd: options.maxCostUsd,
|
|
1804
|
+
}, signal, protectedRoots)),
|
|
1802
1805
|
policyPaths: sources.policyPaths,
|
|
1803
1806
|
gitMetadataPaths: [
|
|
1804
1807
|
...new Set([...protectedRoots.slice(1), ...sources.gitMetadataPaths]),
|
|
@@ -1839,10 +1842,7 @@ export class CodexSecurity {
|
|
|
1839
1842
|
? await preparePersistentOutputRoot(local.stateDirectory, "scans", basename(local.repository))
|
|
1840
1843
|
: undefined;
|
|
1841
1844
|
let archivedScanDir;
|
|
1842
|
-
scanDir = await prepareOutputDir(local.outputDir ?? undefined, basename(local.repository), outputRoot, (path) => requireOutputOutsideRepository(local.protectedRoot, path), options.archiveExisting, (path) =>
|
|
1843
|
-
archivedScanDir = path;
|
|
1844
|
-
notifyObserver("onOutputArchived", options.onOutputArchived, options.onObserverError, path);
|
|
1845
|
-
});
|
|
1845
|
+
scanDir = await prepareOutputDir(local.outputDir ?? undefined, basename(local.repository), outputRoot, (path) => requireOutputOutsideRepository(local.protectedRoot, path), options.archiveExisting, archiveObserver(options, (path) => (archivedScanDir = path)));
|
|
1846
1846
|
requireModelSafeOutputDir(scanDir);
|
|
1847
1847
|
notifyObserver("onOutputDirReady", options.onOutputDirReady, options.onObserverError, scanDir);
|
|
1848
1848
|
const revision = await repositoryRevision(local.repository, signal);
|
|
@@ -1887,6 +1887,7 @@ export class CodexSecurity {
|
|
|
1887
1887
|
knowledgeBasePaths: options.knowledgeBasePaths,
|
|
1888
1888
|
maxCostUsd: options.maxCostUsd,
|
|
1889
1889
|
auth: options.auth,
|
|
1890
|
+
cyberAccessProgram: options.cyberAccessProgram,
|
|
1890
1891
|
}),
|
|
1891
1892
|
mock: true,
|
|
1892
1893
|
},
|
|
@@ -1945,7 +1946,7 @@ export class CodexSecurity {
|
|
|
1945
1946
|
target: local.target,
|
|
1946
1947
|
mode: local.mode,
|
|
1947
1948
|
pluginVersion: plugin.version,
|
|
1948
|
-
}, signal, true);
|
|
1949
|
+
}, signal, true, python, local.protectedRoot);
|
|
1949
1950
|
// Stable fixture identities are indexed by complete-scan without model matching.
|
|
1950
1951
|
result.repositoryFindings = (await listRepositoryFindings((args) => workbench(workbenchOptions, args), targetId));
|
|
1951
1952
|
return result;
|
|
@@ -1957,7 +1958,7 @@ export class CodexSecurity {
|
|
|
1957
1958
|
"--scan-id",
|
|
1958
1959
|
activeScan.id,
|
|
1959
1960
|
"--message",
|
|
1960
|
-
|
|
1961
|
+
errorMessage(error).slice(0, 2400),
|
|
1961
1962
|
]).catch(() => undefined);
|
|
1962
1963
|
}
|
|
1963
1964
|
if (this.#closed)
|
|
@@ -1988,6 +1989,9 @@ export class CodexSecurity {
|
|
|
1988
1989
|
throw new CodexSecurityError("Mock scans support Standard mode without custom validation or post-scan prompts; those workflows require model calls.");
|
|
1989
1990
|
}
|
|
1990
1991
|
const deep = deepScanOptions(options);
|
|
1992
|
+
if (!ScanSettingsSchema.shape.cyberAccessProgram.safeParse(options.cyberAccessProgram).success) {
|
|
1993
|
+
throw new ConfigurationError("cyberAccessProgram must be standard, daybreak_blue, or daybreak_red.");
|
|
1994
|
+
}
|
|
1991
1995
|
const identifier = options.safetyIdentifier;
|
|
1992
1996
|
if (identifier !== undefined &&
|
|
1993
1997
|
(typeof identifier !== "string" ||
|
|
@@ -2026,21 +2030,7 @@ export class CodexSecurity {
|
|
|
2026
2030
|
protectedRoots ??= [protectedRoot];
|
|
2027
2031
|
const requestedOutput = await prepareScanOutputDir(options, protectedRoots);
|
|
2028
2032
|
const stateDirectory = codexSecurityStateDirectory(this.#dependencies.environment);
|
|
2029
|
-
|
|
2030
|
-
while (true) {
|
|
2031
|
-
try {
|
|
2032
|
-
canonicalStateDirectory = join(await realpath(canonicalStateDirectory), relative(canonicalStateDirectory, stateDirectory));
|
|
2033
|
-
break;
|
|
2034
|
-
}
|
|
2035
|
-
catch (error) {
|
|
2036
|
-
if (error.code !== "ENOENT")
|
|
2037
|
-
throw error;
|
|
2038
|
-
const parent = dirname(canonicalStateDirectory);
|
|
2039
|
-
if (parent === canonicalStateDirectory)
|
|
2040
|
-
throw error;
|
|
2041
|
-
canonicalStateDirectory = parent;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2033
|
+
const canonicalStateDirectory = await canonicalConfigPath(stateDirectory);
|
|
2044
2034
|
requireOutputOutsideRepositories(protectedRoots, canonicalStateDirectory);
|
|
2045
2035
|
return {
|
|
2046
2036
|
repository: repo,
|
|
@@ -2058,19 +2048,15 @@ export class CodexSecurity {
|
|
|
2058
2048
|
: {}),
|
|
2059
2049
|
};
|
|
2060
2050
|
}
|
|
2061
|
-
async #prepareRuntime(signal, temporaryRoot, validateLocation, auth
|
|
2051
|
+
async #prepareRuntime(signal, temporaryRoot, validateLocation, auth, requestedConfig) {
|
|
2062
2052
|
if (this.#dependencies.prepareRuntime !== undefined) {
|
|
2063
2053
|
return await this.#dependencies.prepareRuntime(this.config, signal);
|
|
2064
2054
|
}
|
|
2065
|
-
const modelProvider = requestedConfig
|
|
2066
|
-
|
|
2067
|
-
: scanModelProvider(requestedConfig);
|
|
2068
|
-
const processEnvironment = selectedScanEnvironment(requestedConfig !== undefined && hasCommandAuth(requestedConfig)
|
|
2055
|
+
const modelProvider = scanModelProvider(requestedConfig);
|
|
2056
|
+
const processEnvironment = selectedScanEnvironment(hasCommandAuth(requestedConfig)
|
|
2069
2057
|
? withoutOpenAiApiKeys(this.#dependencies.environment)
|
|
2070
2058
|
: this.#dependencies.environment, auth, modelProvider);
|
|
2071
|
-
const codexHome =
|
|
2072
|
-
? await prepareCodexSecurityCredentialHome(processEnvironment)
|
|
2073
|
-
: await realpath(codexSecurityCredentialHome(processEnvironment));
|
|
2059
|
+
const codexHome = await realpath(codexSecurityCredentialHome(processEnvironment));
|
|
2074
2060
|
let bootstrapWorkspace;
|
|
2075
2061
|
try {
|
|
2076
2062
|
throwIfAborted(signal);
|
|
@@ -2079,27 +2065,27 @@ export class CodexSecurity {
|
|
|
2079
2065
|
const nodeAmbientHome = join(homedir(), ".codex");
|
|
2080
2066
|
const configuredAmbientHome = environmentValue(processEnvironment, "CODEX_HOME");
|
|
2081
2067
|
const ambientHome = configuredAmbientHome ?? nodeAmbientHome;
|
|
2082
|
-
const
|
|
2083
|
-
const codexConfig = await preserveCodexSecurityPluginRegistration(codexHome, sharedCredentialCodexConfig(mergedConfig, codexHome));
|
|
2068
|
+
const codexConfig = await preserveCodexSecurityPluginRegistration(codexHome, sharedCredentialCodexConfig(requestedConfig, codexHome));
|
|
2084
2069
|
await writeCodexConfig(join(codexHome, "config.toml"), codexConfig);
|
|
2085
2070
|
const configPath = join(bootstrapWorkspace, "config-preflight.toml");
|
|
2086
2071
|
throwIfAborted(signal);
|
|
2072
|
+
const codexCommand = this.#codexCommand();
|
|
2073
|
+
await (this.#dependencies.probeCodexSandbox ?? probeCodexSandbox)(codexCommand, { ...withoutCodexHome(processEnvironment), CODEX_HOME: codexHome }, signal);
|
|
2087
2074
|
const plugin = await bootstrapPlugin(codexHome, pluginRoot, {
|
|
2088
|
-
codexCommand
|
|
2075
|
+
codexCommand,
|
|
2089
2076
|
environment: withoutCodexHome(processEnvironment),
|
|
2090
2077
|
signal,
|
|
2091
2078
|
});
|
|
2092
2079
|
const deepScanConfigPath = (await pluginSupportsIsolatedDeepScanConfig(plugin.pluginRoot))
|
|
2093
2080
|
? join(bootstrapWorkspace, "deep-scan-config.toml")
|
|
2094
2081
|
: undefined;
|
|
2095
|
-
const credentialsAvailable = hasCommandAuth(
|
|
2082
|
+
const credentialsAvailable = hasCommandAuth(requestedConfig) ||
|
|
2096
2083
|
isExternalModelProvider(modelProvider) ||
|
|
2097
2084
|
modelProvider === "amazon-bedrock"
|
|
2098
2085
|
? false
|
|
2099
2086
|
: await initialCredentialsAvailable(processEnvironment, ambientHome, codexHome);
|
|
2100
2087
|
return {
|
|
2101
2088
|
codexHome,
|
|
2102
|
-
persistentCredentialHome: true,
|
|
2103
2089
|
bootstrapWorkspace,
|
|
2104
2090
|
configPath,
|
|
2105
2091
|
deepScanConfigPath,
|
|
@@ -2110,7 +2096,6 @@ export class CodexSecurity {
|
|
|
2110
2096
|
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(processEnvironment),
|
|
2111
2097
|
},
|
|
2112
2098
|
credentialsAvailable,
|
|
2113
|
-
effectiveConfig: mergedConfig,
|
|
2114
2099
|
};
|
|
2115
2100
|
}
|
|
2116
2101
|
catch (error) {
|
|
@@ -2201,7 +2186,9 @@ export async function runScanEvents(options) {
|
|
|
2201
2186
|
thread: options.thread,
|
|
2202
2187
|
events: options.events,
|
|
2203
2188
|
onEvent: async (event) => {
|
|
2204
|
-
if (!tacStatusReported
|
|
2189
|
+
if (!tacStatusReported &&
|
|
2190
|
+
options.modelProvider !== "amazon-bedrock" &&
|
|
2191
|
+
options.authentication?.method !== "aws_credentials") {
|
|
2205
2192
|
const tacStatus = trustedAccessStatusFromEvent(event);
|
|
2206
2193
|
if (tacStatus !== null) {
|
|
2207
2194
|
tacStatusReported = true;
|
|
@@ -2260,7 +2247,7 @@ export async function runScanEvents(options) {
|
|
|
2260
2247
|
finalResponse,
|
|
2261
2248
|
usage,
|
|
2262
2249
|
...(options.model === undefined ? {} : { model: options.model }),
|
|
2263
|
-
}, threadId, options.scanDir, options.pluginRoot, options.expectation, options.signal, options.workbenchValidated);
|
|
2250
|
+
}, threadId, options.scanDir, options.pluginRoot, options.expectation, options.signal, options.workbenchValidated, options.pythonPath, options.protectedRoot);
|
|
2264
2251
|
if (options.signal.aborted) {
|
|
2265
2252
|
throw new ScanInterruptedError(`Codex Security scan was interrupted; partial output remains at ${options.scanDir}.`, options.scanDir);
|
|
2266
2253
|
}
|
|
@@ -2383,22 +2370,25 @@ function trustedAccessWarning(status, authentication) {
|
|
|
2383
2370
|
? ORGANIZATIONAL_TRUSTED_ACCESS_URL
|
|
2384
2371
|
: PERSONAL_TRUSTED_ACCESS_URL;
|
|
2385
2372
|
if (status === "not_granted") {
|
|
2386
|
-
|
|
2387
|
-
return `Some cybersecurity requests or findings may be refused because ${account} does not have Trusted Access for Cyber. Apply at ${applicationUrl}.`;
|
|
2373
|
+
return `Some cybersecurity requests or findings may be refused because ${apiOrganization ? "your API organization" : "your account"} does not have Trusted Access for Cyber. Apply at ${applicationUrl}.`;
|
|
2388
2374
|
}
|
|
2389
2375
|
const access = apiOrganization
|
|
2390
2376
|
? "Trusted Access for Cyber for your API organization"
|
|
2391
2377
|
: "your Trusted Access for Cyber status";
|
|
2392
|
-
|
|
2393
|
-
return `Some cybersecurity requests or findings may be refused because ${access} could not be verified. Check ${action} or apply at ${applicationUrl}.`;
|
|
2378
|
+
return `Some cybersecurity requests or findings may be refused because ${access} could not be verified. Check ${apiOrganization ? "your organization's access" : "your access"} or apply at ${applicationUrl}.`;
|
|
2394
2379
|
}
|
|
2395
|
-
function scanPrompt(target, mode, skillName, scanId, hasConfigPath = false, hasKnowledgeBase = false, additionalPrompt, enforceCostLimit = false, discoveryPrompt) {
|
|
2380
|
+
function scanPrompt(target, mode, skillName, scanId, hasConfigPath = false, hasKnowledgeBase = false, additionalPrompt, enforceCostLimit = false, discoveryPrompt, modelProvider) {
|
|
2396
2381
|
const python = pluginPythonCommand();
|
|
2397
2382
|
const customValidation = discoveryPrompt !== undefined;
|
|
2398
2383
|
return [
|
|
2399
2384
|
discoveryPrompt ??
|
|
2400
2385
|
`Use the installed $codex-security:${skillName} skill at ${shellEnvironmentReference("CODEX_SECURITY_PLUGIN_ROOT", `/skills/${skillName}/SKILL.md`)}.`,
|
|
2401
2386
|
"Run this Codex Security scan non-interactively.",
|
|
2387
|
+
...(modelProvider === "amazon-bedrock"
|
|
2388
|
+
? [
|
|
2389
|
+
"This scan uses Amazon Bedrock with AWS authentication. Skip the ChatGPT account Daybreak access advisory, including get_codex_security_daybreak_access and get_tac_status; it does not check Bedrock model access or access to local scan results. OpenAI login is not required for this scan. Report any actual provider error unchanged.",
|
|
2390
|
+
]
|
|
2391
|
+
: []),
|
|
2402
2392
|
...(mode === "deep"
|
|
2403
2393
|
? [
|
|
2404
2394
|
`The SDK has already registered this scan. Call start_codex_security_deep_scan with ${JSON.stringify({ scanId })}; never pass targetPath or create another scan.`,
|
|
@@ -2411,6 +2401,7 @@ function scanPrompt(target, mode, skillName, scanId, hasConfigPath = false, hasK
|
|
|
2411
2401
|
...(skillName === "security-scan"
|
|
2412
2402
|
? [
|
|
2413
2403
|
"This Standard scan authorizes its independent baseline auditor and focused investigators; use available subagent tools and continue with parent-agent fallback if capacity changes.",
|
|
2404
|
+
"After architecture mapping yields a usable threatModel, call record_codex_security_scan_draft for this already registered scan with complete:false, findings:[], and truthful partial coverage, before continuing discovery. Preserve the model in later checkpoints as it changes. This checkpoint does not start or complete a scan; write final canonical files as instructed below.",
|
|
2414
2405
|
]
|
|
2415
2406
|
: skillName === "deep-security-scan"
|
|
2416
2407
|
? []
|
|
@@ -2489,7 +2480,7 @@ function targetInstruction(target, python) {
|
|
|
2489
2480
|
}
|
|
2490
2481
|
return `Scan target: staged and unstaged working-tree changes against ${target.base}.`;
|
|
2491
2482
|
}
|
|
2492
|
-
function scanRecipe({ repository, target, mode, repositoryRevision, pluginVersion, config, failOnSeverity, knowledgeBasePaths, maxCostUsd, deepScan, auth, }) {
|
|
2483
|
+
function scanRecipe({ repository, target, mode, repositoryRevision, pluginVersion, config, failOnSeverity, knowledgeBasePaths, maxCostUsd, deepScan, auth, cyberAccessProgram, }) {
|
|
2493
2484
|
return {
|
|
2494
2485
|
repository,
|
|
2495
2486
|
target: {
|
|
@@ -2505,6 +2496,7 @@ function scanRecipe({ repository, target, mode, repositoryRevision, pluginVersio
|
|
|
2505
2496
|
pluginVersion,
|
|
2506
2497
|
config,
|
|
2507
2498
|
...(auth === undefined ? {} : { auth }),
|
|
2499
|
+
...(cyberAccessProgram === undefined ? {} : { cyberAccessProgram }),
|
|
2508
2500
|
...(failOnSeverity === undefined ? {} : { failOnSeverity }),
|
|
2509
2501
|
...(knowledgeBasePaths === undefined ? {} : { knowledgeBasePaths }),
|
|
2510
2502
|
...(maxCostUsd === undefined ? {} : { maxCostUsd }),
|
|
@@ -2555,7 +2547,7 @@ function addScanCosts(previous, current) {
|
|
|
2555
2547
|
}),
|
|
2556
2548
|
};
|
|
2557
2549
|
}
|
|
2558
|
-
async function collectResult(turnResult, threadId, scanDir, pluginRoot, expectation, signal, workbenchValidated = false) {
|
|
2550
|
+
async function collectResult(turnResult, threadId, scanDir, pluginRoot, expectation, signal, workbenchValidated = false, pythonPath, protectedRoot) {
|
|
2559
2551
|
const required = [
|
|
2560
2552
|
"scan-manifest.json",
|
|
2561
2553
|
"findings.json",
|
|
@@ -2598,6 +2590,12 @@ async function collectResult(turnResult, threadId, scanDir, pluginRoot, expectat
|
|
|
2598
2590
|
threadId,
|
|
2599
2591
|
turnResult,
|
|
2600
2592
|
sarifPath,
|
|
2593
|
+
threatModelPath: await readThreatModelPath(scanDir, {
|
|
2594
|
+
pluginRoot,
|
|
2595
|
+
pythonPath,
|
|
2596
|
+
protectedRoot,
|
|
2597
|
+
signal,
|
|
2598
|
+
}),
|
|
2601
2599
|
});
|
|
2602
2600
|
}
|
|
2603
2601
|
export function scanAuthentication(environment, auth = DEFAULT_SCAN_AUTH, modelProvider, commandAuth = false) {
|
|
@@ -2689,9 +2687,10 @@ export function selectedScanEnvironment(environment, auth = "auto", modelProvide
|
|
|
2689
2687
|
return true;
|
|
2690
2688
|
}));
|
|
2691
2689
|
}
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2690
|
+
const archiveObserver = (options, save) => (path) => {
|
|
2691
|
+
save(path);
|
|
2692
|
+
notifyObserver("onOutputArchived", options.onOutputArchived, options.onObserverError, path);
|
|
2693
|
+
};
|
|
2695
2694
|
function notifyObserver(observerName, observer, onObserverError, ...args) {
|
|
2696
2695
|
void Promise.resolve()
|
|
2697
2696
|
.then(() => observer?.(...args))
|
|
@@ -2712,9 +2711,6 @@ function environmentApiKeyEntry(environment, modelProvider) {
|
|
|
2712
2711
|
}
|
|
2713
2712
|
return null;
|
|
2714
2713
|
}
|
|
2715
|
-
function isRecord(value) {
|
|
2716
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2717
|
-
}
|
|
2718
2714
|
function reconnectAttempt(message) {
|
|
2719
2715
|
const match = /^Reconnecting(?:\.\.\.|…)[ \t]+([1-9]\d{0,2})\/([1-9]\d{0,2})(?=[ \t(]|$)/u.exec(message);
|
|
2720
2716
|
if (match === null)
|
|
@@ -2759,6 +2755,14 @@ export function classifyConnectionFailure(error) {
|
|
|
2759
2755
|
if (/\b(?:sqlite3?|database|workbench)\b/iu.test(message)) {
|
|
2760
2756
|
return "unknown";
|
|
2761
2757
|
}
|
|
2758
|
+
if (/\b(?:ExpiredTokenException|UnrecognizedClientException|IncompleteSignature)\b/iu.test(message)) {
|
|
2759
|
+
return "unauthorized";
|
|
2760
|
+
}
|
|
2761
|
+
if (/\b(?:AccessDeniedException|NotAuthorized|OptInRequired)\b/iu.test(message)) {
|
|
2762
|
+
return "forbidden";
|
|
2763
|
+
}
|
|
2764
|
+
if (/\bThrottlingException\b/iu.test(message))
|
|
2765
|
+
return "rate_limited";
|
|
2762
2766
|
if (/\brate[_ -]?limit(?:ed|[_ -]exceeded)?\b|\b429\b|\btoo many requests\b/iu.test(message)) {
|
|
2763
2767
|
return "rate_limited";
|
|
2764
2768
|
}
|
|
@@ -2792,9 +2796,6 @@ export function scanRuntimeCodexConfig(config, protectedCredentialHome) {
|
|
|
2792
2796
|
delete profile["sandbox_mode"];
|
|
2793
2797
|
}
|
|
2794
2798
|
}
|
|
2795
|
-
const configuredPermissions = isRecord(hardened["permissions"])
|
|
2796
|
-
? hardened["permissions"]
|
|
2797
|
-
: {};
|
|
2798
2799
|
return {
|
|
2799
2800
|
...hardened,
|
|
2800
2801
|
approval_policy: approvalPolicy,
|
|
@@ -2802,7 +2803,7 @@ export function scanRuntimeCodexConfig(config, protectedCredentialHome) {
|
|
|
2802
2803
|
allow_login_shell: false,
|
|
2803
2804
|
default_permissions: SCAN_PERMISSION_PROFILE,
|
|
2804
2805
|
permissions: {
|
|
2805
|
-
...
|
|
2806
|
+
...(isRecord(hardened["permissions"]) ? hardened["permissions"] : {}),
|
|
2806
2807
|
[SCAN_PERMISSION_PROFILE]: {
|
|
2807
2808
|
filesystem: {
|
|
2808
2809
|
":root": "read",
|
|
@@ -2846,7 +2847,6 @@ function policyCodexConfig(config) {
|
|
|
2846
2847
|
// The selected provider is already written as TOML. The SDK cannot quote
|
|
2847
2848
|
// provider names when it flattens this table into command-line overrides.
|
|
2848
2849
|
delete resolved["model_providers"];
|
|
2849
|
-
const features = isRecord(resolved["features"]) ? resolved["features"] : {};
|
|
2850
2850
|
return {
|
|
2851
2851
|
...resolved,
|
|
2852
2852
|
approval_policy: "never",
|
|
@@ -2860,7 +2860,7 @@ function policyCodexConfig(config) {
|
|
|
2860
2860
|
ignore_default_excludes: false,
|
|
2861
2861
|
},
|
|
2862
2862
|
features: {
|
|
2863
|
-
...features,
|
|
2863
|
+
...(isRecord(resolved["features"]) ? resolved["features"] : {}),
|
|
2864
2864
|
plugins: false,
|
|
2865
2865
|
apps: false,
|
|
2866
2866
|
shell_snapshot: false,
|
|
@@ -2902,12 +2902,17 @@ export function scanPreflightCodexConfig(config) {
|
|
|
2902
2902
|
value.length > 0 &&
|
|
2903
2903
|
!/[\u0000-\u001f\u007f]/u.test(value);
|
|
2904
2904
|
const safeProfileName = (value) => safeString(value) && /^[A-Za-z0-9_-]+$/u.test(value);
|
|
2905
|
-
const safeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2906
2905
|
const capabilityFeatures = (value) => {
|
|
2907
2906
|
if (!isRecord(value))
|
|
2908
2907
|
return {};
|
|
2909
2908
|
const result = {};
|
|
2910
|
-
for (const key of [
|
|
2909
|
+
for (const key of [
|
|
2910
|
+
"goals",
|
|
2911
|
+
"multi_agent",
|
|
2912
|
+
"enable_fanout",
|
|
2913
|
+
"api_key_cyber_access_programs",
|
|
2914
|
+
"api_key_model_discovery",
|
|
2915
|
+
]) {
|
|
2911
2916
|
if (typeof value[key] === "boolean")
|
|
2912
2917
|
result[key] = value[key];
|
|
2913
2918
|
}
|
|
@@ -2966,10 +2971,24 @@ export function scanPreflightCodexConfig(config) {
|
|
|
2966
2971
|
return result;
|
|
2967
2972
|
};
|
|
2968
2973
|
const result = executionConfig(config);
|
|
2969
|
-
// Keep
|
|
2970
|
-
const
|
|
2971
|
-
|
|
2972
|
-
|
|
2974
|
+
// Keep effective worker settings even when preflight filters the profile name.
|
|
2975
|
+
const resolved = resolveCodexProfile(config);
|
|
2976
|
+
for (const key of ["model_reasoning_summary", "service_tier"]) {
|
|
2977
|
+
const value = resolved[key];
|
|
2978
|
+
if (safeString(value))
|
|
2979
|
+
result[key] = value;
|
|
2980
|
+
}
|
|
2981
|
+
const resolvedFeatures = capabilityFeatures(resolved["features"]);
|
|
2982
|
+
for (const key of [
|
|
2983
|
+
"api_key_cyber_access_programs",
|
|
2984
|
+
"api_key_model_discovery",
|
|
2985
|
+
]) {
|
|
2986
|
+
if (resolvedFeatures[key] !== undefined) {
|
|
2987
|
+
result["features"] = {
|
|
2988
|
+
...(isRecord(result["features"]) ? result["features"] : {}),
|
|
2989
|
+
[key]: resolvedFeatures[key],
|
|
2990
|
+
};
|
|
2991
|
+
}
|
|
2973
2992
|
}
|
|
2974
2993
|
const selectedProfile = safeProfileName(config["profile"])
|
|
2975
2994
|
? config["profile"]
|
|
@@ -3066,31 +3085,6 @@ function throwIfAborted(signal, scanDir = "") {
|
|
|
3066
3085
|
: "Codex Security scan was interrupted during preparation.";
|
|
3067
3086
|
throw new ScanInterruptedError(message, scanDir, { cause: signal.reason });
|
|
3068
3087
|
}
|
|
3069
|
-
function bundledCodexSdkEnvironment(command, environment) {
|
|
3070
|
-
// An SDK executable override disables its bundled-tool PATH setup.
|
|
3071
|
-
const toolsDirectory = join(dirname(dirname(command)), "codex-path");
|
|
3072
|
-
try {
|
|
3073
|
-
if (!statSync(toolsDirectory).isDirectory())
|
|
3074
|
-
return environment;
|
|
3075
|
-
}
|
|
3076
|
-
catch {
|
|
3077
|
-
return environment;
|
|
3078
|
-
}
|
|
3079
|
-
const result = { ...environment };
|
|
3080
|
-
const pathKeys = Object.keys(result).filter((key) => key.toLowerCase() === "path");
|
|
3081
|
-
const pathKey = pathKeys.includes("Path")
|
|
3082
|
-
? "Path"
|
|
3083
|
-
: (pathKeys.at(-1) ?? "PATH");
|
|
3084
|
-
for (const key of pathKeys) {
|
|
3085
|
-
if (key !== pathKey)
|
|
3086
|
-
delete result[key];
|
|
3087
|
-
}
|
|
3088
|
-
const entries = (result[pathKey] ?? "")
|
|
3089
|
-
.split(delimiter)
|
|
3090
|
-
.filter((entry) => entry.length > 0 && entry !== toolsDirectory);
|
|
3091
|
-
result[pathKey] = [toolsDirectory, ...entries].join(delimiter);
|
|
3092
|
-
return result;
|
|
3093
|
-
}
|
|
3094
3088
|
function definedEnvironment(environment) {
|
|
3095
3089
|
return Object.fromEntries(Object.entries(environment).filter((entry) => entry[1] !== undefined));
|
|
3096
3090
|
}
|