@openai/codex-security 0.1.31 → 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 +295 -32
- 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/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 +85 -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 +8 -3
- 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 +19 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +631 -714
- 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 +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +2 -2
- 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.map +1 -1
- package/dist/owner-evidence.js +2 -6
- package/dist/owner-evidence.js.map +1 -1
- 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 +203 -131
- 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 +3 -3
- 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 +2 -3
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +4 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +24 -21
- package/dist/targets.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 +11 -10
- 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/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { isNonEmptyString } from "./value.js";
|
|
2
3
|
import { execFile as execFileCallback, execFileSync, spawn, } from "node:child_process";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
5
|
import { accessSync, constants, createReadStream, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
@@ -8,15 +9,18 @@ import { basename, dirname, isAbsolute, join, parse, relative, resolve, win32, }
|
|
|
8
9
|
import { cwd } from "node:process";
|
|
9
10
|
import { createInterface } from "node:readline";
|
|
10
11
|
import { Readable, Writable as NodeWritable } from "node:stream";
|
|
11
|
-
import { pipeline } from "node:stream/promises";
|
|
12
12
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
13
|
import { promisify, stripVTControlCharacters } from "node:util";
|
|
14
14
|
import { Cli, z } from "incur";
|
|
15
|
+
import { formatCliHelp } from "./cli-help.js";
|
|
15
16
|
import { scanLogsJson } from "./cli-scan-logs-json.js";
|
|
17
|
+
import { ARTIFACT_EXPORT_FILENAMES, exportEnvironment, resolveArtifactFormat, resolveArtifactExportOutput, resolveSavedArtifactDirectory, runArtifactExport, writeArtifactOutput as writeCliOutput, } from "./artifact-export.js";
|
|
18
|
+
export { exportEnvironment } from "./artifact-export.js";
|
|
16
19
|
import { parse as parseToml } from "smol-toml";
|
|
17
20
|
import { classifyConnectionFailure, createSecurityInternal, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, runtimeScanAuthentication, selectedScanEnvironment, } from "./api.js";
|
|
18
|
-
import { accountStatus, CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, configuredCodexHome, readCodexHomeConfig, } from "./auth.js";
|
|
19
|
-
import { loadContract } from "./contract.js";
|
|
21
|
+
import { accountStatus, CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, configuredCodexHome, environmentEntry, readCodexHomeConfig, } from "./auth.js";
|
|
22
|
+
import { loadContract, sha256Text } from "./contract.js";
|
|
23
|
+
import { isRecord as isJsonObject } from "./record.js";
|
|
20
24
|
import { suggestOwnersInternal } from "./suggest-owners.js";
|
|
21
25
|
import { parseImportedFindings } from "./findings-import.js";
|
|
22
26
|
import { publishScanToCustom } from "./custom-publish.js";
|
|
@@ -26,12 +30,12 @@ import { runRecordsProtocol } from "./deduplication/records-protocol.js";
|
|
|
26
30
|
import { classifyScanSeverityInternal, classifyScanDirectorySeverityInternal, } from "./classify-scan-severity.js";
|
|
27
31
|
import { resolveCompletedScan, resolveWorkflowScan, } from "./saved-scan.js";
|
|
28
32
|
import { publishFindingsCsvToCloud, publishScanToCloud, } from "./cloud-publish.js";
|
|
29
|
-
import { createBulkScanDiscoveryDependencies, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
30
|
-
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergeCodexOverrides, hasCommandAuth, inlineToml, modelProviderConfigOverride, resolveCommandAuthConfig, mergedCodexConfig, scanModel, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
33
|
+
import { createBulkScanDiscoveryDependencies, createTerminalPrompt, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
34
|
+
import { DEFAULT_CODEX_CONFIG, deepMerge, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergeCodexOverrides, hasCommandAuth, inlineToml, modelProviderConfigOverride, resolveCommandAuthConfig, resolveCodexProfile, mergedCodexConfig, scanModel, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
31
35
|
import { formatUsd } from "./cost.js";
|
|
32
36
|
import { formatScanCost, formatScanCostTokens, formatTokenUsage, } from "./cost-model.js";
|
|
33
|
-
import {
|
|
34
|
-
import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage,
|
|
37
|
+
import { readRegularInputFile, resolveScanPrompts } from "./prompt-files.js";
|
|
38
|
+
import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
35
39
|
import { GITHUB_ALERT_STATES, importGitHubCodeScanningAlerts, } from "./github.js";
|
|
36
40
|
import { importLinearIssues, isLinearIssueIdentifier, resolveLinearApiKey, } from "./linear.js";
|
|
37
41
|
import { runMultiscan } from "./multiscan.js";
|
|
@@ -39,7 +43,7 @@ import { componentPlanSchema } from "./component-plan.js";
|
|
|
39
43
|
import { runComponentScans, } from "./component-scan.js";
|
|
40
44
|
import { checkScanPublication, forceTerminatePublicationProcesses as terminatePublishers, publishScan, } from "./publish.js";
|
|
41
45
|
import { importScan } from "./import-scan.js";
|
|
42
|
-
import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, requireOutputOutsideRepositories, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome,
|
|
46
|
+
import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, requireOutputOutsideRepositories, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
43
47
|
import { comparisonFindingGroups, comparisonForScan, matchScanFindingsInternal, unionFindingGroups, } from "./scan-comparison.js";
|
|
44
48
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
45
49
|
import { CODEX_SECURITY_THREAD_SOURCES, } from "./thread-source.js";
|
|
@@ -49,7 +53,7 @@ import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
|
49
53
|
import { ScanDashboard } from "./scan-dashboard.js";
|
|
50
54
|
import { policyDisplayData, runPolicyCommand, } from "./security-policy-cli.js";
|
|
51
55
|
import { scanPhaseLabel as scanPhase, } from "./worker-progress.js";
|
|
52
|
-
import { abortable, DiffTarget, enclosingGitWorktreeRoots, } from "./targets.js";
|
|
56
|
+
import { abortable, DiffTarget, enclosingGitWorktreeRoots, relativePathIsOutside as isOutsidePath, } from "./targets.js";
|
|
53
57
|
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
54
58
|
import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
|
|
55
59
|
import { readProjectConfig, resolveScanSettings, projectScopeTarget, configurationSources, projectConfigStarter, } from "./project-config.js";
|
|
@@ -69,27 +73,37 @@ const DUPLICATE_SIGNAL_WINDOW_MS = 500;
|
|
|
69
73
|
const PUBLICATION_GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {
|
|
70
74
|
granularity: "grapheme",
|
|
71
75
|
});
|
|
72
|
-
const DISPLAY_SEVERITIES = SCAN_SEVERITIES;
|
|
73
|
-
const MODEL_REASONING_EFFORTS = [
|
|
74
|
-
"minimal",
|
|
75
|
-
"low",
|
|
76
|
-
"medium",
|
|
77
|
-
"high",
|
|
78
|
-
"xhigh",
|
|
79
|
-
"max",
|
|
80
|
-
];
|
|
81
76
|
const DEFAULT_SCAN_MODEL_CONFIGURATION = scanModelConfiguration(DEFAULT_CODEX_CONFIG);
|
|
77
|
+
const MODEL_OPTIONS = modelOptions();
|
|
78
|
+
const MATCHING_MODEL_OPTIONS = modelOptions("Model for finding matching (default: Codex's configured model).", "Matching reasoning effort (default: medium).");
|
|
79
|
+
const SKILL_CODEX_OVERRIDE_DESCRIPTION = 'Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", model_provider="gateway", model_providers.<name>.<key>=VALUE, or analytics.enabled=false.';
|
|
80
|
+
const SKILL_CONFIG_OPTIONS = MODEL_OPTIONS.extend({
|
|
81
|
+
codex: z
|
|
82
|
+
.array(optionValue("--codex"))
|
|
83
|
+
.default([])
|
|
84
|
+
.describe(SKILL_CODEX_OVERRIDE_DESCRIPTION),
|
|
85
|
+
});
|
|
82
86
|
const CODEX_OVERRIDE_DESCRIPTION = 'Repeat TOML KEY=VALUE; e.g. model_reasoning_effort="high" or features.multi_agent_v2.max_concurrent_threads_per_session=4.';
|
|
83
87
|
const PLUGIN_PATH_DESCRIPTION = "Codex Security plugin directory or ZIP (default: bundled plugin).";
|
|
84
88
|
const PYTHON_PATH_DESCRIPTION = "Python interpreter (default: PYTHON or automatic discovery).";
|
|
89
|
+
const RUNTIME_OPTION_SCHEMAS = {
|
|
90
|
+
pluginPath: optionValue("--plugin-path")
|
|
91
|
+
.optional()
|
|
92
|
+
.describe(PLUGIN_PATH_DESCRIPTION),
|
|
93
|
+
python: optionValue("--python").optional().describe(PYTHON_PATH_DESCRIPTION),
|
|
94
|
+
codex: z
|
|
95
|
+
.array(optionValue("--codex"))
|
|
96
|
+
.default([])
|
|
97
|
+
.describe(CODEX_OVERRIDE_DESCRIPTION),
|
|
98
|
+
};
|
|
99
|
+
const SKILL_AUTH_OPTION = z
|
|
100
|
+
.enum(SCAN_AUTH_MODES)
|
|
101
|
+
.default("auto")
|
|
102
|
+
.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication.");
|
|
85
103
|
const PROJECT_CONFIG_OPTION = optionValue("--config")
|
|
86
104
|
.optional()
|
|
87
105
|
.describe("Load a trusted YAML/JSON file (default: CODEX_SECURITY_PROJECT_CONFIG, otherwise no file).");
|
|
88
|
-
const EXPORT_DEFAULT_OUTPUTS =
|
|
89
|
-
csv: "findings.csv",
|
|
90
|
-
json: "findings.json",
|
|
91
|
-
sarif: "results.sarif",
|
|
92
|
-
};
|
|
106
|
+
const EXPORT_DEFAULT_OUTPUTS = ARTIFACT_EXPORT_FILENAMES;
|
|
93
107
|
const VALUE_OPTIONS = new Set([
|
|
94
108
|
"--config",
|
|
95
109
|
"-c",
|
|
@@ -98,6 +112,7 @@ const VALUE_OPTIONS = new Set([
|
|
|
98
112
|
"--concurrency",
|
|
99
113
|
"--auth",
|
|
100
114
|
"--safety-identifier",
|
|
115
|
+
"--cyber-access-program",
|
|
101
116
|
"--path",
|
|
102
117
|
"--component",
|
|
103
118
|
"--components-file",
|
|
@@ -138,6 +153,7 @@ const VALUE_OPTIONS = new Set([
|
|
|
138
153
|
"--max-time-hours",
|
|
139
154
|
"--max-attempts",
|
|
140
155
|
"--export-format",
|
|
156
|
+
"--artifact",
|
|
141
157
|
"--csv",
|
|
142
158
|
"--output",
|
|
143
159
|
"--source-root",
|
|
@@ -275,8 +291,7 @@ function publicationIssueUrl(value) {
|
|
|
275
291
|
if (value === undefined ||
|
|
276
292
|
value !== value.trim() ||
|
|
277
293
|
value !== stripVTControlCharacters(value) ||
|
|
278
|
-
/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/u.test(value)
|
|
279
|
-
safeErrorMessage(value) !== value) {
|
|
294
|
+
/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/u.test(value)) {
|
|
280
295
|
return undefined;
|
|
281
296
|
}
|
|
282
297
|
let url;
|
|
@@ -308,7 +323,7 @@ function renderPublicationSummary(result, color) {
|
|
|
308
323
|
: `${marker} ${title}`;
|
|
309
324
|
const lines = [heading, ""];
|
|
310
325
|
for (const issue of result.created.slice(0, 5)) {
|
|
311
|
-
const identifier = stripVTControlCharacters(
|
|
326
|
+
const identifier = stripVTControlCharacters(issue.issueIdentifier)
|
|
312
327
|
.replaceAll(/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/gu, " ")
|
|
313
328
|
.replace(/\s+/gu, " ")
|
|
314
329
|
.trim() || "Unknown Linear issue";
|
|
@@ -348,7 +363,6 @@ class PublicationProgressPresenter {
|
|
|
348
363
|
presentation: "publication",
|
|
349
364
|
clock: this.#dependencies,
|
|
350
365
|
color: this.#dependencies.environment["NO_COLOR"] === undefined,
|
|
351
|
-
sanitize: safeErrorMessage,
|
|
352
366
|
});
|
|
353
367
|
dashboard.setStage("Connecting to Linear");
|
|
354
368
|
try {
|
|
@@ -389,9 +403,7 @@ class PublicationProgressPresenter {
|
|
|
389
403
|
}
|
|
390
404
|
for (const activity of scanActivitiesFromEvent(event.event, this.#repository)) {
|
|
391
405
|
const item = event.event["item"];
|
|
392
|
-
const tool =
|
|
393
|
-
? item["tool"]
|
|
394
|
-
: undefined;
|
|
406
|
+
const tool = isJsonObject(item) ? item["tool"] : undefined;
|
|
395
407
|
const hidesShellCommand = activity.kind === "command" ||
|
|
396
408
|
(activity.kind === "tool" &&
|
|
397
409
|
typeof tool === "string" &&
|
|
@@ -452,7 +464,7 @@ class PublicationProgressPresenter {
|
|
|
452
464
|
}
|
|
453
465
|
}
|
|
454
466
|
#write(message, compact = false) {
|
|
455
|
-
const sanitized = diagnosticValue(
|
|
467
|
+
const sanitized = diagnosticValue(message);
|
|
456
468
|
if (!compact) {
|
|
457
469
|
this.#stream.write(`${sanitized}\n`);
|
|
458
470
|
return;
|
|
@@ -489,7 +501,6 @@ class FindingProgressPresenter {
|
|
|
489
501
|
presentation: "verification",
|
|
490
502
|
clock: this.#dependencies,
|
|
491
503
|
color: this.#dependencies.environment["NO_COLOR"] === undefined,
|
|
492
|
-
sanitize: safeErrorMessage,
|
|
493
504
|
});
|
|
494
505
|
dashboard.setPublicationProgress(0, this.#total);
|
|
495
506
|
dashboard.setStage(`Verifying findings · 0/${this.#total}`);
|
|
@@ -518,16 +529,13 @@ class FindingProgressPresenter {
|
|
|
518
529
|
observe(event) {
|
|
519
530
|
const method = event["method"];
|
|
520
531
|
const params = event["params"];
|
|
521
|
-
if (
|
|
522
|
-
params === null ||
|
|
523
|
-
Array.isArray(params)) {
|
|
532
|
+
if (!isJsonObject(params)) {
|
|
524
533
|
return;
|
|
525
534
|
}
|
|
526
|
-
const values = params;
|
|
527
535
|
let normalized;
|
|
528
536
|
if (method === "item/reasoning/summaryTextDelta") {
|
|
529
|
-
const id =
|
|
530
|
-
const delta =
|
|
537
|
+
const id = params["itemId"];
|
|
538
|
+
const delta = params["delta"];
|
|
531
539
|
if (typeof id !== "string" || typeof delta !== "string")
|
|
532
540
|
return;
|
|
533
541
|
if (this.#dashboard === null)
|
|
@@ -540,34 +548,33 @@ class FindingProgressPresenter {
|
|
|
540
548
|
};
|
|
541
549
|
}
|
|
542
550
|
else if (method === "item/started" || method === "item/completed") {
|
|
543
|
-
const item =
|
|
544
|
-
if (
|
|
551
|
+
const item = params["item"];
|
|
552
|
+
if (!isJsonObject(item)) {
|
|
545
553
|
return;
|
|
546
554
|
}
|
|
547
|
-
const
|
|
548
|
-
const type = current["type"];
|
|
555
|
+
const type = item["type"];
|
|
549
556
|
let converted;
|
|
550
557
|
if (type === "commandExecution") {
|
|
551
|
-
converted = { ...
|
|
558
|
+
converted = { ...item, type: "command_execution" };
|
|
552
559
|
}
|
|
553
560
|
else if (type === "mcpToolCall") {
|
|
554
|
-
converted = { ...
|
|
561
|
+
converted = { ...item, type: "mcp_tool_call" };
|
|
555
562
|
}
|
|
556
563
|
else if (type === "agentMessage") {
|
|
557
|
-
if (
|
|
564
|
+
if (item["phase"] !== "commentary")
|
|
558
565
|
return;
|
|
559
|
-
converted = { ...
|
|
566
|
+
converted = { ...item, type: "agent_message" };
|
|
560
567
|
}
|
|
561
568
|
else if (type === "reasoning") {
|
|
562
|
-
const summary =
|
|
569
|
+
const summary = item["summary"];
|
|
563
570
|
const text = Array.isArray(summary)
|
|
564
571
|
? summary
|
|
565
572
|
.filter((entry) => typeof entry === "string")
|
|
566
573
|
.join("\n")
|
|
567
|
-
:
|
|
574
|
+
: item["text"];
|
|
568
575
|
if (typeof text !== "string")
|
|
569
576
|
return;
|
|
570
|
-
converted = { ...
|
|
577
|
+
converted = { ...item, text };
|
|
571
578
|
}
|
|
572
579
|
else {
|
|
573
580
|
return;
|
|
@@ -621,18 +628,15 @@ class FindingProgressPresenter {
|
|
|
621
628
|
catch { }
|
|
622
629
|
}
|
|
623
630
|
}
|
|
624
|
-
function
|
|
625
|
-
return z
|
|
626
|
-
.
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
+
function modelOptions(modelDescription = `Model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`, effortDescription = `Model reasoning effort (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort}).`) {
|
|
632
|
+
return z.object({
|
|
633
|
+
model: optionValue("--model").optional().describe(modelDescription),
|
|
634
|
+
effort: optionValue("--effort")
|
|
635
|
+
.optional()
|
|
636
|
+
.describe(`${effortDescription} Passed through to Codex; supported values depend on the model, provider, and Codex version.`),
|
|
637
|
+
});
|
|
631
638
|
}
|
|
632
|
-
const DEEP_SCAN_OPTION_SCHEMAS = Object.fromEntries(DEEP_SCAN_SETTINGS.
|
|
633
|
-
name,
|
|
634
|
-
DeepScanSettingsSchema.shape[name],
|
|
635
|
-
]));
|
|
639
|
+
const DEEP_SCAN_OPTION_SCHEMAS = Object.fromEntries(DEEP_SCAN_SETTINGS.flatMap(([name, , , flag]) => flag !== null ? [[name, DeepScanSettingsSchema.shape[name]]] : []));
|
|
636
640
|
export function resolveCliPath(directory, value) {
|
|
637
641
|
return resolveConfigPath(directory, value);
|
|
638
642
|
}
|
|
@@ -715,70 +719,18 @@ const DEFAULT_DEPENDENCIES = {
|
|
|
715
719
|
});
|
|
716
720
|
return options?.trim === false ? stdout : stdout.trim();
|
|
717
721
|
},
|
|
718
|
-
exportFindings:
|
|
719
|
-
|
|
720
|
-
const python = await resolvePluginPython({
|
|
721
|
-
configuredPath: arguments_.pythonPath,
|
|
722
|
-
environment,
|
|
723
|
-
});
|
|
724
|
-
const plugin = await bundledPluginRoot();
|
|
725
|
-
const invocation = spawn(python, [
|
|
726
|
-
"-I",
|
|
727
|
-
"-X",
|
|
728
|
-
"utf8",
|
|
729
|
-
join(plugin, "scripts", "finalize_scan_contract.py"),
|
|
730
|
-
"--scan-dir",
|
|
731
|
-
arguments_.scanDir,
|
|
732
|
-
"--export-format",
|
|
733
|
-
arguments_.format,
|
|
734
|
-
...(arguments_.output === "-"
|
|
735
|
-
? []
|
|
736
|
-
: ["--export-output", arguments_.output]),
|
|
737
|
-
...(arguments_.sourceRoot === undefined
|
|
738
|
-
? []
|
|
739
|
-
: ["--source-root", arguments_.sourceRoot]),
|
|
740
|
-
], {
|
|
741
|
-
env: environment,
|
|
742
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
743
|
-
windowsHide: true,
|
|
744
|
-
});
|
|
745
|
-
let stderr = "";
|
|
746
|
-
invocation.stderr.on("data", (chunk) => {
|
|
747
|
-
stderr = `${stderr}${chunk.toString("utf8")}`.slice(-64 * 1024);
|
|
748
|
-
});
|
|
749
|
-
const forwarded = arguments_.output === "-" && output !== undefined
|
|
750
|
-
? writeCliOutput(output, invocation.stdout)
|
|
751
|
-
: Promise.resolve(invocation.stdout.resume());
|
|
752
|
-
let status;
|
|
753
|
-
try {
|
|
754
|
-
[status] = await Promise.all([
|
|
755
|
-
new Promise((resolve, reject) => {
|
|
756
|
-
invocation.once("error", reject);
|
|
757
|
-
invocation.once("close", (code, signal) => resolve(signal === null ? (code ?? 1) : 1));
|
|
758
|
-
}),
|
|
759
|
-
forwarded,
|
|
760
|
-
]);
|
|
761
|
-
}
|
|
762
|
-
catch (error) {
|
|
763
|
-
invocation.stdout.destroy();
|
|
764
|
-
invocation.kill();
|
|
765
|
-
throw error;
|
|
766
|
-
}
|
|
767
|
-
if (status !== 0) {
|
|
768
|
-
const detail = stderr.trim().split("\n").at(-1);
|
|
769
|
-
throw new CodexSecurityError(detail?.replace(/^finalize_scan_contract\.py: error: /, "") ||
|
|
770
|
-
`Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`);
|
|
771
|
-
}
|
|
772
|
-
return undefined;
|
|
773
|
-
},
|
|
774
|
-
runWorkbench: async (args, input, signal) => {
|
|
722
|
+
exportFindings: runArtifactExport,
|
|
723
|
+
runWorkbench: async (args, input, signal, pythonPath) => {
|
|
775
724
|
const environment = {
|
|
776
725
|
...exportEnvironment(),
|
|
777
726
|
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
|
|
778
727
|
};
|
|
779
|
-
const python = await resolvePluginPython({ environment, signal });
|
|
780
728
|
return await runWorkbench({
|
|
781
|
-
python
|
|
729
|
+
python: await resolvePluginPython({
|
|
730
|
+
configuredPath: pythonPath,
|
|
731
|
+
environment,
|
|
732
|
+
signal,
|
|
733
|
+
}),
|
|
782
734
|
pluginRoot: await bundledPluginRoot(),
|
|
783
735
|
environment,
|
|
784
736
|
signal,
|
|
@@ -787,6 +739,10 @@ const DEFAULT_DEPENDENCIES = {
|
|
|
787
739
|
},
|
|
788
740
|
matchFindings: (input, options) => matchScanFindingsInternal(input, options, { surface: "cli" }),
|
|
789
741
|
};
|
|
742
|
+
function signalHandlers(dependencies, operation, interrupt, terminate) {
|
|
743
|
+
dependencies[`${operation}SignalListener`]("SIGINT", interrupt);
|
|
744
|
+
dependencies[`${operation}SignalListener`]("SIGTERM", terminate);
|
|
745
|
+
}
|
|
790
746
|
export async function runCodexSkillCommand(args, output, command = resolveCodexCommand(), processEnvironment = process.env, input) {
|
|
791
747
|
let releaseCredentialHome;
|
|
792
748
|
try {
|
|
@@ -795,36 +751,83 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
795
751
|
let modelProvider;
|
|
796
752
|
// runSkill selects auth; other process callers supply their own environment.
|
|
797
753
|
if (output?.auth !== undefined) {
|
|
798
|
-
const
|
|
799
|
-
? {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}),
|
|
808
|
-
}
|
|
809
|
-
: output.appServer === undefined
|
|
810
|
-
? {}
|
|
811
|
-
: await readCodexHomeConfig(processEnvironment);
|
|
812
|
-
const provider = scanModelProvider(config);
|
|
813
|
-
const providerConfiguration = typeof provider === "string"
|
|
754
|
+
const ambientConfig = output.appServer === undefined
|
|
755
|
+
? {}
|
|
756
|
+
: resolveCodexProfile(await readCodexHomeConfig(processEnvironment));
|
|
757
|
+
const overrides = structuredClone(output.codexOverrides ?? {});
|
|
758
|
+
const config = deepMerge(ambientConfig, overrides);
|
|
759
|
+
const provider = output.modelProvider ?? scanModelProvider(config);
|
|
760
|
+
// Native Codex ignores configured tables for these built-in providers.
|
|
761
|
+
const providerConfiguration = typeof provider === "string" &&
|
|
762
|
+
!["openai", "ollama", "lmstudio"].includes(provider)
|
|
814
763
|
? config["model_providers"]?.[provider]
|
|
815
764
|
: undefined;
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
765
|
+
const providerEnvKey = typeof providerConfiguration?.["env_key"] === "string"
|
|
766
|
+
? providerConfiguration["env_key"]
|
|
767
|
+
: undefined;
|
|
768
|
+
const commandAuth = providerConfiguration?.["auth"] !== undefined;
|
|
769
|
+
const explicitChatgpt = output.auth === "chatgpt" && !isExternalModelProvider(provider);
|
|
770
|
+
const providerBearer = typeof providerConfiguration?.["experimental_bearer_token"] ===
|
|
771
|
+
"string";
|
|
772
|
+
const providerKeyConfigured = providerEnvKey !== undefined || providerBearer;
|
|
773
|
+
const requiresOpenAiAuth = !commandAuth &&
|
|
774
|
+
(explicitChatgpt || !providerKeyConfigured) &&
|
|
775
|
+
(provider === undefined ||
|
|
776
|
+
provider === "openai" ||
|
|
777
|
+
providerConfiguration?.["requires_openai_auth"] === true ||
|
|
778
|
+
(explicitChatgpt && providerKeyConfigured));
|
|
819
779
|
modelProvider = output.modelProvider;
|
|
820
780
|
let credentialConfig;
|
|
821
|
-
|
|
781
|
+
if (providerEnvKey !== undefined && !commandAuth && !explicitChatgpt) {
|
|
782
|
+
const key = environmentEntry(processEnvironment, providerEnvKey)?.trim();
|
|
783
|
+
if (!key && output.auth === "api-key") {
|
|
784
|
+
throw new AuthenticationRequiredError(`API-key authentication requires ${providerEnvKey}. Set a valid API key for the selected provider.`);
|
|
785
|
+
}
|
|
786
|
+
authentication = key
|
|
787
|
+
? { method: "api_key", source: providerEnvKey, verified: false }
|
|
788
|
+
: { method: "stored_credentials", verified: false };
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
authentication = scanAuthentication(processEnvironment, output.auth, provider, commandAuth);
|
|
792
|
+
}
|
|
822
793
|
if (authentication.method === "stored_credentials" &&
|
|
823
794
|
isExternalModelProvider(provider)) {
|
|
824
795
|
const externalProvider = EXTERNAL_CODEX_PROVIDERS[provider];
|
|
825
|
-
throw new AuthenticationRequiredError(`Set ${externalProvider.env_key} to run ${output.command} through ${externalProvider.name}.`);
|
|
796
|
+
throw new AuthenticationRequiredError(`Set ${providerEnvKey ?? externalProvider.env_key} to run ${output.command} through ${externalProvider.name}.`);
|
|
826
797
|
}
|
|
827
798
|
let selected = selectedScanEnvironment(processEnvironment, authentication.method === "command" ? "chatgpt" : output.auth, provider);
|
|
799
|
+
if (explicitChatgpt &&
|
|
800
|
+
!commandAuth &&
|
|
801
|
+
providerConfiguration !== undefined &&
|
|
802
|
+
providerKeyConfigured) {
|
|
803
|
+
if (providerEnvKey !== undefined) {
|
|
804
|
+
selected = Object.fromEntries(Object.entries(selected).filter(([name]) => process.platform === "win32"
|
|
805
|
+
? name.toUpperCase() !== providerEnvKey.toUpperCase()
|
|
806
|
+
: name !== providerEnvKey));
|
|
807
|
+
}
|
|
808
|
+
// Native provider keys take precedence over stored authentication.
|
|
809
|
+
// Apply explicit ChatGPT selection to the home and CLI configuration.
|
|
810
|
+
const providerOverrides = typeof provider === "string"
|
|
811
|
+
? overrides["model_providers"]?.[provider]
|
|
812
|
+
: undefined;
|
|
813
|
+
for (const selectedConfig of [
|
|
814
|
+
providerConfiguration,
|
|
815
|
+
providerOverrides,
|
|
816
|
+
]) {
|
|
817
|
+
if (selectedConfig === undefined)
|
|
818
|
+
continue;
|
|
819
|
+
delete selectedConfig["env_key"];
|
|
820
|
+
delete selectedConfig["experimental_bearer_token"];
|
|
821
|
+
selectedConfig["requires_openai_auth"] = true;
|
|
822
|
+
}
|
|
823
|
+
args = [
|
|
824
|
+
...args,
|
|
825
|
+
...modelProviderConfigOverride(overrides).flatMap((value) => [
|
|
826
|
+
"--config",
|
|
827
|
+
value,
|
|
828
|
+
]),
|
|
829
|
+
];
|
|
830
|
+
}
|
|
828
831
|
if (authentication.method === "stored_credentials" &&
|
|
829
832
|
requiresOpenAiAuth) {
|
|
830
833
|
const directory = await realpath(output.directory ?? output.appServer?.directory ?? process.cwd());
|
|
@@ -892,6 +895,12 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
892
895
|
];
|
|
893
896
|
}
|
|
894
897
|
}
|
|
898
|
+
if (authentication.method === "api_key" && providerEnvKey !== undefined) {
|
|
899
|
+
const providerKey = environmentEntry(processEnvironment, providerEnvKey);
|
|
900
|
+
if (providerKey !== undefined) {
|
|
901
|
+
selected = { ...selected, [providerEnvKey]: providerKey };
|
|
902
|
+
}
|
|
903
|
+
}
|
|
895
904
|
if (output.appServer === undefined) {
|
|
896
905
|
const authConfig = credentialConfig ?? (await readCodexHomeConfig(selected));
|
|
897
906
|
args = [
|
|
@@ -1056,60 +1065,6 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
1056
1065
|
await releaseCredentialHome?.();
|
|
1057
1066
|
}
|
|
1058
1067
|
}
|
|
1059
|
-
async function writeCliOutput(output, value) {
|
|
1060
|
-
const destination = new NodeWritable({
|
|
1061
|
-
write(chunk, _encoding, callback) {
|
|
1062
|
-
try {
|
|
1063
|
-
if (output instanceof NodeWritable) {
|
|
1064
|
-
output.write(chunk, callback);
|
|
1065
|
-
}
|
|
1066
|
-
else if (output.write(chunk)) {
|
|
1067
|
-
callback();
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
callback(new CodexSecurityError("The export stdout stream cannot report backpressure safely."));
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
catch (error) {
|
|
1074
|
-
callback(error instanceof Error ? error : new Error(String(error)));
|
|
1075
|
-
}
|
|
1076
|
-
},
|
|
1077
|
-
});
|
|
1078
|
-
const forwardError = (error) => {
|
|
1079
|
-
destination.destroy(error);
|
|
1080
|
-
};
|
|
1081
|
-
if (output instanceof NodeWritable)
|
|
1082
|
-
output.once("error", forwardError);
|
|
1083
|
-
try {
|
|
1084
|
-
await pipeline(typeof value === "string" || value instanceof Uint8Array
|
|
1085
|
-
? [value]
|
|
1086
|
-
: value, destination);
|
|
1087
|
-
}
|
|
1088
|
-
finally {
|
|
1089
|
-
if (output instanceof NodeWritable) {
|
|
1090
|
-
output.removeListener("error", forwardError);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
export function exportEnvironment(environment = process.env) {
|
|
1095
|
-
return pythonUtf8Environment(Object.fromEntries([
|
|
1096
|
-
"PATH",
|
|
1097
|
-
"Path",
|
|
1098
|
-
"PATHEXT",
|
|
1099
|
-
"SystemRoot",
|
|
1100
|
-
"SYSTEMROOT",
|
|
1101
|
-
"WINDIR",
|
|
1102
|
-
"TMP",
|
|
1103
|
-
"TEMP",
|
|
1104
|
-
"TMPDIR",
|
|
1105
|
-
"PYTHON",
|
|
1106
|
-
"LANG",
|
|
1107
|
-
"LC_ALL",
|
|
1108
|
-
"LC_CTYPE",
|
|
1109
|
-
]
|
|
1110
|
-
.filter((key) => environment[key] !== undefined)
|
|
1111
|
-
.map((key) => [key, environment[key]])));
|
|
1112
|
-
}
|
|
1113
1068
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
1114
1069
|
if (argv[0] === "dedupe" &&
|
|
1115
1070
|
argv.includes("--records") &&
|
|
@@ -1121,10 +1076,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1121
1076
|
return 2;
|
|
1122
1077
|
}
|
|
1123
1078
|
const controller = new AbortController();
|
|
1124
|
-
const
|
|
1125
|
-
const terminate = () => controller.abort("SIGTERM");
|
|
1126
|
-
dependencies.addSignalListener("SIGINT", interrupt);
|
|
1127
|
-
dependencies.addSignalListener("SIGTERM", terminate);
|
|
1079
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
1128
1080
|
let exitCode;
|
|
1129
1081
|
try {
|
|
1130
1082
|
const code = await runRecordsProtocol(dependencies.recordsInput ?? process.stdin, output, controller.signal);
|
|
@@ -1136,8 +1088,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1136
1088
|
: code;
|
|
1137
1089
|
}
|
|
1138
1090
|
finally {
|
|
1139
|
-
|
|
1140
|
-
dependencies.removeSignalListener("SIGTERM", terminate);
|
|
1091
|
+
removeSignals();
|
|
1141
1092
|
}
|
|
1142
1093
|
// Protocol writes have flushed or been canceled. Node's stdout ignores destroy().
|
|
1143
1094
|
if (output === process.stdout)
|
|
@@ -1172,7 +1123,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1172
1123
|
: undefined;
|
|
1173
1124
|
let exitCode = 0;
|
|
1174
1125
|
let frameworkExit;
|
|
1175
|
-
|
|
1126
|
+
const frameworkCapture = captureOutput();
|
|
1176
1127
|
let streamedLogs;
|
|
1177
1128
|
let renderedHistory;
|
|
1178
1129
|
let renderedPublication;
|
|
@@ -1181,9 +1132,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1181
1132
|
let patchStructuredError = false;
|
|
1182
1133
|
let scanStructuredError = false;
|
|
1183
1134
|
const runImport = (options) => runScanImport(options, errorOutput, dependencies);
|
|
1184
|
-
const history = async (args, select = (value) => value) => {
|
|
1135
|
+
const history = async (args, select = (value) => value, pythonPath) => {
|
|
1185
1136
|
try {
|
|
1186
|
-
return await select(await dependencies.runWorkbench(args));
|
|
1137
|
+
return await select(await dependencies.runWorkbench(args, undefined, undefined, pythonPath));
|
|
1187
1138
|
}
|
|
1188
1139
|
catch (error) {
|
|
1189
1140
|
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
@@ -1191,7 +1142,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1191
1142
|
throw error;
|
|
1192
1143
|
}
|
|
1193
1144
|
};
|
|
1194
|
-
const latestScans = async (count = 1, status = "complete") => {
|
|
1145
|
+
const latestScans = async (count = 1, status = "complete", pythonPath) => {
|
|
1195
1146
|
const result = await history([
|
|
1196
1147
|
"list-scans",
|
|
1197
1148
|
"--repository",
|
|
@@ -1207,10 +1158,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1207
1158
|
: `At least ${count} ${kind} scans are required for the current repository.`);
|
|
1208
1159
|
}
|
|
1209
1160
|
return value;
|
|
1210
|
-
});
|
|
1161
|
+
}, pythonPath);
|
|
1211
1162
|
return result?.["scans"];
|
|
1212
1163
|
};
|
|
1213
|
-
const runMatching = async (operation) => {
|
|
1164
|
+
const runMatching = async (operation, selection) => {
|
|
1214
1165
|
const controller = new AbortController();
|
|
1215
1166
|
let firstSignalAt = 0;
|
|
1216
1167
|
const cancel = (signal) => {
|
|
@@ -1230,14 +1181,16 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1230
1181
|
const onInterrupt = () => cancel("SIGINT");
|
|
1231
1182
|
const onTerminate = () => cancel("SIGTERM");
|
|
1232
1183
|
const removeListeners = () => {
|
|
1233
|
-
dependencies
|
|
1234
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
1184
|
+
signalHandlers(dependencies, "remove", onInterrupt, onTerminate);
|
|
1235
1185
|
};
|
|
1236
|
-
dependencies
|
|
1237
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
1186
|
+
signalHandlers(dependencies, "add", onInterrupt, onTerminate);
|
|
1238
1187
|
let previousProgress = "";
|
|
1239
1188
|
try {
|
|
1240
1189
|
const result = await operation({
|
|
1190
|
+
...(selection.model === undefined ? {} : { model: selection.model }),
|
|
1191
|
+
...(selection.effort === undefined
|
|
1192
|
+
? {}
|
|
1193
|
+
: { reasoningEffort: selection.effort }),
|
|
1241
1194
|
environment: dependencies.environment,
|
|
1242
1195
|
workingDirectory: dependencies.currentDirectory(),
|
|
1243
1196
|
signal: controller.signal,
|
|
@@ -1258,8 +1211,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1258
1211
|
}
|
|
1259
1212
|
catch (error) {
|
|
1260
1213
|
const interrupted = controller.signal.reason;
|
|
1261
|
-
exitCode =
|
|
1262
|
-
interrupted === "SIGINT" ? 130 : interrupted === "SIGTERM" ? 143 : 2;
|
|
1214
|
+
exitCode = interruptedExitCode(controller.signal) ?? 2;
|
|
1263
1215
|
const message = interrupted === "SIGINT"
|
|
1264
1216
|
? "Finding matching canceled by Ctrl-C. Saved comparisons are preserved."
|
|
1265
1217
|
: interrupted === "SIGTERM"
|
|
@@ -1272,7 +1224,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1272
1224
|
removeListeners();
|
|
1273
1225
|
}
|
|
1274
1226
|
};
|
|
1275
|
-
const matchScanPair = async (beforeId, afterId,
|
|
1227
|
+
const matchScanPair = async (beforeId, afterId, selection) => runMatching(async (options) => {
|
|
1276
1228
|
const { matchingCached, matchingInputs, ...comparison } = await dependencies.runWorkbench([
|
|
1277
1229
|
"compare-scans",
|
|
1278
1230
|
"--before-scan-id",
|
|
@@ -1281,7 +1233,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1281
1233
|
afterId,
|
|
1282
1234
|
"--include-matching-inputs",
|
|
1283
1235
|
], undefined, options.signal);
|
|
1284
|
-
if (matchingCached && !force)
|
|
1236
|
+
if (matchingCached && !selection.force)
|
|
1285
1237
|
return comparison;
|
|
1286
1238
|
const input = matchingInputs;
|
|
1287
1239
|
const matching = await dependencies.matchFindings(input, options);
|
|
@@ -1294,7 +1246,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1294
1246
|
afterId,
|
|
1295
1247
|
"--matches-json-stdin",
|
|
1296
1248
|
], JSON.stringify(matching), options.signal);
|
|
1297
|
-
});
|
|
1249
|
+
}, selection);
|
|
1298
1250
|
const presentHistory = (result, command, format, settings = {}) => {
|
|
1299
1251
|
if (result === undefined ||
|
|
1300
1252
|
format !== "toon" ||
|
|
@@ -1314,7 +1266,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1314
1266
|
return result;
|
|
1315
1267
|
};
|
|
1316
1268
|
const findingFeedback = Cli.create("findings", {
|
|
1317
|
-
description: "Review
|
|
1269
|
+
description: "Review saved findings (default: list).",
|
|
1318
1270
|
}).command("false-positive", {
|
|
1319
1271
|
description: "Mark a finding as a false positive for future scans.",
|
|
1320
1272
|
destructive: true,
|
|
@@ -1372,7 +1324,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1372
1324
|
},
|
|
1373
1325
|
});
|
|
1374
1326
|
const scanHistory = Cli.create("scans", {
|
|
1375
|
-
description: "
|
|
1327
|
+
description: "Review saved scans (default: list).",
|
|
1376
1328
|
})
|
|
1377
1329
|
.command("list", {
|
|
1378
1330
|
description: "List saved scans for a repository or scan root.",
|
|
@@ -1426,6 +1378,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1426
1378
|
.default(false)
|
|
1427
1379
|
.describe("Show findings linked across previous scans."),
|
|
1428
1380
|
}),
|
|
1381
|
+
examples: [
|
|
1382
|
+
{ args: {}, description: "Show the latest completed scan." },
|
|
1383
|
+
{
|
|
1384
|
+
args: { scanId: "scan_abc123" },
|
|
1385
|
+
description: "Show a saved scan by ID or unique prefix.",
|
|
1386
|
+
},
|
|
1387
|
+
],
|
|
1429
1388
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1430
1389
|
async run({ args, format, options }) {
|
|
1431
1390
|
const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;
|
|
@@ -1451,6 +1410,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1451
1410
|
.optional()
|
|
1452
1411
|
.describe("Scan identifier or unique prefix (default: latest)."),
|
|
1453
1412
|
}),
|
|
1413
|
+
examples: [
|
|
1414
|
+
{ args: {}, description: "Show activity from the latest scan." },
|
|
1415
|
+
{
|
|
1416
|
+
args: { scanId: "scan_abc123" },
|
|
1417
|
+
description: "Show activity from a saved scan.",
|
|
1418
|
+
},
|
|
1419
|
+
],
|
|
1454
1420
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1455
1421
|
async run({ args, format }) {
|
|
1456
1422
|
const scanId = args.scanId ?? (await latestScans(1, "any"))?.[0]?.scanId;
|
|
@@ -1480,7 +1446,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1480
1446
|
verbose: z
|
|
1481
1447
|
.boolean()
|
|
1482
1448
|
.default(false)
|
|
1483
|
-
.describe("Print scan diagnostics to stderr."),
|
|
1449
|
+
.describe("Print additional scan diagnostics to stderr."),
|
|
1484
1450
|
}),
|
|
1485
1451
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1486
1452
|
async run({ args, error: incurError, options }) {
|
|
@@ -1552,10 +1518,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1552
1518
|
verbose: z
|
|
1553
1519
|
.boolean()
|
|
1554
1520
|
.default(false)
|
|
1555
|
-
.describe("Print scan diagnostics to stderr."),
|
|
1521
|
+
.describe("Print additional scan diagnostics to stderr."),
|
|
1556
1522
|
}),
|
|
1557
1523
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1558
|
-
async run({ args, error: incurError, options }) {
|
|
1524
|
+
async run({ args, error: incurError, format, options }) {
|
|
1525
|
+
if (format === "md") {
|
|
1526
|
+
errorOutput.write("codex-security: Markdown output is not supported for scan results.\n");
|
|
1527
|
+
exitCode = 2;
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1559
1530
|
const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;
|
|
1560
1531
|
if (scanId === undefined)
|
|
1561
1532
|
return;
|
|
@@ -1566,8 +1537,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1566
1537
|
"--scan-id",
|
|
1567
1538
|
scanId,
|
|
1568
1539
|
]);
|
|
1569
|
-
if (recipe
|
|
1570
|
-
isJsonObject(recipe) &&
|
|
1540
|
+
if (isJsonObject(recipe) &&
|
|
1571
1541
|
recipe["import"] !== undefined &&
|
|
1572
1542
|
isJsonObject(recipe["import"])) {
|
|
1573
1543
|
if (options.validationPromptFile !== undefined ||
|
|
@@ -1580,8 +1550,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1580
1550
|
const imported = recipe["import"];
|
|
1581
1551
|
const sourcePath = imported["sourcePath"];
|
|
1582
1552
|
const format = imported["format"];
|
|
1583
|
-
if (
|
|
1584
|
-
sourcePath.length === 0 ||
|
|
1553
|
+
if (!isNonEmptyString(sourcePath) ||
|
|
1585
1554
|
(format !== "csv" && format !== "json")) {
|
|
1586
1555
|
throw new CodexSecurityError("The saved scan recipe contains invalid import settings.");
|
|
1587
1556
|
}
|
|
@@ -1621,7 +1590,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1621
1590
|
exitCode,
|
|
1622
1591
|
});
|
|
1623
1592
|
}
|
|
1624
|
-
const outcome = await runScan(scanArguments, errorOutput, dependencies);
|
|
1593
|
+
const outcome = await runScan(scanArguments, errorOutput, dependencies, format !== "json" && format !== "jsonl");
|
|
1625
1594
|
exitCode = outcome.exitCode;
|
|
1626
1595
|
if (outcome.error !== undefined) {
|
|
1627
1596
|
return incurError({
|
|
@@ -1658,13 +1627,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1658
1627
|
.boolean()
|
|
1659
1628
|
.default(false)
|
|
1660
1629
|
.describe("Recompute an existing semantic finding comparison."),
|
|
1630
|
+
...MATCHING_MODEL_OPTIONS.shape,
|
|
1661
1631
|
}),
|
|
1662
1632
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1663
1633
|
async run({ args, format, options }) {
|
|
1664
1634
|
if (options.all) {
|
|
1665
|
-
return presentHistory(await runMatching((matchingOptions) => matchAllScans(dependencies, options.force, matchingOptions)), "match-all", format);
|
|
1635
|
+
return presentHistory(await runMatching((matchingOptions) => matchAllScans(dependencies, options.force, matchingOptions), options), "match-all", format);
|
|
1666
1636
|
}
|
|
1667
|
-
return presentHistory(await matchScanPair(args.beforeId, args.afterId, options
|
|
1637
|
+
return presentHistory(await matchScanPair(args.beforeId, args.afterId, options), "compare", format);
|
|
1668
1638
|
},
|
|
1669
1639
|
})
|
|
1670
1640
|
.command("compare", {
|
|
@@ -1683,8 +1653,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1683
1653
|
.optional()
|
|
1684
1654
|
.describe("Later saved scan identifier (default: latest completed)."),
|
|
1685
1655
|
}),
|
|
1656
|
+
options: MATCHING_MODEL_OPTIONS,
|
|
1686
1657
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1687
|
-
async run({ args, format }) {
|
|
1658
|
+
async run({ args, format, options }) {
|
|
1688
1659
|
let { beforeId, afterId } = args;
|
|
1689
1660
|
if (beforeId === undefined) {
|
|
1690
1661
|
const scans = await latestScans(2);
|
|
@@ -1698,7 +1669,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1698
1669
|
if (afterId === undefined)
|
|
1699
1670
|
return;
|
|
1700
1671
|
}
|
|
1701
|
-
return presentHistory(await matchScanPair(beforeId, afterId), "compare", format);
|
|
1672
|
+
return presentHistory(await matchScanPair(beforeId, afterId, options), "compare", format);
|
|
1702
1673
|
},
|
|
1703
1674
|
});
|
|
1704
1675
|
const reportPublicationError = (error, signal) => {
|
|
@@ -1706,7 +1677,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1706
1677
|
const reason = signal === "SIGINT"
|
|
1707
1678
|
? "Publication canceled by Ctrl-C."
|
|
1708
1679
|
: "Publication terminated by SIGTERM.";
|
|
1709
|
-
const recovery = error === signal ? "" : ` ${diagnosticValue(
|
|
1680
|
+
const recovery = error === signal ? "" : ` ${diagnosticValue(error)}`;
|
|
1710
1681
|
errorOutput.write(`codex-security: ${reason}${recovery}\n`);
|
|
1711
1682
|
exitCode = signal === "SIGINT" ? 130 : 143;
|
|
1712
1683
|
}
|
|
@@ -1718,7 +1689,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1718
1689
|
const publication = Cli.create("publish", {
|
|
1719
1690
|
description: "Publish Codex Security findings.",
|
|
1720
1691
|
}).command("scan", {
|
|
1721
|
-
description: "Publish findings from a completed scan or CSV.",
|
|
1692
|
+
description: "Publish findings from a completed scan, or a CSV for internal publication.",
|
|
1693
|
+
hint: "Examples:\n" +
|
|
1694
|
+
" codex-security publish scan --to linear --scan latest --linear-team TEAM_ID --dry-run\n" +
|
|
1695
|
+
" codex-security publish scan --to custom --scan latest --findings-url http://localhost:3000",
|
|
1722
1696
|
destructive: true,
|
|
1723
1697
|
mcp: false,
|
|
1724
1698
|
args: z.object({
|
|
@@ -1749,7 +1723,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1749
1723
|
.refine((value) => value === "linear" || value === "cloud" || value === "custom", {
|
|
1750
1724
|
message: "Unsupported publication destination. Use --to linear or --to custom.",
|
|
1751
1725
|
})
|
|
1752
|
-
.describe("
|
|
1726
|
+
.describe("Required publication destination: linear or custom."),
|
|
1753
1727
|
findingsUrl: optionValue("--findings-url")
|
|
1754
1728
|
.url()
|
|
1755
1729
|
.optional()
|
|
@@ -1760,7 +1734,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1760
1734
|
.describe("Preview the findings without publishing them."),
|
|
1761
1735
|
csv: optionValue("--csv")
|
|
1762
1736
|
.optional()
|
|
1763
|
-
.describe("Findings CSV
|
|
1737
|
+
.describe("Findings CSV for internal publication; not supported with linear or custom."),
|
|
1764
1738
|
skipExisting: z
|
|
1765
1739
|
.boolean()
|
|
1766
1740
|
.default(false)
|
|
@@ -1803,7 +1777,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1803
1777
|
: "Publication terminated by SIGTERM.";
|
|
1804
1778
|
const recovery = error === undefined || error === signal
|
|
1805
1779
|
? ""
|
|
1806
|
-
: ` ${diagnosticValue(
|
|
1780
|
+
: ` ${diagnosticValue(error)}`;
|
|
1807
1781
|
errorOutput.write(`codex-security: ${reason}${recovery}\n`);
|
|
1808
1782
|
exitCode = signal === "SIGINT" ? 130 : 143;
|
|
1809
1783
|
return true;
|
|
@@ -1813,8 +1787,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1813
1787
|
const removeSignalListeners = () => {
|
|
1814
1788
|
if (!observingSignals)
|
|
1815
1789
|
return;
|
|
1816
|
-
dependencies
|
|
1817
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
1790
|
+
signalHandlers(dependencies, "remove", onInterrupt, onTerminate);
|
|
1818
1791
|
observingSignals = false;
|
|
1819
1792
|
};
|
|
1820
1793
|
try {
|
|
@@ -1873,8 +1846,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1873
1846
|
? publicationDestination({ ...options, to: "linear" }, dependencies.environment)
|
|
1874
1847
|
: undefined;
|
|
1875
1848
|
if (options.to !== "linear") {
|
|
1876
|
-
dependencies
|
|
1877
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
1849
|
+
signalHandlers(dependencies, "add", onInterrupt, onTerminate);
|
|
1878
1850
|
observingSignals = true;
|
|
1879
1851
|
}
|
|
1880
1852
|
if (csvPath !== undefined) {
|
|
@@ -1899,12 +1871,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1899
1871
|
let scanDir = selectedScans[0]?.scanDir;
|
|
1900
1872
|
let publicationRepository = scanDir === undefined ? "scan" : basename(scanDir);
|
|
1901
1873
|
if (scanDir === undefined) {
|
|
1902
|
-
const prompt = dependencies.publishPrompt ??
|
|
1903
|
-
createBulkScanDiscoveryDependencies({
|
|
1904
|
-
output: errorOutput,
|
|
1905
|
-
now: dependencies.now,
|
|
1906
|
-
currentDirectory: dependencies.currentDirectory,
|
|
1907
|
-
}).prompt;
|
|
1874
|
+
const prompt = dependencies.publishPrompt ?? createTerminalPrompt(errorOutput);
|
|
1908
1875
|
if (!prompt.isInteractive()) {
|
|
1909
1876
|
throw new CodexSecurityError(`Interactive scan selection requires a terminal. Select a saved scan: codex-security publish scan --scan SCAN_ID --to ${options.to}${options.to === "linear" ? " --linear-team TEAM_ID" : ""}.`);
|
|
1910
1877
|
}
|
|
@@ -1921,14 +1888,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1921
1888
|
if (!isJsonObject(scan))
|
|
1922
1889
|
return undefined;
|
|
1923
1890
|
const directory = scan["scanDir"];
|
|
1924
|
-
if (
|
|
1891
|
+
if (!isNonEmptyString(directory)) {
|
|
1925
1892
|
return undefined;
|
|
1926
1893
|
}
|
|
1927
1894
|
const metadata = await lstat(resolveCliPath(currentDirectory, directory)).catch(() => undefined);
|
|
1928
|
-
return metadata?.isDirectory() === true
|
|
1929
|
-
!metadata.isSymbolicLink()
|
|
1930
|
-
? scan
|
|
1931
|
-
: undefined;
|
|
1895
|
+
return metadata?.isDirectory() === true ? scan : undefined;
|
|
1932
1896
|
}))).filter((scan) => scan !== undefined);
|
|
1933
1897
|
const now = dependencies.now();
|
|
1934
1898
|
const emphasizeRepository = errorOutput.isTTY === true &&
|
|
@@ -1942,11 +1906,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1942
1906
|
const progress = scan["progress"];
|
|
1943
1907
|
const scanId = scan["scanId"];
|
|
1944
1908
|
const directory = scan["scanDir"];
|
|
1945
|
-
if (
|
|
1946
|
-
|
|
1947
|
-
typeof directory !== "string" ||
|
|
1948
|
-
directory.length === 0 ||
|
|
1949
|
-
progress === undefined ||
|
|
1909
|
+
if (!isNonEmptyString(scanId) ||
|
|
1910
|
+
!isNonEmptyString(directory) ||
|
|
1950
1911
|
!isJsonObject(progress) ||
|
|
1951
1912
|
progress["status"] !== "complete") {
|
|
1952
1913
|
return [];
|
|
@@ -2080,7 +2041,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2080
2041
|
cloudBatch.results.push({ scanDir: directory, ...result });
|
|
2081
2042
|
}
|
|
2082
2043
|
catch (error) {
|
|
2083
|
-
const message =
|
|
2044
|
+
const message = errorMessage(error);
|
|
2084
2045
|
cloudBatch.failed.push({
|
|
2085
2046
|
scanDir: directory,
|
|
2086
2047
|
...(scanId === undefined ? {} : { scanId }),
|
|
@@ -2089,7 +2050,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2089
2050
|
if (controller.signal.aborted)
|
|
2090
2051
|
throw error;
|
|
2091
2052
|
exitCode = 2;
|
|
2092
|
-
errorOutput.write(`codex-security: ${diagnosticValue(
|
|
2053
|
+
errorOutput.write(`codex-security: ${diagnosticValue(scanId ?? directory)}: ${diagnosticValue(message)}\n`);
|
|
2093
2054
|
}
|
|
2094
2055
|
}
|
|
2095
2056
|
return cloudBatch;
|
|
@@ -2121,8 +2082,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2121
2082
|
}
|
|
2122
2083
|
const progress = new PublicationProgressPresenter(errorOutput, dependencies, publicationRepository);
|
|
2123
2084
|
presentation = progress;
|
|
2124
|
-
dependencies
|
|
2125
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2085
|
+
signalHandlers(dependencies, "add", onInterrupt, onTerminate);
|
|
2126
2086
|
observingSignals = true;
|
|
2127
2087
|
if (!options.dryRun) {
|
|
2128
2088
|
progress.start();
|
|
@@ -2157,7 +2117,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2157
2117
|
for (const warning of result.warnings) {
|
|
2158
2118
|
if (typeof warning !== "string")
|
|
2159
2119
|
continue;
|
|
2160
|
-
errorOutput.write(`codex-security: ${diagnosticValue(
|
|
2120
|
+
errorOutput.write(`codex-security: ${diagnosticValue(warning)}\n`);
|
|
2161
2121
|
}
|
|
2162
2122
|
}
|
|
2163
2123
|
if (format === "toon" &&
|
|
@@ -2172,7 +2132,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2172
2132
|
}
|
|
2173
2133
|
catch (error) {
|
|
2174
2134
|
if (!finishCancellation(error)) {
|
|
2175
|
-
errorOutput.write(`codex-security: ${
|
|
2135
|
+
errorOutput.write(`codex-security: ${diagnosticValue(error)}\n`);
|
|
2176
2136
|
exitCode = 2;
|
|
2177
2137
|
}
|
|
2178
2138
|
return cloudBatch;
|
|
@@ -2192,10 +2152,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2192
2152
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
2193
2153
|
async run({ args, options }) {
|
|
2194
2154
|
const controller = new AbortController();
|
|
2195
|
-
const
|
|
2196
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
2197
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2198
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2155
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2199
2156
|
try {
|
|
2200
2157
|
const result = await (dependencies.checkScanPublication ?? checkScanPublication)(resolve(dependencies.currentDirectory(), args.scanDir), {
|
|
2201
2158
|
...publicationDestination(options, dependencies.environment),
|
|
@@ -2209,15 +2166,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2209
2166
|
return undefined;
|
|
2210
2167
|
}
|
|
2211
2168
|
finally {
|
|
2212
|
-
|
|
2213
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2169
|
+
removeSignals();
|
|
2214
2170
|
}
|
|
2215
2171
|
},
|
|
2216
2172
|
});
|
|
2217
2173
|
const imports = Cli.create("import", {
|
|
2218
|
-
description: "Read
|
|
2174
|
+
description: "Read GitHub code scanning alerts.",
|
|
2219
2175
|
}).command("github", {
|
|
2220
|
-
description: "
|
|
2176
|
+
description: "Read GitHub code scanning alerts without changing GitHub.",
|
|
2177
|
+
hint: "To save CSV or JSON findings as a local scan, use codex-security scan import --help.",
|
|
2221
2178
|
destructive: false,
|
|
2222
2179
|
mcp: false,
|
|
2223
2180
|
args: z.object({
|
|
@@ -2250,10 +2207,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2250
2207
|
.optional(),
|
|
2251
2208
|
async run({ args, options }) {
|
|
2252
2209
|
const controller = new AbortController();
|
|
2253
|
-
const
|
|
2254
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
2255
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2256
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2210
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2257
2211
|
try {
|
|
2258
2212
|
return await (dependencies.importGitHubAlerts ?? importGitHubCodeScanningAlerts)({
|
|
2259
2213
|
repository: args.repository,
|
|
@@ -2274,18 +2228,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2274
2228
|
}
|
|
2275
2229
|
else {
|
|
2276
2230
|
exitCode = 2;
|
|
2277
|
-
errorOutput.write(`codex-security: ${
|
|
2231
|
+
errorOutput.write(`codex-security: ${diagnosticValue(error)}\n`);
|
|
2278
2232
|
}
|
|
2279
2233
|
return undefined;
|
|
2280
2234
|
}
|
|
2281
2235
|
finally {
|
|
2282
|
-
|
|
2283
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2236
|
+
removeSignals();
|
|
2284
2237
|
}
|
|
2285
2238
|
},
|
|
2286
2239
|
});
|
|
2287
2240
|
const cli = Cli.create("codex-security", {
|
|
2288
|
-
description: "
|
|
2241
|
+
description: "Find, review, and fix security issues in your code.",
|
|
2289
2242
|
version: VERSION,
|
|
2290
2243
|
mcp: {
|
|
2291
2244
|
command: "npx --yes @openai/codex-security --mcp",
|
|
@@ -2294,7 +2247,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2294
2247
|
},
|
|
2295
2248
|
})
|
|
2296
2249
|
.command("policy", {
|
|
2297
|
-
description: "Draft SECURITY.md guidance for
|
|
2250
|
+
description: "Draft SECURITY.md guidance for review.",
|
|
2298
2251
|
destructive: true,
|
|
2299
2252
|
mcp: false,
|
|
2300
2253
|
args: z.object({
|
|
@@ -2325,27 +2278,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2325
2278
|
auth: z
|
|
2326
2279
|
.enum(["auto", "chatgpt", "api-key"])
|
|
2327
2280
|
.default("auto")
|
|
2328
|
-
.describe("Select ChatGPT,
|
|
2329
|
-
|
|
2330
|
-
.optional()
|
|
2331
|
-
.describe(`Model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
2332
|
-
effort: effortOption(),
|
|
2281
|
+
.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication."),
|
|
2282
|
+
...MODEL_OPTIONS.shape,
|
|
2333
2283
|
provider: PROVIDER_OPTION.describe("Inference provider for policy generation."),
|
|
2334
2284
|
maxCost: z
|
|
2335
2285
|
.number()
|
|
2336
2286
|
.positive()
|
|
2337
2287
|
.optional()
|
|
2338
2288
|
.describe("Stop when estimated total USD cost across all three stages exceeds AMOUNT."),
|
|
2339
|
-
|
|
2340
|
-
.optional()
|
|
2341
|
-
.describe(PLUGIN_PATH_DESCRIPTION),
|
|
2342
|
-
python: optionValue("--python")
|
|
2343
|
-
.optional()
|
|
2344
|
-
.describe(PYTHON_PATH_DESCRIPTION),
|
|
2345
|
-
codex: z
|
|
2346
|
-
.array(optionValue("--codex"))
|
|
2347
|
-
.default([])
|
|
2348
|
-
.describe(CODEX_OVERRIDE_DESCRIPTION),
|
|
2289
|
+
...RUNTIME_OPTION_SCHEMAS,
|
|
2349
2290
|
}),
|
|
2350
2291
|
examples: [
|
|
2351
2292
|
{ args: { repository: "." } },
|
|
@@ -2406,11 +2347,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2406
2347
|
signal,
|
|
2407
2348
|
}, errorOutput, dependencies),
|
|
2408
2349
|
prompt: dependencies.policyPrompt ??
|
|
2409
|
-
|
|
2410
|
-
output: errorOutput,
|
|
2411
|
-
now: dependencies.now,
|
|
2412
|
-
currentDirectory: dependencies.currentDirectory,
|
|
2413
|
-
}).prompt,
|
|
2350
|
+
createTerminalPrompt(errorOutput),
|
|
2414
2351
|
environment: dependencies.environment,
|
|
2415
2352
|
errorOutput,
|
|
2416
2353
|
now: dependencies.now,
|
|
@@ -2436,9 +2373,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2436
2373
|
: outcome.data;
|
|
2437
2374
|
}
|
|
2438
2375
|
catch (error) {
|
|
2439
|
-
const message =
|
|
2376
|
+
const message = errorMessage(error);
|
|
2440
2377
|
try {
|
|
2441
|
-
errorOutput.write(`codex-security: ${message}\n`);
|
|
2378
|
+
errorOutput.write(`codex-security: ${diagnosticValue(message)}\n`);
|
|
2442
2379
|
}
|
|
2443
2380
|
catch { }
|
|
2444
2381
|
return fail(message, 2);
|
|
@@ -2446,8 +2383,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2446
2383
|
},
|
|
2447
2384
|
})
|
|
2448
2385
|
.command("scan", {
|
|
2449
|
-
description: "
|
|
2450
|
-
hint: "
|
|
2386
|
+
description: "Scan a repository, selected paths, or Git changes.",
|
|
2387
|
+
hint: "Examples:\n" +
|
|
2388
|
+
" codex-security scan .\n" +
|
|
2389
|
+
" codex-security scan . --path src --path tests\n" +
|
|
2390
|
+
" codex-security scan . --working-tree\n" +
|
|
2391
|
+
" codex-security scan . --diff origin/main\n" +
|
|
2392
|
+
" codex-security scan . --mode deep\n\n" +
|
|
2393
|
+
"Import existing findings without security analysis:\n" +
|
|
2451
2394
|
" codex-security scan import --csv findings.csv\n" +
|
|
2452
2395
|
" codex-security scan import --json findings.json\n" +
|
|
2453
2396
|
"Use ./import to scan a repository named import.",
|
|
@@ -2466,11 +2409,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2466
2409
|
workflowId: optionValue("--workflow-id")
|
|
2467
2410
|
.optional()
|
|
2468
2411
|
.describe("Reuse completed work in the named local findings workflow."),
|
|
2412
|
+
cyberAccessProgram: ScanSettingsSchema.shape.cyberAccessProgram,
|
|
2469
2413
|
auth: ScanSettingsSchema.shape.auth.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication (default: auto)."),
|
|
2470
2414
|
verbose: z
|
|
2471
2415
|
.boolean()
|
|
2472
2416
|
.default(false)
|
|
2473
|
-
.describe("Print scan diagnostics to stderr."),
|
|
2417
|
+
.describe("Print additional scan diagnostics to stderr."),
|
|
2474
2418
|
safetyIdentifier: optionValue("--safety-identifier")
|
|
2475
2419
|
.optional()
|
|
2476
2420
|
.describe("Stable hashed end-user ID for this scan's model requests (1–64 characters)."),
|
|
@@ -2509,10 +2453,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2509
2453
|
.describe("Git base ref for --working-tree (default: HEAD)."),
|
|
2510
2454
|
mode: ScanSettingsSchema.shape.mode.describe("Scan mode (default: standard); deep supports repository and path targets."),
|
|
2511
2455
|
...DEEP_SCAN_OPTION_SCHEMAS,
|
|
2512
|
-
model:
|
|
2513
|
-
.optional()
|
|
2514
|
-
.describe(`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
2515
|
-
effort: effortOption(),
|
|
2456
|
+
...modelOptions(`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`).shape,
|
|
2516
2457
|
provider: PROVIDER_OPTION,
|
|
2517
2458
|
outputDir: optionValue("--output-dir")
|
|
2518
2459
|
.optional()
|
|
@@ -2521,16 +2462,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2521
2462
|
.boolean()
|
|
2522
2463
|
.default(false)
|
|
2523
2464
|
.describe("Archive existing results; requires --output-dir."),
|
|
2524
|
-
|
|
2525
|
-
.optional()
|
|
2526
|
-
.describe(PLUGIN_PATH_DESCRIPTION),
|
|
2527
|
-
python: optionValue("--python")
|
|
2528
|
-
.optional()
|
|
2529
|
-
.describe(PYTHON_PATH_DESCRIPTION),
|
|
2530
|
-
codex: z
|
|
2531
|
-
.array(optionValue("--codex"))
|
|
2532
|
-
.default([])
|
|
2533
|
-
.describe(CODEX_OVERRIDE_DESCRIPTION),
|
|
2465
|
+
...RUNTIME_OPTION_SCHEMAS,
|
|
2534
2466
|
failOnSeverity: FailureSeveritySchema.optional().describe("Exit 1 for findings at or above LEVEL."),
|
|
2535
2467
|
patch: z
|
|
2536
2468
|
.boolean()
|
|
@@ -2540,7 +2472,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2540
2472
|
.enum(REPORTABLE_SEVERITIES)
|
|
2541
2473
|
.optional()
|
|
2542
2474
|
.describe("Patch findings at or above LEVEL; requires --patch."),
|
|
2543
|
-
createPr: CREATE_PR_OPTION,
|
|
2475
|
+
createPr: CREATE_PR_OPTION.describe("Create a draft pull request or merge request after verified patches; requires --patch."),
|
|
2544
2476
|
maxCost: ScanSettingsSchema.shape.maxCostUsd.describe("Stop above AMOUNT in estimated USD; the dashboard offers increases near the limit."),
|
|
2545
2477
|
showCost: SHOW_COST_OPTION,
|
|
2546
2478
|
headless: z
|
|
@@ -2568,28 +2500,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2568
2500
|
.refine((options) => !options.mock || (!options.dryRun && !options.patch), {
|
|
2569
2501
|
message: "--mock cannot be combined with --dry-run or --patch.",
|
|
2570
2502
|
}),
|
|
2571
|
-
examples: [
|
|
2572
|
-
{ args: { repository: "." } },
|
|
2573
|
-
{
|
|
2574
|
-
args: { repository: "." },
|
|
2575
|
-
options: { config: "codex-security.yaml" },
|
|
2576
|
-
},
|
|
2577
|
-
{ args: { repository: "." }, options: { model: "gpt-5.6-terra" } },
|
|
2578
|
-
{
|
|
2579
|
-
args: { repository: "." },
|
|
2580
|
-
options: { model: "gpt-5.6-terra", effort: "high" },
|
|
2581
|
-
},
|
|
2582
|
-
{ args: { repository: "." }, options: { path: ["src"] } },
|
|
2583
|
-
{ args: { repository: "." }, options: { diff: "origin/main" } },
|
|
2584
|
-
{
|
|
2585
|
-
args: { repository: "." },
|
|
2586
|
-
options: {
|
|
2587
|
-
codex: [
|
|
2588
|
-
"features.multi_agent_v2.max_concurrent_threads_per_session=4",
|
|
2589
|
-
],
|
|
2590
|
-
},
|
|
2591
|
-
},
|
|
2592
|
-
],
|
|
2593
2503
|
output: scanOutputSchema,
|
|
2594
2504
|
async run({ args, error: incurError, format, options }) {
|
|
2595
2505
|
if (format === "md") {
|
|
@@ -2609,19 +2519,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2609
2519
|
base: options.base,
|
|
2610
2520
|
});
|
|
2611
2521
|
const { config, options: settings, projectConfig: provenance, } = resolveScanSettings(project, {
|
|
2612
|
-
|
|
2522
|
+
...pickScanSettings(options),
|
|
2613
2523
|
target: scope.target,
|
|
2614
2524
|
knowledgeBasePaths: options.knowledgeBase,
|
|
2615
|
-
scanPromptFile: options.scanPromptFile,
|
|
2616
|
-
validationPromptFile: options.validationPromptFile,
|
|
2617
|
-
postScanPromptFile: options.postScanPromptFile,
|
|
2618
|
-
mode: options.mode,
|
|
2619
|
-
workers: options.workers,
|
|
2620
|
-
subagents: options.subagents,
|
|
2621
|
-
stopAfterNoNew: options.stopAfterNoNew,
|
|
2622
|
-
maxDiscoveryRuns: options.maxDiscoveryRuns,
|
|
2623
|
-
maxTimeHours: options.maxTimeHours,
|
|
2624
|
-
outputDir: options.outputDir,
|
|
2625
2525
|
failureSeverity: options.failOnSeverity,
|
|
2626
2526
|
maxCostUsd: options.maxCost,
|
|
2627
2527
|
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex),
|
|
@@ -2657,7 +2557,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2657
2557
|
exitCode = outcome.exitCode;
|
|
2658
2558
|
if (outcome.error !== undefined) {
|
|
2659
2559
|
if (format === "json" || format === "jsonl") {
|
|
2660
|
-
const message =
|
|
2560
|
+
const message = errorMessage(outcome.error);
|
|
2661
2561
|
if (!argv.includes("--full-output"))
|
|
2662
2562
|
return { status: "failed", code: "SCAN_FAILED", message };
|
|
2663
2563
|
// Incur would wrap returned data in an ok: true envelope.
|
|
@@ -2679,7 +2579,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2679
2579
|
},
|
|
2680
2580
|
})
|
|
2681
2581
|
.command("install-hook", {
|
|
2682
|
-
description: "Install an advisory
|
|
2582
|
+
description: "Install an advisory Git pre-commit check.",
|
|
2583
|
+
hint: "Require a passing scan in CI to enforce a scan before merging.",
|
|
2683
2584
|
destructive: true,
|
|
2684
2585
|
mcp: false,
|
|
2685
2586
|
args: z.object({
|
|
@@ -2747,7 +2648,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2747
2648
|
.command(findingFeedback)
|
|
2748
2649
|
.command(publication)
|
|
2749
2650
|
.command("suggest-owners", {
|
|
2750
|
-
description: "Suggest finding owners from
|
|
2651
|
+
description: "Suggest finding owners from source and Git history.",
|
|
2751
2652
|
destructive: false,
|
|
2752
2653
|
mcp: false,
|
|
2753
2654
|
args: z.object({
|
|
@@ -2760,18 +2661,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2760
2661
|
sourceRoot: optionValue("--source-root")
|
|
2761
2662
|
.optional()
|
|
2762
2663
|
.describe("Local Git repository (default: current directory); analyzes committed HEAD."),
|
|
2763
|
-
|
|
2764
|
-
.optional()
|
|
2765
|
-
.describe("Model for owner suggestions (default: Codex Security model)."),
|
|
2766
|
-
effort: effortOption().describe("Reasoning effort (default: Codex Security effort)."),
|
|
2664
|
+
...modelOptions("Model for owner suggestions (default: Codex Security model).", "Reasoning effort (default: Codex Security effort).").shape,
|
|
2767
2665
|
}),
|
|
2768
2666
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
2769
2667
|
async run({ args, options }) {
|
|
2770
2668
|
const controller = new AbortController();
|
|
2771
|
-
const
|
|
2772
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
2773
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2774
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2669
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2775
2670
|
try {
|
|
2776
2671
|
const directory = dependencies.currentDirectory();
|
|
2777
2672
|
const repository = resolveCliPath(directory, options.sourceRoot ?? ".");
|
|
@@ -2788,18 +2683,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2788
2683
|
}
|
|
2789
2684
|
catch (error) {
|
|
2790
2685
|
const signal = controller.signal.reason;
|
|
2791
|
-
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM" ? "Owner suggestions canceled." :
|
|
2792
|
-
exitCode = signal
|
|
2686
|
+
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM" ? "Owner suggestions canceled." : diagnosticValue(error)}\n`);
|
|
2687
|
+
exitCode = interruptedExitCode(controller.signal) ?? 2;
|
|
2793
2688
|
return undefined;
|
|
2794
2689
|
}
|
|
2795
2690
|
finally {
|
|
2796
|
-
|
|
2797
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2691
|
+
removeSignals();
|
|
2798
2692
|
}
|
|
2799
2693
|
},
|
|
2800
2694
|
})
|
|
2801
2695
|
.command("classify-severity", {
|
|
2802
|
-
description: "
|
|
2696
|
+
description: "Assess severity for saved findings.",
|
|
2697
|
+
hint: "Use --rubric to classify findings with a policy. The assessment is saved separately.",
|
|
2803
2698
|
destructive: true,
|
|
2804
2699
|
mcp: false,
|
|
2805
2700
|
options: z.object({
|
|
@@ -2824,18 +2719,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2824
2719
|
.array(optionValue("--finding-id"))
|
|
2825
2720
|
.default([])
|
|
2826
2721
|
.describe("Classify only this finding ID; repeat to select deduplicated findings."),
|
|
2827
|
-
|
|
2828
|
-
.optional()
|
|
2829
|
-
.describe("Model for rubric classification."),
|
|
2830
|
-
effort: effortOption().describe("Classification reasoning effort (default: medium)."),
|
|
2722
|
+
...modelOptions("Model for rubric classification.", "Classification reasoning effort (default: medium).").shape,
|
|
2831
2723
|
}),
|
|
2832
2724
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
2833
2725
|
async run({ options }) {
|
|
2834
2726
|
const controller = new AbortController();
|
|
2835
|
-
const
|
|
2836
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
2837
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2838
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2727
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2839
2728
|
try {
|
|
2840
2729
|
if ((options.scan === undefined) ===
|
|
2841
2730
|
(options.scanDir === undefined)) {
|
|
@@ -2864,18 +2753,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2864
2753
|
}
|
|
2865
2754
|
catch (error) {
|
|
2866
2755
|
const signal = controller.signal.reason;
|
|
2867
|
-
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM" ? "Severity classification canceled." :
|
|
2868
|
-
exitCode = signal
|
|
2756
|
+
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM" ? "Severity classification canceled." : diagnosticValue(error)}\n`);
|
|
2757
|
+
exitCode = interruptedExitCode(controller.signal) ?? 2;
|
|
2869
2758
|
return undefined;
|
|
2870
2759
|
}
|
|
2871
2760
|
finally {
|
|
2872
|
-
|
|
2873
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2761
|
+
removeSignals();
|
|
2874
2762
|
}
|
|
2875
2763
|
},
|
|
2876
2764
|
})
|
|
2877
2765
|
.command("dedupe", {
|
|
2878
|
-
description: "
|
|
2766
|
+
description: "Identify duplicate findings in a saved scan.",
|
|
2767
|
+
hint: "Use --records alone for host-provided reviews over JSON-RPC.",
|
|
2879
2768
|
destructive: true,
|
|
2880
2769
|
mcp: false,
|
|
2881
2770
|
options: z.object({
|
|
@@ -2926,10 +2815,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2926
2815
|
if (options.records)
|
|
2927
2816
|
throw new CodexSecurityError("Use dedupe --records alone.");
|
|
2928
2817
|
const controller = new AbortController();
|
|
2929
|
-
const
|
|
2930
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
2931
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2932
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2818
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2933
2819
|
try {
|
|
2934
2820
|
if (options.findingsUrl === undefined)
|
|
2935
2821
|
throw new CodexSecurityError("Saved-scan deduplication requires --findings-url.");
|
|
@@ -2967,19 +2853,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2967
2853
|
const signal = controller.signal.reason;
|
|
2968
2854
|
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM"
|
|
2969
2855
|
? "Deduplication canceled. Findings are unchanged."
|
|
2970
|
-
:
|
|
2971
|
-
exitCode = signal
|
|
2856
|
+
: diagnosticValue(error)}\n`);
|
|
2857
|
+
exitCode = interruptedExitCode(controller.signal) ?? 2;
|
|
2972
2858
|
return undefined;
|
|
2973
2859
|
}
|
|
2974
2860
|
finally {
|
|
2975
|
-
|
|
2976
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2861
|
+
removeSignals();
|
|
2977
2862
|
}
|
|
2978
2863
|
},
|
|
2979
2864
|
})
|
|
2980
2865
|
.command(imports)
|
|
2981
2866
|
.command("scan-components", {
|
|
2982
|
-
description: "
|
|
2867
|
+
description: "Scan project components and combine results.",
|
|
2983
2868
|
destructive: true,
|
|
2984
2869
|
mcp: false,
|
|
2985
2870
|
alias: { config: "c" },
|
|
@@ -2993,7 +2878,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2993
2878
|
options: z
|
|
2994
2879
|
.object({
|
|
2995
2880
|
config: PROJECT_CONFIG_OPTION,
|
|
2996
|
-
|
|
2881
|
+
cyberAccessProgram: ScanSettingsSchema.shape.cyberAccessProgram,
|
|
2882
|
+
auth: ScanSettingsSchema.shape.auth.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication (default: auto)."),
|
|
2997
2883
|
component: z
|
|
2998
2884
|
.array(optionValue("--component"))
|
|
2999
2885
|
.default([])
|
|
@@ -3033,10 +2919,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3033
2919
|
postScanPromptFile: optionValue("--post-scan-prompt-file")
|
|
3034
2920
|
.optional()
|
|
3035
2921
|
.describe("Run FILE after each scan, including failures."),
|
|
3036
|
-
|
|
3037
|
-
.optional()
|
|
3038
|
-
.describe("Model for planning and component scans."),
|
|
3039
|
-
effort: effortOption(),
|
|
2922
|
+
...modelOptions("Model for planning and component scans.").shape,
|
|
3040
2923
|
provider: PROVIDER_OPTION,
|
|
3041
2924
|
maxCost: z
|
|
3042
2925
|
.number()
|
|
@@ -3044,16 +2927,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3044
2927
|
.optional()
|
|
3045
2928
|
.describe("Stop each component scan if estimated USD cost exceeds AMOUNT."),
|
|
3046
2929
|
showCost: SHOW_COST_OPTION,
|
|
3047
|
-
|
|
3048
|
-
.optional()
|
|
3049
|
-
.describe(PLUGIN_PATH_DESCRIPTION),
|
|
3050
|
-
python: optionValue("--python")
|
|
3051
|
-
.optional()
|
|
3052
|
-
.describe(PYTHON_PATH_DESCRIPTION),
|
|
3053
|
-
codex: z
|
|
3054
|
-
.array(optionValue("--codex"))
|
|
3055
|
-
.default([])
|
|
3056
|
-
.describe(CODEX_OVERRIDE_DESCRIPTION),
|
|
2930
|
+
...RUNTIME_OPTION_SCHEMAS,
|
|
3057
2931
|
})
|
|
3058
2932
|
.refine((options) => Number(options.component.length > 0) +
|
|
3059
2933
|
Number(options.componentsFile !== undefined) +
|
|
@@ -3074,23 +2948,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3074
2948
|
};
|
|
3075
2949
|
const onInterrupt = () => controller.abort("SIGINT");
|
|
3076
2950
|
const onTerminate = () => controller.abort("SIGTERM");
|
|
3077
|
-
|
|
3078
|
-
? 130
|
|
3079
|
-
: controller.signal.reason === "SIGTERM"
|
|
3080
|
-
? 143
|
|
3081
|
-
: undefined;
|
|
3082
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
3083
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2951
|
+
signalHandlers(dependencies, "add", onInterrupt, onTerminate);
|
|
3084
2952
|
try {
|
|
3085
2953
|
const directory = dependencies.currentDirectory();
|
|
3086
2954
|
const repository = resolveCliPath(directory, args.repository ?? ".");
|
|
3087
2955
|
const project = await selectedProjectConfig(options.config, dependencies);
|
|
3088
2956
|
const resolved = resolveScanSettings(project, {
|
|
3089
|
-
|
|
3090
|
-
outputDir: options.outputDir,
|
|
2957
|
+
...pickScanSettings({ ...options, workers: undefined }),
|
|
3091
2958
|
knowledgeBasePaths: options.knowledgeBase,
|
|
3092
|
-
scanPromptFile: options.scanPromptFile,
|
|
3093
|
-
postScanPromptFile: options.postScanPromptFile,
|
|
3094
2959
|
maxCostUsd: options.maxCost,
|
|
3095
2960
|
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex),
|
|
3096
2961
|
}, directory);
|
|
@@ -3119,7 +2984,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3119
2984
|
showCost: options.showCost,
|
|
3120
2985
|
clock: dependencies,
|
|
3121
2986
|
color: dependencies.environment["NO_COLOR"] === undefined,
|
|
3122
|
-
sanitize: safeErrorMessage,
|
|
3123
2987
|
input: process.stdin,
|
|
3124
2988
|
onInterrupt,
|
|
3125
2989
|
});
|
|
@@ -3175,7 +3039,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3175
3039
|
if (dashboard !== null)
|
|
3176
3040
|
dashboard.updateComponent(component);
|
|
3177
3041
|
else
|
|
3178
|
-
errorOutput.write(`codex-security: ${component.name} ${component.status}${component.error === undefined ? "" : `: ${component.error}`}\n`);
|
|
3042
|
+
errorOutput.write(`codex-security: ${component.name} ${component.status}${component.error === undefined ? "" : `: ${diagnosticValue(component.error)}`}\n`);
|
|
3179
3043
|
},
|
|
3180
3044
|
onComplete: (result) => {
|
|
3181
3045
|
dashboard?.finishComponents(result);
|
|
@@ -3186,7 +3050,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3186
3050
|
},
|
|
3187
3051
|
});
|
|
3188
3052
|
exitCode =
|
|
3189
|
-
interruptedExitCode() ??
|
|
3053
|
+
interruptedExitCode(controller.signal) ??
|
|
3190
3054
|
(result.failed ||
|
|
3191
3055
|
result.incomplete ||
|
|
3192
3056
|
result.deduplication?.status === "incomplete"
|
|
@@ -3198,18 +3062,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3198
3062
|
}
|
|
3199
3063
|
catch (error) {
|
|
3200
3064
|
stopDashboard();
|
|
3201
|
-
exitCode = interruptedExitCode() ?? 2;
|
|
3065
|
+
exitCode = interruptedExitCode(controller.signal) ?? 2;
|
|
3202
3066
|
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
3203
3067
|
}
|
|
3204
3068
|
finally {
|
|
3205
3069
|
stopDashboard();
|
|
3206
|
-
dependencies
|
|
3207
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
3070
|
+
signalHandlers(dependencies, "remove", onInterrupt, onTerminate);
|
|
3208
3071
|
}
|
|
3209
3072
|
},
|
|
3210
3073
|
})
|
|
3211
3074
|
.command("bulk-scan", {
|
|
3212
|
-
description: "Discover
|
|
3075
|
+
description: "Discover and scan multiple repositories.",
|
|
3213
3076
|
destructive: true,
|
|
3214
3077
|
mcp: false,
|
|
3215
3078
|
alias: { config: "c" },
|
|
@@ -3252,10 +3115,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3252
3115
|
postScanPromptFile: optionValue("--post-scan-prompt-file")
|
|
3253
3116
|
.optional()
|
|
3254
3117
|
.describe("Run FILE after each scan, including failures."),
|
|
3255
|
-
model:
|
|
3256
|
-
.optional()
|
|
3257
|
-
.describe(`OpenAI model for each repository (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
3258
|
-
effort: effortOption(),
|
|
3118
|
+
...modelOptions(`OpenAI model for each repository (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`).shape,
|
|
3259
3119
|
provider: PROVIDER_OPTION,
|
|
3260
3120
|
maxAttempts: z
|
|
3261
3121
|
.number()
|
|
@@ -3292,15 +3152,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3292
3152
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
3293
3153
|
async run({ args, options }) {
|
|
3294
3154
|
const controller = new AbortController();
|
|
3295
|
-
const
|
|
3296
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
3297
|
-
const interruptedExitCode = () => controller.signal.reason === "SIGINT"
|
|
3298
|
-
? 130
|
|
3299
|
-
: controller.signal.reason === "SIGTERM"
|
|
3300
|
-
? 143
|
|
3301
|
-
: undefined;
|
|
3302
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
3303
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
3155
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
3304
3156
|
try {
|
|
3305
3157
|
const currentDirectory = dependencies.currentDirectory();
|
|
3306
3158
|
if (options.recover && args.input === undefined) {
|
|
@@ -3308,12 +3160,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3308
3160
|
}
|
|
3309
3161
|
const project = await selectedProjectConfig(options.config, dependencies);
|
|
3310
3162
|
const overrides = {
|
|
3311
|
-
|
|
3312
|
-
outputDir: options.outputDir,
|
|
3163
|
+
...pickScanSettings({ ...options, workers: undefined }),
|
|
3313
3164
|
knowledgeBasePaths: options.knowledgeBase,
|
|
3314
|
-
scanPromptFile: options.scanPromptFile,
|
|
3315
|
-
validationPromptFile: options.validationPromptFile,
|
|
3316
|
-
postScanPromptFile: options.postScanPromptFile,
|
|
3317
3165
|
maxCostUsd: options.maxCost,
|
|
3318
3166
|
};
|
|
3319
3167
|
const resolved = resolveScanSettings(project, overrides, currentDirectory);
|
|
@@ -3442,11 +3290,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3442
3290
|
signal: controller.signal,
|
|
3443
3291
|
onProgress: ({ repository, status, attempt, error, warning }) => {
|
|
3444
3292
|
const detail = error ?? warning;
|
|
3445
|
-
errorOutput.write(`codex-security: ${repository} ${status} (attempt ${attempt})${detail === undefined ? "" : `: ${
|
|
3293
|
+
errorOutput.write(`codex-security: ${repository} ${status} (attempt ${attempt})${detail === undefined ? "" : `: ${diagnosticValue(detail)}`}\n`);
|
|
3446
3294
|
},
|
|
3447
3295
|
});
|
|
3448
3296
|
exitCode =
|
|
3449
|
-
interruptedExitCode() ??
|
|
3297
|
+
interruptedExitCode(controller.signal) ??
|
|
3450
3298
|
(result.failed > 0 || result.incomplete > 0
|
|
3451
3299
|
? 2
|
|
3452
3300
|
: result.policyFailed
|
|
@@ -3456,37 +3304,50 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3456
3304
|
}
|
|
3457
3305
|
catch (error) {
|
|
3458
3306
|
exitCode =
|
|
3459
|
-
interruptedExitCode() ??
|
|
3307
|
+
interruptedExitCode(controller.signal) ??
|
|
3460
3308
|
(error instanceof Error && error.name === "ExitPromptError"
|
|
3461
3309
|
? 130
|
|
3462
3310
|
: 2);
|
|
3463
3311
|
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
3464
3312
|
}
|
|
3465
3313
|
finally {
|
|
3466
|
-
|
|
3467
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
3314
|
+
removeSignals();
|
|
3468
3315
|
}
|
|
3469
3316
|
},
|
|
3470
3317
|
})
|
|
3471
3318
|
.command("export", {
|
|
3472
|
-
description: "Export findings
|
|
3319
|
+
description: "Export saved findings or a threat model without running an analysis.",
|
|
3320
|
+
hint: "Examples:\n" +
|
|
3321
|
+
" codex-security export\n" +
|
|
3322
|
+
" codex-security export --export-format json --output -\n" +
|
|
3323
|
+
" codex-security export ../scan-results --export-format csv\n" +
|
|
3324
|
+
" codex-security export --artifact threat-model --output -\n\n" +
|
|
3325
|
+
"Use --export-format for artifact format. The global --format option controls\n" +
|
|
3326
|
+
"framework output such as --schema; it does not change exported files.",
|
|
3473
3327
|
destructive: true,
|
|
3474
3328
|
mcp: false,
|
|
3475
3329
|
args: z.object({
|
|
3476
3330
|
scanDir: z
|
|
3477
3331
|
.string()
|
|
3478
3332
|
.optional()
|
|
3479
|
-
.describe("
|
|
3333
|
+
.describe("Saved result directory (default: latest completed scan)."),
|
|
3480
3334
|
}),
|
|
3481
3335
|
options: z
|
|
3482
3336
|
.object({
|
|
3337
|
+
artifact: z
|
|
3338
|
+
.enum(["findings", "threat-model"])
|
|
3339
|
+
.default("findings")
|
|
3340
|
+
.describe("Saved artifact to export."),
|
|
3341
|
+
scan: optionValue("--scan")
|
|
3342
|
+
.optional()
|
|
3343
|
+
.describe("Saved scan ID or unique prefix; cannot be combined with a result directory."),
|
|
3483
3344
|
exportFormat: z
|
|
3484
|
-
.enum(["csv", "json", "sarif"])
|
|
3485
|
-
.
|
|
3486
|
-
.describe("
|
|
3345
|
+
.enum(["csv", "json", "sarif", "md"])
|
|
3346
|
+
.optional()
|
|
3347
|
+
.describe("Findings: csv, json, or sarif (default); threat-model: md (default)."),
|
|
3487
3348
|
output: optionValue("--output")
|
|
3488
3349
|
.optional()
|
|
3489
|
-
.describe("FILE or '-' for stdout (default: results.sarif, findings.json, or
|
|
3350
|
+
.describe("FILE or '-' for stdout (default: results.sarif, findings.json, findings.csv, or threatmodel.md)."),
|
|
3490
3351
|
sourceRoot: optionValue("--source-root")
|
|
3491
3352
|
.optional()
|
|
3492
3353
|
.describe("Repository checkout used for SARIF source-line fingerprints."),
|
|
@@ -3495,26 +3356,45 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3495
3356
|
.describe("Python interpreter for the bundled plugin exporter."),
|
|
3496
3357
|
})
|
|
3497
3358
|
.refine((options) => options.sourceRoot === undefined ||
|
|
3498
|
-
options.
|
|
3359
|
+
(options.artifact === "findings" &&
|
|
3360
|
+
(options.exportFormat === undefined ||
|
|
3361
|
+
options.exportFormat === "sarif")), {
|
|
3499
3362
|
message: "--source-root is only supported with --export-format sarif",
|
|
3500
3363
|
}),
|
|
3501
3364
|
async run({ args, options }) {
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3365
|
+
try {
|
|
3366
|
+
const currentDirectory = dependencies.currentDirectory();
|
|
3367
|
+
if (args.scanDir !== undefined && options.scan !== undefined) {
|
|
3368
|
+
throw new CodexSecurityError("--scan cannot be combined with a result directory.");
|
|
3369
|
+
}
|
|
3370
|
+
const format = resolveArtifactFormat(options.artifact, options.exportFormat);
|
|
3371
|
+
let scanDir = args.scanDir;
|
|
3372
|
+
if (scanDir === undefined) {
|
|
3373
|
+
const scanId = options.scan ??
|
|
3374
|
+
(await latestScans(1, "complete", options.python))?.[0]?.scanId;
|
|
3375
|
+
if (scanId === undefined)
|
|
3376
|
+
return;
|
|
3377
|
+
scanDir = await resolveSavedArtifactDirectory(scanId, options.artifact, format, (args) => dependencies.runWorkbench(args, undefined, undefined, options.python));
|
|
3378
|
+
}
|
|
3379
|
+
exitCode = await runExport({
|
|
3380
|
+
scanDir: resolveCliPath(currentDirectory, scanDir),
|
|
3381
|
+
artifact: options.artifact,
|
|
3382
|
+
format,
|
|
3383
|
+
output: options.output === "-"
|
|
3384
|
+
? "-"
|
|
3385
|
+
: resolveCliPath(currentDirectory, options.output ?? EXPORT_DEFAULT_OUTPUTS[format]),
|
|
3386
|
+
sourceRoot: options.sourceRoot === undefined
|
|
3387
|
+
? undefined
|
|
3388
|
+
: resolveCliPath(currentDirectory, options.sourceRoot),
|
|
3389
|
+
pythonPath: options.python,
|
|
3390
|
+
}, output, errorOutput, dependencies);
|
|
3391
|
+
}
|
|
3392
|
+
catch (error) {
|
|
3393
|
+
if (exitCode !== 2) {
|
|
3394
|
+
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
3395
|
+
}
|
|
3396
|
+
exitCode = 2;
|
|
3397
|
+
}
|
|
3518
3398
|
},
|
|
3519
3399
|
})
|
|
3520
3400
|
.command("validate", {
|
|
@@ -3528,19 +3408,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3528
3408
|
.describe("Finding text or a file containing findings."),
|
|
3529
3409
|
}),
|
|
3530
3410
|
options: z.object({
|
|
3531
|
-
auth:
|
|
3532
|
-
|
|
3533
|
-
.default("auto")
|
|
3534
|
-
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
3535
|
-
effort: effortOption(),
|
|
3536
|
-
codex: z
|
|
3537
|
-
.array(optionValue("--codex"))
|
|
3538
|
-
.default([])
|
|
3539
|
-
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
3411
|
+
auth: SKILL_AUTH_OPTION,
|
|
3412
|
+
...SKILL_CONFIG_OPTIONS.shape,
|
|
3540
3413
|
}),
|
|
3541
3414
|
async run({ options }) {
|
|
3542
3415
|
try {
|
|
3543
|
-
exitCode = await runSkill("validation", positionals, options
|
|
3416
|
+
exitCode = await runSkill("validation", positionals, options, output, errorOutput, dependencies, { auth: options.auth });
|
|
3544
3417
|
}
|
|
3545
3418
|
catch (error) {
|
|
3546
3419
|
exitCode = 2;
|
|
@@ -3560,14 +3433,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3560
3433
|
.describe("Finding text, a file, or a saved finding identifier."),
|
|
3561
3434
|
}),
|
|
3562
3435
|
options: z.object({
|
|
3563
|
-
auth:
|
|
3564
|
-
|
|
3565
|
-
.default("auto")
|
|
3566
|
-
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
3567
|
-
effort: effortOption(),
|
|
3436
|
+
auth: SKILL_AUTH_OPTION,
|
|
3437
|
+
...MODEL_OPTIONS.shape,
|
|
3568
3438
|
scan: optionValue("--scan")
|
|
3569
3439
|
.optional()
|
|
3570
|
-
.describe("Verify open findings from a saved scan."),
|
|
3440
|
+
.describe("Verify open findings from a saved scan ID or the latest completed scan."),
|
|
3571
3441
|
severity: z
|
|
3572
3442
|
.enum(REPORTABLE_SEVERITIES)
|
|
3573
3443
|
.optional()
|
|
@@ -3583,11 +3453,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3583
3453
|
.optional()
|
|
3584
3454
|
.describe("JSON Linear issue filter for --linear-project."),
|
|
3585
3455
|
linearApiKey: linearApiKeyOption(),
|
|
3586
|
-
codex:
|
|
3587
|
-
.array(optionValue("--codex"))
|
|
3588
|
-
.default([])
|
|
3589
|
-
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
3456
|
+
codex: SKILL_CONFIG_OPTIONS.shape.codex,
|
|
3590
3457
|
}),
|
|
3458
|
+
examples: [
|
|
3459
|
+
{
|
|
3460
|
+
options: { scan: "latest" },
|
|
3461
|
+
description: "Verify fixes for the latest completed scan.",
|
|
3462
|
+
},
|
|
3463
|
+
{
|
|
3464
|
+
args: { "findings...": "finding.md" },
|
|
3465
|
+
description: "Verify a fix described in a file.",
|
|
3466
|
+
},
|
|
3467
|
+
],
|
|
3591
3468
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
3592
3469
|
async run({ format, options }) {
|
|
3593
3470
|
try {
|
|
@@ -3639,18 +3516,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3639
3516
|
if (identifiers.length > 0) {
|
|
3640
3517
|
const environment = imports.length === 0
|
|
3641
3518
|
? undefined
|
|
3642
|
-
:
|
|
3643
|
-
|
|
3644
|
-
const verificationOutput = {
|
|
3645
|
-
write(value) {
|
|
3646
|
-
response += value.toString();
|
|
3647
|
-
return true;
|
|
3648
|
-
},
|
|
3649
|
-
};
|
|
3519
|
+
: withoutLinearCredentials(dependencies.environment);
|
|
3520
|
+
const response = captureOutput();
|
|
3650
3521
|
const progress = new FindingProgressPresenter(errorOutput, dependencies, repository, identifiers.length);
|
|
3651
3522
|
progress.startVerification();
|
|
3652
3523
|
try {
|
|
3653
|
-
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options
|
|
3524
|
+
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options, response.stream, errorOutput, dependencies, {
|
|
3654
3525
|
directory: repository,
|
|
3655
3526
|
...(selected === undefined
|
|
3656
3527
|
? {}
|
|
@@ -3667,7 +3538,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3667
3538
|
}
|
|
3668
3539
|
let reported;
|
|
3669
3540
|
try {
|
|
3670
|
-
reported = JSON.parse(response);
|
|
3541
|
+
reported = JSON.parse(response.text());
|
|
3671
3542
|
}
|
|
3672
3543
|
catch {
|
|
3673
3544
|
throw new CodexSecurityError("Verification results were not valid JSON.");
|
|
@@ -3706,7 +3577,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3706
3577
|
}
|
|
3707
3578
|
catch (error) {
|
|
3708
3579
|
exitCode = 2;
|
|
3709
|
-
errorOutput.write(`codex-security: ${
|
|
3580
|
+
errorOutput.write(`codex-security: ${diagnosticValue(error)}\n`);
|
|
3710
3581
|
return undefined;
|
|
3711
3582
|
}
|
|
3712
3583
|
},
|
|
@@ -3720,21 +3591,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3720
3591
|
.string()
|
|
3721
3592
|
.min(1, "An issue must not be empty.")
|
|
3722
3593
|
.optional()
|
|
3723
|
-
.describe("Issue text or a
|
|
3594
|
+
.describe("Issue text, a file, or a saved finding identifier."),
|
|
3724
3595
|
}),
|
|
3725
3596
|
options: z.object({
|
|
3726
|
-
auth:
|
|
3727
|
-
|
|
3728
|
-
.default("auto")
|
|
3729
|
-
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
3730
|
-
effort: effortOption(),
|
|
3597
|
+
auth: SKILL_AUTH_OPTION,
|
|
3598
|
+
...MODEL_OPTIONS.shape,
|
|
3731
3599
|
externalSandbox: z
|
|
3732
3600
|
.boolean()
|
|
3733
3601
|
.default(false)
|
|
3734
3602
|
.describe("Use the container's isolation instead of the Codex sandbox (default: false)."),
|
|
3735
3603
|
scan: optionValue("--scan")
|
|
3736
3604
|
.optional()
|
|
3737
|
-
.describe("Patch open findings from a saved scan."),
|
|
3605
|
+
.describe("Patch open findings from a saved scan ID or the latest completed scan."),
|
|
3738
3606
|
severity: z
|
|
3739
3607
|
.enum(REPORTABLE_SEVERITIES)
|
|
3740
3608
|
.optional()
|
|
@@ -3758,11 +3626,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3758
3626
|
resumePr: optionValue("--resume-pr")
|
|
3759
3627
|
.optional()
|
|
3760
3628
|
.describe("Resume publication of a saved patch branch without patching again."),
|
|
3761
|
-
codex:
|
|
3762
|
-
.array(optionValue("--codex"))
|
|
3763
|
-
.default([])
|
|
3764
|
-
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
3629
|
+
codex: SKILL_CONFIG_OPTIONS.shape.codex,
|
|
3765
3630
|
}),
|
|
3631
|
+
examples: [
|
|
3632
|
+
{
|
|
3633
|
+
options: { scan: "latest", severity: "high" },
|
|
3634
|
+
description: "Patch high and critical findings from the latest completed scan.",
|
|
3635
|
+
},
|
|
3636
|
+
{
|
|
3637
|
+
args: { "issues...": "finding.md" },
|
|
3638
|
+
description: "Patch a finding described in a file.",
|
|
3639
|
+
},
|
|
3640
|
+
],
|
|
3766
3641
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
3767
3642
|
async run({ format, options, error: commandError }) {
|
|
3768
3643
|
const jsonOutput = format === "json" || format === "jsonl";
|
|
@@ -3786,6 +3661,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3786
3661
|
linear ||
|
|
3787
3662
|
options.linearFilter !== undefined ||
|
|
3788
3663
|
options.linearApiKey !== undefined ||
|
|
3664
|
+
options.model !== undefined ||
|
|
3789
3665
|
options.effort !== undefined ||
|
|
3790
3666
|
options.auth !== "auto" ||
|
|
3791
3667
|
options.codex.length > 0) {
|
|
@@ -3822,7 +3698,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3822
3698
|
: undefined;
|
|
3823
3699
|
const patchBase = patchRiskBase ??
|
|
3824
3700
|
(await snapshotPatchState(selected.repository, dependencies));
|
|
3825
|
-
const patches = await runFindingPatches(selected, options
|
|
3701
|
+
const patches = await runFindingPatches(selected, options, errorOutput, dependencies, {
|
|
3826
3702
|
auth: options.auth,
|
|
3827
3703
|
externalSandbox: options.externalSandbox,
|
|
3828
3704
|
validationPrompt,
|
|
@@ -3849,8 +3725,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3849
3725
|
repository: selected.repository,
|
|
3850
3726
|
base: patchRiskBase,
|
|
3851
3727
|
files,
|
|
3852
|
-
|
|
3853
|
-
effort: options.effort,
|
|
3728
|
+
configuration: options,
|
|
3854
3729
|
auth: options.auth,
|
|
3855
3730
|
}, errorOutput, dependencies);
|
|
3856
3731
|
}
|
|
@@ -3889,7 +3764,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3889
3764
|
: [];
|
|
3890
3765
|
const environment = imports.length === 0
|
|
3891
3766
|
? undefined
|
|
3892
|
-
:
|
|
3767
|
+
: withoutLinearCredentials(dependencies.environment);
|
|
3893
3768
|
const patchGitBase = options.assessPatchRisk || options.createPr
|
|
3894
3769
|
? await snapshotPatchTree(repository, dependencies)
|
|
3895
3770
|
: undefined;
|
|
@@ -3898,20 +3773,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3898
3773
|
if (options.createPr) {
|
|
3899
3774
|
await requireCleanPatchPullRequestBase(repository, patchGitBase, dependencies);
|
|
3900
3775
|
}
|
|
3901
|
-
|
|
3902
|
-
exitCode = await runSkill("fix-finding", [...positionals, ...imports], options
|
|
3903
|
-
write: (value) => {
|
|
3904
|
-
report += value.toString();
|
|
3905
|
-
return true;
|
|
3906
|
-
},
|
|
3907
|
-
}, errorOutput, dependencies, {
|
|
3776
|
+
const report = captureOutput();
|
|
3777
|
+
exitCode = await runSkill("fix-finding", [...positionals, ...imports], options, report.stream, errorOutput, dependencies, {
|
|
3908
3778
|
environment,
|
|
3909
3779
|
auth: options.auth,
|
|
3910
3780
|
externalSandbox: options.externalSandbox,
|
|
3911
3781
|
validationPrompt,
|
|
3912
3782
|
});
|
|
3913
3783
|
if (!jsonOutput)
|
|
3914
|
-
output.write(report);
|
|
3784
|
+
output.write(report.text());
|
|
3915
3785
|
const files = await changedPatchFiles(repository, patchBase, dependencies);
|
|
3916
3786
|
patchResult = {
|
|
3917
3787
|
repository,
|
|
@@ -3932,8 +3802,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3932
3802
|
environment,
|
|
3933
3803
|
base: patchGitBase,
|
|
3934
3804
|
files,
|
|
3935
|
-
|
|
3936
|
-
effort: options.effort,
|
|
3805
|
+
configuration: options,
|
|
3937
3806
|
auth: options.auth,
|
|
3938
3807
|
}, errorOutput, dependencies)
|
|
3939
3808
|
: undefined;
|
|
@@ -3946,14 +3815,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3946
3815
|
if (structuredOutput)
|
|
3947
3816
|
return {
|
|
3948
3817
|
...patchResult,
|
|
3949
|
-
...(jsonOutput ? { report } : {}),
|
|
3818
|
+
...(jsonOutput ? { report: report.text() } : {}),
|
|
3950
3819
|
};
|
|
3951
3820
|
}
|
|
3952
3821
|
catch (error) {
|
|
3953
3822
|
if (exitCode === 0)
|
|
3954
3823
|
exitCode = 2;
|
|
3955
|
-
const message =
|
|
3956
|
-
errorOutput.write(`codex-security: ${message}\n`);
|
|
3824
|
+
const message = errorMessage(error);
|
|
3825
|
+
errorOutput.write(`codex-security: ${diagnosticValue(message)}\n`);
|
|
3957
3826
|
if (!structuredOutput)
|
|
3958
3827
|
return;
|
|
3959
3828
|
patchStructuredError = true;
|
|
@@ -3975,16 +3844,28 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3975
3844
|
})
|
|
3976
3845
|
.command("login", {
|
|
3977
3846
|
description: "Sign in with ChatGPT or store credentials.",
|
|
3847
|
+
hint: "For remote login, use --device-auth if your workspace allows it.\n" +
|
|
3848
|
+
"If device auth is disabled, sign in over SSH:\n" +
|
|
3849
|
+
" On your local machine (replace user@remote):\n" +
|
|
3850
|
+
" ssh -L 1455:localhost:1455 user@remote\n" +
|
|
3851
|
+
" In that SSH session:\n" +
|
|
3852
|
+
" codex-security login\n" +
|
|
3853
|
+
" Open the sign-in URL in your local browser.\n" +
|
|
3854
|
+
" Keep SSH connected until login finishes.\n" +
|
|
3855
|
+
"Docs: https://learn.chatgpt.com/docs/auth?surface=cli#cli-fallback-forward-the-localhost-callback-over-ssh",
|
|
3978
3856
|
destructive: true,
|
|
3979
3857
|
mcp: false,
|
|
3980
3858
|
args: z.object({
|
|
3981
|
-
action: z
|
|
3859
|
+
action: z
|
|
3860
|
+
.enum(["status"])
|
|
3861
|
+
.optional()
|
|
3862
|
+
.describe("Use status to inspect credentials; omit to sign in."),
|
|
3982
3863
|
}),
|
|
3983
3864
|
options: z.object({
|
|
3984
3865
|
deviceAuth: z
|
|
3985
3866
|
.boolean()
|
|
3986
3867
|
.default(false)
|
|
3987
|
-
.describe("Use device
|
|
3868
|
+
.describe("Use device auth if your workspace allows it."),
|
|
3988
3869
|
withApiKey: z
|
|
3989
3870
|
.boolean()
|
|
3990
3871
|
.default(false)
|
|
@@ -3994,6 +3875,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3994
3875
|
.default(false)
|
|
3995
3876
|
.describe("Read an access token from stdin."),
|
|
3996
3877
|
}),
|
|
3878
|
+
examples: [
|
|
3879
|
+
{ args: {}, description: "Sign in with ChatGPT." },
|
|
3880
|
+
{ args: { action: "status" }, description: "Check authentication." },
|
|
3881
|
+
],
|
|
3997
3882
|
async run({ args, options }) {
|
|
3998
3883
|
const credentialHome = dependencies.prepareAuthenticationHome !== undefined
|
|
3999
3884
|
? await dependencies.prepareAuthenticationHome(dependencies.environment)
|
|
@@ -4031,11 +3916,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4031
3916
|
else if (exitCode === 0 && !options.withApiKey) {
|
|
4032
3917
|
const authentication = scanAuthentication(dependencies.environment);
|
|
4033
3918
|
if (authentication.method === "api_key") {
|
|
4034
|
-
const configuredApiKeyVariables = Object.entries(dependencies.environment)
|
|
4035
|
-
.filter(([name, value]) => value?.trim() &&
|
|
3919
|
+
const configuredApiKeyVariables = Object.entries(dependencies.environment).flatMap(([name, value]) => value?.trim() &&
|
|
4036
3920
|
(name.toUpperCase() === "OPENAI_API_KEY" ||
|
|
4037
|
-
name.toUpperCase() === "CODEX_API_KEY")
|
|
4038
|
-
|
|
3921
|
+
name.toUpperCase() === "CODEX_API_KEY")
|
|
3922
|
+
? name
|
|
3923
|
+
: []);
|
|
4039
3924
|
const loginWarning = options.withAccessToken
|
|
4040
3925
|
? `Access-token login succeeded, but noninteractive scans will use ${authentication.source}.\n`
|
|
4041
3926
|
: "ChatGPT login succeeded. Interactive scans will ask which account to use; " +
|
|
@@ -4070,7 +3955,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4070
3955
|
},
|
|
4071
3956
|
})
|
|
4072
3957
|
.command("serve", {
|
|
4073
|
-
description: "Start the findings HTTP service
|
|
3958
|
+
description: "Start the local findings HTTP service.",
|
|
3959
|
+
hint: "Environment: HOST=127.0.0.1, PORT=3000.\n" +
|
|
3960
|
+
"CODEX_SECURITY_EMBEDDINGS_URL overrides the embeddings endpoint\n" +
|
|
3961
|
+
"(default: https://api.openai.com/v1/embeddings).",
|
|
4074
3962
|
destructive: true,
|
|
4075
3963
|
mcp: false,
|
|
4076
3964
|
options: z.object({
|
|
@@ -4096,7 +3984,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4096
3984
|
},
|
|
4097
3985
|
})
|
|
4098
3986
|
.command("init", {
|
|
4099
|
-
description: "
|
|
3987
|
+
description: "Create a starter project configuration.",
|
|
3988
|
+
hint: "Existing files are never overwritten.",
|
|
4100
3989
|
destructive: true,
|
|
4101
3990
|
mcp: false,
|
|
4102
3991
|
args: z.object({
|
|
@@ -4161,10 +4050,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4161
4050
|
? undefined
|
|
4162
4051
|
: (await history(["get-scan", "--scan-id", scanId]))["scan"];
|
|
4163
4052
|
const controller = new AbortController();
|
|
4164
|
-
const
|
|
4165
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
4166
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
4167
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
4053
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
4168
4054
|
try {
|
|
4169
4055
|
return await (dependencies.sendFeedback ?? sendFeedback)({
|
|
4170
4056
|
...options,
|
|
@@ -4182,13 +4068,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4182
4068
|
throw error;
|
|
4183
4069
|
}
|
|
4184
4070
|
finally {
|
|
4185
|
-
|
|
4186
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
4071
|
+
removeSignals();
|
|
4187
4072
|
}
|
|
4188
4073
|
},
|
|
4189
4074
|
})
|
|
4190
4075
|
.command("info", {
|
|
4191
|
-
description: "Show SDK metadata and resolved configuration
|
|
4076
|
+
description: "Show SDK metadata and resolved configuration.",
|
|
4192
4077
|
alias: { config: "c" },
|
|
4193
4078
|
options: z.object({ config: PROJECT_CONFIG_OPTION }),
|
|
4194
4079
|
mcp: {
|
|
@@ -4308,12 +4193,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4308
4193
|
}
|
|
4309
4194
|
let notice;
|
|
4310
4195
|
try {
|
|
4311
|
-
await cli.serve(argv.flatMap((argument) =>
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4196
|
+
await cli.serve(argv.flatMap((argument) => {
|
|
4197
|
+
if (!/^--(?:format|filter-output|token-limit|token-offset)=/u.test(argument))
|
|
4198
|
+
return [argument];
|
|
4199
|
+
const separator = argument.indexOf("=");
|
|
4200
|
+
return [argument.slice(0, separator), argument.slice(separator + 1)];
|
|
4201
|
+
}), {
|
|
4202
|
+
stdout: frameworkCapture.stream.write,
|
|
4317
4203
|
exit: (code) => {
|
|
4318
4204
|
frameworkExit = code;
|
|
4319
4205
|
},
|
|
@@ -4325,6 +4211,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4325
4211
|
finally {
|
|
4326
4212
|
updateController.abort();
|
|
4327
4213
|
}
|
|
4214
|
+
const frameworkOutput = frameworkCapture.text();
|
|
4328
4215
|
if (notice !== undefined)
|
|
4329
4216
|
errorOutput.write(formatUpdateNotice(notice));
|
|
4330
4217
|
if (frameworkExit !== undefined) {
|
|
@@ -4351,7 +4238,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4351
4238
|
renderedPatch ??
|
|
4352
4239
|
renderedPublication ??
|
|
4353
4240
|
renderedHistory ??
|
|
4354
|
-
frameworkOutput);
|
|
4241
|
+
formatCliHelp(frameworkOutput, output.columns));
|
|
4355
4242
|
return exitCode;
|
|
4356
4243
|
}
|
|
4357
4244
|
catch (error) {
|
|
@@ -4361,10 +4248,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4361
4248
|
}
|
|
4362
4249
|
async function runScanImport(options, errorOutput, dependencies) {
|
|
4363
4250
|
const controller = new AbortController();
|
|
4364
|
-
const
|
|
4365
|
-
const onTerminate = () => controller.abort("SIGTERM");
|
|
4366
|
-
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
4367
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
4251
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
4368
4252
|
try {
|
|
4369
4253
|
const result = await (dependencies.importScan ?? importScan)({ ...options, signal: controller.signal }, { environment: dependencies.environment });
|
|
4370
4254
|
if ("dryRun" in result)
|
|
@@ -4380,16 +4264,15 @@ async function runScanImport(options, errorOutput, dependencies) {
|
|
|
4380
4264
|
const signal = controller.signal.reason;
|
|
4381
4265
|
const message = signal === "SIGINT" || signal === "SIGTERM"
|
|
4382
4266
|
? "Scan import canceled."
|
|
4383
|
-
:
|
|
4384
|
-
errorOutput.write(`codex-security: ${message}\n`);
|
|
4267
|
+
: errorMessage(error);
|
|
4268
|
+
errorOutput.write(`codex-security: ${diagnosticValue(message)}\n`);
|
|
4385
4269
|
return {
|
|
4386
|
-
exitCode: signal
|
|
4270
|
+
exitCode: interruptedExitCode(controller.signal) ?? 2,
|
|
4387
4271
|
error: message,
|
|
4388
4272
|
};
|
|
4389
4273
|
}
|
|
4390
4274
|
finally {
|
|
4391
|
-
|
|
4392
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
4275
|
+
removeSignals();
|
|
4393
4276
|
}
|
|
4394
4277
|
}
|
|
4395
4278
|
function isScanImportCommand(argv) {
|
|
@@ -4457,7 +4340,7 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
4457
4340
|
throw new CodexSecurityError("This scan used custom validation. Supply --validation-prompt-file to rerun it.");
|
|
4458
4341
|
}
|
|
4459
4342
|
const repository = recipe["repository"];
|
|
4460
|
-
if (
|
|
4343
|
+
if (!isNonEmptyString(repository)) {
|
|
4461
4344
|
throw new CodexSecurityError("The saved scan recipe does not contain a repository.");
|
|
4462
4345
|
}
|
|
4463
4346
|
const target = recipe["target"];
|
|
@@ -4465,13 +4348,12 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
4465
4348
|
throw new CodexSecurityError("The saved scan recipe contains no target.");
|
|
4466
4349
|
}
|
|
4467
4350
|
const paths = target["paths"];
|
|
4468
|
-
if (!Array.isArray(paths) ||
|
|
4469
|
-
!paths.every((path) => typeof path === "string" && path.length > 0)) {
|
|
4351
|
+
if (!Array.isArray(paths) || !paths.every(isNonEmptyString)) {
|
|
4470
4352
|
throw new CodexSecurityError("The saved scan recipe contains invalid paths.");
|
|
4471
4353
|
}
|
|
4472
4354
|
const knowledgeBasePaths = recipe["knowledgeBasePaths"] ?? [];
|
|
4473
4355
|
if (!Array.isArray(knowledgeBasePaths) ||
|
|
4474
|
-
!knowledgeBasePaths.every(
|
|
4356
|
+
!knowledgeBasePaths.every(isNonEmptyString)) {
|
|
4475
4357
|
throw new CodexSecurityError("The saved scan recipe contains invalid knowledge base paths.");
|
|
4476
4358
|
}
|
|
4477
4359
|
const kind = target["kind"];
|
|
@@ -4495,7 +4377,7 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
4495
4377
|
throw new CodexSecurityError("The saved scan recipe has an invalid Git base.");
|
|
4496
4378
|
}
|
|
4497
4379
|
const head = target["headRef"];
|
|
4498
|
-
if (head !== undefined && (
|
|
4380
|
+
if (head !== undefined && !isNonEmptyString(head)) {
|
|
4499
4381
|
throw new CodexSecurityError("The saved scan recipe has an invalid Git head.");
|
|
4500
4382
|
}
|
|
4501
4383
|
const threshold = recipe["failOnSeverity"];
|
|
@@ -4520,6 +4402,10 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
4520
4402
|
throw new CodexSecurityError("The saved scan recipe is missing resolved deep scan settings.");
|
|
4521
4403
|
}
|
|
4522
4404
|
const auth = z.enum(SCAN_AUTH_MODES).optional().safeParse(recipe["auth"]);
|
|
4405
|
+
const cyberAccessProgram = ScanSettingsSchema.shape.cyberAccessProgram.safeParse(recipe["cyberAccessProgram"]);
|
|
4406
|
+
if (!cyberAccessProgram.success) {
|
|
4407
|
+
throw new CodexSecurityError("The saved scan recipe contains an invalid Cyber access program.");
|
|
4408
|
+
}
|
|
4523
4409
|
if (!auth.success)
|
|
4524
4410
|
throw new CodexSecurityError("The saved scan recipe contains an invalid authentication choice.");
|
|
4525
4411
|
if (mode !== "deep" &&
|
|
@@ -4540,6 +4426,7 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
4540
4426
|
return {
|
|
4541
4427
|
repository,
|
|
4542
4428
|
auth: auth.data ?? DEFAULT_SCAN_AUTH,
|
|
4429
|
+
cyberAccessProgram: cyberAccessProgram.data,
|
|
4543
4430
|
target: paths.length > 0
|
|
4544
4431
|
? paths
|
|
4545
4432
|
: kind === "refs"
|
|
@@ -4587,6 +4474,8 @@ function validateCliArguments(argv, positionals) {
|
|
|
4587
4474
|
"validate",
|
|
4588
4475
|
"verify-fix",
|
|
4589
4476
|
"suggest-owners",
|
|
4477
|
+
"classify-severity",
|
|
4478
|
+
"dedupe",
|
|
4590
4479
|
"patch",
|
|
4591
4480
|
"login",
|
|
4592
4481
|
"logout",
|
|
@@ -4618,6 +4507,16 @@ function validateCliArguments(argv, positionals) {
|
|
|
4618
4507
|
(value === "--export-format" && argv[index + 1] === "csv"))) {
|
|
4619
4508
|
return "CSV stdout cannot be combined with JSON output; write CSV to a file or omit --json.";
|
|
4620
4509
|
}
|
|
4510
|
+
if (command === "export" &&
|
|
4511
|
+
structuredOutput &&
|
|
4512
|
+
argv.some((value, index) => value === "--output=-" ||
|
|
4513
|
+
(value === "--output" && argv[index + 1] === "-")) &&
|
|
4514
|
+
argv.some((value, index) => value === "--artifact=threat-model" ||
|
|
4515
|
+
(value === "--artifact" && argv[index + 1] === "threat-model") ||
|
|
4516
|
+
value === "--export-format=md" ||
|
|
4517
|
+
(value === "--export-format" && argv[index + 1] === "md"))) {
|
|
4518
|
+
return "Markdown stdout cannot be combined with JSON output; write Markdown to a file or omit --json.";
|
|
4519
|
+
}
|
|
4621
4520
|
if (command === "scan" && !argv.includes("--schema")) {
|
|
4622
4521
|
if (argv.some((value) => value === "--filter-output" || value.startsWith("--filter-output="))) {
|
|
4623
4522
|
return "--filter-output is not supported for scan results.";
|
|
@@ -4671,8 +4570,10 @@ function validateCliArguments(argv, positionals) {
|
|
|
4671
4570
|
}
|
|
4672
4571
|
const equals = value.indexOf("=");
|
|
4673
4572
|
const option = equals < 0 ? value : value.slice(0, equals);
|
|
4573
|
+
const canonicalOption = option.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
4674
4574
|
if (equals >= 0 ||
|
|
4675
|
-
(!VALUE_OPTIONS.has(
|
|
4575
|
+
(!VALUE_OPTIONS.has(canonicalOption) &&
|
|
4576
|
+
!(scanImport && option === "--json")))
|
|
4676
4577
|
continue;
|
|
4677
4578
|
const next = argv[index + 1];
|
|
4678
4579
|
if (next === undefined || next.startsWith("--") || next === "-h") {
|
|
@@ -4862,8 +4763,7 @@ async function selectSavedFindings(identifiers, requestedScanId, severity, depen
|
|
|
4862
4763
|
}
|
|
4863
4764
|
}
|
|
4864
4765
|
const selected = findings.filter((finding) => {
|
|
4865
|
-
|
|
4866
|
-
return (triage?.["status"] !== "closed" &&
|
|
4766
|
+
return (finding["triage"]?.["status"] !== "closed" &&
|
|
4867
4767
|
(identifiers.length === 0 ||
|
|
4868
4768
|
identifiers.includes(finding.occurrenceId) ||
|
|
4869
4769
|
identifiers.includes(finding.findingId)) &&
|
|
@@ -4912,10 +4812,7 @@ function directPatchIdentifier(positionals, imports) {
|
|
|
4912
4812
|
return isLinearIssueIdentifier(candidate) ? candidate : undefined;
|
|
4913
4813
|
}
|
|
4914
4814
|
function directPatchDigest(positionals, imports) {
|
|
4915
|
-
return `issues-${
|
|
4916
|
-
.update(JSON.stringify([...positionals, ...imports.map(({ id }) => id)]))
|
|
4917
|
-
.digest("hex")
|
|
4918
|
-
.slice(0, 12)}`;
|
|
4815
|
+
return `issues-${sha256Text(JSON.stringify([...positionals, ...imports.map(({ id }) => id)])).slice(0, 12)}`;
|
|
4919
4816
|
}
|
|
4920
4817
|
async function publishPatchBranch(repository, branch, body, stderr, dependencies) {
|
|
4921
4818
|
const run = (command, args) => dependencies.runRepositoryCommand(command, args, repository);
|
|
@@ -5123,7 +5020,7 @@ async function snapshotPatchDirectory(repository) {
|
|
|
5123
5020
|
return files;
|
|
5124
5021
|
}
|
|
5125
5022
|
function safePatchText(value) {
|
|
5126
|
-
return stripVTControlCharacters(
|
|
5023
|
+
return stripVTControlCharacters(value).replaceAll(/[\u0000-\u001F\u007F-\u009F\u2028\u2029]/gu, " ");
|
|
5127
5024
|
}
|
|
5128
5025
|
function safePatchReport(value) {
|
|
5129
5026
|
return value.split(/\r?\n/gu).map(safePatchText).join("\n").trim();
|
|
@@ -5198,14 +5095,8 @@ async function assessPatchRisk(request, stderr, dependencies) {
|
|
|
5198
5095
|
for await (const chunk of createReadStream(patchPath)) {
|
|
5199
5096
|
digest.update(chunk);
|
|
5200
5097
|
}
|
|
5201
|
-
|
|
5202
|
-
const
|
|
5203
|
-
write(value) {
|
|
5204
|
-
report += value.toString();
|
|
5205
|
-
return true;
|
|
5206
|
-
},
|
|
5207
|
-
};
|
|
5208
|
-
const status = await runSkill("assess-patch-risk", [], request.codexOverrides, request.effort, stdout, stderr, dependencies, {
|
|
5098
|
+
const report = captureOutput();
|
|
5099
|
+
const status = await runSkill("assess-patch-risk", [], request.configuration, report.stream, stderr, dependencies, {
|
|
5209
5100
|
directory: request.repository,
|
|
5210
5101
|
auth: request.auth,
|
|
5211
5102
|
environment: request.environment,
|
|
@@ -5222,7 +5113,7 @@ async function assessPatchRisk(request, stderr, dependencies) {
|
|
|
5222
5113
|
if (status !== 0) {
|
|
5223
5114
|
throw new CodexSecurityError(`Patch risk assessment exited with status ${status}.`);
|
|
5224
5115
|
}
|
|
5225
|
-
return { report: report.trim() };
|
|
5116
|
+
return { report: report.text().trim() };
|
|
5226
5117
|
}
|
|
5227
5118
|
finally {
|
|
5228
5119
|
await rm(root, { recursive: true, force: true });
|
|
@@ -5255,7 +5146,7 @@ async function resolvePatchValidationPrompt(file, repository, directory) {
|
|
|
5255
5146
|
const { validationPrompt } = await resolveScanPrompts({ validationPromptFile: file }, [...roots], directory);
|
|
5256
5147
|
return validationPrompt;
|
|
5257
5148
|
}
|
|
5258
|
-
async function runFindingPatches(selected,
|
|
5149
|
+
async function runFindingPatches(selected, configuration, stderr, dependencies, options = {}, interactive = true) {
|
|
5259
5150
|
if (selected.findings.length === 0) {
|
|
5260
5151
|
stderr.write("No matching open findings to patch.\n");
|
|
5261
5152
|
return [];
|
|
@@ -5263,13 +5154,7 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
5263
5154
|
stderr.write(`\nPatching ${selected.findings.length} confirmed finding${selected.findings.length === 1 ? "" : "s"}...\n`);
|
|
5264
5155
|
const patches = [];
|
|
5265
5156
|
for (const finding of selected.findings) {
|
|
5266
|
-
|
|
5267
|
-
const stdout = {
|
|
5268
|
-
write(value) {
|
|
5269
|
-
response += value.toString();
|
|
5270
|
-
return true;
|
|
5271
|
-
},
|
|
5272
|
-
};
|
|
5157
|
+
const response = captureOutput();
|
|
5273
5158
|
const instruction = options.findingInstructions?.[finding.occurrenceId];
|
|
5274
5159
|
const progress = new FindingProgressPresenter(stderr, dependencies, selected.repository, selected.findings.length, interactive);
|
|
5275
5160
|
progress.startPatch(finding, patches.length);
|
|
@@ -5283,7 +5168,7 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
5283
5168
|
let changedFiles;
|
|
5284
5169
|
try {
|
|
5285
5170
|
const base = await snapshotPatchState(selected.repository, dependencies);
|
|
5286
|
-
status = await runSkill("fix-finding", [],
|
|
5171
|
+
status = await runSkill("fix-finding", [], configuration, response.stream, patchErrors, dependencies, {
|
|
5287
5172
|
...options,
|
|
5288
5173
|
directory: selected.repository,
|
|
5289
5174
|
findings: [finding],
|
|
@@ -5312,7 +5197,7 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
5312
5197
|
}
|
|
5313
5198
|
else {
|
|
5314
5199
|
try {
|
|
5315
|
-
const reported = JSON.parse(response);
|
|
5200
|
+
const reported = JSON.parse(response.text());
|
|
5316
5201
|
const entries = Array.isArray(reported?.patches)
|
|
5317
5202
|
? reported.patches
|
|
5318
5203
|
: [];
|
|
@@ -5324,7 +5209,8 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
5324
5209
|
if (matches.length !== 1 || !parsed.success) {
|
|
5325
5210
|
patch = failed("No complete patch result was returned for this finding.");
|
|
5326
5211
|
}
|
|
5327
|
-
else if (parsed.data.status === "verified"
|
|
5212
|
+
else if ((parsed.data.status === "verified" ||
|
|
5213
|
+
parsed.data.status === "no_change") &&
|
|
5328
5214
|
!parsed.data.verification?.trim()) {
|
|
5329
5215
|
patch = failed("Patch verification was not reported.", parsed.data.files);
|
|
5330
5216
|
}
|
|
@@ -5347,16 +5233,49 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
5347
5233
|
}
|
|
5348
5234
|
return patches;
|
|
5349
5235
|
}
|
|
5350
|
-
|
|
5351
|
-
|
|
5236
|
+
function captureOutput() {
|
|
5237
|
+
let text = "";
|
|
5238
|
+
return {
|
|
5239
|
+
stream: {
|
|
5240
|
+
write(value) {
|
|
5241
|
+
text += value.toString();
|
|
5242
|
+
return true;
|
|
5243
|
+
},
|
|
5244
|
+
},
|
|
5245
|
+
text: () => text,
|
|
5246
|
+
};
|
|
5247
|
+
}
|
|
5248
|
+
async function runSkill(skill, inputs, configuration, stdout, stderr, dependencies, options = {}) {
|
|
5249
|
+
const { codex, model: selectedModel, effort } = configuration;
|
|
5250
|
+
const overrides = parseCodexOverrides(codex, selectedModel, effort);
|
|
5352
5251
|
if (Object.entries(overrides).some(([key, value]) => key !== "model" &&
|
|
5353
5252
|
key !== "model_reasoning_effort" &&
|
|
5253
|
+
key !== "model_provider" &&
|
|
5254
|
+
key !== "model_providers" &&
|
|
5354
5255
|
!(key === "analytics" &&
|
|
5355
5256
|
isJsonObject(value) &&
|
|
5356
5257
|
Object.keys(value).every((key) => key === "enabled")))) {
|
|
5357
|
-
throw new CodexSecurityError("Skill commands only support model, model_reasoning_effort, and analytics.enabled overrides.");
|
|
5258
|
+
throw new CodexSecurityError("Skill commands only support model, model_reasoning_effort, model_provider, model_providers, and analytics.enabled overrides.");
|
|
5358
5259
|
}
|
|
5260
|
+
if (options.serviceTier !== undefined)
|
|
5261
|
+
overrides["service_tier"] = options.serviceTier;
|
|
5359
5262
|
const { model, reasoningEffort } = scanModelConfiguration(await mergedCodexConfig({ codexOverrides: overrides }));
|
|
5263
|
+
const provider = options.provider ?? overrides["model_provider"];
|
|
5264
|
+
const providerConfiguration = options.providerConfiguration ??
|
|
5265
|
+
(provider === undefined
|
|
5266
|
+
? undefined
|
|
5267
|
+
: (overrides["model_providers"]?.[provider] ??
|
|
5268
|
+
(isExternalModelProvider(provider)
|
|
5269
|
+
? EXTERNAL_CODEX_PROVIDERS[provider]
|
|
5270
|
+
: undefined)));
|
|
5271
|
+
const effectiveOverrides = resolveCommandAuthConfig(mergeCodexOverrides(overrides, provider === undefined
|
|
5272
|
+
? {}
|
|
5273
|
+
: {
|
|
5274
|
+
model_provider: provider,
|
|
5275
|
+
...(providerConfiguration === undefined
|
|
5276
|
+
? {}
|
|
5277
|
+
: { model_providers: { [provider]: providerConfiguration } }),
|
|
5278
|
+
}), configuredCodexHome(options.environment ?? dependencies.environment));
|
|
5360
5279
|
const directory = options.directory ?? dependencies.currentDirectory();
|
|
5361
5280
|
const contents = [...(options.findings ?? [])];
|
|
5362
5281
|
for (const input of inputs) {
|
|
@@ -5431,7 +5350,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
5431
5350
|
...(options.findings === undefined
|
|
5432
5351
|
? []
|
|
5433
5352
|
: [
|
|
5434
|
-
'Return exactly one JSON object with a "patches" array. Include one object for every supplied finding: {"occurrenceId":"...","status":"verified|no_change|blocked|failed","files":["relative/path"],"verification":"proof that the original issue is fixed and legitimate behavior still works","reason":"required for blocked or failed outcomes"}. Use "verified" only after the original issue no longer reproduces and relevant checks pass. Preserve unrelated local changes.',
|
|
5353
|
+
'Return exactly one JSON object with a "patches" array. Include one object for every supplied finding: {"occurrenceId":"...","status":"verified|no_change|blocked|failed","files":["relative/path"],"verification":"required for verified and no_change outcomes: proof that the original issue is fixed or that the current code is already safe, and that legitimate behavior still works","reason":"required for blocked or failed outcomes"}. Use "verified" only after the original issue no longer reproduces and relevant checks pass. Preserve unrelated local changes.',
|
|
5435
5354
|
]),
|
|
5436
5355
|
]),
|
|
5437
5356
|
...(options.findingInstructions === undefined
|
|
@@ -5481,20 +5400,19 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
5481
5400
|
`model=${JSON.stringify(model)}`,
|
|
5482
5401
|
"--config",
|
|
5483
5402
|
`model_reasoning_effort=${JSON.stringify(reasoningEffort)}`,
|
|
5484
|
-
...
|
|
5403
|
+
...(options.serviceTier === undefined
|
|
5404
|
+
? []
|
|
5405
|
+
: ["--config", `service_tier=${JSON.stringify(options.serviceTier)}`]),
|
|
5406
|
+
...codex
|
|
5485
5407
|
.filter((value) => value.startsWith("analytics.") || value.startsWith("analytics="))
|
|
5486
5408
|
.flatMap((value) => ["--config", value]),
|
|
5487
|
-
...(
|
|
5488
|
-
? []
|
|
5489
|
-
: ["--config", `model_provider=${JSON.stringify(options.provider)}`]),
|
|
5490
|
-
...(options.provider === undefined ||
|
|
5491
|
-
options.providerConfiguration === undefined
|
|
5409
|
+
...(provider === undefined
|
|
5492
5410
|
? []
|
|
5493
|
-
:
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5411
|
+
: ["--config", `model_provider=${JSON.stringify(provider)}`]),
|
|
5412
|
+
...modelProviderConfigOverride(effectiveOverrides).flatMap((value) => [
|
|
5413
|
+
"--config",
|
|
5414
|
+
value,
|
|
5415
|
+
]),
|
|
5498
5416
|
"--config",
|
|
5499
5417
|
verify || assess
|
|
5500
5418
|
? 'approval_policy="on-request"'
|
|
@@ -5524,8 +5442,8 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
5524
5442
|
command: verify ? "verify-fix" : patch || assess ? "patch" : "validate",
|
|
5525
5443
|
auth: options.auth ?? "auto",
|
|
5526
5444
|
directory,
|
|
5527
|
-
modelProvider:
|
|
5528
|
-
|
|
5445
|
+
modelProvider: provider,
|
|
5446
|
+
codexOverrides: effectiveOverrides,
|
|
5529
5447
|
stdout,
|
|
5530
5448
|
stderr,
|
|
5531
5449
|
...(appServer
|
|
@@ -5547,7 +5465,6 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
5547
5465
|
export async function readSkillCommandOutput(stream, appServer) {
|
|
5548
5466
|
let message;
|
|
5549
5467
|
let error;
|
|
5550
|
-
let malformed = false;
|
|
5551
5468
|
let threadId;
|
|
5552
5469
|
let turnId;
|
|
5553
5470
|
let completed = false;
|
|
@@ -5603,11 +5520,9 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
5603
5520
|
event = JSON.parse(line);
|
|
5604
5521
|
}
|
|
5605
5522
|
catch {
|
|
5606
|
-
malformed = true;
|
|
5607
5523
|
continue;
|
|
5608
5524
|
}
|
|
5609
5525
|
if (typeof event !== "object" || event === null) {
|
|
5610
|
-
malformed = true;
|
|
5611
5526
|
continue;
|
|
5612
5527
|
}
|
|
5613
5528
|
const value = event;
|
|
@@ -5638,7 +5553,7 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
5638
5553
|
}
|
|
5639
5554
|
else if (value["id"] === 1 || value["id"] === "login") {
|
|
5640
5555
|
if (value["id"] === 1) {
|
|
5641
|
-
send({ method: "
|
|
5556
|
+
send({ method: "initialized" });
|
|
5642
5557
|
if (appServer.apiKey !== undefined) {
|
|
5643
5558
|
send({
|
|
5644
5559
|
id: "login",
|
|
@@ -5811,7 +5726,6 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
5811
5726
|
return {
|
|
5812
5727
|
...(message === undefined ? {} : { message }),
|
|
5813
5728
|
...(error === undefined ? {} : { error }),
|
|
5814
|
-
malformed,
|
|
5815
5729
|
...(appServer === undefined ? {} : { completed }),
|
|
5816
5730
|
...(sandboxUnavailable ? { sandboxUnavailable } : {}),
|
|
5817
5731
|
};
|
|
@@ -5851,36 +5765,8 @@ function incurErrorMessage(output) {
|
|
|
5851
5765
|
}
|
|
5852
5766
|
async function runExport(arguments_, output, errorOutput, dependencies) {
|
|
5853
5767
|
try {
|
|
5854
|
-
const
|
|
5855
|
-
const
|
|
5856
|
-
const scanLocalOutput = join("exports", EXPORT_DEFAULT_OUTPUTS[arguments_.format]);
|
|
5857
|
-
if (arguments_.output !== "-" &&
|
|
5858
|
-
!isOutsidePath(scanRelativeOutput) &&
|
|
5859
|
-
scanRelativeOutput !== scanLocalOutput) {
|
|
5860
|
-
throw new CodexSecurityError("The export output path cannot overwrite a scan artifact.");
|
|
5861
|
-
}
|
|
5862
|
-
const outputPath = arguments_.output === "-"
|
|
5863
|
-
? "-"
|
|
5864
|
-
: !isOutsidePath(scanRelativeOutput)
|
|
5865
|
-
? join(canonicalScan, scanRelativeOutput)
|
|
5866
|
-
: join(await realpath(dirname(arguments_.output)).catch((error) => {
|
|
5867
|
-
if (error.code === "ENOENT") {
|
|
5868
|
-
throw new CodexSecurityError(`Export output directory does not exist: ${dirname(arguments_.output)}. Create the directory and retry.`);
|
|
5869
|
-
}
|
|
5870
|
-
throw error;
|
|
5871
|
-
}), basename(arguments_.output));
|
|
5872
|
-
if (arguments_.output !== "-") {
|
|
5873
|
-
const currentDirectory = dependencies.currentDirectory();
|
|
5874
|
-
const outputFromCurrent = relative(currentDirectory, arguments_.output);
|
|
5875
|
-
if (!isOutsidePath(outputFromCurrent)) {
|
|
5876
|
-
const canonicalCurrent = await realpath(currentDirectory).catch(() => currentDirectory);
|
|
5877
|
-
if (relative(resolve(canonicalCurrent, outputFromCurrent), outputPath) !==
|
|
5878
|
-
"") {
|
|
5879
|
-
throw new CodexSecurityError("The export output path cannot traverse a repository symlink.");
|
|
5880
|
-
}
|
|
5881
|
-
}
|
|
5882
|
-
}
|
|
5883
|
-
const contents = await dependencies.exportFindings({ ...arguments_, scanDir: canonicalScan, output: outputPath }, output);
|
|
5768
|
+
const prepared = await resolveArtifactExportOutput(arguments_, dependencies.currentDirectory());
|
|
5769
|
+
const contents = await dependencies.exportFindings(prepared, output);
|
|
5884
5770
|
if (arguments_.output === "-") {
|
|
5885
5771
|
if (contents !== undefined) {
|
|
5886
5772
|
await writeCliOutput(output, Buffer.from(contents));
|
|
@@ -5908,12 +5794,7 @@ async function chooseInteractiveAuthentication(options, errorOutput, dependencie
|
|
|
5908
5794
|
const authentication = scanAuthentication(dependencies.environment, auth, provider);
|
|
5909
5795
|
if (authentication.method !== "api_key")
|
|
5910
5796
|
return auth;
|
|
5911
|
-
const prompt = dependencies.scanAuthenticationPrompt ??
|
|
5912
|
-
createBulkScanDiscoveryDependencies({
|
|
5913
|
-
output: errorOutput,
|
|
5914
|
-
now: dependencies.now,
|
|
5915
|
-
currentDirectory: dependencies.currentDirectory,
|
|
5916
|
-
}).prompt;
|
|
5797
|
+
const prompt = dependencies.scanAuthenticationPrompt ?? createTerminalPrompt(errorOutput);
|
|
5917
5798
|
const hasStoredSignIn = dependencies.hasStoredChatGPTSignIn;
|
|
5918
5799
|
if (!prompt.isInteractive() ||
|
|
5919
5800
|
hasStoredSignIn === undefined ||
|
|
@@ -5987,11 +5868,12 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
5987
5868
|
const diagnostic = (event, fields = {}) => {
|
|
5988
5869
|
if (!verbose)
|
|
5989
5870
|
return;
|
|
5990
|
-
const attributes = Object.entries(fields).flatMap(([name, value]) =>
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
]
|
|
5871
|
+
const attributes = Object.entries(fields).flatMap(([name, value]) => {
|
|
5872
|
+
if (value === undefined)
|
|
5873
|
+
return [];
|
|
5874
|
+
const displayed = typeof value === "string" ? diagnosticValue(value) : value;
|
|
5875
|
+
return [`${name}=${JSON.stringify(displayed)}`];
|
|
5876
|
+
});
|
|
5995
5877
|
writeAboveProgress(() => {
|
|
5996
5878
|
errorOutput.write(`codex-security: debug: ${event}${attributes.length === 0 ? "" : ` ${attributes.join(" ")}`}\n`);
|
|
5997
5879
|
});
|
|
@@ -6036,11 +5918,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6036
5918
|
const onInterrupt = signalListener("SIGINT");
|
|
6037
5919
|
const onTerminate = signalListener("SIGTERM");
|
|
6038
5920
|
const removeSignalListeners = () => {
|
|
6039
|
-
dependencies
|
|
6040
|
-
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
5921
|
+
signalHandlers(dependencies, "remove", onInterrupt, onTerminate);
|
|
6041
5922
|
};
|
|
6042
|
-
dependencies
|
|
6043
|
-
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
5923
|
+
signalHandlers(dependencies, "add", onInterrupt, onTerminate);
|
|
6044
5924
|
let security = null;
|
|
6045
5925
|
let result = null;
|
|
6046
5926
|
let preflight = null;
|
|
@@ -6049,6 +5929,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6049
5929
|
let providerOptions = { provider: "openai" };
|
|
6050
5930
|
let auth = arguments_.auth;
|
|
6051
5931
|
let patchAnalyticsOverride;
|
|
5932
|
+
let patchServiceTier;
|
|
6052
5933
|
let selectedAuthentication = null;
|
|
6053
5934
|
let repository = "";
|
|
6054
5935
|
let failed = false;
|
|
@@ -6070,11 +5951,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6070
5951
|
};
|
|
6071
5952
|
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
6072
5953
|
scanModelConfiguration(effectiveConfiguration));
|
|
5954
|
+
patchServiceTier =
|
|
5955
|
+
resolveCodexProfile(effectiveConfiguration)["service_tier"] ?? "default";
|
|
6073
5956
|
const provider = scanModelProvider(effectiveConfiguration);
|
|
6074
5957
|
const analytics = effectiveConfiguration["analytics"];
|
|
6075
|
-
if (analytics !== undefined
|
|
6076
|
-
isJsonObject(analytics) &&
|
|
6077
|
-
analytics["enabled"] !== undefined) {
|
|
5958
|
+
if (isJsonObject(analytics) && analytics["enabled"] !== undefined) {
|
|
6078
5959
|
patchAnalyticsOverride = `analytics.enabled=${JSON.stringify(analytics["enabled"])}`;
|
|
6079
5960
|
}
|
|
6080
5961
|
auth =
|
|
@@ -6136,7 +6017,6 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6136
6017
|
: { maxCostUsd: arguments_.maxCostUsd }),
|
|
6137
6018
|
clock: dependencies,
|
|
6138
6019
|
color: dependencies.environment["NO_COLOR"] === undefined,
|
|
6139
|
-
sanitize: safeErrorMessage,
|
|
6140
6020
|
input: scanInput,
|
|
6141
6021
|
onInterrupt,
|
|
6142
6022
|
});
|
|
@@ -6244,6 +6124,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6244
6124
|
},
|
|
6245
6125
|
onAuthentication: (authentication) => {
|
|
6246
6126
|
selectedAuthentication = authentication;
|
|
6127
|
+
const bedrock = providerOptions.provider === "amazon-bedrock" ||
|
|
6128
|
+
authentication.method === "aws_credentials";
|
|
6247
6129
|
diagnostic("authentication.selected", {
|
|
6248
6130
|
requested: auth ?? DEFAULT_SCAN_AUTH,
|
|
6249
6131
|
method: authentication.method,
|
|
@@ -6258,6 +6140,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6258
6140
|
: authentication.method === "command"
|
|
6259
6141
|
? "Using native Codex command authentication"
|
|
6260
6142
|
: "Using stored Codex credentials");
|
|
6143
|
+
if (bedrock) {
|
|
6144
|
+
dashboard.note("Amazon Bedrock uses AWS authentication; OpenAI sign-in is not required for model access or local results.");
|
|
6145
|
+
}
|
|
6261
6146
|
return;
|
|
6262
6147
|
}
|
|
6263
6148
|
progress?.stopTimer();
|
|
@@ -6274,6 +6159,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6274
6159
|
else {
|
|
6275
6160
|
progress?.stage("Authentication: stored Codex credentials.");
|
|
6276
6161
|
}
|
|
6162
|
+
if (bedrock) {
|
|
6163
|
+
progress?.stage("Amazon Bedrock uses AWS authentication; OpenAI sign-in is not required for model access or local results.");
|
|
6164
|
+
}
|
|
6277
6165
|
progress?.startTimer("Preparing scan");
|
|
6278
6166
|
},
|
|
6279
6167
|
onTrustedAccessStatus: (status) => {
|
|
@@ -6455,7 +6343,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6455
6343
|
const costLimitFailure = failure instanceof ScanCostLimitExceededError ? failure : undefined;
|
|
6456
6344
|
const message = failure instanceof OutputInsideProtectedRootError
|
|
6457
6345
|
? errorMessage(protectedRootErrorMessage(failure))
|
|
6458
|
-
: scanFailureMessage(failure, selectedAuthentication);
|
|
6346
|
+
: scanFailureMessage(failure, selectedAuthentication, providerOptions.provider);
|
|
6459
6347
|
diagnostic("scan.failed", {
|
|
6460
6348
|
classification: costLimitFailure !== undefined
|
|
6461
6349
|
? "cost_limit_exceeded"
|
|
@@ -6574,11 +6462,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6574
6462
|
(dependencies.patchEditor !== undefined || process.stdin.isTTY === true)) {
|
|
6575
6463
|
const confirmed = arguments_.patch ||
|
|
6576
6464
|
(await (dependencies.confirmPatchReview ??
|
|
6577
|
-
|
|
6578
|
-
output: errorOutput,
|
|
6579
|
-
now: dependencies.now,
|
|
6580
|
-
currentDirectory: dependencies.currentDirectory,
|
|
6581
|
-
}).prompt.confirm)("Review and patch these findings?"));
|
|
6465
|
+
createTerminalPrompt(errorOutput).confirm)("Review and patch these findings?"));
|
|
6582
6466
|
if (confirmed) {
|
|
6583
6467
|
const selectPatches = dependencies.patchEditor ??
|
|
6584
6468
|
(async (target, candidates) => {
|
|
@@ -6603,13 +6487,17 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6603
6487
|
patchSelection.occurrenceIds.includes(finding.occurrenceId))),
|
|
6604
6488
|
};
|
|
6605
6489
|
try {
|
|
6606
|
-
patches = await runFindingPatches(selected,
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6490
|
+
patches = await runFindingPatches(selected, {
|
|
6491
|
+
codex: [
|
|
6492
|
+
`model=${JSON.stringify(effectiveModel)}`,
|
|
6493
|
+
`model_reasoning_effort=${JSON.stringify(effectiveReasoningEffort)}`,
|
|
6494
|
+
...(patchAnalyticsOverride === undefined
|
|
6495
|
+
? []
|
|
6496
|
+
: [patchAnalyticsOverride]),
|
|
6497
|
+
],
|
|
6498
|
+
}, errorOutput, dependencies, {
|
|
6612
6499
|
...providerOptions,
|
|
6500
|
+
serviceTier: patchServiceTier,
|
|
6613
6501
|
safetyIdentifier: arguments_.safetyIdentifier,
|
|
6614
6502
|
auth,
|
|
6615
6503
|
findingInstructions: patchSelection?.instructions,
|
|
@@ -6624,7 +6512,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6624
6512
|
}
|
|
6625
6513
|
}
|
|
6626
6514
|
catch (error) {
|
|
6627
|
-
errorOutput.write(`codex-security: ${
|
|
6515
|
+
errorOutput.write(`codex-security: ${diagnosticValue(error)}\n`);
|
|
6628
6516
|
scanData = { ...scanData, patches };
|
|
6629
6517
|
return completedScan(2);
|
|
6630
6518
|
}
|
|
@@ -6689,10 +6577,9 @@ function authenticationFailureMessage(authentication) {
|
|
|
6689
6577
|
"Sign in again with 'codex-security login --with-api-key' or provide a valid API key.");
|
|
6690
6578
|
}
|
|
6691
6579
|
if (authentication?.method === "api_key") {
|
|
6692
|
-
const openAiKey = authentication.source === "OPENAI_API_KEY" ||
|
|
6693
|
-
authentication.source === "CODEX_API_KEY";
|
|
6694
6580
|
return (`Authentication failed using ${authentication.source}. ` +
|
|
6695
|
-
(
|
|
6581
|
+
(authentication.source === "OPENAI_API_KEY" ||
|
|
6582
|
+
authentication.source === "CODEX_API_KEY"
|
|
6696
6583
|
? "Retry with '--auth chatgpt' or provide a valid API key."
|
|
6697
6584
|
: `Provide a valid ${authentication.source} for the selected provider.`));
|
|
6698
6585
|
}
|
|
@@ -6705,17 +6592,41 @@ function authenticationFailureMessage(authentication) {
|
|
|
6705
6592
|
}
|
|
6706
6593
|
return "Authentication failed. Check the selected provider's credentials and retry.";
|
|
6707
6594
|
}
|
|
6708
|
-
function scanFailureMessage(error, authentication) {
|
|
6595
|
+
function scanFailureMessage(error, authentication, provider) {
|
|
6709
6596
|
// A local failure keeps its own message. Classification matches bare words
|
|
6710
6597
|
// such as "permission denied" anywhere in the text, so an EACCES from a
|
|
6711
6598
|
// read-only TMPDIR would otherwise be reported as a credential problem.
|
|
6712
|
-
//
|
|
6713
|
-
// The advice branches below still replace the underlying text rather than
|
|
6714
|
-
// appending it. That is deliberate: upstream authentication and authorization
|
|
6715
|
-
// errors can name the organization or project, which must not reach stderr or
|
|
6716
|
-
// the JSON error field.
|
|
6717
6599
|
if (isLocalScanFailure(error))
|
|
6718
6600
|
return diagnosticValue(error);
|
|
6601
|
+
const classification = classifyConnectionFailure(error);
|
|
6602
|
+
if (provider === "amazon-bedrock" ||
|
|
6603
|
+
authentication?.method === "aws_credentials") {
|
|
6604
|
+
const detail = diagnosticValue(error);
|
|
6605
|
+
switch (classification) {
|
|
6606
|
+
case "unauthorized":
|
|
6607
|
+
if (authentication?.method === "command") {
|
|
6608
|
+
return `${detail}\n${authenticationFailureMessage(authentication)}`;
|
|
6609
|
+
}
|
|
6610
|
+
if (authentication?.method === "aws_credentials") {
|
|
6611
|
+
return (`${detail}\n${authenticationFailureMessage(authentication)} ` +
|
|
6612
|
+
(authentication.source === "AWS_BEARER_TOKEN_BEDROCK"
|
|
6613
|
+
? "Refresh AWS_BEARER_TOKEN_BEDROCK in the environment running this command."
|
|
6614
|
+
: "Refresh the selected AWS credentials in the environment running this command. Temporary access-key credentials also require AWS_SESSION_TOKEN."));
|
|
6615
|
+
}
|
|
6616
|
+
return `${detail}\nAmazon Bedrock authentication failed. Check the credentials configured for the selected provider.`;
|
|
6617
|
+
case "forbidden":
|
|
6618
|
+
if (authentication?.method === "command") {
|
|
6619
|
+
return (`${detail}\nThe configured provider auth command's credentials cannot access the Amazon Bedrock model. ` +
|
|
6620
|
+
"Check the configured provider auth command, AWS identity and Bedrock model permissions, configured AWS region, and model ID.");
|
|
6621
|
+
}
|
|
6622
|
+
return (`${detail}\nThe AWS credentials${authentication?.method === "aws_credentials" ? ` from ${authentication.source}` : ""} cannot access the configured Amazon Bedrock model. ` +
|
|
6623
|
+
"Check your AWS identity and Bedrock model permissions, configured AWS region, and model ID.");
|
|
6624
|
+
case "rate_limited":
|
|
6625
|
+
return `${detail}\nAmazon Bedrock throttled the request. Check the model quota in the configured AWS region and retry.`;
|
|
6626
|
+
default:
|
|
6627
|
+
return detail;
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6719
6630
|
const message = errorMessage(error);
|
|
6720
6631
|
const nativeRefreshRecovery = message.match(/\b(?:your access token could not be refreshed because you have since logged out or signed in to another account\. Please sign in again\.|your authentication session could not be refreshed automatically\. Please log out and sign in again\.)/iu)?.[0];
|
|
6721
6632
|
if (nativeRefreshRecovery !== undefined)
|
|
@@ -6726,17 +6637,13 @@ function scanFailureMessage(error, authentication) {
|
|
|
6726
6637
|
"If the sign-in recently changed, check 'npx @openai/codex-security login status' and retry. " +
|
|
6727
6638
|
"Otherwise run 'npx @openai/codex-security logout', then 'npx @openai/codex-security login'.");
|
|
6728
6639
|
}
|
|
6729
|
-
switch (
|
|
6640
|
+
switch (classification) {
|
|
6730
6641
|
case "unauthorized":
|
|
6731
6642
|
return authenticationFailureMessage(authentication);
|
|
6732
6643
|
case "forbidden":
|
|
6733
6644
|
if (authentication?.method === "command") {
|
|
6734
6645
|
return "The configured Codex provider denied access. Check the command credentials and provider permissions.";
|
|
6735
6646
|
}
|
|
6736
|
-
if (authentication?.method === "aws_credentials") {
|
|
6737
|
-
return (`The AWS credentials from ${authentication.source} cannot access the configured Amazon Bedrock model. ` +
|
|
6738
|
-
"Check your AWS identity and Bedrock model permissions.");
|
|
6739
|
-
}
|
|
6740
6647
|
return authentication?.method === "api_key"
|
|
6741
6648
|
? `The API key from ${authentication.source} cannot access the configured model. ` +
|
|
6742
6649
|
"Retry with '--auth chatgpt' or use an API key with model access."
|
|
@@ -6798,9 +6705,8 @@ async function readDeepScanStop(result, maxCostUsd, runWorkbench) {
|
|
|
6798
6705
|
return undefined;
|
|
6799
6706
|
const { maxDiscoveryRuns, maxTimeHours } = state.config;
|
|
6800
6707
|
if (state.dispatchedCount >= maxDiscoveryRuns) {
|
|
6801
|
-
const stillFindingIssues = state.completionSequence > 0 && state.noNewStreak === 0;
|
|
6802
6708
|
return {
|
|
6803
|
-
reason: `Reached the limit of ${maxDiscoveryRuns} review rounds. ${
|
|
6709
|
+
reason: `Reached the limit of ${maxDiscoveryRuns} review rounds. ${state.completionSequence > 0 && state.noNewStreak === 0 ? "The latest review still found new issues." : "More issues may remain."}`,
|
|
6804
6710
|
nextStep: `To scan further, rerun with --max-discovery-runs greater than ${maxDiscoveryRuns}.`,
|
|
6805
6711
|
};
|
|
6806
6712
|
}
|
|
@@ -6825,12 +6731,7 @@ function printScanSummary(result, progress, errorOutput, color, showCost, deepSc
|
|
|
6825
6731
|
for (const finding of findings) {
|
|
6826
6732
|
severities.set(finding.severity.level, (severities.get(finding.severity.level) ?? 0) + 1);
|
|
6827
6733
|
}
|
|
6828
|
-
const severitySummary =
|
|
6829
|
-
const count = severities.get(severity);
|
|
6830
|
-
return count === undefined ? null : `${count} ${severity}`;
|
|
6831
|
-
})
|
|
6832
|
-
.filter((value) => value !== null)
|
|
6833
|
-
.join(", ");
|
|
6734
|
+
const severitySummary = SCAN_SEVERITIES.flatMap((severity) => severities.has(severity) ? `${severities.get(severity)} ${severity}` : []).join(", ");
|
|
6834
6735
|
const started = Date.parse(result.manifest.scan.startedAt);
|
|
6835
6736
|
const completed = Date.parse(result.manifest.scan.completedAt);
|
|
6836
6737
|
const elapsed = Number.isFinite(started) &&
|
|
@@ -6854,8 +6755,12 @@ function printScanSummary(result, progress, errorOutput, color, showCost, deepSc
|
|
|
6854
6755
|
: severities.has("medium")
|
|
6855
6756
|
? 33
|
|
6856
6757
|
: 36;
|
|
6857
|
-
|
|
6858
|
-
|
|
6758
|
+
const threatModelPath = result.threatModelPath;
|
|
6759
|
+
errorOutput.write(`\n ${paint("REPORT", "1;36")} ${paint(errorMessage(result.reportPath), 4)}\n` +
|
|
6760
|
+
(threatModelPath === null
|
|
6761
|
+
? ""
|
|
6762
|
+
: ` ${paint("THREAT MODEL", "1;36")} ${paint(errorMessage(threatModelPath), 4)}\n`) +
|
|
6763
|
+
`\n ${paint("FINDINGS", 1)} ${paint(`${findingCount}${findingSummary === "" ? "" : ` (${findingSummary})`}`, findingColor)}\n` +
|
|
6859
6764
|
` ${paint("COVERAGE", 1)} ${result.coverage.completeness}\n` +
|
|
6860
6765
|
(deepScanStop === undefined
|
|
6861
6766
|
? ""
|
|
@@ -6896,19 +6801,18 @@ function protectedRootErrorMessage(error) {
|
|
|
6896
6801
|
? "Scan artifacts cannot be written inside the protected scan root."
|
|
6897
6802
|
: "Temporary and runtime files cannot be created inside the protected scan root.";
|
|
6898
6803
|
const suggestion = suggestedOutputDirectory(error.protectedRoot);
|
|
6899
|
-
const recovery = error.pathKind === "output"
|
|
6900
|
-
? suggestion === undefined
|
|
6901
|
-
? "Choose a private output directory outside the protected root."
|
|
6902
|
-
: `Re-run with --output-dir ${quoteCliPath(suggestion)}.`
|
|
6903
|
-
: suggestion === undefined
|
|
6904
|
-
? "Set TMPDIR (or TEMP on Windows) to a writable directory outside the protected root."
|
|
6905
|
-
: `Set TMPDIR (or TEMP on Windows) to ${quoteCliPath(suggestion)} after creating that directory.`;
|
|
6906
6804
|
return [
|
|
6907
6805
|
`${description} must be outside the scanned directory and any enclosing Git worktree.`,
|
|
6908
6806
|
` Resolved path: ${error.outputDirectory}`,
|
|
6909
6807
|
` Protected root: ${error.protectedRoot}`,
|
|
6910
6808
|
` Reason: ${reason}`,
|
|
6911
|
-
|
|
6809
|
+
error.pathKind === "output"
|
|
6810
|
+
? suggestion === undefined
|
|
6811
|
+
? "Choose a private output directory outside the protected root."
|
|
6812
|
+
: `Re-run with --output-dir ${quoteCliPath(suggestion)}.`
|
|
6813
|
+
: suggestion === undefined
|
|
6814
|
+
? "Set TMPDIR (or TEMP on Windows) to a writable directory outside the protected root."
|
|
6815
|
+
: `Set TMPDIR (or TEMP on Windows) to ${quoteCliPath(suggestion)} after creating that directory.`,
|
|
6912
6816
|
].join("\n");
|
|
6913
6817
|
}
|
|
6914
6818
|
function suggestedOutputDirectory(protectedRoot) {
|
|
@@ -7023,12 +6927,12 @@ export function parseCodexOverrides(values, model, effort, provider, defaults) {
|
|
|
7023
6927
|
}
|
|
7024
6928
|
for (const value of values) {
|
|
7025
6929
|
const separator = value.indexOf("=");
|
|
7026
|
-
const key = separator < 0 ? "" : value.slice(0, separator);
|
|
6930
|
+
const key = separator < 0 ? "" : value.slice(0, separator).trim();
|
|
7027
6931
|
const literal = separator < 0 ? "" : value.slice(separator + 1);
|
|
7028
6932
|
if (key.length === 0 || literal.length === 0) {
|
|
7029
6933
|
throw new CodexSecurityError("--codex expects KEY=VALUE");
|
|
7030
6934
|
}
|
|
7031
|
-
const parts = key.split(".");
|
|
6935
|
+
const parts = key.split(".").map((part) => part.trim());
|
|
7032
6936
|
if (parts.some((part) => part.length === 0 ||
|
|
7033
6937
|
part === "__proto__" ||
|
|
7034
6938
|
part === "prototype" ||
|
|
@@ -7205,9 +7109,7 @@ export class Progress {
|
|
|
7205
7109
|
}
|
|
7206
7110
|
#line(message) {
|
|
7207
7111
|
const elapsedSeconds = this.elapsedSeconds;
|
|
7208
|
-
|
|
7209
|
-
const seconds = elapsedSeconds % 60;
|
|
7210
|
-
return `[${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}] ${message}`;
|
|
7112
|
+
return `[${String(Math.floor(elapsedSeconds / 60)).padStart(2, "0")}:${String(elapsedSeconds % 60).padStart(2, "0")}] ${message}`;
|
|
7211
7113
|
}
|
|
7212
7114
|
#observeStreamErrors() {
|
|
7213
7115
|
this.#streamErrorsActive = true;
|
|
@@ -7244,9 +7146,6 @@ function interruptedExit(signal, scanDir, errorOutput) {
|
|
|
7244
7146
|
: `codex-security: Partial output was kept at ${errorMessage(scanDir)}.\n`);
|
|
7245
7147
|
return ctrlC ? 130 : 143;
|
|
7246
7148
|
}
|
|
7247
|
-
function isJsonObject(value) {
|
|
7248
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7249
|
-
}
|
|
7250
7149
|
function invokedAsMain() {
|
|
7251
7150
|
const entrypoint = process.argv[1];
|
|
7252
7151
|
if (entrypoint === undefined)
|
|
@@ -7260,6 +7159,11 @@ function invokedAsMain() {
|
|
|
7260
7159
|
return false;
|
|
7261
7160
|
}
|
|
7262
7161
|
}
|
|
7162
|
+
const interruptedExitCode = (signal) => signal.reason === "SIGINT"
|
|
7163
|
+
? 130
|
|
7164
|
+
: signal.reason === "SIGTERM"
|
|
7165
|
+
? 143
|
|
7166
|
+
: undefined;
|
|
7263
7167
|
if (invokedAsMain()) {
|
|
7264
7168
|
void main().then((exitCode) => {
|
|
7265
7169
|
process.exitCode = exitCode;
|
|
@@ -7268,4 +7172,17 @@ if (invokedAsMain()) {
|
|
|
7268
7172
|
process.exitCode = 2;
|
|
7269
7173
|
});
|
|
7270
7174
|
}
|
|
7175
|
+
function listenForAbort(dependencies, controller) {
|
|
7176
|
+
const onInterrupt = () => controller.abort("SIGINT");
|
|
7177
|
+
const onTerminate = () => controller.abort("SIGTERM");
|
|
7178
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
7179
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
7180
|
+
return () => {
|
|
7181
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
7182
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
7183
|
+
};
|
|
7184
|
+
}
|
|
7185
|
+
function withoutLinearCredentials(environment) {
|
|
7186
|
+
return Object.fromEntries(Object.entries(environment).filter(([name]) => !/^(?:CODEX_SECURITY_)?LINEAR_(?:API_KEY|ACCESS_TOKEN)$/iu.test(name)));
|
|
7187
|
+
}
|
|
7271
7188
|
//# sourceMappingURL=cli.js.map
|