@openai/codex-security 0.6.0 → 0.7.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 +68 -37
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
- 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/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/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/access-advisory.md +11 -0
- package/_bundled_plugin/references/core-scan.md +30 -77
- package/_bundled_plugin/references/final-report.md +45 -189
- package/_bundled_plugin/references/scan-contract.md +2 -0
- package/_bundled_plugin/references/scan-prologue.md +1 -1
- package/_bundled_plugin/references/scan-runtime.md +1 -5
- package/_bundled_plugin/references/threat-model.md +33 -41
- package/_bundled_plugin/schemas/coverage.schema.json +12 -1
- package/_bundled_plugin/schemas/scan-manifest.schema.json +1 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
- package/_bundled_plugin/scripts/deep_scan_workbench.py +145 -85
- package/_bundled_plugin/scripts/finalize_scan_contract.py +189 -57
- package/_bundled_plugin/scripts/report_projection.py +44 -15
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +3218 -0
- package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +644 -1
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +712 -0
- package/_bundled_plugin/scripts/workbench_cli.py +3 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
- package/_bundled_plugin/scripts/workbench_db.py +51 -22
- package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +51 -9
- package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
- package/_bundled_plugin/scripts/workbench_saved_results.py +641 -2387
- package/_bundled_plugin/scripts/workbench_scan_history.py +72 -7
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
- package/_bundled_plugin/scripts/workbench_target.py +142 -17
- package/_bundled_plugin/scripts/workbench_validation.py +9 -2
- package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
- package/_bundled_plugin/shared/workbench-migrations.json +28 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
- package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
- package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
- package/_bundled_plugin/skills/fix-finding/SKILL.md +9 -28
- package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
- package/_bundled_plugin/skills/publish-findings/SKILL.md +28 -24
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
- package/_bundled_plugin/skills/security-scan/SKILL.md +28 -16
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
- package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
- package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
- package/_bundled_plugin/skills/validation/SKILL.md +42 -104
- package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
- package/_bundled_plugin/skills/verify-fix/SKILL.md +4 -2
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
- package/dist/api.d.ts +5 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +341 -37
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +674 -419
- package/dist/cli.js.map +1 -1
- package/dist/component-scan.d.ts +8 -2
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +2 -0
- package/dist/component-scan.js.map +1 -1
- package/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +67 -33
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +18 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +107 -12
- package/dist/cost.js.map +1 -1
- package/dist/coverage-presentation.d.ts +6 -0
- package/dist/coverage-presentation.d.ts.map +1 -0
- package/dist/coverage-presentation.js +34 -0
- package/dist/coverage-presentation.js.map +1 -0
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +30 -4
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +3 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +7 -5
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/endor-findings.d.ts +4 -3
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +16 -11
- package/dist/endor-findings.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +13 -5
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +8 -1
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +1 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +11 -3
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +11 -1
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +15 -6
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-import-contract.d.ts +3 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +33 -25
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-imports-feature.d.ts +6 -0
- package/dist/external-imports-feature.d.ts.map +1 -0
- package/dist/external-imports-feature.js +51 -0
- package/dist/external-imports-feature.js.map +1 -0
- package/dist/finding-workflow.d.ts +22 -5
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +21 -9
- package/dist/finding-workflow.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +3 -1
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-findings.d.ts +4 -3
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +16 -14
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +19 -2
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/hosted-scan.d.ts +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +0 -5
- package/dist/hosted-scan.js.map +1 -1
- package/dist/import-scan.js +1 -1
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -0
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +17 -8
- package/dist/knowledge-base.js.map +1 -1
- package/dist/models.d.ts +1 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/owner-evidence.d.ts +2 -0
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +2 -1
- package/dist/owner-evidence.js.map +1 -1
- package/dist/publish.d.ts +2 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +1 -1
- package/dist/publish.js.map +1 -1
- package/dist/remediation.d.ts +1 -25
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -24
- package/dist/remediation.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +7 -7
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts +5 -3
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +79 -26
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +8 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-owner-suggestions.d.ts +1 -1
- package/dist/scan-owner-suggestions.d.ts.map +1 -1
- package/dist/scan-owner-suggestions.js +4 -4
- package/dist/scan-owner-suggestions.js.map +1 -1
- package/dist/scan-usage-display.d.ts +8 -0
- package/dist/scan-usage-display.d.ts.map +1 -0
- package/dist/scan-usage-display.js +46 -0
- package/dist/scan-usage-display.js.map +1 -0
- package/dist/scanner-import.d.ts +1 -1
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +7 -3
- package/dist/scanner-import.js.map +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +1 -20
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +4 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +9 -9
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/skill-authentication.d.ts +18 -0
- package/dist/skill-authentication.d.ts.map +1 -0
- package/dist/skill-authentication.js +82 -0
- package/dist/skill-authentication.js.map +1 -0
- package/dist/snyk-findings.d.ts +5 -4
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +18 -17
- package/dist/snyk-findings.js.map +1 -1
- package/dist/suggest-owners.d.ts +4 -1
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +53 -21
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +4 -1
- package/dist/targets.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -1
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +3 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +2 -1
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +27 -23
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +3 -4
- package/docs/cli.md +155 -38
- package/docs/findings-service.md +119 -118
- package/docs/hosted-remediation.md +19 -17
- package/docs/hosted-scans.md +37 -11
- package/package.json +8 -8
- package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
- package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
- package/_bundled_plugin/scripts/rank_preview.py +0 -129
package/dist/cli.js
CHANGED
|
@@ -15,9 +15,9 @@ import { withCodexPreflightLock } from "./provider-profile.js";
|
|
|
15
15
|
import { isNonEmptyString, notify, parseJson } from "./value.js";
|
|
16
16
|
import { compareTimestamps } from "./timestamps.js";
|
|
17
17
|
import { execFile as execFileCallback, execFileSync, spawn, } from "node:child_process";
|
|
18
|
-
import { createHash } from "node:crypto";
|
|
18
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
19
19
|
import { accessSync, constants, createReadStream, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
20
|
-
import { chmod, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm, writeFile, } from "node:fs/promises";
|
|
20
|
+
import { chmod, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, writeFile, } from "node:fs/promises";
|
|
21
21
|
import { tmpdir } from "node:os";
|
|
22
22
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, win32, } from "node:path";
|
|
23
23
|
import { cwd } from "node:process";
|
|
@@ -28,10 +28,12 @@ import { isDeepStrictEqual, parseArgs, promisify, stripVTControlCharacters, } fr
|
|
|
28
28
|
import { Cli, z } from "incur";
|
|
29
29
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
30
30
|
import { formatCliHelp } from "./cli-help.js";
|
|
31
|
+
import { formatCoverageScope } from "./coverage-presentation.js";
|
|
32
|
+
import { resolveSkillAuthentication } from "./skill-authentication.js";
|
|
31
33
|
import { scanLogsJson } from "./cli-scan-logs-json.js";
|
|
32
34
|
import { ARTIFACT_EXPORT_FILENAMES, exportEnvironment, resolveArtifactFormat, resolveArtifactExportOutput, resolveSavedArtifactDirectory, runArtifactExport, writeArtifactOutput as writeCliOutput, } from "./artifact-export.js";
|
|
33
35
|
export { exportEnvironment } from "./artifact-export.js";
|
|
34
|
-
import { parse as parseToml
|
|
36
|
+
import { parse as parseToml } from "smol-toml";
|
|
35
37
|
import { parse as parseYaml } from "yaml";
|
|
36
38
|
import { classifyConnectionFailure, CodexSecurity, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, scanCodexHome, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, runtimeScanAuthentication, selectedScanEnvironment, } from "./api.js";
|
|
37
39
|
import { accountStatus, CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, configuredCodexHome, environmentEntry, readCodexHomeConfig, } from "./auth.js";
|
|
@@ -42,7 +44,9 @@ import { parseImportedFindings } from "./findings-import.js";
|
|
|
42
44
|
import { publishScanToCustom } from "./custom-publish.js";
|
|
43
45
|
import { ExternalPublicationError, prepareExternalPublication, } from "./external-findings-publish.js";
|
|
44
46
|
import { prepareLocalExternalImport } from "./external-findings-import.js";
|
|
47
|
+
import { externalImportsDisabledMessage, externalImportsEnabled, } from "./external-imports-feature.js";
|
|
45
48
|
import { listLocalExternalFindings } from "./external-findings-local.js";
|
|
49
|
+
import { EXTERNAL_FINDINGS_READERS } from "./external-findings-read.js";
|
|
46
50
|
import { publishPatchReview, resolvePatchReviewPublisher, } from "./patch-publication.js";
|
|
47
51
|
import { DEFAULT_DEDUPE_CONCURRENCY } from "./deduplication/deduplication.js";
|
|
48
52
|
import { savedScanWorkbench } from "./saved-scan-bootstrap.js";
|
|
@@ -58,7 +62,7 @@ import { classifyScanSeverityInternal, classifyScanDirectorySeverityInternal, }
|
|
|
58
62
|
import { resolveCompletedScan, resolveWorkflowScan, } from "./saved-scan.js";
|
|
59
63
|
import { publishFindingsCsvToCloud, publishScanToCloud, } from "./cloud-publish.js";
|
|
60
64
|
import { createBulkScanDiscoveryDependencies, createTerminalPrompt, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
61
|
-
import { DEFAULT_CODEX_CONFIG,
|
|
65
|
+
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergeCodexOverrides, hasCommandAuth, inlineToml, quoteTomlString, modelProviderConfigOverride, resolveCommandAuthConfig, resolveCodexProfile, mergedCodexConfig, scanModel, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
62
66
|
import { formatUsd } from "./cost.js";
|
|
63
67
|
import { formatScanCost, formatScanCostTokens, formatTokenUsage, } from "./cost-model.js";
|
|
64
68
|
import { readRegularInputFile, resolveScanPrompts } from "./prompt-files.js";
|
|
@@ -75,7 +79,7 @@ import { componentPlanSchema } from "./component-plan.js";
|
|
|
75
79
|
import { runComponentScans, } from "./component-scan.js";
|
|
76
80
|
import { checkScanPublication, forceTerminatePublicationProcesses as terminatePublishers, publishScanInternal, } from "./publish.js";
|
|
77
81
|
import { importScan } from "./import-scan.js";
|
|
78
|
-
import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, withCredentialHomeLock, requireOutputOutsideRepositories, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome, resolveCodexCommand, resolvePluginPython, pluginMetadata, runWorkbench, sameFile, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
82
|
+
import { bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, resolvePluginPath, acquireCodexSecurityCredentialHomeLock, withCredentialHomeLock, requireOutputOutsideRepositories, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, environmentWithGit, expandHome, prepareCodexSecurityCredentialHome, resolveCodexCommand, resolvePluginPython, pluginMetadata, runWorkbench, workbenchEnvironment, sameFile, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
79
83
|
import { comparisonFindingGroups, comparisonForScan, matchScanFindingsInternal, unionFindingGroups, } from "./scan-comparison.js";
|
|
80
84
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
81
85
|
import { codexSecurityRequestContext } from "./request-metadata.js";
|
|
@@ -84,10 +88,11 @@ import { findScanSession, readSavedScanLogs, } from "./scan-logs.js";
|
|
|
84
88
|
import { sendFeedback } from "./feedback.js";
|
|
85
89
|
import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
86
90
|
import { ScanDashboard } from "./scan-dashboard.js";
|
|
91
|
+
import { ACCOUNT_LIMITS_UNAVAILABLE, formatAccountLimits, formatUsageFreshness, isChatGptAuthentication, USAGE_TIME_UNAVAILABLE, } from "./scan-usage-display.js";
|
|
87
92
|
import { policyDisplayData, runPolicyCommand, } from "./security-policy-cli.js";
|
|
88
93
|
import { scanPhaseLabel as scanPhase, scanProgressCount, } from "./worker-progress.js";
|
|
89
|
-
import { abortable, DiffTarget, enclosingGitWorktreeRoots, UNSUPPORTED_GIT_ENVIRONMENT, relativePathIsOutside as isOutsidePath, } from "./targets.js";
|
|
90
|
-
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
94
|
+
import { abortable, DiffTarget, enclosingGitWorktreeRoots, gitMarkerRoot, normalizeRepository, UNSUPPORTED_GIT_ENVIRONMENT, relativePathIsOutside as isOutsidePath, } from "./targets.js";
|
|
95
|
+
import { inspectTrustedExecutable, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
91
96
|
import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
|
|
92
97
|
import { readProjectConfig, resolveScanSettings, projectScopeTarget, configurationSources, projectConfigStarter, } from "./project-config.js";
|
|
93
98
|
import { resolveConfigPath } from "./config-path.js";
|
|
@@ -98,6 +103,19 @@ const PROGRESS_REFRESH_MILLISECONDS = 1_000;
|
|
|
98
103
|
const execFile = promisify(execFileCallback);
|
|
99
104
|
const WINDOWS_NETWORK_PATH = /^[\\/]{2}/u;
|
|
100
105
|
const WINDOWS_LOCAL_DEVICE_ROOT = /^[\\/]{2}[?.][\\/](?:[A-Za-z]:|Volume\{[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\}|GLOBALROOT[\\/]Device[\\/]HarddiskVolume[0-9]+)(?=[\\/]|$)/iu;
|
|
106
|
+
const FRAMEWORK_ACTIONS = new Set([
|
|
107
|
+
"--llms",
|
|
108
|
+
"--llms-full",
|
|
109
|
+
"--mcp",
|
|
110
|
+
"--update",
|
|
111
|
+
"--incur-update-check",
|
|
112
|
+
]);
|
|
113
|
+
const FRAMEWORK_VALUE_OPTIONS = new Set([
|
|
114
|
+
"--format",
|
|
115
|
+
"--filter-output",
|
|
116
|
+
"--token-limit",
|
|
117
|
+
"--token-offset",
|
|
118
|
+
]);
|
|
101
119
|
const OUTPUT_OPTION = /^--(?:format|filter-output|full-output|token-count|token-limit|token-offset)(?:=|$)/u;
|
|
102
120
|
const HIDE_CURSOR = "\u001B[?25l";
|
|
103
121
|
const SHOW_CURSOR = "\u001B[?25h";
|
|
@@ -701,23 +719,50 @@ const DEFAULT_DEPENDENCIES = {
|
|
|
701
719
|
runCodex: (args, output, environment, input) => runCodexSkillCommand(args, output, resolveCodexCommand(environment), environment, input),
|
|
702
720
|
runRepositoryCommand,
|
|
703
721
|
exportFindings: runArtifactExport,
|
|
704
|
-
runWorkbench: async (args, input, signal, pythonPath, protectedRoot) => {
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
722
|
+
runWorkbench: async (args, input, signal, pythonPath, protectedRoot, gitProtectedRoots = [], pluginPath) => {
|
|
723
|
+
const checkingTarget = args[0] === "get-scan" && args.includes("--check-target");
|
|
724
|
+
let environment = !checkingTarget || protectedRoot === undefined
|
|
725
|
+
? {
|
|
726
|
+
...exportEnvironment(),
|
|
727
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
|
|
728
|
+
}
|
|
729
|
+
: workbenchEnvironment(process.env);
|
|
730
|
+
const protectedRoots = await Promise.all((protectedRoot === undefined
|
|
731
|
+
? []
|
|
732
|
+
: typeof protectedRoot === "string"
|
|
733
|
+
? [protectedRoot]
|
|
734
|
+
: protectedRoot).map(async (root) => (await gitMarkerRoot(root, signal, "outermost")) ?? root));
|
|
735
|
+
const python = await resolvePluginPython({
|
|
736
|
+
configuredPath: pythonPath,
|
|
717
737
|
environment,
|
|
718
738
|
signal,
|
|
719
|
-
|
|
720
|
-
}
|
|
739
|
+
protectedRoot: protectedRoot === undefined ? undefined : protectedRoots,
|
|
740
|
+
});
|
|
741
|
+
if (checkingTarget && protectedRoot !== undefined) {
|
|
742
|
+
const git = await inspectTrustedExecutable("git", environment, [
|
|
743
|
+
...protectedRoots,
|
|
744
|
+
...gitProtectedRoots,
|
|
745
|
+
]);
|
|
746
|
+
environment = environmentWithGit(git.environment, git);
|
|
747
|
+
}
|
|
748
|
+
const workspace = pluginPath === undefined
|
|
749
|
+
? undefined
|
|
750
|
+
: await createIsolatedHome(undefined, (path) => requireOutputOutsideRepositories([...protectedRoots, ...gitProtectedRoots], path, "runtime"));
|
|
751
|
+
try {
|
|
752
|
+
return await runWorkbench({
|
|
753
|
+
python,
|
|
754
|
+
pluginRoot: workspace === undefined
|
|
755
|
+
? await bundledPluginRoot()
|
|
756
|
+
: await resolvePluginPath(pluginPath, workspace, signal),
|
|
757
|
+
environment,
|
|
758
|
+
signal,
|
|
759
|
+
failureMessage: "Could not read Codex Security scan history",
|
|
760
|
+
}, args, input);
|
|
761
|
+
}
|
|
762
|
+
finally {
|
|
763
|
+
if (workspace !== undefined)
|
|
764
|
+
await cleanupSdkDirectory(workspace).catch(() => undefined);
|
|
765
|
+
}
|
|
721
766
|
},
|
|
722
767
|
matchFindings: (input, options) => matchScanFindingsInternal(input, options, { surface: "cli" }),
|
|
723
768
|
};
|
|
@@ -736,80 +781,16 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
736
781
|
const ambientConfig = output.appServer === undefined
|
|
737
782
|
? {}
|
|
738
783
|
: resolveCodexProfile(await readCodexHomeConfig(processEnvironment));
|
|
739
|
-
const
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
// Native Codex ignores configured tables for these built-in providers.
|
|
743
|
-
const providerConfiguration = typeof provider === "string" &&
|
|
744
|
-
!["openai", "ollama", "lmstudio"].includes(provider)
|
|
745
|
-
? config["model_providers"]?.[provider]
|
|
746
|
-
: undefined;
|
|
747
|
-
const providerEnvKey = typeof providerConfiguration?.["env_key"] === "string"
|
|
748
|
-
? providerConfiguration["env_key"]
|
|
749
|
-
: undefined;
|
|
750
|
-
const commandAuth = providerConfiguration?.["auth"] != null;
|
|
751
|
-
const explicitChatgpt = output.auth === "chatgpt" && !isExternalModelProvider(provider);
|
|
752
|
-
const providerBearer = typeof providerConfiguration?.["experimental_bearer_token"] ===
|
|
753
|
-
"string";
|
|
754
|
-
const providerKeyConfigured = providerEnvKey !== undefined || providerBearer;
|
|
755
|
-
const requiresOpenAiAuth = !commandAuth &&
|
|
756
|
-
(explicitChatgpt || !providerKeyConfigured) &&
|
|
757
|
-
(provider === undefined ||
|
|
758
|
-
provider === "openai" ||
|
|
759
|
-
providerConfiguration?.["requires_openai_auth"] === true ||
|
|
760
|
-
(explicitChatgpt && providerKeyConfigured));
|
|
784
|
+
const resolved = resolveSkillAuthentication({ ...output, auth: output.auth }, processEnvironment, ambientConfig);
|
|
785
|
+
const { provider, providerConfiguration, providerEnvKey, requiresOpenAiAuth, } = resolved;
|
|
786
|
+
authentication = resolved.authentication;
|
|
761
787
|
modelProvider = output.modelProvider;
|
|
762
788
|
let credentialConfig;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
authentication = key
|
|
769
|
-
? { method: "api_key", source: providerEnvKey, verified: false }
|
|
770
|
-
: { method: "stored_credentials", verified: false };
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
authentication = scanAuthentication(processEnvironment, output.auth, provider, commandAuth);
|
|
774
|
-
}
|
|
775
|
-
if (authentication.method === "stored_credentials" &&
|
|
776
|
-
isExternalModelProvider(provider)) {
|
|
777
|
-
const externalProvider = EXTERNAL_CODEX_PROVIDERS[provider];
|
|
778
|
-
throw new AuthenticationRequiredError(`Set ${providerEnvKey ?? externalProvider.env_key} to run ${output.command} through ${externalProvider.name}.`);
|
|
779
|
-
}
|
|
780
|
-
let selected = selectedScanEnvironment(processEnvironment, authentication.method === "command" ? "chatgpt" : output.auth, provider);
|
|
781
|
-
if (explicitChatgpt &&
|
|
782
|
-
!commandAuth &&
|
|
783
|
-
providerConfiguration !== undefined &&
|
|
784
|
-
providerKeyConfigured) {
|
|
785
|
-
if (providerEnvKey !== undefined) {
|
|
786
|
-
selected = Object.fromEntries(Object.entries(selected).filter(([name]) => process.platform === "win32"
|
|
787
|
-
? name.toUpperCase() !== providerEnvKey.toUpperCase()
|
|
788
|
-
: name !== providerEnvKey));
|
|
789
|
-
}
|
|
790
|
-
// Native provider keys take precedence over stored authentication.
|
|
791
|
-
// Apply explicit ChatGPT selection to the home and CLI configuration.
|
|
792
|
-
const providerOverrides = typeof provider === "string"
|
|
793
|
-
? overrides["model_providers"]?.[provider]
|
|
794
|
-
: undefined;
|
|
795
|
-
for (const selectedConfig of [
|
|
796
|
-
providerConfiguration,
|
|
797
|
-
providerOverrides,
|
|
798
|
-
]) {
|
|
799
|
-
if (selectedConfig === undefined)
|
|
800
|
-
continue;
|
|
801
|
-
delete selectedConfig["env_key"];
|
|
802
|
-
delete selectedConfig["experimental_bearer_token"];
|
|
803
|
-
selectedConfig["requires_openai_auth"] = true;
|
|
804
|
-
}
|
|
805
|
-
args = [
|
|
806
|
-
...args,
|
|
807
|
-
...modelProviderConfigOverride(overrides).flatMap((value) => [
|
|
808
|
-
"--config",
|
|
809
|
-
value,
|
|
810
|
-
]),
|
|
811
|
-
];
|
|
812
|
-
}
|
|
789
|
+
let selected = resolved.environment;
|
|
790
|
+
args = [
|
|
791
|
+
...args,
|
|
792
|
+
...resolved.configOverrides.flatMap((value) => ["--config", value]),
|
|
793
|
+
];
|
|
813
794
|
if (authentication.method === "stored_credentials" &&
|
|
814
795
|
requiresOpenAiAuth) {
|
|
815
796
|
const directory = await realpath(output.directory ?? output.appServer?.directory ?? process.cwd());
|
|
@@ -1123,6 +1104,7 @@ async function skillDaybreakConfigOverrides(args, command, environment, director
|
|
|
1123
1104
|
return overrides;
|
|
1124
1105
|
}
|
|
1125
1106
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
1107
|
+
const importsEnabled = externalImportsEnabled(dependencies.environment);
|
|
1126
1108
|
const remediationOperation = argv[0] === "patch"
|
|
1127
1109
|
? "patch"
|
|
1128
1110
|
: argv[0] === "verify-fix"
|
|
@@ -1394,7 +1376,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1394
1376
|
async run({ args, format }) {
|
|
1395
1377
|
const requestedRepository = resolveCliPath(dependencies.currentDirectory(), args.repository ?? ".");
|
|
1396
1378
|
const repository = await realpath(requestedRepository).catch(() => requestedRepository);
|
|
1397
|
-
return presentHistory(await history(["list-repositories"], async (value) => {
|
|
1379
|
+
return presentHistory(await history(["list-repositories", "--status", "scanned"], async (value) => {
|
|
1398
1380
|
const repositories = value["repositories"];
|
|
1399
1381
|
let target = repositories.find((entry) => entry["targetPath"] === requestedRepository);
|
|
1400
1382
|
const canonicalTarget = repositories.find((entry) => entry["targetPath"] === repository);
|
|
@@ -1422,45 +1404,50 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1422
1404
|
}), "findings", format, { repository: requestedRepository });
|
|
1423
1405
|
},
|
|
1424
1406
|
});
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1407
|
+
if (importsEnabled) {
|
|
1408
|
+
findingFeedback.command("imported", {
|
|
1409
|
+
description: "List imported vendor evidence for a local repository.",
|
|
1410
|
+
mcp: false,
|
|
1411
|
+
args: z.object({
|
|
1412
|
+
repository: z
|
|
1413
|
+
.string()
|
|
1414
|
+
.optional()
|
|
1415
|
+
.describe("Local repository to inspect (default: current directory)."),
|
|
1416
|
+
}),
|
|
1417
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
1418
|
+
async run({ args, format, error: incurError }) {
|
|
1419
|
+
const controller = new AbortController();
|
|
1420
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
1421
|
+
try {
|
|
1422
|
+
const repository = resolveCliPath(dependencies.currentDirectory(), args.repository ?? ".");
|
|
1423
|
+
const findings = await (dependencies.listLocalExternalFindings ?? listLocalExternalFindings)({ repository }, {
|
|
1424
|
+
environment: dependencies.environment,
|
|
1425
|
+
signal: controller.signal,
|
|
1426
|
+
});
|
|
1427
|
+
return { repository, findings };
|
|
1428
|
+
}
|
|
1429
|
+
catch (error) {
|
|
1430
|
+
if (controller.signal.aborted) {
|
|
1431
|
+
exitCode = controller.signal.reason === "SIGINT" ? 130 : 143;
|
|
1432
|
+
if (argv.includes("--full-output") &&
|
|
1433
|
+
(format === "json" || format === "jsonl")) {
|
|
1434
|
+
structuredError = true;
|
|
1435
|
+
return incurError({
|
|
1436
|
+
code: "FINDINGS_READ_FAILED",
|
|
1437
|
+
message: diagnosticValue(error),
|
|
1438
|
+
exitCode,
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
return;
|
|
1454
1442
|
}
|
|
1455
|
-
|
|
1443
|
+
throw error;
|
|
1456
1444
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
});
|
|
1445
|
+
finally {
|
|
1446
|
+
removeSignals();
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1464
1451
|
const scanHistory = Cli.create("scans", {
|
|
1465
1452
|
description: "Review saved scans (default: list).",
|
|
1466
1453
|
})
|
|
@@ -2307,205 +2294,212 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2307
2294
|
});
|
|
2308
2295
|
},
|
|
2309
2296
|
});
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
.describe("
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
const
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
if (errorOutput.isTTY !== true)
|
|
2378
|
-
return;
|
|
2379
|
-
const step = event.total
|
|
2380
|
-
? Math.floor((event.completed * 10) / event.total)
|
|
2381
|
-
: 0;
|
|
2382
|
-
const key = `${event.phase}:${step}`;
|
|
2383
|
-
if (key === lastProgress)
|
|
2384
|
-
return;
|
|
2385
|
-
lastProgress = key;
|
|
2386
|
-
const labels = {
|
|
2387
|
-
reading: "Reading selected findings",
|
|
2388
|
-
discovering: "Checking Cloud account and repository",
|
|
2389
|
-
preparing: "Preparing findings",
|
|
2390
|
-
waiting: "Waiting for publication access",
|
|
2391
|
-
uploading: "Acknowledged findings",
|
|
2392
|
-
verifying: "Verifying source records",
|
|
2297
|
+
let disabledImportInvocation = false;
|
|
2298
|
+
function registerFindingPublication() {
|
|
2299
|
+
publication.command("findings", {
|
|
2300
|
+
description: "Preview and import selected Wiz, Snyk, Semgrep Code, Endor, or GitHub findings locally or to Cloud.",
|
|
2301
|
+
hint: "For Snyk Open Source SCA vulnerabilities only, prefer native snyk test JSON or an official plugin snyk-findings-export/v1 bundle; Open Source SARIF 2.1.0 is also supported. Snyk licenses, Code, Container, IaC and platform backlogs are unsupported. For Semgrep Code, supply native JSON or SARIF and --source-repository-url. For Endor, supply native Finding JSON or endorctl SARIF 2.1.0. For GitHub, supply complete JSON/JSONL saved by import github or import github-advisories. GHSA advisories do not establish an installed dependency or applicability. For Wiz, prefer a native package vulnerability JSON report or named SAST/repository-secret/IaC JSON collections with repository metadata. Normalized JSONL and repository package-vulnerability CSV (SCA only, GitHub repositories) are also supported. Gzip is supported for each format; Wiz CSV does not cover SAST or cloud posture. Other Wiz CSV profiles, scan events, workload secrets, and cloud configuration exports are not supported. --to local stores unassessed evidence for a local repository path without Cloud login. --full-output requires --format json or --format jsonl.\nExample: codex-security publish findings selected-wiz.json --to local --repository ./project --provider wiz --source-key TENANT_ID/vulnerability-finding --dry-run --format json",
|
|
2302
|
+
destructive: true,
|
|
2303
|
+
mcp: false,
|
|
2304
|
+
args: z.object({
|
|
2305
|
+
file: z
|
|
2306
|
+
.string()
|
|
2307
|
+
.describe("Snyk native test JSON, plugin SCA bundle or Open Source SARIF; Semgrep Code JSON/SARIF; Endor Finding JSON/endorctl SARIF; saved GitHub import output; native Wiz JSON, normalized JSONL, or repository package-vulnerability CSV."),
|
|
2308
|
+
}),
|
|
2309
|
+
options: z.object({
|
|
2310
|
+
to: z
|
|
2311
|
+
.enum(["cloud", "local"])
|
|
2312
|
+
.describe("Import destination (required)."),
|
|
2313
|
+
repository: optionValue("--repository").describe("Local repository path for --to local; authorized repository ID or URL for --to cloud."),
|
|
2314
|
+
provider: z
|
|
2315
|
+
.enum(EXTERNAL_FINDINGS_READERS)
|
|
2316
|
+
.describe("Provider that produced these findings."),
|
|
2317
|
+
sourceRepositoryUrl: optionValue("--source-repository-url")
|
|
2318
|
+
.optional()
|
|
2319
|
+
.describe("Required for Semgrep: source repository URL, checked against the Cloud destination or configured local Git remotes."),
|
|
2320
|
+
sourceKey: optionValue("--source-key").describe("Stable vendor tenant and finding namespace; not a project selection filter."),
|
|
2321
|
+
dryRun: z
|
|
2322
|
+
.boolean()
|
|
2323
|
+
.default(false)
|
|
2324
|
+
.describe("Read and preview the destination and findings without storing them."),
|
|
2325
|
+
yes: z
|
|
2326
|
+
.boolean()
|
|
2327
|
+
.default(false)
|
|
2328
|
+
.describe("Confirm publication of the previewed input without a terminal prompt."),
|
|
2329
|
+
}),
|
|
2330
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
2331
|
+
async run({ args, options, format, formatExplicit, error: incurError }) {
|
|
2332
|
+
return await withTerminalErrorsHandled(errorOutput, async () => {
|
|
2333
|
+
const writeDiagnostic = (message) => notify(() => errorOutput.write(message));
|
|
2334
|
+
const machineFormat = format === "json" || format === "jsonl";
|
|
2335
|
+
if (argv.includes("--full-output") && !machineFormat) {
|
|
2336
|
+
structuredError = true;
|
|
2337
|
+
exitCode = 2;
|
|
2338
|
+
return incurError({
|
|
2339
|
+
code: "INVALID_ARGUMENTS",
|
|
2340
|
+
message: "Finding imports support --full-output with --format json or --format jsonl. Choose one of those formats or omit --full-output.",
|
|
2341
|
+
exitCode,
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
const controller = new AbortController();
|
|
2345
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2346
|
+
const structured = formatExplicit && format !== "toon";
|
|
2347
|
+
const humanSummary = format === "toon" &&
|
|
2348
|
+
!formatExplicit &&
|
|
2349
|
+
!argv.some((argument) => OUTPUT_OPTION.test(argument));
|
|
2350
|
+
const confirmImport = async (preview, showPreview) => {
|
|
2351
|
+
if (options.yes)
|
|
2352
|
+
return true;
|
|
2353
|
+
const prompt = dependencies.externalPublicationPrompt ??
|
|
2354
|
+
createTerminalPrompt(errorOutput);
|
|
2355
|
+
const local = options.to === "local";
|
|
2356
|
+
if (!prompt.isInteractive())
|
|
2357
|
+
throw new CodexSecurityError(`${local ? "Local import" : "Publication"} needs confirmation. Run --dry-run, review the results, then use --yes to approve this input.`);
|
|
2358
|
+
if (structured)
|
|
2359
|
+
showPreview();
|
|
2360
|
+
const action = local
|
|
2361
|
+
? `Store these ${preview.findings.length} findings locally`
|
|
2362
|
+
: `Publish these ${preview.findings.length} findings`;
|
|
2363
|
+
return prompt.confirm(`${action}${preview.excluded.length ? ` and skip ${preview.excluded.length} excluded records` : ""}?`, false, controller.signal);
|
|
2393
2364
|
};
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
const
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2365
|
+
let lastProgress = "";
|
|
2366
|
+
const onProgress = (event) => {
|
|
2367
|
+
if (errorOutput.isTTY !== true)
|
|
2368
|
+
return;
|
|
2369
|
+
const step = event.total
|
|
2370
|
+
? Math.floor((event.completed * 10) / event.total)
|
|
2371
|
+
: 0;
|
|
2372
|
+
const key = `${event.phase}:${step}`;
|
|
2373
|
+
if (key === lastProgress)
|
|
2374
|
+
return;
|
|
2375
|
+
lastProgress = key;
|
|
2376
|
+
const labels = {
|
|
2377
|
+
reading: "Reading selected findings",
|
|
2378
|
+
discovering: "Checking Cloud account and repository",
|
|
2379
|
+
preparing: "Preparing findings",
|
|
2380
|
+
waiting: "Waiting for publication access",
|
|
2381
|
+
uploading: "Acknowledged findings",
|
|
2382
|
+
verifying: "Verifying source records",
|
|
2383
|
+
};
|
|
2384
|
+
writeDiagnostic(`${labels[event.phase]}${event.total === undefined ? "..." : `: ${event.completed}/${event.total}`}\n`);
|
|
2385
|
+
};
|
|
2386
|
+
try {
|
|
2387
|
+
if (!importsEnabled)
|
|
2388
|
+
throw new CodexSecurityError(externalImportsDisabledMessage);
|
|
2389
|
+
if (options.to === "local") {
|
|
2390
|
+
const prepared = await (dependencies.prepareLocalExternalImport ??
|
|
2391
|
+
prepareLocalExternalImport)(resolveCliPath(dependencies.currentDirectory(), args.file), {
|
|
2392
|
+
...options,
|
|
2393
|
+
repository: resolveCliPath(dependencies.currentDirectory(), options.repository),
|
|
2394
|
+
}, {
|
|
2395
|
+
environment: dependencies.environment,
|
|
2396
|
+
signal: controller.signal,
|
|
2397
|
+
});
|
|
2398
|
+
const { preview } = prepared;
|
|
2399
|
+
const showPreview = () => {
|
|
2400
|
+
writeDiagnostic(`Local repository: ${diagnosticValue(preview.repository)}\nSource: ${preview.source.provider} / ${diagnosticValue(preview.source.source_key)}\nRead: ${preview.read} Ready: ${preview.findings.length} Excluded: ${preview.excluded.length}\n`);
|
|
2401
|
+
for (const excluded of preview.excluded)
|
|
2402
|
+
writeDiagnostic(`Excluded item ${excluded.position}: ${diagnosticValue(excluded.reason)}\n`);
|
|
2403
|
+
for (const finding of preview.findings.slice(0, 5))
|
|
2404
|
+
writeDiagnostic(` ${diagnosticValue(finding.source_finding_id)} [${finding.evidence.severity}] ${diagnosticValue(finding.evidence.title)}\n`);
|
|
2405
|
+
writeDiagnostic(`Evidence file: ${diagnosticValue(resolveCliPath(dependencies.currentDirectory(), args.file))}\nImported evidence remains not assessed by Codex.\nUse --dry-run --format json to inspect all normalized findings and complete evidence before storing them.\n`);
|
|
2406
|
+
};
|
|
2407
|
+
if (!structured)
|
|
2408
|
+
showPreview();
|
|
2409
|
+
if (options.dryRun) {
|
|
2410
|
+
if (humanSummary)
|
|
2411
|
+
renderedOutput = "Dry run complete. No findings stored.\n";
|
|
2412
|
+
return { ...preview, dryRun: true };
|
|
2413
|
+
}
|
|
2414
|
+
if (!(await confirmImport(preview, showPreview))) {
|
|
2415
|
+
if (humanSummary)
|
|
2416
|
+
renderedOutput = "No findings stored.\n";
|
|
2417
|
+
return { imported: false, preview };
|
|
2418
|
+
}
|
|
2419
|
+
const result = await prepared.import();
|
|
2420
|
+
if (result.excluded.length > 0)
|
|
2421
|
+
exitCode = 1;
|
|
2422
|
+
const summary = `Local import complete.\nCreated: ${result.counts.created} Updated: ${result.counts.updated} Unchanged: ${result.counts.unchanged} Excluded: ${result.excluded.length}\nImported evidence remains not assessed by Codex.\nRead stored evidence with codex-security findings imported REPOSITORY.\n`;
|
|
2423
|
+
if (humanSummary)
|
|
2424
|
+
renderedOutput = summary;
|
|
2425
|
+
else if (!structured)
|
|
2426
|
+
writeDiagnostic(summary);
|
|
2427
|
+
return { ...result };
|
|
2428
|
+
}
|
|
2429
|
+
const prepared = await prepareExternalPublication(resolveCliPath(dependencies.currentDirectory(), args.file), options, {
|
|
2403
2430
|
environment: dependencies.environment,
|
|
2431
|
+
fetch: dependencies.cloudFetch,
|
|
2404
2432
|
signal: controller.signal,
|
|
2433
|
+
onProgress,
|
|
2405
2434
|
});
|
|
2406
2435
|
const { preview } = prepared;
|
|
2407
2436
|
const showPreview = () => {
|
|
2408
|
-
writeDiagnostic(`
|
|
2437
|
+
writeDiagnostic(`Cloud API: ${diagnosticValue(preview.cloudApiUrl)}\nAccount: ${diagnosticValue(preview.accountId)}\nDestination: ${diagnosticValue(preview.destination.url)} (${diagnosticValue(preview.destination.id)})\nEnvironment: ${[...new Set(preview.requests.map((request) => request.repository.environment_id))].map(diagnosticValue).join(", ")}\nSource: ${preview.source.provider} / ${diagnosticValue(preview.source.source_key)}\nRead: ${preview.read} Ready: ${preview.findings.length} Excluded: ${preview.excluded.length}${preview.resumed ? "\nResuming the saved submission." : ""}\n`);
|
|
2438
|
+
if (preview.cloudUrl)
|
|
2439
|
+
writeDiagnostic(`Cloud app: ${diagnosticValue(preview.cloudUrl)}\n`);
|
|
2409
2440
|
for (const excluded of preview.excluded)
|
|
2410
2441
|
writeDiagnostic(`Excluded item ${excluded.position}: ${diagnosticValue(excluded.reason)}\n`);
|
|
2442
|
+
writeDiagnostic(`Evidence file: ${diagnosticValue(resolveCliPath(dependencies.currentDirectory(), args.file))}\nImported evidence remains not assessed by Codex.\n`);
|
|
2443
|
+
const severities = new Map();
|
|
2444
|
+
for (const finding of preview.findings)
|
|
2445
|
+
severities.set(finding.evidence.severity, (severities.get(finding.evidence.severity) ?? 0) + 1);
|
|
2446
|
+
writeDiagnostic(`Severities: ${[...severities].map(([severity, count]) => `${severity}: ${count}`).join(" ")}\n`);
|
|
2411
2447
|
for (const finding of preview.findings.slice(0, 5))
|
|
2412
2448
|
writeDiagnostic(` ${diagnosticValue(finding.source_finding_id)} [${finding.evidence.severity}] ${diagnosticValue(finding.evidence.title)}\n`);
|
|
2413
|
-
|
|
2449
|
+
if (preview.findings.length > 5)
|
|
2450
|
+
writeDiagnostic(`Showing 5 of ${preview.findings.length} findings.\n`);
|
|
2451
|
+
writeDiagnostic("Use --dry-run --format json to inspect all normalized findings and the complete evidence before uploading.\n");
|
|
2414
2452
|
};
|
|
2415
2453
|
if (!structured)
|
|
2416
2454
|
showPreview();
|
|
2417
2455
|
if (options.dryRun) {
|
|
2418
2456
|
if (humanSummary)
|
|
2419
|
-
renderedOutput = "Dry run complete. No findings
|
|
2457
|
+
renderedOutput = "Dry run complete. No findings uploaded.\n";
|
|
2420
2458
|
return { ...preview, dryRun: true };
|
|
2421
2459
|
}
|
|
2422
2460
|
if (!(await confirmImport(preview, showPreview))) {
|
|
2423
2461
|
if (humanSummary)
|
|
2424
|
-
renderedOutput = "No findings
|
|
2425
|
-
return {
|
|
2462
|
+
renderedOutput = "No findings published.\n";
|
|
2463
|
+
return { published: false, preview };
|
|
2426
2464
|
}
|
|
2427
|
-
const result = await prepared.
|
|
2428
|
-
if (result.
|
|
2465
|
+
const result = await prepared.publish();
|
|
2466
|
+
if (result.status === "partial")
|
|
2429
2467
|
exitCode = 1;
|
|
2430
|
-
const summary = `Local import complete.\nCreated: ${result.counts.created} Updated: ${result.counts.updated} Unchanged: ${result.counts.unchanged} Excluded: ${result.excluded.length}\nImported evidence remains not assessed by Codex.\nRead stored evidence with codex-security findings imported REPOSITORY.\n`;
|
|
2431
2468
|
if (humanSummary)
|
|
2432
|
-
renderedOutput =
|
|
2469
|
+
renderedOutput = renderExternalPublicationSummary(result);
|
|
2433
2470
|
else if (!structured)
|
|
2434
|
-
writeDiagnostic(
|
|
2471
|
+
writeDiagnostic(renderExternalPublicationSummary(result));
|
|
2435
2472
|
return { ...result };
|
|
2436
2473
|
}
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
writeDiagnostic(` ${diagnosticValue(finding.source_finding_id)} [${finding.evidence.severity}] ${diagnosticValue(finding.evidence.title)}\n`);
|
|
2457
|
-
if (preview.findings.length > 5)
|
|
2458
|
-
writeDiagnostic(`Showing 5 of ${preview.findings.length} findings.\n`);
|
|
2459
|
-
writeDiagnostic("Use --dry-run --format json to inspect all normalized findings and the complete evidence before uploading.\n");
|
|
2460
|
-
};
|
|
2461
|
-
if (!structured)
|
|
2462
|
-
showPreview();
|
|
2463
|
-
if (options.dryRun) {
|
|
2464
|
-
if (humanSummary)
|
|
2465
|
-
renderedOutput = "Dry run complete. No findings uploaded.\n";
|
|
2466
|
-
return { ...preview, dryRun: true };
|
|
2467
|
-
}
|
|
2468
|
-
if (!(await confirmImport(preview, showPreview))) {
|
|
2469
|
-
if (humanSummary)
|
|
2470
|
-
renderedOutput = "No findings published.\n";
|
|
2471
|
-
return { published: false, preview };
|
|
2474
|
+
catch (error) {
|
|
2475
|
+
if (argv.includes("--full-output") && machineFormat)
|
|
2476
|
+
failedResultOutput = {
|
|
2477
|
+
format,
|
|
2478
|
+
code: "IMPORT_FAILED",
|
|
2479
|
+
message: diagnosticValue(error),
|
|
2480
|
+
};
|
|
2481
|
+
reportPublicationError(diagnosticValue(error), controller.signal.aborted ? controller.signal.reason : undefined);
|
|
2482
|
+
if (error instanceof ExternalPublicationError) {
|
|
2483
|
+
if (humanSummary)
|
|
2484
|
+
renderedOutput = renderExternalPublicationSummary(error.result);
|
|
2485
|
+
return { ...error.result };
|
|
2486
|
+
}
|
|
2487
|
+
const failure = { status: "failed", error: diagnosticValue(error) };
|
|
2488
|
+
if (machineFormat &&
|
|
2489
|
+
!argv.includes("--full-output") &&
|
|
2490
|
+
argv.some((argument) => /^--filter-output(?:=|$)/u.test(argument)))
|
|
2491
|
+
filteredScanFailure = { format, data: failure };
|
|
2492
|
+
return structured ? failure : undefined;
|
|
2472
2493
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
exitCode = 1;
|
|
2476
|
-
if (humanSummary)
|
|
2477
|
-
renderedOutput = renderExternalPublicationSummary(result);
|
|
2478
|
-
else if (!structured)
|
|
2479
|
-
writeDiagnostic(renderExternalPublicationSummary(result));
|
|
2480
|
-
return { ...result };
|
|
2481
|
-
}
|
|
2482
|
-
catch (error) {
|
|
2483
|
-
if (argv.includes("--full-output") &&
|
|
2484
|
-
(format === "json" || format === "jsonl"))
|
|
2485
|
-
failedResultOutput = {
|
|
2486
|
-
format,
|
|
2487
|
-
code: "IMPORT_FAILED",
|
|
2488
|
-
message: diagnosticValue(error),
|
|
2489
|
-
};
|
|
2490
|
-
reportPublicationError(diagnosticValue(error), controller.signal.aborted ? controller.signal.reason : undefined);
|
|
2491
|
-
if (error instanceof ExternalPublicationError) {
|
|
2492
|
-
if (humanSummary)
|
|
2493
|
-
renderedOutput = renderExternalPublicationSummary(error.result);
|
|
2494
|
-
return { ...error.result };
|
|
2494
|
+
finally {
|
|
2495
|
+
removeSignals();
|
|
2495
2496
|
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
}
|
|
2503
|
-
finally {
|
|
2504
|
-
removeSignals();
|
|
2505
|
-
}
|
|
2506
|
-
});
|
|
2507
|
-
},
|
|
2508
|
-
});
|
|
2497
|
+
});
|
|
2498
|
+
},
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
if (importsEnabled)
|
|
2502
|
+
registerFindingPublication();
|
|
2509
2503
|
publication.command("check", {
|
|
2510
2504
|
description: "Check saved scan history and Linear access without creating issues.",
|
|
2511
2505
|
mcp: false,
|
|
@@ -2537,10 +2531,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2537
2531
|
},
|
|
2538
2532
|
});
|
|
2539
2533
|
const imports = Cli.create("import", {
|
|
2540
|
-
description:
|
|
2534
|
+
description: importsEnabled
|
|
2535
|
+
? "Read GitHub code scanning alerts and security advisories."
|
|
2536
|
+
: "Read GitHub code scanning alerts.",
|
|
2541
2537
|
}).command("github", {
|
|
2542
2538
|
description: "Read GitHub code scanning alerts without changing GitHub.",
|
|
2543
|
-
hint: "Save complete --format json output for publish findings --provider github. This command reads code-scanning alerts; Dependabot and secret-scanning alerts are not supported. To save CSV or JSON findings as a local scan, use codex-security scan import --help
|
|
2539
|
+
hint: `${importsEnabled ? "Save complete --format json output for publish findings --provider github. " : ""}This command reads code-scanning alerts; Dependabot and secret-scanning alerts are not supported. To save CSV or JSON findings as a local scan, use codex-security scan import --help.`,
|
|
2544
2540
|
destructive: false,
|
|
2545
2541
|
mcp: false,
|
|
2546
2542
|
args: z.object({
|
|
@@ -2603,82 +2599,88 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2603
2599
|
}
|
|
2604
2600
|
},
|
|
2605
2601
|
});
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
if (signal === "SIGINT" || signal === "SIGTERM") {
|
|
2660
|
-
exitCode = signal === "SIGINT" ? 130 : 143;
|
|
2661
|
-
errorOutput.write(`codex-security: GitHub advisory import ${signal === "SIGINT" ? "canceled" : "terminated"}.\n`);
|
|
2602
|
+
function registerGitHubAdvisories() {
|
|
2603
|
+
imports.command("github-advisories", {
|
|
2604
|
+
description: "Read GitHub security advisories without changing GitHub.",
|
|
2605
|
+
hint: "Defaults to published repository advisories. Use --github-advisory-source global with explicit --github-advisory IDs to select public database entries. Advisories do not establish an installed dependency or applicability to the selected repository.",
|
|
2606
|
+
destructive: false,
|
|
2607
|
+
mcp: false,
|
|
2608
|
+
args: z.object({
|
|
2609
|
+
repository: z
|
|
2610
|
+
.string()
|
|
2611
|
+
.min(1)
|
|
2612
|
+
.describe("Source repository, or target context for global IDs, in OWNER/REPO form."),
|
|
2613
|
+
}),
|
|
2614
|
+
options: z.object({
|
|
2615
|
+
githubAdvisory: z
|
|
2616
|
+
.array(optionValue("--github-advisory").regex(/^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/iu, "GitHub advisory IDs must use GHSA-xxxx-xxxx-xxxx form."))
|
|
2617
|
+
.default([])
|
|
2618
|
+
.describe("Exact GHSA ID; repeat to select a subset. Required for global advisories."),
|
|
2619
|
+
githubAdvisorySource: z
|
|
2620
|
+
.enum(["repository", "global"])
|
|
2621
|
+
.default("repository")
|
|
2622
|
+
.describe("Advisory API to read; global requires exact IDs and never lists the database."),
|
|
2623
|
+
githubState: z
|
|
2624
|
+
.enum(GITHUB_ADVISORY_STATES)
|
|
2625
|
+
.default("published")
|
|
2626
|
+
.describe("Repository advisory list state; omit when selecting exact GHSA IDs."),
|
|
2627
|
+
}),
|
|
2628
|
+
output: z
|
|
2629
|
+
.array(z.object({
|
|
2630
|
+
source: z.literal("github-security-advisory"),
|
|
2631
|
+
selection: z.enum(["repository", "global"]),
|
|
2632
|
+
repository: z.string(),
|
|
2633
|
+
githubHost: z.string(),
|
|
2634
|
+
ghsaId: z.string(),
|
|
2635
|
+
url: z.string(),
|
|
2636
|
+
advisory: z.record(z.string(), z.unknown()),
|
|
2637
|
+
}))
|
|
2638
|
+
.optional(),
|
|
2639
|
+
async run({ args, options, error: incurError }) {
|
|
2640
|
+
const controller = new AbortController();
|
|
2641
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2642
|
+
try {
|
|
2643
|
+
if (!importsEnabled)
|
|
2644
|
+
throw new CodexSecurityError(externalImportsDisabledMessage);
|
|
2645
|
+
return await (dependencies.importGitHubAdvisories ?? importGitHubAdvisories)({
|
|
2646
|
+
repository: args.repository,
|
|
2647
|
+
advisoryIds: options.githubAdvisory,
|
|
2648
|
+
source: options.githubAdvisorySource,
|
|
2649
|
+
state: options.githubState,
|
|
2650
|
+
signal: controller.signal,
|
|
2651
|
+
}, {
|
|
2652
|
+
environment: dependencies.environment,
|
|
2653
|
+
currentDirectory: dependencies.currentDirectory(),
|
|
2654
|
+
});
|
|
2662
2655
|
}
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2656
|
+
catch (error) {
|
|
2657
|
+
const signal = controller.signal.reason;
|
|
2658
|
+
if (signal === "SIGINT" || signal === "SIGTERM") {
|
|
2659
|
+
exitCode = signal === "SIGINT" ? 130 : 143;
|
|
2660
|
+
errorOutput.write(`codex-security: GitHub advisory import ${signal === "SIGINT" ? "canceled" : "terminated"}.\n`);
|
|
2661
|
+
}
|
|
2662
|
+
else {
|
|
2663
|
+
exitCode = 2;
|
|
2664
|
+
errorOutput.write(`codex-security: ${diagnosticValue(error)}\n`);
|
|
2665
|
+
}
|
|
2666
|
+
if (argv.includes("--full-output")) {
|
|
2667
|
+
structuredError = true;
|
|
2668
|
+
return incurError({
|
|
2669
|
+
code: "GITHUB_IMPORT_FAILED",
|
|
2670
|
+
message: diagnosticValue(error),
|
|
2671
|
+
exitCode,
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
return undefined;
|
|
2666
2675
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
return incurError({
|
|
2670
|
-
code: "GITHUB_IMPORT_FAILED",
|
|
2671
|
-
message: diagnosticValue(error),
|
|
2672
|
-
exitCode,
|
|
2673
|
-
});
|
|
2676
|
+
finally {
|
|
2677
|
+
removeSignals();
|
|
2674
2678
|
}
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
},
|
|
2681
|
-
});
|
|
2679
|
+
},
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2682
|
+
if (importsEnabled)
|
|
2683
|
+
registerGitHubAdvisories();
|
|
2682
2684
|
const infoOutput = z.object({
|
|
2683
2685
|
sdkVersion: z.string(),
|
|
2684
2686
|
bundledPluginVersion: z.string(),
|
|
@@ -2692,7 +2694,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2692
2694
|
nextStep: z.string(),
|
|
2693
2695
|
configuration: z.record(z.string(), z.unknown()),
|
|
2694
2696
|
});
|
|
2695
|
-
const
|
|
2697
|
+
const cliOptions = {
|
|
2696
2698
|
aliases: ["cs"],
|
|
2697
2699
|
description: "Find, review, and fix security issues in your code.",
|
|
2698
2700
|
version: VERSION,
|
|
@@ -2701,7 +2703,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2701
2703
|
tools: { discovery: "direct" },
|
|
2702
2704
|
instructions: "Use info for read-only SDK metadata. Scans and other state-changing commands are CLI-only because the MCP transport cannot cancel active commands.",
|
|
2703
2705
|
},
|
|
2704
|
-
}
|
|
2706
|
+
};
|
|
2707
|
+
const cli = Cli.create("codex-security", cliOptions)
|
|
2705
2708
|
.command("policy", {
|
|
2706
2709
|
description: "Draft SECURITY.md for review.",
|
|
2707
2710
|
destructive: true,
|
|
@@ -2925,6 +2928,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2925
2928
|
.boolean()
|
|
2926
2929
|
.default(false)
|
|
2927
2930
|
.describe("Patch and verify confirmed findings after the scan."),
|
|
2931
|
+
validate: z
|
|
2932
|
+
.boolean()
|
|
2933
|
+
.default(false)
|
|
2934
|
+
.describe("Run standalone finding validation after the scan."),
|
|
2928
2935
|
patchSeverity: z
|
|
2929
2936
|
.enum(REPORTABLE_SEVERITIES)
|
|
2930
2937
|
.optional()
|
|
@@ -2955,8 +2962,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2955
2962
|
.refine((options) => !options.patch || !options.dryRun, {
|
|
2956
2963
|
message: "--patch cannot be combined with --dry-run.",
|
|
2957
2964
|
})
|
|
2958
|
-
.refine((options) => !options.
|
|
2959
|
-
message: "--
|
|
2965
|
+
.refine((options) => !options.validate || !options.dryRun, {
|
|
2966
|
+
message: "--validate cannot be combined with --dry-run.",
|
|
2967
|
+
})
|
|
2968
|
+
.refine((options) => !options.mock ||
|
|
2969
|
+
(!options.dryRun && !options.patch && !options.validate), {
|
|
2970
|
+
message: "--mock cannot be combined with --dry-run, --patch, or --validate.",
|
|
2960
2971
|
}),
|
|
2961
2972
|
output: scanOutputSchema("SCAN_FAILED"),
|
|
2962
2973
|
async run({ args, error: incurError, format, options }) {
|
|
@@ -2991,6 +3002,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2991
3002
|
if (options.archiveExisting && settings.outputDir === undefined) {
|
|
2992
3003
|
throw new CodexSecurityError("--archive-existing requires --output-dir.");
|
|
2993
3004
|
}
|
|
3005
|
+
if (options.validate && settings.maxCostUsd !== undefined) {
|
|
3006
|
+
throw new CodexSecurityError("--validate cannot be combined with a scan cost limit because standalone validation is not cost-tracked.");
|
|
3007
|
+
}
|
|
2994
3008
|
outcome = await runScan({
|
|
2995
3009
|
...settings,
|
|
2996
3010
|
codexOverrides: config.codexOverrides,
|
|
@@ -3003,6 +3017,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3003
3017
|
pluginPath: options.pluginPath,
|
|
3004
3018
|
pythonPath: options.python,
|
|
3005
3019
|
patch: options.patch,
|
|
3020
|
+
validate: options.validate,
|
|
3006
3021
|
patchSeverity: options.patchSeverity,
|
|
3007
3022
|
createPr: options.createPr,
|
|
3008
3023
|
showCost: options.showCost,
|
|
@@ -3530,11 +3545,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3530
3545
|
? (event) => {
|
|
3531
3546
|
const componentName = componentNames.get(event.componentId) ??
|
|
3532
3547
|
event.componentId;
|
|
3533
|
-
const line = componentScanEventLine(componentName, event, options.showCost || settings.maxCostUsd !== undefined);
|
|
3548
|
+
const line = componentScanEventLine(componentName, event, options.showCost || settings.maxCostUsd !== undefined, settings.auth);
|
|
3534
3549
|
if (line !== null)
|
|
3535
3550
|
errorOutput.write(line);
|
|
3536
3551
|
}
|
|
3537
|
-
: (event) => dashboard?.recordComponentEvent(event),
|
|
3552
|
+
: (event) => dashboard?.recordComponentEvent(event, settings.auth),
|
|
3538
3553
|
onDeduplicationStarted: () => {
|
|
3539
3554
|
if (dashboard !== null)
|
|
3540
3555
|
dashboard.showComponents("Combining duplicate findings");
|
|
@@ -4015,7 +4030,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4015
4030
|
},
|
|
4016
4031
|
],
|
|
4017
4032
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
4018
|
-
async run({ format, options }) {
|
|
4033
|
+
async run({ format, options, error: incurError }) {
|
|
4034
|
+
const diagnostics = captureOutput();
|
|
4035
|
+
let failureReported = false;
|
|
4019
4036
|
try {
|
|
4020
4037
|
if (options.host)
|
|
4021
4038
|
throw new CodexSecurityError("Use verify-fix --host alone.");
|
|
@@ -4071,8 +4088,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4071
4088
|
const response = captureOutput();
|
|
4072
4089
|
const progress = new FindingProgressPresenter(errorOutput, dependencies, repository, identifiers.length);
|
|
4073
4090
|
progress.startVerification();
|
|
4091
|
+
const verificationErrors = new NodeWritable({
|
|
4092
|
+
write(chunk, _encoding, callback) {
|
|
4093
|
+
diagnostics.stream.write(chunk);
|
|
4094
|
+
progress.stop();
|
|
4095
|
+
void writeCliOutput(errorOutput, chunk).then(() => callback(), callback);
|
|
4096
|
+
},
|
|
4097
|
+
});
|
|
4074
4098
|
try {
|
|
4075
|
-
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options, response.stream,
|
|
4099
|
+
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options, response.stream, verificationErrors, dependencies, {
|
|
4076
4100
|
directory: repository,
|
|
4077
4101
|
...(selected === undefined
|
|
4078
4102
|
? {}
|
|
@@ -4084,10 +4108,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4084
4108
|
onEvent: progress.observe.bind(progress),
|
|
4085
4109
|
});
|
|
4086
4110
|
if (exitCode !== 0) {
|
|
4087
|
-
if (exitCode
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4111
|
+
if (exitCode === 130 || exitCode === 143) {
|
|
4112
|
+
frameworkExit = exitCode;
|
|
4113
|
+
return undefined;
|
|
4114
|
+
}
|
|
4115
|
+
failureReported = diagnostics.text().trim().length > 0;
|
|
4116
|
+
throw new CodexSecurityError(diagnostics.text().trim() ||
|
|
4117
|
+
`Codex verification failed with exit code ${exitCode}.`);
|
|
4091
4118
|
}
|
|
4092
4119
|
results = parseFindingVerifications(response.text(), identifiers);
|
|
4093
4120
|
progress.complete(results);
|
|
@@ -4115,8 +4142,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4115
4142
|
}
|
|
4116
4143
|
catch (error) {
|
|
4117
4144
|
exitCode = 2;
|
|
4118
|
-
|
|
4119
|
-
|
|
4145
|
+
const message = errorMessage(error);
|
|
4146
|
+
if (!failureReported)
|
|
4147
|
+
errorOutput.write(`codex-security: ${diagnosticValue(message)}\n`);
|
|
4148
|
+
return finishScan({ exitCode, error: message }, format, incurError, "VERIFICATION_FAILED");
|
|
4120
4149
|
}
|
|
4121
4150
|
},
|
|
4122
4151
|
})
|
|
@@ -4633,7 +4662,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4633
4662
|
},
|
|
4634
4663
|
});
|
|
4635
4664
|
const commands = Cli.toCommands.get(cli);
|
|
4636
|
-
|
|
4665
|
+
let valueOptions = cliValueOptions(commands);
|
|
4637
4666
|
function isScanImportCommand(argv) {
|
|
4638
4667
|
const commandIndex = cliCommandIndex(argv);
|
|
4639
4668
|
return argv[commandIndex] === "scan" && argv[commandIndex + 1] === "import";
|
|
@@ -4741,6 +4770,36 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4741
4770
|
command === "publish" ||
|
|
4742
4771
|
command === "import";
|
|
4743
4772
|
const subcommand = nestedCommand ? argv[commandIndex + 1] : undefined;
|
|
4773
|
+
if (command === "import" &&
|
|
4774
|
+
(subcommand === "github" || subcommand === "github-advisories") &&
|
|
4775
|
+
frameworkFlags.rawCollector) {
|
|
4776
|
+
// Incur's skill-sync notice turns a saved collector array into an object.
|
|
4777
|
+
cliOptions.sync = false;
|
|
4778
|
+
}
|
|
4779
|
+
if (!importsEnabled &&
|
|
4780
|
+
((command === "publish" && subcommand === "findings") ||
|
|
4781
|
+
(command === "findings" && subcommand === "imported") ||
|
|
4782
|
+
(command === "import" && subcommand === "github-advisories"))) {
|
|
4783
|
+
if (process.env["COMPLETE"] ||
|
|
4784
|
+
argv.some((value) => FRAMEWORK_ACTIONS.has(value))) {
|
|
4785
|
+
return externalImportsDisabledMessage;
|
|
4786
|
+
}
|
|
4787
|
+
if (!argv.includes("--version")) {
|
|
4788
|
+
if (argv.includes("--schema") ||
|
|
4789
|
+
(command !== "publish" &&
|
|
4790
|
+
(command !== "import" || !argv.includes("--full-output")))) {
|
|
4791
|
+
return externalImportsDisabledMessage;
|
|
4792
|
+
}
|
|
4793
|
+
disabledImportInvocation = true;
|
|
4794
|
+
// This route only formats a disabled command; it is not an installed skill.
|
|
4795
|
+
cliOptions.sync = false;
|
|
4796
|
+
if (command === "publish")
|
|
4797
|
+
registerFindingPublication();
|
|
4798
|
+
else
|
|
4799
|
+
registerGitHubAdvisories();
|
|
4800
|
+
valueOptions = cliValueOptions(commands);
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4744
4803
|
if (command === "info") {
|
|
4745
4804
|
for (let index = 0; index < argv.length; index += 1) {
|
|
4746
4805
|
const argument = argv[index];
|
|
@@ -4798,8 +4857,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4798
4857
|
: 1)) {
|
|
4799
4858
|
return `Unexpected positional argument for ${command}${subcommand === undefined ? "" : ` ${subcommand}`}.`;
|
|
4800
4859
|
}
|
|
4860
|
+
if (disabledImportInvocation && frameworkFlags.hideDisabledRoute)
|
|
4861
|
+
return externalImportsDisabledMessage;
|
|
4801
4862
|
}
|
|
4802
4863
|
argv = normalizeScanImportArguments(defaultListCommand(argv));
|
|
4864
|
+
const frameworkArgv = argv.flatMap((argument) => {
|
|
4865
|
+
const separator = argument.indexOf("=");
|
|
4866
|
+
if (separator < 0 ||
|
|
4867
|
+
!FRAMEWORK_VALUE_OPTIONS.has(argument.slice(0, separator)))
|
|
4868
|
+
return [argument];
|
|
4869
|
+
return [argument.slice(0, separator), argument.slice(separator + 1)];
|
|
4870
|
+
});
|
|
4871
|
+
const frameworkFlags = frameworkOutputFlags(frameworkArgv);
|
|
4803
4872
|
const policyFullOutput = argv[cliCommandIndex(argv)] === "policy" && argv.includes("--full-output");
|
|
4804
4873
|
const argumentError = validateCliArguments(argv, positionals);
|
|
4805
4874
|
if (argumentError !== undefined && !policyFullOutput) {
|
|
@@ -4893,12 +4962,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4893
4962
|
}
|
|
4894
4963
|
let notice;
|
|
4895
4964
|
try {
|
|
4896
|
-
await cli.serve(
|
|
4897
|
-
if (!/^--(?:format|filter-output|token-limit|token-offset)=/u.test(argument))
|
|
4898
|
-
return [argument];
|
|
4899
|
-
const separator = argument.indexOf("=");
|
|
4900
|
-
return [argument.slice(0, separator), argument.slice(separator + 1)];
|
|
4901
|
-
}), {
|
|
4965
|
+
await cli.serve(frameworkArgv, {
|
|
4902
4966
|
stdout: frameworkCapture.stream.write,
|
|
4903
4967
|
exit: (code) => {
|
|
4904
4968
|
frameworkExit = code;
|
|
@@ -4946,6 +5010,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4946
5010
|
catch { }
|
|
4947
5011
|
}
|
|
4948
5012
|
if (frameworkExit !== undefined) {
|
|
5013
|
+
if (disabledImportInvocation && exitCode === 0) {
|
|
5014
|
+
reportPublicationError(externalImportsDisabledMessage, undefined);
|
|
5015
|
+
return exitCode;
|
|
5016
|
+
}
|
|
4949
5017
|
if (policyFullOutput || structuredError) {
|
|
4950
5018
|
if (exitCode === 0)
|
|
4951
5019
|
exitCode = 2;
|
|
@@ -5164,13 +5232,32 @@ async function prepareScanArgumentsFromRecipe(recipe, parentScanId, { scanPrompt
|
|
|
5164
5232
|
: undefined,
|
|
5165
5233
|
};
|
|
5166
5234
|
}
|
|
5235
|
+
function frameworkOutputFlags(argv) {
|
|
5236
|
+
let hideDisabledRoute = false;
|
|
5237
|
+
let fullOutput = false;
|
|
5238
|
+
let rawCollector = false;
|
|
5239
|
+
for (let index = 0; index < argv.length; index++) {
|
|
5240
|
+
const value = argv[index];
|
|
5241
|
+
if (FRAMEWORK_ACTIONS.has(value) ||
|
|
5242
|
+
value === "--schema" ||
|
|
5243
|
+
value === "--help" ||
|
|
5244
|
+
value === "-h")
|
|
5245
|
+
hideDisabledRoute = true;
|
|
5246
|
+
if (value === "--full-output")
|
|
5247
|
+
fullOutput = true;
|
|
5248
|
+
if (value === "--json")
|
|
5249
|
+
rawCollector = true;
|
|
5250
|
+
if (FRAMEWORK_VALUE_OPTIONS.has(value)) {
|
|
5251
|
+
const operand = argv[++index];
|
|
5252
|
+
if (value === "--format")
|
|
5253
|
+
rawCollector =
|
|
5254
|
+
operand === "json" || operand === "jsonl" || operand === "yaml";
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
return { hideDisabledRoute, rawCollector: rawCollector && !fullOutput };
|
|
5258
|
+
}
|
|
5167
5259
|
function cliValueOptions(commands) {
|
|
5168
|
-
const options = new Set(
|
|
5169
|
-
"--format",
|
|
5170
|
-
"--filter-output",
|
|
5171
|
-
"--token-limit",
|
|
5172
|
-
"--token-offset",
|
|
5173
|
-
]);
|
|
5260
|
+
const options = new Set(FRAMEWORK_VALUE_OPTIONS);
|
|
5174
5261
|
for (const command of commands.values()) {
|
|
5175
5262
|
if ("_group" in command) {
|
|
5176
5263
|
for (const option of cliValueOptions(command.commands))
|
|
@@ -6500,6 +6587,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6500
6587
|
let deepConsolidating = false;
|
|
6501
6588
|
let runningCost = null;
|
|
6502
6589
|
let runningUsage = null;
|
|
6590
|
+
let usageFreshness = null;
|
|
6591
|
+
let accountLimits = null;
|
|
6503
6592
|
let maxCostUsd = arguments_.maxCostUsd;
|
|
6504
6593
|
const showCost = arguments_.showCost === true || maxCostUsd !== undefined;
|
|
6505
6594
|
let phase = null;
|
|
@@ -6579,6 +6668,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6579
6668
|
let providerOptions = { provider: "openai" };
|
|
6580
6669
|
let auth = arguments_.auth;
|
|
6581
6670
|
let patchAnalyticsOverride;
|
|
6671
|
+
let validation;
|
|
6672
|
+
let validationError;
|
|
6582
6673
|
let patchServiceTier;
|
|
6583
6674
|
let patchRequestMetadata;
|
|
6584
6675
|
let patchOtel;
|
|
@@ -6592,6 +6683,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6592
6683
|
deepScanOptions(arguments_);
|
|
6593
6684
|
const directory = dependencies.currentDirectory();
|
|
6594
6685
|
repository = arguments_.repository ?? directory;
|
|
6686
|
+
if (arguments_.validate) {
|
|
6687
|
+
repository = await normalizeRepository(resolve(directory, expandHome(repository)), preparationAbortController.signal);
|
|
6688
|
+
}
|
|
6595
6689
|
const target = arguments_.target;
|
|
6596
6690
|
const prompts = await resolveScanPrompts(arguments_, resolve(directory, repository), directory);
|
|
6597
6691
|
const config = {
|
|
@@ -6695,6 +6789,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6695
6789
|
input: scanInput,
|
|
6696
6790
|
onInterrupt,
|
|
6697
6791
|
});
|
|
6792
|
+
dashboard.setChatGptAuth(isChatGptAuthentication(selectedAuthentication, auth));
|
|
6698
6793
|
}
|
|
6699
6794
|
const scope = scanScope(arguments_);
|
|
6700
6795
|
const runningMessage = () => {
|
|
@@ -6711,9 +6806,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6711
6806
|
details.push(`Reviews: ${deepProgress.completed} completed, ${deepProgress.active} active, cap ${deepProgress.maximum}`);
|
|
6712
6807
|
}
|
|
6713
6808
|
else if (fileProgress !== null) {
|
|
6714
|
-
|
|
6715
|
-
if (count.total > 0)
|
|
6716
|
-
details.push(`${count.label === "reviews" ? "Reviews" : "Files"}: ${count.completed.toLocaleString("en-US")}/${count.total.toLocaleString("en-US")}`);
|
|
6809
|
+
details.push(formatScanProgressCount(fileProgress, "status"));
|
|
6717
6810
|
}
|
|
6718
6811
|
const tokens = runningCost !== null
|
|
6719
6812
|
? formatScanCostTokens(runningCost)
|
|
@@ -6723,6 +6816,12 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6723
6816
|
if (showCost && runningCost !== null) {
|
|
6724
6817
|
details.push(`Cost: ${formatScanCost(runningCost)}`);
|
|
6725
6818
|
}
|
|
6819
|
+
if (tokens !== null)
|
|
6820
|
+
details.push(usageFreshness ?? USAGE_TIME_UNAVAILABLE);
|
|
6821
|
+
if (accountLimits !== null)
|
|
6822
|
+
details.push(diagnosticValue(accountLimits));
|
|
6823
|
+
else if (isChatGptAuthentication(selectedAuthentication, auth))
|
|
6824
|
+
details.push(ACCOUNT_LIMITS_UNAVAILABLE);
|
|
6726
6825
|
return details.length === 0 ? stage : `${stage} | ${details.join(" | ")}`;
|
|
6727
6826
|
};
|
|
6728
6827
|
if (dashboard === null) {
|
|
@@ -6758,6 +6857,22 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6758
6857
|
archiveExisting: arguments_.archiveExisting,
|
|
6759
6858
|
parentScanId: arguments_.parentScanId,
|
|
6760
6859
|
expectedPluginVersion: arguments_.expectedPluginVersion,
|
|
6860
|
+
onUsageObservation: async (observation) => {
|
|
6861
|
+
if (dashboard !== null) {
|
|
6862
|
+
dashboard.setUsageObservation(observation);
|
|
6863
|
+
return;
|
|
6864
|
+
}
|
|
6865
|
+
usageFreshness = formatUsageFreshness(observation);
|
|
6866
|
+
accountLimits = formatAccountLimits(observation);
|
|
6867
|
+
const priorUsage = runningUsage;
|
|
6868
|
+
const priorCost = runningCost;
|
|
6869
|
+
// Usage and cost callbacks render the same poll. Refresh here for a receipt alone.
|
|
6870
|
+
await Promise.resolve();
|
|
6871
|
+
if (runningUsage === priorUsage && runningCost === priorCost) {
|
|
6872
|
+
progress?.stopTimer();
|
|
6873
|
+
progress?.startTimer(runningMessage());
|
|
6874
|
+
}
|
|
6875
|
+
},
|
|
6761
6876
|
onUsage: async (usage) => {
|
|
6762
6877
|
runningUsage = usage;
|
|
6763
6878
|
if (dashboard !== null) {
|
|
@@ -6827,6 +6942,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6827
6942
|
},
|
|
6828
6943
|
onAuthentication: (authentication) => {
|
|
6829
6944
|
selectedAuthentication = authentication;
|
|
6945
|
+
dashboard?.setChatGptAuth(isChatGptAuthentication(authentication, auth));
|
|
6830
6946
|
const bedrock = providerOptions.provider === "amazon-bedrock" ||
|
|
6831
6947
|
authentication.method === "aws_credentials";
|
|
6832
6948
|
diagnostic("authentication.selected", {
|
|
@@ -6936,8 +7052,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6936
7052
|
if (progress === null)
|
|
6937
7053
|
return;
|
|
6938
7054
|
progress.stopTimer();
|
|
6939
|
-
const count =
|
|
6940
|
-
progress.stage(`Scan phase: ${phase}
|
|
7055
|
+
const count = formatScanProgressCount(update, "phase");
|
|
7056
|
+
progress.stage(`Scan phase: ${phase} (${count}).`);
|
|
6941
7057
|
progress.startTimer(runningMessage());
|
|
6942
7058
|
},
|
|
6943
7059
|
onDeepProgress: (update) => {
|
|
@@ -7013,10 +7129,12 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7013
7129
|
}
|
|
7014
7130
|
},
|
|
7015
7131
|
};
|
|
7132
|
+
if (((arguments_.validate && !arguments_.dryRun) ||
|
|
7133
|
+
arguments_.rerunInputIdentity !== undefined) &&
|
|
7134
|
+
options.knowledgeBasePaths?.length) {
|
|
7135
|
+
options.knowledgeBaseSnapshot = await readKnowledgeBaseSnapshot(options.knowledgeBasePaths, preparationAbortController.signal);
|
|
7136
|
+
}
|
|
7016
7137
|
if (arguments_.rerunInputIdentity !== undefined) {
|
|
7017
|
-
if (options.knowledgeBasePaths?.length) {
|
|
7018
|
-
options.knowledgeBaseSnapshot = await readKnowledgeBaseSnapshot(options.knowledgeBasePaths, preparationAbortController.signal);
|
|
7019
|
-
}
|
|
7020
7138
|
const previousInputs = arguments_.rerunInputIdentity;
|
|
7021
7139
|
const currentInputs = scanInputIdentity(options.scanPrompt, options.knowledgeBaseSnapshot);
|
|
7022
7140
|
const changes = isJsonObject(previousInputs)
|
|
@@ -7041,6 +7159,96 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7041
7159
|
result = await security.run(repository, options);
|
|
7042
7160
|
scanDir = result.scanDir;
|
|
7043
7161
|
repository = resolve(dependencies.currentDirectory(), repository);
|
|
7162
|
+
if (arguments_.validate) {
|
|
7163
|
+
const scanId = result.manifest.scan.id;
|
|
7164
|
+
const checkTarget = async () => {
|
|
7165
|
+
const context = await dependencies.runWorkbench(["get-scan", "--scan-id", scanId, "--check-target"], undefined, preparationAbortController.signal, config.pythonPath, repository, options.knowledgeBaseSnapshot?.protectedRoots, config.pluginPath);
|
|
7166
|
+
const scan = context["scan"];
|
|
7167
|
+
if (!isJsonObject(scan) ||
|
|
7168
|
+
scan["targetPath"] !== (await realpath(repository))) {
|
|
7169
|
+
throw new CodexSecurityError("The recorded scan target does not match the validation repository.");
|
|
7170
|
+
}
|
|
7171
|
+
};
|
|
7172
|
+
const findings = result.findings.findings;
|
|
7173
|
+
if (targetWarnings.length > 0) {
|
|
7174
|
+
validation = {
|
|
7175
|
+
status: "skipped",
|
|
7176
|
+
reason: "The scan target changed during execution.",
|
|
7177
|
+
};
|
|
7178
|
+
}
|
|
7179
|
+
else if (findings.length === 0) {
|
|
7180
|
+
try {
|
|
7181
|
+
await checkTarget();
|
|
7182
|
+
validation = { status: "complete", findings: 0 };
|
|
7183
|
+
}
|
|
7184
|
+
catch (error) {
|
|
7185
|
+
const message = errorMessage(error);
|
|
7186
|
+
validationError = message;
|
|
7187
|
+
validation = { status: "failed", findings: 0, message };
|
|
7188
|
+
errorOutput.write(`codex-security: Validation failed: ${diagnosticValue(message)}\n`);
|
|
7189
|
+
}
|
|
7190
|
+
}
|
|
7191
|
+
else {
|
|
7192
|
+
stopPresentation();
|
|
7193
|
+
try {
|
|
7194
|
+
progress?.stage(`Validating ${findings.length} scan findings`);
|
|
7195
|
+
}
|
|
7196
|
+
catch { }
|
|
7197
|
+
try {
|
|
7198
|
+
const scanDirectory = result.scanDir;
|
|
7199
|
+
let reportPath = join(scanDirectory, "validation.md");
|
|
7200
|
+
const report = await open(reportPath, "wx", 0o600).catch(async (error) => {
|
|
7201
|
+
if (error.code !== "EEXIST")
|
|
7202
|
+
throw error;
|
|
7203
|
+
reportPath = join(scanDirectory, `validation-${randomUUID()}.md`);
|
|
7204
|
+
return await open(reportPath, "wx", 0o600);
|
|
7205
|
+
});
|
|
7206
|
+
validation = { status: "failed", findings: 0, reportPath };
|
|
7207
|
+
let completed = 0;
|
|
7208
|
+
try {
|
|
7209
|
+
for (const finding of findings) {
|
|
7210
|
+
const assessment = await security.validate({
|
|
7211
|
+
repositoryPath: repository,
|
|
7212
|
+
scanId: result.manifest.scan.id,
|
|
7213
|
+
workflowId: arguments_.workflowId,
|
|
7214
|
+
knowledgeBasePaths: options.knowledgeBasePaths,
|
|
7215
|
+
knowledgeBaseSnapshot: options.knowledgeBaseSnapshot,
|
|
7216
|
+
finding,
|
|
7217
|
+
auth,
|
|
7218
|
+
cyberAccessProgram: arguments_.cyberAccessProgram,
|
|
7219
|
+
safetyIdentifier: arguments_.safetyIdentifier,
|
|
7220
|
+
signal: preparationAbortController.signal,
|
|
7221
|
+
});
|
|
7222
|
+
await report.writeFile(`${completed === 0 ? "" : "\n---\n\n"}## ${finding.occurrenceId}\n\nDisposition: ${assessment.disposition}\n\nEvidence: ${assessment.outputDir}\n\n${assessment.report}\n`);
|
|
7223
|
+
completed += 1;
|
|
7224
|
+
validation = { ...validation, findings: completed };
|
|
7225
|
+
}
|
|
7226
|
+
}
|
|
7227
|
+
finally {
|
|
7228
|
+
await report.close();
|
|
7229
|
+
}
|
|
7230
|
+
await checkTarget();
|
|
7231
|
+
validation = {
|
|
7232
|
+
status: "complete",
|
|
7233
|
+
findings: findings.length,
|
|
7234
|
+
reportPath,
|
|
7235
|
+
};
|
|
7236
|
+
try {
|
|
7237
|
+
progress?.stage(`Finding validation saved to ${reportPath}`);
|
|
7238
|
+
}
|
|
7239
|
+
catch { }
|
|
7240
|
+
}
|
|
7241
|
+
catch (error) {
|
|
7242
|
+
const message = errorMessage(error);
|
|
7243
|
+
validationError = message;
|
|
7244
|
+
validation = { ...validation, status: "failed", message };
|
|
7245
|
+
errorOutput.write(`codex-security: Validation failed: ${diagnosticValue(message)}\n`);
|
|
7246
|
+
if (validation["reportPath"] !== undefined) {
|
|
7247
|
+
errorOutput.write(`Partial validation report: ${diagnosticValue(validation["reportPath"])}\n`);
|
|
7248
|
+
}
|
|
7249
|
+
}
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7044
7252
|
}
|
|
7045
7253
|
}
|
|
7046
7254
|
catch (error) {
|
|
@@ -7055,7 +7263,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7055
7263
|
diagnostic("runtime.cleanup.failed", {
|
|
7056
7264
|
classification: classifyConnectionFailure(error),
|
|
7057
7265
|
});
|
|
7058
|
-
if (!failed) {
|
|
7266
|
+
if (!failed && validationError === undefined) {
|
|
7059
7267
|
failed = true;
|
|
7060
7268
|
failure = error;
|
|
7061
7269
|
}
|
|
@@ -7066,8 +7274,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7066
7274
|
let failureData;
|
|
7067
7275
|
if (arguments_.includeFailureResults &&
|
|
7068
7276
|
(failed || requestedSignal !== null)) {
|
|
7069
|
-
if (result !== null)
|
|
7277
|
+
if (result !== null) {
|
|
7070
7278
|
failureData = result.toJSON();
|
|
7279
|
+
if (validation !== undefined)
|
|
7280
|
+
failureData = { ...failureData, validation };
|
|
7281
|
+
}
|
|
7071
7282
|
else if (registeredScan !== undefined) {
|
|
7072
7283
|
try {
|
|
7073
7284
|
const contract = await loadContract(registeredScan.scanDir, {
|
|
@@ -7090,6 +7301,19 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7090
7301
|
signal: requestedSignal,
|
|
7091
7302
|
partial_output: scanDir !== null,
|
|
7092
7303
|
});
|
|
7304
|
+
if (result !== null && arguments_.validate) {
|
|
7305
|
+
const exitCode = requestedSignal === "SIGINT" ? 130 : 143;
|
|
7306
|
+
const message = `Validation interrupted. Completed scan output was kept at ${errorMessage(result.scanDir)}.`;
|
|
7307
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
7308
|
+
return {
|
|
7309
|
+
exitCode,
|
|
7310
|
+
error: message,
|
|
7311
|
+
data: {
|
|
7312
|
+
...result.toJSON(),
|
|
7313
|
+
validation: { ...validation, status: "failed", exitCode },
|
|
7314
|
+
},
|
|
7315
|
+
};
|
|
7316
|
+
}
|
|
7093
7317
|
const exitCode = interruptedExit(requestedSignal, scanDir, errorOutput);
|
|
7094
7318
|
printFailedScanReference(registeredScan, phase, arguments_, errorOutput);
|
|
7095
7319
|
return {
|
|
@@ -7176,6 +7400,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7176
7400
|
let scanData = targetWarnings.length === 0
|
|
7177
7401
|
? result.toJSON()
|
|
7178
7402
|
: { ...result.toJSON(), warnings: targetWarnings };
|
|
7403
|
+
if (validation !== undefined)
|
|
7404
|
+
scanData = { ...scanData, validation };
|
|
7179
7405
|
let deepScanStop;
|
|
7180
7406
|
if (arguments_.mode === "deep") {
|
|
7181
7407
|
deepScanStop = (await readDeepScanStop(result, maxCostUsd, dependencies.runWorkbench).catch(() => undefined)) ?? {
|
|
@@ -7205,6 +7431,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7205
7431
|
...(error === undefined ? {} : { error }),
|
|
7206
7432
|
};
|
|
7207
7433
|
};
|
|
7434
|
+
if (validationError !== undefined) {
|
|
7435
|
+
return finishResult(2, validationError);
|
|
7436
|
+
}
|
|
7208
7437
|
if (targetWarnings.length > 0) {
|
|
7209
7438
|
const message = "Scan target changed during execution; results do not represent the current checkout.";
|
|
7210
7439
|
errorOutput.write(`codex-security: ${message}\n`);
|
|
@@ -7590,6 +7819,7 @@ function printScanSummary(result, progress, errorOutput, color, showCost, deepSc
|
|
|
7590
7819
|
? ""
|
|
7591
7820
|
: ` ${paint("THREAT MODEL", "1;36")} ${paint(errorMessage(threatModelPath), 4)}\n`) +
|
|
7592
7821
|
`\n ${paint("FINDINGS", 1)} ${paint(`${findingCount}${findingSummary === "" ? "" : ` (${findingSummary})`}`, findingColor)}\n` +
|
|
7822
|
+
` ${paint("SCOPE", 1)} ${formatCoverageScope(result.coverage)}\n` +
|
|
7593
7823
|
(deepScanStop === undefined
|
|
7594
7824
|
? ""
|
|
7595
7825
|
: ` ${paint("STOPPED", 1)} ${deepScanStop.reason}\n`) +
|
|
@@ -7614,11 +7844,29 @@ function printScanSummary(result, progress, errorOutput, color, showCost, deepSc
|
|
|
7614
7844
|
errorOutput.write(`\n ${deepScanStop.nextStep}\n`);
|
|
7615
7845
|
}
|
|
7616
7846
|
}
|
|
7617
|
-
function
|
|
7847
|
+
function formatScanProgressCount(progress, style) {
|
|
7848
|
+
const { label, completed, total } = scanProgressCount(progress);
|
|
7849
|
+
const totalText = total.toLocaleString("en-US");
|
|
7850
|
+
if (label === "files" && completed === 0) {
|
|
7851
|
+
return style === "phase"
|
|
7852
|
+
? `${totalText} ${total === 1 ? "file" : "files"} inventoried`
|
|
7853
|
+
: `File inventory: ${totalText}`;
|
|
7854
|
+
}
|
|
7855
|
+
const ratio = `${completed.toLocaleString("en-US")}/${totalText}`;
|
|
7856
|
+
return style === "phase"
|
|
7857
|
+
? `${ratio} ${label}`
|
|
7858
|
+
: `${label === "reviews" ? "Reviews" : "Files"}: ${ratio}`;
|
|
7859
|
+
}
|
|
7860
|
+
function componentScanEventLine(componentName, event, showCost, requestedAuth) {
|
|
7861
|
+
if (event.type === "authentication") {
|
|
7862
|
+
return isChatGptAuthentication(event.value, requestedAuth)
|
|
7863
|
+
? `codex-security: ${componentName} | ${ACCOUNT_LIMITS_UNAVAILABLE}\n`
|
|
7864
|
+
: null;
|
|
7865
|
+
}
|
|
7618
7866
|
if (event.type === "progress") {
|
|
7619
7867
|
const progress = event.value;
|
|
7620
|
-
const count =
|
|
7621
|
-
return `codex-security: ${componentName} ${scanPhase(progress.phase)} | ${count
|
|
7868
|
+
const count = formatScanProgressCount(progress, "status");
|
|
7869
|
+
return `codex-security: ${componentName} ${scanPhase(progress.phase)} | ${count}\n`;
|
|
7622
7870
|
}
|
|
7623
7871
|
if (event.type === "usage") {
|
|
7624
7872
|
const tokens = formatTokenUsage(event.value);
|
|
@@ -7626,6 +7874,13 @@ function componentScanEventLine(componentName, event, showCost) {
|
|
|
7626
7874
|
? null
|
|
7627
7875
|
: `codex-security: ${componentName} | Tokens: ${tokens}\n`;
|
|
7628
7876
|
}
|
|
7877
|
+
if (event.type === "usage-observation") {
|
|
7878
|
+
const details = [
|
|
7879
|
+
formatUsageFreshness(event.value) ?? USAGE_TIME_UNAVAILABLE,
|
|
7880
|
+
formatAccountLimits(event.value),
|
|
7881
|
+
].filter((detail) => detail !== null);
|
|
7882
|
+
return `codex-security: ${componentName} | ${diagnosticValue(details.join(" | "))}\n`;
|
|
7883
|
+
}
|
|
7629
7884
|
if (event.type !== "cost" || !showCost)
|
|
7630
7885
|
return null;
|
|
7631
7886
|
return `codex-security: ${componentName} | Cost: ${formatScanCost(event.value)}\n`;
|