@openai/codex-security 0.8.2 → 0.8.3
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 +43 -61
- package/_bundled_plugin/.app.json +4 -0
- 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/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/permission-profile-preflight.mjs +46 -12
- 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/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +28 -0
- package/_bundled_plugin/references/finding-detail-fields.md +1 -0
- package/_bundled_plugin/references/threat-model.md +1 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
- package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
- package/_bundled_plugin/scripts/finding_preview.py +5 -29
- package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
- package/_bundled_plugin/scripts/report_projection.py +87 -136
- package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
- package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
- package/_bundled_plugin/scripts/workbench_cli.py +102 -13
- package/_bundled_plugin/scripts/workbench_constants.py +9 -0
- package/_bundled_plugin/scripts/workbench_db.py +186 -360
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
- package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
- package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
- package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
- package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_setup.py +239 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
- package/_bundled_plugin/scripts/workbench_target.py +213 -20
- package/_bundled_plugin/scripts/workbench_validation.py +1 -9
- package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
- package/_bundled_plugin/shared/workbench-migrations.json +19 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +64 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +14 -8
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +411 -160
- package/dist/api.js.map +1 -1
- package/dist/auth.js +6 -1
- package/dist/auth.js.map +1 -1
- package/dist/blackduck-findings.d.ts +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +305 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +6 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +28 -9
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +608 -258
- package/dist/cli.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +6 -5
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +162 -40
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +157 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +28 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +75 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +1 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +19 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2120 -39
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +3 -8
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deep-scan.d.ts +11 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +235 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +7 -37
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +5 -11
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +9 -0
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +325 -179
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +12 -0
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1202 -214
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +8 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +65 -54
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +2 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +111 -0
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +29 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +314 -44
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-normalization.d.ts +1 -1
- package/dist/finding-normalization.d.ts.map +1 -1
- package/dist/finding-normalization.js +46 -11
- package/dist/finding-normalization.js.map +1 -1
- package/dist/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- package/dist/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -29
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +7 -16
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +344 -56
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +55 -33
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +13 -18
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.js +18 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +131 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +22 -12
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +34 -20
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- package/dist/private-finding-import.d.ts +246 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +387 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +10 -2
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +72 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/reader-selection.d.ts +13 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +81 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +5 -0
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +30 -0
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -1
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +95 -52
- package/dist/runtime.js.map +1 -1
- package/dist/scan-activity.js +40 -17
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +11 -13
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +16 -37
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +2 -0
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +22 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/scanner-import.d.ts +46 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +208 -42
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +14 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +67 -0
- package/dist/scanner-repository-url.js.map +1 -0
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +20 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +12 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +198 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- package/dist/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +21 -20
- package/dist/snyk-findings.js.map +1 -1
- package/dist/sonar-collector.d.ts +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +383 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +279 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +3 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +18 -12
- package/dist/targets.js.map +1 -1
- package/dist/terminal-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.js.map +1 -0
- package/dist/validation-records.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +0 -16
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +7 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +371 -0
- package/dist/veracode-findings.js.map +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -0
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +10 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +88 -49
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +1 -1
- package/docs/cli.md +310 -477
- package/docs/dedupe-records.md +10 -0
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +8 -9
- package/schemas/external-findings.schema.json +12 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -1
- package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -8,14 +8,16 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
8
8
|
return path;
|
|
9
9
|
};
|
|
10
10
|
import { classificationRunsSchema } from "./severity-review.js";
|
|
11
|
+
import { severityRubricSchema } from "./severity-rubric.js";
|
|
11
12
|
import { workbenchArgs } from "./workbench-arguments.js";
|
|
12
13
|
import { listenForAbort } from "./cli-signals.js";
|
|
13
14
|
import { appServerCyberAccessProgram } from "./cli-daybreak.js";
|
|
14
|
-
import { withCodexPreflightLock } from "./provider-profile.js";
|
|
15
|
+
import { restoreProviderProfile, withCodexPreflightLock, } from "./provider-profile.js";
|
|
15
16
|
import { isNonEmptyString, notify, parseJson } from "./value.js";
|
|
16
17
|
import { compareTimestamps } from "./timestamps.js";
|
|
17
18
|
import { execFile as execFileCallback, execFileSync, spawn, } from "node:child_process";
|
|
18
19
|
import { createHash, randomUUID } from "node:crypto";
|
|
20
|
+
import { errorMonitor } from "node:events";
|
|
19
21
|
import { accessSync, constants, createReadStream, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
20
22
|
import { chmod, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, writeFile, } from "node:fs/promises";
|
|
21
23
|
import { tmpdir } from "node:os";
|
|
@@ -26,6 +28,7 @@ import { Readable, Writable as NodeWritable } from "node:stream";
|
|
|
26
28
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
27
29
|
import { isDeepStrictEqual, parseArgs, promisify, stripVTControlCharacters, } from "node:util";
|
|
28
30
|
import { Cli, z } from "incur";
|
|
31
|
+
import stringWidth from "string-width";
|
|
29
32
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
30
33
|
import { formatCliHelp } from "./cli-help.js";
|
|
31
34
|
import { formatCoverageScope } from "./coverage-presentation.js";
|
|
@@ -34,7 +37,6 @@ import { scanLogsJson } from "./cli-scan-logs-json.js";
|
|
|
34
37
|
import { ARTIFACT_EXPORT_FILENAMES, exportEnvironment, resolveArtifactFormat, resolveArtifactExportOutput, resolveSavedArtifactDirectory, runArtifactExport, writeArtifactOutput as writeCliOutput, } from "./artifact-export.js";
|
|
35
38
|
export { exportEnvironment } from "./artifact-export.js";
|
|
36
39
|
import { parse as parseToml } from "smol-toml";
|
|
37
|
-
import { parse as parseYaml } from "yaml";
|
|
38
40
|
import { classifyConnectionFailure, CodexSecurity, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, scanCodexHome, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, runtimeScanAuthentication, selectedScanEnvironment, } from "./api.js";
|
|
39
41
|
import { accountStatus, CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, configuredCodexHome, environmentEntry, readCodexHomeConfig, } from "./auth.js";
|
|
40
42
|
import { loadContract, sha256Text } from "./contract.js";
|
|
@@ -47,23 +49,21 @@ import { prepareLocalExternalImport } from "./external-findings-import.js";
|
|
|
47
49
|
import { validateInspectorProjectMapping } from "./inspector-findings.js";
|
|
48
50
|
import { externalImportsDisabledMessage, externalImportsEnabled, } from "./external-imports-feature.js";
|
|
49
51
|
import { listLocalExternalFindings } from "./external-findings-local.js";
|
|
52
|
+
import { prepareSonarImport } from "./sonar-import.js";
|
|
50
53
|
import { EXTERNAL_FINDINGS_READERS } from "./external-findings-read.js";
|
|
51
54
|
import { publishPatchReview, resolvePatchReviewPublisher, } from "./patch-publication.js";
|
|
52
55
|
import { DEFAULT_DEDUPE_CONCURRENCY } from "./deduplication/deduplication.js";
|
|
53
56
|
import { savedScanWorkbench } from "./saved-scan-bootstrap.js";
|
|
54
57
|
import { deduplicateScanInternal } from "./deduplication/scan.js";
|
|
55
|
-
import { runRecordsProtocol } from "./deduplication/records-protocol.js";
|
|
56
58
|
import { runHostRecordsProtocol } from "./host-records-protocol.js";
|
|
57
|
-
import { classifySeverityRecords, } from "./classify-severity-records.js";
|
|
58
59
|
import { runHostedScanProtocol } from "./hosted-scan-protocol.js";
|
|
59
60
|
import { runHostedRemediationProtocol } from "./hosted-remediation-protocol.js";
|
|
60
|
-
import {
|
|
61
|
-
import { FindingPatchSchema as findingPatchSchema, parseFindingVerifications, remediationPrompt, VerificationModeSchema, } from "./remediation.js";
|
|
61
|
+
import { FindingPatchSchema as findingPatchSchema, parseFindingVerifications, remediationPrompt, verificationBatches, VerificationFindingTooLargeError, VerificationModeSchema, } from "./remediation.js";
|
|
62
62
|
import { classifyScanSeverityInternal, classifyScanDirectorySeverityInternal, } from "./classify-scan-severity.js";
|
|
63
63
|
import { resolveCompletedScan, resolveWorkflowScan, } from "./saved-scan.js";
|
|
64
64
|
import { publishFindingsCsvToCloud, publishScanToCloud, } from "./cloud-publish.js";
|
|
65
65
|
import { createBulkScanDiscoveryDependencies, createTerminalPrompt, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
66
|
-
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergeCodexOverrides, hasCommandAuth, inlineToml, quoteTomlString, modelProviderConfigOverride, resolveCommandAuthConfig, resolveCodexProfile, mergedCodexConfig, scanModel, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
66
|
+
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergeCodexOverrides, hasCommandAuth, inlineToml, quoteTomlString, modelProviderConfigOverride, resolveCommandAuthConfig, resolveCodexProfile, mergedCodexConfig, readCodexFileProfile, scanModel, scanModelConfiguration, scanModelProvider, scanProviderEnvKey, writeCodexConfig, } from "./config.js";
|
|
67
67
|
import { formatUsd } from "./cost.js";
|
|
68
68
|
import { formatScanCost, formatScanCostTokens, formatTokenUsage, } from "./cost-model.js";
|
|
69
69
|
import { readRegularInputFile, resolveScanPrompts } from "./prompt-files.js";
|
|
@@ -71,7 +71,7 @@ import { standaloneValidationPrompt } from "./standalone-validation-prompt.js";
|
|
|
71
71
|
import { prepareKnowledgeBase, readKnowledgeBaseSnapshot, } from "./knowledge-base.js";
|
|
72
72
|
import { restoreScanKnowledge, scanInputIdentity } from "./scan-inputs.js";
|
|
73
73
|
import { workflowDigest } from "./finding-workflow.js";
|
|
74
|
-
import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, IncompleteScanError, LocalPluginBootstrapError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
74
|
+
import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, IncompleteScanError, LocalPluginBootstrapError, OutputDirectoryError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
75
75
|
import { GHSA_ID } from "./github-identifiers.js";
|
|
76
76
|
import { GITHUB_ADVISORY_STATES, importGitHubAdvisories, } from "./github-advisories.js";
|
|
77
77
|
import { GITHUB_ALERT_STATES, importGitHubCodeScanningAlerts, } from "./github.js";
|
|
@@ -90,6 +90,7 @@ import { findScanSession, readSavedScanLogs, } from "./scan-logs.js";
|
|
|
90
90
|
import { sendFeedback } from "./feedback.js";
|
|
91
91
|
import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
92
92
|
import { ScanDashboard } from "./scan-dashboard.js";
|
|
93
|
+
import { graphemes } from "./terminal-columns.js";
|
|
93
94
|
import { ACCOUNT_LIMITS_UNAVAILABLE, formatAccountLimits, formatUsageFreshness, isChatGptAuthentication, USAGE_TIME_UNAVAILABLE, } from "./scan-usage-display.js";
|
|
94
95
|
import { policyDisplayData, runPolicyCommand, } from "./security-policy-cli.js";
|
|
95
96
|
import { scanPhaseLabel as scanPhase, scanProgressCount, } from "./worker-progress.js";
|
|
@@ -118,14 +119,12 @@ const FRAMEWORK_VALUE_OPTIONS = new Set([
|
|
|
118
119
|
"--token-limit",
|
|
119
120
|
"--token-offset",
|
|
120
121
|
]);
|
|
122
|
+
const TOKEN_OUTPUT_OPTION = /^--token-(?:count|limit|offset)(?:=|$)/u;
|
|
121
123
|
const OUTPUT_OPTION = /^--(?:format|filter-output|full-output|token-count|token-limit|token-offset)(?:=|$)/u;
|
|
122
124
|
const HIDE_CURSOR = "\u001B[?25l";
|
|
123
125
|
const SHOW_CURSOR = "\u001B[?25h";
|
|
124
126
|
const CHILD_TERMINATION_GRACE_MS = 1_000;
|
|
125
127
|
const DUPLICATE_SIGNAL_WINDOW_MS = 500;
|
|
126
|
-
const PUBLICATION_GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {
|
|
127
|
-
granularity: "grapheme",
|
|
128
|
-
});
|
|
129
128
|
const DEFAULT_SCAN_MODEL_CONFIGURATION = scanModelConfiguration(DEFAULT_CODEX_CONFIG);
|
|
130
129
|
const MODEL_OPTIONS = modelOptions();
|
|
131
130
|
const MATCHING_MODEL_OPTIONS = modelOptions("Model for finding matching (default: Codex's configured model).", "Matching reasoning effort (default: medium).");
|
|
@@ -184,6 +183,30 @@ const ASSESS_PATCH_RISK_OPTION = z
|
|
|
184
183
|
function optionValue(flag) {
|
|
185
184
|
return z.string().min(1, `${flag} must not be empty.`);
|
|
186
185
|
}
|
|
186
|
+
function remediationInputOptions(verb) {
|
|
187
|
+
return z.object({
|
|
188
|
+
scan: optionValue("--scan")
|
|
189
|
+
.optional()
|
|
190
|
+
.describe(`${verb} open findings from a saved scan ID or the latest completed scan.`),
|
|
191
|
+
severity: z
|
|
192
|
+
.enum(REPORTABLE_SEVERITIES)
|
|
193
|
+
.optional()
|
|
194
|
+
.describe(`${verb} saved findings at or above LEVEL.`),
|
|
195
|
+
linearIssue: z
|
|
196
|
+
.array(optionValue("--linear-issue"))
|
|
197
|
+
.default([])
|
|
198
|
+
.describe("Linear issue identifier or URL; repeat for more issues."),
|
|
199
|
+
linearProject: optionValue("--linear-project")
|
|
200
|
+
.optional()
|
|
201
|
+
.describe(verb === "Patch"
|
|
202
|
+
? "Patch every open issue in this Linear project."
|
|
203
|
+
: "Verify issues in this Linear project."),
|
|
204
|
+
linearFilter: optionValue("--linear-filter")
|
|
205
|
+
.optional()
|
|
206
|
+
.describe("JSON Linear issue filter for --linear-project."),
|
|
207
|
+
linearApiKey: linearApiKeyOption(),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
187
210
|
function linearApiKeyOption() {
|
|
188
211
|
return z
|
|
189
212
|
.string()
|
|
@@ -267,7 +290,7 @@ function publicationScanAge(timestamp, now) {
|
|
|
267
290
|
return "just now";
|
|
268
291
|
}
|
|
269
292
|
function publicationDisplayWidth(value) {
|
|
270
|
-
const segments =
|
|
293
|
+
const segments = graphemes.segment(stripVTControlCharacters(value));
|
|
271
294
|
let width = 0;
|
|
272
295
|
for (const { segment } of segments) {
|
|
273
296
|
if (/^[\p{Mark}\p{Cf}]+$/u.test(segment))
|
|
@@ -282,6 +305,19 @@ function publicationDisplayWidth(value) {
|
|
|
282
305
|
function padPublicationColumn(value, width) {
|
|
283
306
|
return `${value}${" ".repeat(width - publicationDisplayWidth(value))}`;
|
|
284
307
|
}
|
|
308
|
+
function fitProgressLine(line, width) {
|
|
309
|
+
const plain = stripVTControlCharacters(line);
|
|
310
|
+
let ellipsisIndex = 0;
|
|
311
|
+
let used = 0;
|
|
312
|
+
for (const { index, segment } of graphemes.segment(plain)) {
|
|
313
|
+
used += stringWidth(segment.toWellFormed());
|
|
314
|
+
if (used > width)
|
|
315
|
+
return width > 0 ? `${plain.slice(0, ellipsisIndex)}…` : "";
|
|
316
|
+
if (used < width)
|
|
317
|
+
ellipsisIndex = index + segment.length;
|
|
318
|
+
}
|
|
319
|
+
return line;
|
|
320
|
+
}
|
|
285
321
|
function publicationIssueUrl(value) {
|
|
286
322
|
if (value === undefined ||
|
|
287
323
|
value !== value.trim() ||
|
|
@@ -308,9 +344,16 @@ function publicationIssueUrl(value) {
|
|
|
308
344
|
}
|
|
309
345
|
function renderExternalPublicationSummary(result) {
|
|
310
346
|
return [
|
|
311
|
-
|
|
347
|
+
result.privateJob
|
|
348
|
+
? `Private inbox import ${result.privateJob.status}. Job: ${diagnosticValue(result.privateJob.id)}`
|
|
349
|
+
: `Import ${result.status}.`,
|
|
312
350
|
`Submission totals — Created: ${result.counts.created} Updated: ${result.counts.updated} Unchanged: ${result.counts.unchanged} Failed: ${result.counts.error}`,
|
|
313
|
-
|
|
351
|
+
result.privateJob
|
|
352
|
+
? `Excluded: ${result.excluded.length} Unprocessed: ${result.privateJob.counts.unprocessed}`
|
|
353
|
+
: `Excluded: ${result.excluded.length} Awaiting acknowledgement: ${result.unacknowledged} Verified: ${result.verified}`,
|
|
354
|
+
...(result.privateJob?.error
|
|
355
|
+
? [diagnosticValue(result.privateJob.error.message)]
|
|
356
|
+
: []),
|
|
314
357
|
...result.failures.map((item) => `Failed ${diagnosticValue(item.source_finding_id)} (${item.code}): ${diagnosticValue(item.message)}`),
|
|
315
358
|
...result.excluded.map((item) => `Excluded item ${item.position}${item.source_finding_id ? ` (${diagnosticValue(item.source_finding_id)})` : ""}: ${diagnosticValue(item.reason)}`),
|
|
316
359
|
...(result.savedSubmission
|
|
@@ -320,9 +363,11 @@ function renderExternalPublicationSummary(result) {
|
|
|
320
363
|
? []
|
|
321
364
|
: [
|
|
322
365
|
"Imported evidence remains not assessed by Codex.",
|
|
323
|
-
result.
|
|
324
|
-
?
|
|
325
|
-
:
|
|
366
|
+
result.privateJob
|
|
367
|
+
? "Open the private inbox in Codex Security Cloud to assess a finding and choose whether to publish it."
|
|
368
|
+
: result.cloudUrl
|
|
369
|
+
? `View Cloud repository: ${diagnosticValue(result.cloudUrl)}`
|
|
370
|
+
: "Open the repository in Codex Security Cloud.",
|
|
326
371
|
]),
|
|
327
372
|
"",
|
|
328
373
|
].join("\n");
|
|
@@ -406,11 +451,8 @@ class PublicationProgressPresenter {
|
|
|
406
451
|
return;
|
|
407
452
|
}
|
|
408
453
|
if (event.type === "codex_event") {
|
|
409
|
-
if (
|
|
410
|
-
event.event === null ||
|
|
411
|
-
Array.isArray(event.event)) {
|
|
454
|
+
if (!isJsonObject(event.event))
|
|
412
455
|
return;
|
|
413
|
-
}
|
|
414
456
|
for (const activity of scanActivitiesFromEvent(event.event, this.#repository)) {
|
|
415
457
|
const item = event.event["item"];
|
|
416
458
|
const tool = isJsonObject(item) ? item["tool"] : undefined;
|
|
@@ -433,11 +475,10 @@ class PublicationProgressPresenter {
|
|
|
433
475
|
if (this.#seenActivities.has(key))
|
|
434
476
|
continue;
|
|
435
477
|
this.#seenActivities.add(key);
|
|
436
|
-
const label = visibleActivity.kind === "reasoning"
|
|
478
|
+
const label = visibleActivity.kind === "reasoning" ||
|
|
479
|
+
visibleActivity.kind === "message"
|
|
437
480
|
? "Codex"
|
|
438
|
-
:
|
|
439
|
-
? "Codex"
|
|
440
|
-
: "Tool";
|
|
481
|
+
: "Tool";
|
|
441
482
|
this.#write(`${label}: ${visibleActivity.description}`, true);
|
|
442
483
|
}
|
|
443
484
|
return;
|
|
@@ -480,9 +521,7 @@ class PublicationProgressPresenter {
|
|
|
480
521
|
return;
|
|
481
522
|
}
|
|
482
523
|
const width = Math.max(24, Math.min(this.#stream.columns ?? 120, 160));
|
|
483
|
-
const visible = sanitized
|
|
484
|
-
? sanitized
|
|
485
|
-
: `${sanitized.slice(0, width - 1)}…`;
|
|
524
|
+
const visible = fitProgressLine(sanitized, width);
|
|
486
525
|
this.#stream.write(`${visible}\n`);
|
|
487
526
|
}
|
|
488
527
|
}
|
|
@@ -798,11 +837,10 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
798
837
|
const directory = await realpath(output.directory ?? output.appServer?.directory ?? process.cwd());
|
|
799
838
|
const protectedRoots = [
|
|
800
839
|
directory,
|
|
801
|
-
...(await enclosingGitWorktreeRoots(directory)),
|
|
840
|
+
...(await enclosingGitWorktreeRoots(directory, output.signal)),
|
|
802
841
|
];
|
|
803
842
|
const codexHome = await prepareCodexSecurityCredentialHome(selected, (path) => requireOutputOutsideRepositories(protectedRoots, path, "runtime"));
|
|
804
|
-
releaseCredentialHome =
|
|
805
|
-
await acquireCodexSecurityCredentialHomeLock(codexHome);
|
|
843
|
+
releaseCredentialHome = await acquireCodexSecurityCredentialHomeLock(codexHome, output.signal);
|
|
806
844
|
let credentialsAvailable;
|
|
807
845
|
const ambientAuthConfig = await readCodexHomeConfig(selected);
|
|
808
846
|
credentialConfig = await readCodexHomeConfig({
|
|
@@ -839,27 +877,31 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
839
877
|
CODEX_HOME: codexHome,
|
|
840
878
|
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(selected),
|
|
841
879
|
};
|
|
880
|
+
output.signal?.throwIfAborted();
|
|
842
881
|
if (!credentialsAvailable &&
|
|
843
|
-
!(await accountStatus(command, selected)).authenticated) {
|
|
882
|
+
!(await accountStatus(command, selected, output.signal)).authenticated) {
|
|
844
883
|
throw new AuthenticationRequiredError(NO_CREDENTIALS_MESSAGE);
|
|
845
884
|
}
|
|
846
|
-
authentication = await runtimeScanAuthentication(selected, codexHome, output.auth, provider);
|
|
885
|
+
authentication = await runtimeScanAuthentication(selected, codexHome, output.auth, provider, providerEnvKey);
|
|
847
886
|
if (output.appServer !== undefined) {
|
|
848
887
|
const controller = new AbortController();
|
|
849
|
-
const
|
|
888
|
+
const signal = output.signal ?? controller.signal;
|
|
889
|
+
const removeSignals = output.signal
|
|
890
|
+
? undefined
|
|
891
|
+
: listenForAbort(DEFAULT_DEPENDENCIES, controller);
|
|
850
892
|
try {
|
|
851
893
|
args = [
|
|
852
894
|
...args,
|
|
853
|
-
...(await skillDaybreakConfigOverrides(args, command, selected, directory, ambientConfig,
|
|
895
|
+
...(await skillDaybreakConfigOverrides(args, command, selected, directory, ambientConfig, signal)),
|
|
854
896
|
];
|
|
855
897
|
}
|
|
856
898
|
catch (error) {
|
|
857
|
-
if (
|
|
858
|
-
return
|
|
899
|
+
if (signal.aborted)
|
|
900
|
+
return signal.reason === "SIGINT" ? 130 : 143;
|
|
859
901
|
throw error;
|
|
860
902
|
}
|
|
861
903
|
finally {
|
|
862
|
-
removeSignals();
|
|
904
|
+
removeSignals?.();
|
|
863
905
|
}
|
|
864
906
|
}
|
|
865
907
|
}
|
|
@@ -908,6 +950,7 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
908
950
|
if (configuredHome?.trim()) {
|
|
909
951
|
environment["CODEX_HOME"] = resolve(expandHome(configuredHome, processEnvironment));
|
|
910
952
|
}
|
|
953
|
+
output?.signal?.throwIfAborted();
|
|
911
954
|
const invocation = spawn(executablePathForSpawn(command.command), [...args], {
|
|
912
955
|
env: environment,
|
|
913
956
|
cwd: output?.appServer?.directory ?? parse(process.execPath).root,
|
|
@@ -943,10 +986,12 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
943
986
|
if (invocation.exitCode === null && invocation.signalCode === null) {
|
|
944
987
|
invocation.kill("SIGKILL");
|
|
945
988
|
}
|
|
989
|
+
else {
|
|
990
|
+
forceStatusCompletion?.();
|
|
991
|
+
}
|
|
946
992
|
forceCaptureCompletion?.();
|
|
947
993
|
invocation.stdout?.destroy();
|
|
948
994
|
invocation.stderr?.destroy();
|
|
949
|
-
forceStatusCompletion?.();
|
|
950
995
|
}, CHILD_TERMINATION_GRACE_MS);
|
|
951
996
|
};
|
|
952
997
|
const onInterrupt = () => {
|
|
@@ -955,6 +1000,16 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
955
1000
|
const onTerminate = () => {
|
|
956
1001
|
requestTermination("SIGTERM");
|
|
957
1002
|
};
|
|
1003
|
+
const signal = output?.signal;
|
|
1004
|
+
const onAbort = () => {
|
|
1005
|
+
// A process signal also invokes the handlers below in the same turn.
|
|
1006
|
+
queueMicrotask(() => {
|
|
1007
|
+
if (requestedSignal === null && forceStatusCompletion !== null) {
|
|
1008
|
+
requestTermination(signal?.reason === "SIGINT" ? "SIGINT" : "SIGTERM");
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
1012
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
958
1013
|
process.on("SIGINT", onInterrupt);
|
|
959
1014
|
process.on("SIGTERM", onTerminate);
|
|
960
1015
|
try {
|
|
@@ -1033,6 +1088,7 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
1033
1088
|
clearTimeout(forcedTermination);
|
|
1034
1089
|
forceStatusCompletion = null;
|
|
1035
1090
|
forceCaptureCompletion = null;
|
|
1091
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1036
1092
|
process.off("SIGINT", onInterrupt);
|
|
1037
1093
|
process.off("SIGTERM", onTerminate);
|
|
1038
1094
|
}
|
|
@@ -1105,6 +1161,42 @@ async function skillDaybreakConfigOverrides(args, command, environment, director
|
|
|
1105
1161
|
}
|
|
1106
1162
|
return overrides;
|
|
1107
1163
|
}
|
|
1164
|
+
function writeOptionalVerificationDiagnostic(stream, message) {
|
|
1165
|
+
try {
|
|
1166
|
+
if (!(stream instanceof NodeWritable)) {
|
|
1167
|
+
stream.write(message);
|
|
1168
|
+
}
|
|
1169
|
+
else if (stream.writable) {
|
|
1170
|
+
stream.write(message, (error) => {
|
|
1171
|
+
// Node calls the write callback before emitting its error. A stalled
|
|
1172
|
+
// write needs no listener, and other consumers still receive the event.
|
|
1173
|
+
if (error &&
|
|
1174
|
+
!stream.closed &&
|
|
1175
|
+
stream.errored === error &&
|
|
1176
|
+
!stream.listenerCount("error"))
|
|
1177
|
+
stream.once("error", () => { });
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
catch { }
|
|
1182
|
+
}
|
|
1183
|
+
function guardDisconnectedVerificationTerminal(stream) {
|
|
1184
|
+
if (stream !== process.stderr || !stream.isTTY)
|
|
1185
|
+
return;
|
|
1186
|
+
const stderr = process.stderr;
|
|
1187
|
+
if (!stderr.listeners(errorMonitor).includes(handleDisconnectedResize)) {
|
|
1188
|
+
stderr.on(errorMonitor, handleDisconnectedResize);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
// Node refreshes the TTY size on SIGWINCH even after main() returns. Handle
|
|
1192
|
+
// only a disconnected terminal's resize when no other consumer handles it.
|
|
1193
|
+
function handleDisconnectedResize(error) {
|
|
1194
|
+
if (error.code === "EIO" &&
|
|
1195
|
+
error.syscall === "getWindowSize" &&
|
|
1196
|
+
process.stderr.listenerCount("error") === 0) {
|
|
1197
|
+
process.stderr.once("error", () => { });
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1108
1200
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
1109
1201
|
const importsEnabled = externalImportsEnabled(dependencies.environment);
|
|
1110
1202
|
const remediationOperation = argv[0] === "patch"
|
|
@@ -1112,11 +1204,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1112
1204
|
: argv[0] === "verify-fix"
|
|
1113
1205
|
? "verify"
|
|
1114
1206
|
: undefined;
|
|
1115
|
-
const
|
|
1116
|
-
if ((((argv[0] === "dedupe" ||
|
|
1207
|
+
const recordsCommand = argv[0] === "dedupe" ||
|
|
1117
1208
|
argv[0] === "validate" ||
|
|
1118
|
-
argv[0] === "classify-severity"
|
|
1119
|
-
argv
|
|
1209
|
+
argv[0] === "classify-severity"
|
|
1210
|
+
? argv[0]
|
|
1211
|
+
: undefined;
|
|
1212
|
+
const hostedCommand = argv[0] === "scan" || remediationOperation !== undefined;
|
|
1213
|
+
if (((recordsCommand !== undefined && argv.includes("--records")) ||
|
|
1120
1214
|
(hostedCommand &&
|
|
1121
1215
|
argv.some((arg) => arg === "--host" || arg.startsWith("--host=")))) &&
|
|
1122
1216
|
!argv.includes("--help") &&
|
|
@@ -1149,19 +1243,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1149
1243
|
const removeSignals = listenForAbort(dependencies, controller);
|
|
1150
1244
|
let exitCode;
|
|
1151
1245
|
try {
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
: runRecordsProtocol;
|
|
1157
|
-
const code = argv[0] === "classify-severity"
|
|
1158
|
-
? await runHostRecordsProtocol(dependencies.recordsInput ?? process.stdin, output, (value, options) => classifySeverityRecords(value, {
|
|
1159
|
-
...options,
|
|
1246
|
+
const input = dependencies.recordsInput ?? process.stdin;
|
|
1247
|
+
const code = recordsCommand !== undefined
|
|
1248
|
+
? await runHostRecordsProtocol(recordsCommand, input, output, {
|
|
1249
|
+
signal: controller.signal,
|
|
1160
1250
|
classificationRuns,
|
|
1161
|
-
})
|
|
1251
|
+
})
|
|
1162
1252
|
: remediationOperation !== undefined
|
|
1163
|
-
? await runHostedRemediationProtocol(
|
|
1164
|
-
: await
|
|
1253
|
+
? await runHostedRemediationProtocol(input, output, controller.signal, remediationOperation)
|
|
1254
|
+
: await runHostedScanProtocol(input, output, controller.signal);
|
|
1165
1255
|
exitCode =
|
|
1166
1256
|
controller.signal.reason === "SIGINT"
|
|
1167
1257
|
? 130
|
|
@@ -1182,6 +1272,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1182
1272
|
let frameworkExit;
|
|
1183
1273
|
const frameworkCapture = captureOutput();
|
|
1184
1274
|
let rawExportOutput = false;
|
|
1275
|
+
let batchedVerification = false;
|
|
1276
|
+
let deferredVerificationDiagnostic;
|
|
1185
1277
|
let streamedLogs;
|
|
1186
1278
|
let renderedOutput;
|
|
1187
1279
|
let structuredError = false;
|
|
@@ -1614,7 +1706,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1614
1706
|
scanPrompt: typeof saved["userContext"] === "string"
|
|
1615
1707
|
? saved["userContext"]
|
|
1616
1708
|
: undefined,
|
|
1617
|
-
}, dependencies.currentDirectory());
|
|
1709
|
+
}, dependencies.currentDirectory(), dependencies.environment);
|
|
1618
1710
|
scanArguments.resumeScanId = saved["scanId"];
|
|
1619
1711
|
scanArguments.outputDir = resolveCliPath(dependencies.currentDirectory(), saved["scanDir"]);
|
|
1620
1712
|
if (scanArguments.knowledgeBasePaths.length > 0) {
|
|
@@ -1717,7 +1809,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1717
1809
|
validationPromptFile: options.validationPromptFile === undefined
|
|
1718
1810
|
? undefined
|
|
1719
1811
|
: resolveCliPath(dependencies.currentDirectory(), options.validationPromptFile),
|
|
1720
|
-
}, dependencies.currentDirectory());
|
|
1812
|
+
}, dependencies.currentDirectory(), dependencies.environment);
|
|
1721
1813
|
scanArguments.verbose = options.verbose;
|
|
1722
1814
|
scanArguments.showCost = options.showCost;
|
|
1723
1815
|
scanArguments.parentScanId = parentScanId;
|
|
@@ -2048,8 +2140,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2048
2140
|
const repositories = new Map();
|
|
2049
2141
|
const scansById = new Map();
|
|
2050
2142
|
const rows = scans.flatMap((scan) => {
|
|
2051
|
-
if (!isJsonObject(scan))
|
|
2052
|
-
return [];
|
|
2053
2143
|
const progress = scan["progress"];
|
|
2054
2144
|
const scanId = scan["scanId"];
|
|
2055
2145
|
const directory = scan["scanDir"];
|
|
@@ -2105,9 +2195,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2105
2195
|
if (rows.length === 0) {
|
|
2106
2196
|
throw new CodexSecurityError("No completed Codex Security scans are available to publish.");
|
|
2107
2197
|
}
|
|
2108
|
-
const
|
|
2109
|
-
const
|
|
2110
|
-
const
|
|
2198
|
+
const columnWidth = (heading, field) => Math.max(publicationDisplayWidth(heading), ...rows.map((row) => publicationDisplayWidth(row[field])));
|
|
2199
|
+
const repositoryWidth = columnWidth("REPOSITORY", "repository");
|
|
2200
|
+
const findingsWidth = columnWidth("FINDINGS", "findings");
|
|
2201
|
+
const ageWidth = columnWidth("AGE", "age");
|
|
2111
2202
|
const header = [
|
|
2112
2203
|
padPublicationColumn("REPOSITORY", repositoryWidth),
|
|
2113
2204
|
padPublicationColumn("FINDINGS", findingsWidth),
|
|
@@ -2467,7 +2558,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2467
2558
|
const { preview } = prepared;
|
|
2468
2559
|
const showPreview = () => {
|
|
2469
2560
|
showScannerReport(preview);
|
|
2470
|
-
writeDiagnostic(`Cloud API: ${diagnosticValue(preview.cloudApiUrl)}\nAccount: ${diagnosticValue(preview.accountId)}\nDestination: ${diagnosticValue(preview.destination.url)} (${diagnosticValue(preview.destination.id)})\
|
|
2561
|
+
writeDiagnostic(`Cloud API: ${diagnosticValue(preview.cloudApiUrl)}\nAccount: ${diagnosticValue(preview.accountId)}\nDestination: ${diagnosticValue(preview.destination.url)} (${diagnosticValue(preview.destination.id)})\n${preview.privateImport ? `Visibility: Private inbox\nReport: ${preview.privateImport.format} (${preview.privateImport.bytes} bytes)\nReport SHA-256: ${preview.privateImport.sha256}${preview.privateImport.retryOfJobId ? `\nRetrying private job: ${diagnosticValue(preview.privateImport.retryOfJobId)}` : ""}` : `Environment: ${[...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`);
|
|
2471
2562
|
if (preview.cloudUrl)
|
|
2472
2563
|
writeDiagnostic(`Cloud app: ${diagnosticValue(preview.cloudUrl)}\n`);
|
|
2473
2564
|
for (const excluded of preview.excluded)
|
|
@@ -2565,7 +2656,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2565
2656
|
});
|
|
2566
2657
|
const imports = Cli.create("import", {
|
|
2567
2658
|
description: importsEnabled
|
|
2568
|
-
? "
|
|
2659
|
+
? "Import Sonar security issues or read GitHub security findings."
|
|
2569
2660
|
: "Read GitHub code scanning alerts.",
|
|
2570
2661
|
}).command("github", {
|
|
2571
2662
|
description: "Read GitHub code scanning alerts without changing GitHub.",
|
|
@@ -2712,8 +2803,193 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2712
2803
|
},
|
|
2713
2804
|
});
|
|
2714
2805
|
}
|
|
2715
|
-
|
|
2806
|
+
function registerSonarImport() {
|
|
2807
|
+
imports.command("sonar", {
|
|
2808
|
+
description: "Collect Sonar security findings or replay a saved capture into the local workbench.",
|
|
2809
|
+
hint: "Uses the active sonar CLI login. --to cloud also publishes the locally imported selection to the connected Cloud repository. --dry-run saves a live capture for review without importing findings.",
|
|
2810
|
+
destructive: true,
|
|
2811
|
+
mcp: false,
|
|
2812
|
+
args: z.object({
|
|
2813
|
+
capture: z
|
|
2814
|
+
.string()
|
|
2815
|
+
.min(1)
|
|
2816
|
+
.optional()
|
|
2817
|
+
.describe("Replay a saved sonar-issues/v1 capture without connecting to Sonar."),
|
|
2818
|
+
}),
|
|
2819
|
+
options: z.object({
|
|
2820
|
+
sonarProject: optionValue("--sonar-project")
|
|
2821
|
+
.optional()
|
|
2822
|
+
.describe("Sonar project key (defaults to the checkout’s project binding)."),
|
|
2823
|
+
sonarBranch: optionValue("--sonar-branch")
|
|
2824
|
+
.optional()
|
|
2825
|
+
.describe("Analyzed Sonar branch (default: the project's main branch)."),
|
|
2826
|
+
sonarPullRequest: optionValue("--sonar-pull-request")
|
|
2827
|
+
.optional()
|
|
2828
|
+
.describe("Sonar pull request key, instead of a branch."),
|
|
2829
|
+
sonarIssue: z
|
|
2830
|
+
.array(optionValue("--sonar-issue"))
|
|
2831
|
+
.default([])
|
|
2832
|
+
.describe("Exact Sonar security issue key. Repeat to import a selection. Defaults to open and confirmed security issues."),
|
|
2833
|
+
sourceRepositoryUrl: optionValue("--source-repository-url")
|
|
2834
|
+
.optional()
|
|
2835
|
+
.describe("Verified repository URL when Sonar has no SCM binding."),
|
|
2836
|
+
to: z
|
|
2837
|
+
.enum(["local", "cloud"])
|
|
2838
|
+
.default("local")
|
|
2839
|
+
.describe("Store locally, or also publish to Codex Security Cloud."),
|
|
2840
|
+
dryRun: z
|
|
2841
|
+
.boolean()
|
|
2842
|
+
.default(false)
|
|
2843
|
+
.describe("Preview destinations and evidence without storing or publishing findings."),
|
|
2844
|
+
yes: z
|
|
2845
|
+
.boolean()
|
|
2846
|
+
.default(false)
|
|
2847
|
+
.describe("Confirm import of the reviewed selection."),
|
|
2848
|
+
}),
|
|
2849
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
2850
|
+
async run({ args, options, format, formatExplicit, error: incurError }) {
|
|
2851
|
+
return await withTerminalErrorsHandled(errorOutput, async () => {
|
|
2852
|
+
const humanSummary = format === "toon" &&
|
|
2853
|
+
!formatExplicit &&
|
|
2854
|
+
!argv.some((arg) => OUTPUT_OPTION.test(arg));
|
|
2855
|
+
const controller = new AbortController();
|
|
2856
|
+
const removeSignals = listenForAbort(dependencies, controller);
|
|
2857
|
+
const note = (line) => notify(() => errorOutput.write(line + "\n"));
|
|
2858
|
+
const cloudFailure = (message) => {
|
|
2859
|
+
const reason = controller.signal.reason;
|
|
2860
|
+
exitCode =
|
|
2861
|
+
reason === "SIGINT" ? 130 : reason === "SIGTERM" ? 143 : 2;
|
|
2862
|
+
if (argv.includes("--full-output") &&
|
|
2863
|
+
(format === "json" || format === "jsonl"))
|
|
2864
|
+
failedResultOutput = {
|
|
2865
|
+
format,
|
|
2866
|
+
code: "SONAR_IMPORT_FAILED",
|
|
2867
|
+
message,
|
|
2868
|
+
};
|
|
2869
|
+
};
|
|
2870
|
+
try {
|
|
2871
|
+
if (importsEnabled &&
|
|
2872
|
+
argv.includes("--full-output") &&
|
|
2873
|
+
format !== "json" &&
|
|
2874
|
+
format !== "jsonl") {
|
|
2875
|
+
structuredError = true;
|
|
2876
|
+
exitCode = 2;
|
|
2877
|
+
return incurError({
|
|
2878
|
+
code: "INVALID_ARGUMENTS",
|
|
2879
|
+
message: "Sonar imports support --full-output with --format json or --format jsonl. Choose one of those formats or omit --full-output.",
|
|
2880
|
+
exitCode,
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
const prepared = await prepareSonarImport({
|
|
2884
|
+
cwd: dependencies.currentDirectory(),
|
|
2885
|
+
capture: args.capture,
|
|
2886
|
+
project: options.sonarProject,
|
|
2887
|
+
branch: options.sonarBranch,
|
|
2888
|
+
pullRequest: options.sonarPullRequest,
|
|
2889
|
+
issueKeys: options.sonarIssue,
|
|
2890
|
+
sourceRepositoryUrl: options.sourceRepositoryUrl,
|
|
2891
|
+
to: options.to,
|
|
2892
|
+
dryRun: options.dryRun,
|
|
2893
|
+
yes: options.yes,
|
|
2894
|
+
}, {
|
|
2895
|
+
environment: dependencies.environment,
|
|
2896
|
+
signal: controller.signal,
|
|
2897
|
+
fetch: dependencies.cloudFetch,
|
|
2898
|
+
collect: dependencies.collectSonarIssues,
|
|
2899
|
+
onCapture: (path) => note("Evidence file: " + diagnosticValue(path)),
|
|
2900
|
+
});
|
|
2901
|
+
const { info, local, cloud, cloudError } = prepared;
|
|
2902
|
+
const ref = info.pullRequest
|
|
2903
|
+
? `pull request ${info.pullRequest}`
|
|
2904
|
+
: (info.branch ?? "unspecified ref");
|
|
2905
|
+
note(`Sonar project: ${diagnosticValue(info.organization)}/${diagnosticValue(info.project)} (${diagnosticValue(ref)}) on ${diagnosticValue(info.server)}`);
|
|
2906
|
+
note(`Local repository: ${diagnosticValue(info.repository)}`);
|
|
2907
|
+
note(`Local: ${local.findings.length} ready, ${local.excluded.length} excluded.`);
|
|
2908
|
+
if (cloud) {
|
|
2909
|
+
const environments = new Set(cloud.requests.map((request) => request.repository.environment_id));
|
|
2910
|
+
note(`Cloud account: ${diagnosticValue(cloud.accountId)} on ${diagnosticValue(cloud.cloudApiUrl)}`);
|
|
2911
|
+
note(`Cloud repository: ${diagnosticValue(cloud.destination.url)} · ${cloud.privateImport ? `Private inbox · ${cloud.privateImport.format} (${cloud.privateImport.bytes} bytes)` : `Environments: ${[...environments].map(diagnosticValue).join(", ")}`}`);
|
|
2912
|
+
note(`Cloud: ${cloud.findings.length} ready, ${cloud.excluded.length} excluded.`);
|
|
2913
|
+
}
|
|
2914
|
+
if (options.to === "cloud" && local.read === 0)
|
|
2915
|
+
note("No Sonar findings to publish to Cloud.");
|
|
2916
|
+
if (cloudError)
|
|
2917
|
+
note(`Cloud unavailable: ${diagnosticValue(cloudError)}`);
|
|
2918
|
+
for (const { source_finding_id, evidence } of local.findings.slice(0, 5))
|
|
2919
|
+
note(` ${diagnosticValue(source_finding_id)} [${evidence.severity}] ${diagnosticValue(evidence.title)}`);
|
|
2920
|
+
if (local.findings.length > 5)
|
|
2921
|
+
note(` Showing the first 5 of ${local.findings.length} ready findings. Use --dry-run --format json for the full selection.`);
|
|
2922
|
+
const exclusions = new Set([...local.excluded, ...(cloud?.excluded ?? [])].map((item) => `Excluded ${diagnosticValue(item.source_finding_id ?? `item ${item.position}`)}: ${diagnosticValue(item.reason)}`));
|
|
2923
|
+
for (const line of exclusions)
|
|
2924
|
+
note(line);
|
|
2925
|
+
if (options.dryRun) {
|
|
2926
|
+
if (cloudError)
|
|
2927
|
+
cloudFailure(cloudError);
|
|
2928
|
+
if (humanSummary)
|
|
2929
|
+
renderedOutput = cloudError
|
|
2930
|
+
? "Evidence saved. Retry with the saved file and --to cloud --dry-run to review the Cloud destination.\n"
|
|
2931
|
+
: "Preview complete. Use the saved evidence file to import this selection.\n";
|
|
2932
|
+
return { ...info, local, cloud, cloudError, dryRun: true };
|
|
2933
|
+
}
|
|
2934
|
+
if (!options.yes) {
|
|
2935
|
+
const prompt = dependencies.externalPublicationPrompt ??
|
|
2936
|
+
createTerminalPrompt(errorOutput);
|
|
2937
|
+
if (!prompt.isInteractive())
|
|
2938
|
+
throw new Error("Review the saved capture with --dry-run, then pass its path and --yes to confirm.");
|
|
2939
|
+
const action = cloud
|
|
2940
|
+
? " and publish " +
|
|
2941
|
+
cloud.findings.length +
|
|
2942
|
+
" to the displayed Cloud destination"
|
|
2943
|
+
: " locally";
|
|
2944
|
+
if (!(await prompt.confirm("Import " +
|
|
2945
|
+
local.findings.length +
|
|
2946
|
+
" Sonar findings" +
|
|
2947
|
+
action +
|
|
2948
|
+
"?", false, controller.signal))) {
|
|
2949
|
+
if (humanSummary)
|
|
2950
|
+
renderedOutput = "Import canceled.\n";
|
|
2951
|
+
return { ...info, imported: false };
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
const result = await prepared.import();
|
|
2955
|
+
if (result.cloudError) {
|
|
2956
|
+
cloudFailure(result.cloudError);
|
|
2957
|
+
note("Stored locally. Cloud: " + diagnosticValue(result.cloudError));
|
|
2958
|
+
}
|
|
2959
|
+
else if (result.local.excluded.length ||
|
|
2960
|
+
result.cloud?.status === "partial")
|
|
2961
|
+
exitCode = 1;
|
|
2962
|
+
if (result.cloud?.cloudUrl)
|
|
2963
|
+
note("Cloud repository: " + diagnosticValue(result.cloud.cloudUrl));
|
|
2964
|
+
if (humanSummary) {
|
|
2965
|
+
const { created, updated, unchanged } = result.local.counts;
|
|
2966
|
+
renderedOutput = `Local import: ${created} created, ${updated} updated, ${unchanged} unchanged.\n`;
|
|
2967
|
+
if (result.cloud)
|
|
2968
|
+
renderedOutput += renderExternalPublicationSummary(result.cloud);
|
|
2969
|
+
}
|
|
2970
|
+
return { ...result };
|
|
2971
|
+
}
|
|
2972
|
+
catch (error) {
|
|
2973
|
+
reportPublicationError(error, controller.signal.reason);
|
|
2974
|
+
if (argv.includes("--full-output"))
|
|
2975
|
+
structuredError = true;
|
|
2976
|
+
return incurError({
|
|
2977
|
+
code: "SONAR_IMPORT_FAILED",
|
|
2978
|
+
message: diagnosticValue(error),
|
|
2979
|
+
exitCode,
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2982
|
+
finally {
|
|
2983
|
+
removeSignals();
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
2986
|
+
},
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
if (importsEnabled) {
|
|
2716
2990
|
registerGitHubAdvisories();
|
|
2991
|
+
registerSonarImport();
|
|
2992
|
+
}
|
|
2717
2993
|
const infoOutput = z.object({
|
|
2718
2994
|
sdkVersion: z.string(),
|
|
2719
2995
|
bundledPluginVersion: z.string(),
|
|
@@ -2801,12 +3077,13 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2801
3077
|
if (argumentError !== undefined)
|
|
2802
3078
|
return fail(argumentError, 2);
|
|
2803
3079
|
const directory = dependencies.currentDirectory();
|
|
3080
|
+
const codexOverrides = await parseScanCodexOverrides(options.codex, options.model, options.effort, options.provider, undefined, scanCodexHome(dependencies.environment));
|
|
2804
3081
|
const outcome = await withTerminalErrorsHandled(errorOutput, () => runPolicyCommand({
|
|
2805
3082
|
repository: resolveCliPath(directory, args.repository ?? "."),
|
|
2806
3083
|
config: {
|
|
2807
3084
|
pluginPath: options.pluginPath,
|
|
2808
3085
|
pythonPath: options.python,
|
|
2809
|
-
codexOverrides
|
|
3086
|
+
codexOverrides,
|
|
2810
3087
|
},
|
|
2811
3088
|
generation: {
|
|
2812
3089
|
auth: options.auth,
|
|
@@ -2824,15 +3101,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2824
3101
|
}, {
|
|
2825
3102
|
createSecurity: dependencies.createPolicySecurity ??
|
|
2826
3103
|
((config) => new CodexSecurity(config, undefined, { surface: "cli" })),
|
|
2827
|
-
chooseAuthentication: (config, auth, signal) =>
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3104
|
+
chooseAuthentication: async (config, auth, signal) => {
|
|
3105
|
+
const effectiveConfig = await mergedCodexConfig(config, scanCodexHome(dependencies.environment));
|
|
3106
|
+
if (hasCommandAuth(effectiveConfig))
|
|
3107
|
+
return auth;
|
|
3108
|
+
return await chooseInteractiveAuthentication({
|
|
3109
|
+
auth,
|
|
3110
|
+
provider: scanModelProvider(effectiveConfig),
|
|
3111
|
+
command: "policy",
|
|
3112
|
+
signal,
|
|
3113
|
+
}, errorOutput, dependencies);
|
|
3114
|
+
},
|
|
2836
3115
|
prompt: dependencies.policyPrompt ??
|
|
2837
3116
|
createTerminalPrompt(errorOutput),
|
|
2838
3117
|
environment: dependencies.environment,
|
|
@@ -2920,6 +3199,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2920
3199
|
.optional()
|
|
2921
3200
|
.meta({ default: [] })
|
|
2922
3201
|
.describe("Add security-context files or directories; repeat for multiple paths."),
|
|
3202
|
+
rubric: optionValue("--rubric")
|
|
3203
|
+
.optional()
|
|
3204
|
+
.describe("Use this Markdown file to grade findings. Takes precedence over the default severity rubric."),
|
|
2923
3205
|
scanPromptFile: optionValue("--scan-prompt-file")
|
|
2924
3206
|
.optional()
|
|
2925
3207
|
.describe("Append scan instructions from FILE."),
|
|
@@ -3030,7 +3312,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3030
3312
|
failureSeverity: options.failOnSeverity,
|
|
3031
3313
|
maxCostUsd: options.maxCost,
|
|
3032
3314
|
maxTimeMinutes: options.maxTime,
|
|
3033
|
-
codexOverrides:
|
|
3315
|
+
codexOverrides: await parseScanCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex, scanCodexHome(dependencies.environment)),
|
|
3034
3316
|
}, directory, scope.sources);
|
|
3035
3317
|
if (options.archiveExisting && settings.outputDir === undefined) {
|
|
3036
3318
|
throw new CodexSecurityError("--archive-existing requires --output-dir.");
|
|
@@ -3040,6 +3322,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3040
3322
|
}
|
|
3041
3323
|
outcome = await runScan({
|
|
3042
3324
|
...settings,
|
|
3325
|
+
rubricPath: options.rubric === undefined
|
|
3326
|
+
? undefined
|
|
3327
|
+
: resolveCliPath(directory, options.rubric),
|
|
3043
3328
|
codexOverrides: config.codexOverrides,
|
|
3044
3329
|
projectConfig: provenance,
|
|
3045
3330
|
workflowId: options.workflowId,
|
|
@@ -3197,7 +3482,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3197
3482
|
})
|
|
3198
3483
|
.command("classify-severity", {
|
|
3199
3484
|
description: "Assess severity for saved findings or canonical records.",
|
|
3200
|
-
hint: "
|
|
3485
|
+
hint: "For saved findings, use --rubric for your own policy or set CODEX_SECURITY_ENABLE_REMOTE_SEVERITY_RUBRIC=1 for the Statsig default. For host-provided reviews, use --records.",
|
|
3201
3486
|
destructive: true,
|
|
3202
3487
|
mcp: false,
|
|
3203
3488
|
options: z.object({
|
|
@@ -3220,7 +3505,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3220
3505
|
.describe("External completed scan directory."),
|
|
3221
3506
|
rubric: optionValue("--rubric")
|
|
3222
3507
|
.optional()
|
|
3223
|
-
.describe("Classification policy document
|
|
3508
|
+
.describe("Classification policy document. Takes precedence over the default rubric."),
|
|
3224
3509
|
knowledgeBase: z
|
|
3225
3510
|
.array(optionValue("--knowledge-base"))
|
|
3226
3511
|
.default([])
|
|
@@ -3516,7 +3801,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3516
3801
|
...pickScanSettings({ ...options, workers: undefined }),
|
|
3517
3802
|
knowledgeBasePaths: options.knowledgeBase,
|
|
3518
3803
|
maxCostUsd: options.maxCost,
|
|
3519
|
-
codexOverrides:
|
|
3804
|
+
codexOverrides: await parseScanCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex, scanCodexHome(dependencies.environment)),
|
|
3520
3805
|
}, directory);
|
|
3521
3806
|
const settings = resolved.options;
|
|
3522
3807
|
deepScanOptions(settings);
|
|
@@ -3529,7 +3814,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3529
3814
|
};
|
|
3530
3815
|
const components = options.componentsFile === undefined
|
|
3531
3816
|
? options.component.map((path) => ({ name: path, paths: [path] }))
|
|
3532
|
-
: componentPlanSchema.parse(JSON.parse(await readRegularInputFile(resolveCliPath(directory, options.componentsFile), repository))).components;
|
|
3817
|
+
: componentPlanSchema.parse(JSON.parse((await readRegularInputFile(resolveCliPath(directory, options.componentsFile), repository)).replace(/^\uFEFF/u, ""))).components;
|
|
3533
3818
|
if (!options.headless &&
|
|
3534
3819
|
!options.planOnly &&
|
|
3535
3820
|
errorOutput.isTTY === true &&
|
|
@@ -3538,7 +3823,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3538
3823
|
const candidate = new ScanDashboard(errorOutput, {
|
|
3539
3824
|
repository,
|
|
3540
3825
|
presentation: "components",
|
|
3541
|
-
model: scanModelConfiguration(await mergedCodexConfig(config)),
|
|
3826
|
+
model: scanModelConfiguration(await mergedCodexConfig(config, scanCodexHome(dependencies.environment))),
|
|
3542
3827
|
mode: settings.mode,
|
|
3543
3828
|
maxCostUsd: settings.maxCostUsd,
|
|
3544
3829
|
showCost: options.showCost,
|
|
@@ -3759,7 +4044,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3759
4044
|
validationPromptFile: settings.validationPromptFile,
|
|
3760
4045
|
postScanPromptFile: settings.postScanPromptFile,
|
|
3761
4046
|
config: {
|
|
3762
|
-
codexOverrides: mergeCodexOverrides(resolved.config.codexOverrides,
|
|
4047
|
+
codexOverrides: mergeCodexOverrides(resolved.config.codexOverrides, await parseScanCodexOverrides(options.codex, options.model, options.effort, options.provider, project?.input.codex, scanCodexHome(dependencies.environment))),
|
|
3763
4048
|
pluginPath: options.pluginPath,
|
|
3764
4049
|
pythonPath: options.python,
|
|
3765
4050
|
},
|
|
@@ -3806,7 +4091,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3806
4091
|
scanPrompt: typeof saved["userContext"] === "string"
|
|
3807
4092
|
? saved["userContext"]
|
|
3808
4093
|
: undefined,
|
|
3809
|
-
}, currentDirectory);
|
|
4094
|
+
}, currentDirectory, dependencies.environment);
|
|
3810
4095
|
const security = dependencies.createSecurity({
|
|
3811
4096
|
pluginPath: options.pluginPath,
|
|
3812
4097
|
pythonPath: options.python,
|
|
@@ -4040,24 +4325,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4040
4325
|
verificationMode: VERIFICATION_MODE_OPTION,
|
|
4041
4326
|
auth: SKILL_AUTH_OPTION,
|
|
4042
4327
|
...MODEL_OPTIONS.shape,
|
|
4043
|
-
|
|
4044
|
-
.optional()
|
|
4045
|
-
.describe("Verify open findings from a saved scan ID or the latest completed scan."),
|
|
4046
|
-
severity: z
|
|
4047
|
-
.enum(REPORTABLE_SEVERITIES)
|
|
4048
|
-
.optional()
|
|
4049
|
-
.describe("Verify saved findings at or above LEVEL."),
|
|
4050
|
-
linearIssue: z
|
|
4051
|
-
.array(optionValue("--linear-issue"))
|
|
4052
|
-
.default([])
|
|
4053
|
-
.describe("Linear issue identifier or URL; repeat for more issues."),
|
|
4054
|
-
linearProject: optionValue("--linear-project")
|
|
4055
|
-
.optional()
|
|
4056
|
-
.describe("Verify issues in this Linear project."),
|
|
4057
|
-
linearFilter: optionValue("--linear-filter")
|
|
4058
|
-
.optional()
|
|
4059
|
-
.describe("JSON Linear issue filter for --linear-project."),
|
|
4060
|
-
linearApiKey: linearApiKeyOption(),
|
|
4328
|
+
...remediationInputOptions("Verify").shape,
|
|
4061
4329
|
codex: SKILL_CONFIG_OPTIONS.shape.codex,
|
|
4062
4330
|
}),
|
|
4063
4331
|
examples: [
|
|
@@ -4072,41 +4340,35 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4072
4340
|
],
|
|
4073
4341
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
4074
4342
|
async run({ format, options, error: incurError }) {
|
|
4075
|
-
|
|
4076
|
-
|
|
4343
|
+
let workerDiagnostic;
|
|
4344
|
+
const structured = format === "json" || format === "jsonl";
|
|
4345
|
+
const reportDiagnostic = async (chunk) => {
|
|
4346
|
+
if (structured) {
|
|
4347
|
+
if (!batchedVerification || frameworkFlags.tokenOutput)
|
|
4348
|
+
deferredVerificationDiagnostic = chunk;
|
|
4349
|
+
}
|
|
4350
|
+
else {
|
|
4351
|
+
await writeCliOutput(errorOutput, chunk).catch(() => { });
|
|
4352
|
+
}
|
|
4353
|
+
};
|
|
4077
4354
|
try {
|
|
4078
4355
|
if (options.host)
|
|
4079
4356
|
throw new CodexSecurityError("Use verify-fix --host alone.");
|
|
4080
|
-
const linear = options
|
|
4081
|
-
if (options.linearIssue.length > 0 && options.linearProject) {
|
|
4082
|
-
throw new CodexSecurityError("Use either --linear-issue or --linear-project, not both.");
|
|
4083
|
-
}
|
|
4084
|
-
if (options.linearFilter && !options.linearProject) {
|
|
4085
|
-
throw new CodexSecurityError("--linear-filter requires --linear-project.");
|
|
4086
|
-
}
|
|
4087
|
-
if (options.linearApiKey !== undefined && !linear) {
|
|
4088
|
-
throw new CodexSecurityError("--linear-api-key requires --linear-issue or --linear-project.");
|
|
4089
|
-
}
|
|
4090
|
-
const savedFindings = options.scan !== undefined ||
|
|
4091
|
-
(positionals.length > 0 && positionals.every(isFindingIdentifier));
|
|
4092
|
-
if (savedFindings && linear) {
|
|
4093
|
-
throw new CodexSecurityError("Saved findings cannot be combined with Linear issues or projects.");
|
|
4094
|
-
}
|
|
4357
|
+
const { savedFindings, linear } = resolveRemediationInputs(options, positionals);
|
|
4095
4358
|
if (options.severity !== undefined && !savedFindings) {
|
|
4096
4359
|
throw new CodexSecurityError("--severity requires a saved finding identifier or --scan.");
|
|
4097
4360
|
}
|
|
4098
4361
|
if (positionals.length === 0 && !linear && !savedFindings) {
|
|
4099
4362
|
throw new CodexSecurityError("Verify-fix requires a finding, --scan, --linear-issue, or --linear-project.");
|
|
4100
4363
|
}
|
|
4364
|
+
if (savedFindings)
|
|
4365
|
+
guardDisconnectedVerificationTerminal(errorOutput);
|
|
4101
4366
|
const selected = savedFindings
|
|
4102
4367
|
? await selectSavedFindings(positionals, options.scan, options.severity, dependencies)
|
|
4103
4368
|
: undefined;
|
|
4104
4369
|
const imports = linear
|
|
4105
4370
|
? await importLinearIssues({
|
|
4106
|
-
|
|
4107
|
-
project: options.linearProject,
|
|
4108
|
-
filter: options.linearFilter,
|
|
4109
|
-
apiKey: options.linearApiKey,
|
|
4371
|
+
...linear,
|
|
4110
4372
|
environment: dependencies.environment,
|
|
4111
4373
|
linearClient: dependencies.linearClient,
|
|
4112
4374
|
})
|
|
@@ -4121,55 +4383,88 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4121
4383
|
throw new CodexSecurityError("Verification inputs must have unique finding or issue identifiers.");
|
|
4122
4384
|
}
|
|
4123
4385
|
const repository = selected?.repository ?? dependencies.currentDirectory();
|
|
4124
|
-
|
|
4386
|
+
const results = [];
|
|
4125
4387
|
if (identifiers.length > 0) {
|
|
4126
4388
|
const environment = imports.length === 0
|
|
4127
4389
|
? undefined
|
|
4128
4390
|
: withoutLinearCredentials(dependencies.environment);
|
|
4129
|
-
const
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4391
|
+
const batches = selected
|
|
4392
|
+
? await verificationBatches(selected.findings, await bundledPluginRoot(), options.verificationMode)
|
|
4393
|
+
: [undefined];
|
|
4394
|
+
// Multi-batch verification can outlive its stderr reader. Keep
|
|
4395
|
+
// optional progress off that execution path so terminal failures
|
|
4396
|
+
// and backpressure cannot prevent a complete stdout result.
|
|
4397
|
+
batchedVerification = batches.length > 1;
|
|
4398
|
+
const progress = batchedVerification
|
|
4399
|
+
? undefined
|
|
4400
|
+
: new FindingProgressPresenter(errorOutput, dependencies, repository, identifiers.length);
|
|
4401
|
+
const controller = batchedVerification
|
|
4402
|
+
? new AbortController()
|
|
4403
|
+
: undefined;
|
|
4404
|
+
const removeSignals = controller && listenForAbort(dependencies, controller);
|
|
4139
4405
|
try {
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4406
|
+
progress?.startVerification();
|
|
4407
|
+
for (const findings of batches) {
|
|
4408
|
+
const batchIds = findings?.map(({ occurrenceId }) => occurrenceId) ??
|
|
4409
|
+
identifiers;
|
|
4410
|
+
const response = captureOutput();
|
|
4411
|
+
const diagnostics = captureOutput();
|
|
4412
|
+
const verificationErrors = progress
|
|
4413
|
+
? new NodeWritable({
|
|
4414
|
+
write(chunk, _encoding, callback) {
|
|
4415
|
+
diagnostics.stream.write(chunk);
|
|
4416
|
+
progress.stop();
|
|
4417
|
+
void writeCliOutput(errorOutput, chunk).then(() => callback(), callback);
|
|
4418
|
+
},
|
|
4419
|
+
})
|
|
4420
|
+
: diagnostics.stream;
|
|
4421
|
+
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options, response.stream, verificationErrors, dependencies, {
|
|
4422
|
+
directory: repository,
|
|
4423
|
+
findings,
|
|
4424
|
+
auth: options.auth,
|
|
4425
|
+
verificationIds: batchIds,
|
|
4426
|
+
signal: controller?.signal,
|
|
4427
|
+
verificationMode: options.verificationMode,
|
|
4428
|
+
environment,
|
|
4429
|
+
onEvent: progress?.observe.bind(progress),
|
|
4430
|
+
});
|
|
4152
4431
|
if (exitCode === 130 || exitCode === 143) {
|
|
4153
4432
|
frameworkExit = exitCode;
|
|
4154
4433
|
return undefined;
|
|
4155
4434
|
}
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4435
|
+
controller?.signal.throwIfAborted();
|
|
4436
|
+
if (exitCode !== 0) {
|
|
4437
|
+
const diagnostic = diagnostics.text();
|
|
4438
|
+
const message = diagnostic.trim();
|
|
4439
|
+
if (message)
|
|
4440
|
+
workerDiagnostic = diagnostic;
|
|
4441
|
+
throw new CodexSecurityError(message ||
|
|
4442
|
+
`Codex verification failed with exit code ${exitCode}.`);
|
|
4443
|
+
}
|
|
4444
|
+
results.push(...parseFindingVerifications(response.text(), batchIds));
|
|
4445
|
+
progress?.complete(results);
|
|
4159
4446
|
}
|
|
4160
|
-
results = parseFindingVerifications(response.text(), identifiers);
|
|
4161
|
-
progress.complete(results);
|
|
4162
4447
|
exitCode = results.some(({ status }) => status === "inconclusive")
|
|
4163
4448
|
? 2
|
|
4164
4449
|
: results.some(({ status }) => status === "still_vulnerable")
|
|
4165
4450
|
? 1
|
|
4166
4451
|
: 0;
|
|
4167
4452
|
}
|
|
4453
|
+
catch (error) {
|
|
4454
|
+
if (!controller?.signal.aborted)
|
|
4455
|
+
throw error;
|
|
4456
|
+
}
|
|
4168
4457
|
finally {
|
|
4169
|
-
progress
|
|
4458
|
+
progress?.stop();
|
|
4459
|
+
removeSignals?.();
|
|
4460
|
+
}
|
|
4461
|
+
if (controller?.signal.aborted) {
|
|
4462
|
+
exitCode = controller.signal.reason === "SIGINT" ? 130 : 143;
|
|
4463
|
+
frameworkExit = exitCode;
|
|
4464
|
+
return undefined;
|
|
4170
4465
|
}
|
|
4171
4466
|
}
|
|
4172
|
-
if (
|
|
4467
|
+
if (structured) {
|
|
4173
4468
|
return {
|
|
4174
4469
|
repository,
|
|
4175
4470
|
...(selected === undefined ? {} : { scanId: selected.scanId }),
|
|
@@ -4183,9 +4478,12 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4183
4478
|
}
|
|
4184
4479
|
catch (error) {
|
|
4185
4480
|
exitCode = 2;
|
|
4481
|
+
if (error instanceof VerificationFindingTooLargeError)
|
|
4482
|
+
batchedVerification = true;
|
|
4186
4483
|
const message = errorMessage(error);
|
|
4187
|
-
if (
|
|
4188
|
-
|
|
4484
|
+
if (workerDiagnostic === undefined || batchedVerification)
|
|
4485
|
+
await reportDiagnostic(workerDiagnostic ??
|
|
4486
|
+
`codex-security: ${diagnosticValue(message)}\n`);
|
|
4189
4487
|
return finishScan({ exitCode, error: message }, format, incurError, "VERIFICATION_FAILED");
|
|
4190
4488
|
}
|
|
4191
4489
|
},
|
|
@@ -4213,24 +4511,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4213
4511
|
.boolean()
|
|
4214
4512
|
.default(false)
|
|
4215
4513
|
.describe("Use the container's isolation instead of the Codex sandbox (default: false)."),
|
|
4216
|
-
|
|
4217
|
-
.optional()
|
|
4218
|
-
.describe("Patch open findings from a saved scan ID or the latest completed scan."),
|
|
4219
|
-
severity: z
|
|
4220
|
-
.enum(REPORTABLE_SEVERITIES)
|
|
4221
|
-
.optional()
|
|
4222
|
-
.describe("Patch saved findings at or above LEVEL."),
|
|
4223
|
-
linearIssue: z
|
|
4224
|
-
.array(optionValue("--linear-issue"))
|
|
4225
|
-
.default([])
|
|
4226
|
-
.describe("Linear issue identifier or URL; repeat for more issues."),
|
|
4227
|
-
linearProject: optionValue("--linear-project")
|
|
4228
|
-
.optional()
|
|
4229
|
-
.describe("Patch every open issue in this Linear project."),
|
|
4230
|
-
linearFilter: optionValue("--linear-filter")
|
|
4231
|
-
.optional()
|
|
4232
|
-
.describe("JSON Linear issue filter for --linear-project."),
|
|
4233
|
-
linearApiKey: linearApiKeyOption(),
|
|
4514
|
+
...remediationInputOptions("Patch").shape,
|
|
4234
4515
|
createPr: CREATE_PR_OPTION,
|
|
4235
4516
|
assessPatchRisk: ASSESS_PATCH_RISK_OPTION,
|
|
4236
4517
|
validationPromptFile: optionValue("--validation-prompt-file")
|
|
@@ -4264,7 +4545,6 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4264
4545
|
try {
|
|
4265
4546
|
if (options.host)
|
|
4266
4547
|
throw new CodexSecurityError("Use patch --host alone.");
|
|
4267
|
-
const linear = options.linearIssue.length > 0 || !!options.linearProject;
|
|
4268
4548
|
if (options.resumePr !== undefined) {
|
|
4269
4549
|
if (positionals.length > 0 ||
|
|
4270
4550
|
options.scan !== undefined ||
|
|
@@ -4274,7 +4554,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4274
4554
|
options.validationPromptFile !== undefined ||
|
|
4275
4555
|
options.externalSandbox ||
|
|
4276
4556
|
options.verificationMode !== undefined ||
|
|
4277
|
-
|
|
4557
|
+
options.linearIssue.length > 0 ||
|
|
4558
|
+
options.linearProject ||
|
|
4278
4559
|
options.linearFilter !== undefined ||
|
|
4279
4560
|
options.linearApiKey !== undefined ||
|
|
4280
4561
|
options.model !== undefined ||
|
|
@@ -4289,20 +4570,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4289
4570
|
}
|
|
4290
4571
|
return;
|
|
4291
4572
|
}
|
|
4292
|
-
|
|
4293
|
-
throw new CodexSecurityError("Use either --linear-issue or --linear-project, not both.");
|
|
4294
|
-
}
|
|
4295
|
-
if (options.linearFilter && !options.linearProject) {
|
|
4296
|
-
throw new CodexSecurityError("--linear-filter requires --linear-project.");
|
|
4297
|
-
}
|
|
4298
|
-
if (options.linearApiKey !== undefined && !linear) {
|
|
4299
|
-
throw new CodexSecurityError("--linear-api-key requires --linear-issue or --linear-project.");
|
|
4300
|
-
}
|
|
4301
|
-
const savedFindings = options.scan !== undefined ||
|
|
4302
|
-
(positionals.length > 0 && positionals.every(isFindingIdentifier));
|
|
4303
|
-
if (savedFindings && linear) {
|
|
4304
|
-
throw new CodexSecurityError("Saved findings cannot be combined with Linear issues or projects.");
|
|
4305
|
-
}
|
|
4573
|
+
const { savedFindings, linear } = resolveRemediationInputs(options, positionals);
|
|
4306
4574
|
if (options.externalSandbox) {
|
|
4307
4575
|
errorOutput.write("WARNING: --external-sandbox disables Codex sandbox enforcement for patching. The container must provide isolation.\n");
|
|
4308
4576
|
}
|
|
@@ -4348,7 +4616,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4348
4616
|
}
|
|
4349
4617
|
}
|
|
4350
4618
|
const pullRequest = options.createPr
|
|
4351
|
-
? await createPatchPullRequest(selected.repository, selected.scanId, verifiedPatchFiles(selected, patches), errorOutput, dependencies, patchRisk
|
|
4619
|
+
? await createPatchPullRequest(selected.repository, selected.scanId, verifiedPatchFiles(selected, patches), errorOutput, dependencies, patchRisk)
|
|
4352
4620
|
: undefined;
|
|
4353
4621
|
if (structuredOutput) {
|
|
4354
4622
|
return {
|
|
@@ -4371,10 +4639,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4371
4639
|
const validationPrompt = await resolvePatchValidationPrompt(options.validationPromptFile, repository, repository);
|
|
4372
4640
|
const imports = linear
|
|
4373
4641
|
? await importLinearIssues({
|
|
4374
|
-
|
|
4375
|
-
project: options.linearProject,
|
|
4376
|
-
filter: options.linearFilter,
|
|
4377
|
-
apiKey: options.linearApiKey,
|
|
4642
|
+
...linear,
|
|
4378
4643
|
environment: dependencies.environment,
|
|
4379
4644
|
linearClient: dependencies.linearClient,
|
|
4380
4645
|
})
|
|
@@ -4427,7 +4692,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4427
4692
|
let pullRequest;
|
|
4428
4693
|
if (options.createPr) {
|
|
4429
4694
|
const identifier = directPatchIdentifier(positionals, imports);
|
|
4430
|
-
pullRequest = await createPatchPullRequest(repository, identifier ?? directPatchDigest(positionals, imports), files, errorOutput, dependencies, patchRisk
|
|
4695
|
+
pullRequest = await createPatchPullRequest(repository, identifier ?? directPatchDigest(positionals, imports), files, errorOutput, dependencies, patchRisk, identifier === undefined
|
|
4431
4696
|
? "Applies a security fix generated from supplied issue data."
|
|
4432
4697
|
: `Applies a security fix generated for ${identifier}.`);
|
|
4433
4698
|
}
|
|
@@ -4680,7 +4945,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4680
4945
|
const project = await selectedProjectConfig(options.config, dependencies);
|
|
4681
4946
|
const resolved = resolveScanSettings(project, {}, directory);
|
|
4682
4947
|
deepScanOptions(resolved.options);
|
|
4683
|
-
const codex = await mergedCodexConfig(resolved.config);
|
|
4948
|
+
const codex = await mergedCodexConfig(resolved.config, scanCodexHome(dependencies.environment));
|
|
4684
4949
|
const deep = resolved.options.mode === "deep"
|
|
4685
4950
|
? await resolveDeepScanConfig(resolved.options, join(scanCodexHome(dependencies.environment), "codex-security", "config.toml"))
|
|
4686
4951
|
: undefined;
|
|
@@ -4814,7 +5079,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4814
5079
|
if (!importsEnabled &&
|
|
4815
5080
|
((command === "publish" && subcommand === "findings") ||
|
|
4816
5081
|
(command === "findings" && subcommand === "imported") ||
|
|
4817
|
-
(command === "import" &&
|
|
5082
|
+
(command === "import" &&
|
|
5083
|
+
(subcommand === "github-advisories" || subcommand === "sonar")))) {
|
|
4818
5084
|
if (process.env["COMPLETE"] ||
|
|
4819
5085
|
argv.some((value) => FRAMEWORK_ACTIONS.has(value))) {
|
|
4820
5086
|
return externalImportsDisabledMessage;
|
|
@@ -4830,6 +5096,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
4830
5096
|
cliOptions.sync = false;
|
|
4831
5097
|
if (command === "publish")
|
|
4832
5098
|
registerFindingPublication();
|
|
5099
|
+
else if (subcommand === "sonar")
|
|
5100
|
+
registerSonarImport();
|
|
4833
5101
|
else
|
|
4834
5102
|
registerGitHubAdvisories();
|
|
4835
5103
|
valueOptions = cliValueOptions(commands);
|
|
@@ -5017,7 +5285,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
5017
5285
|
const failureArguments = ["render", "--format", filteredScanFailure.format];
|
|
5018
5286
|
for (let index = 0; index < argv.length; index += 1) {
|
|
5019
5287
|
const argument = argv[index];
|
|
5020
|
-
if (
|
|
5288
|
+
if (!TOKEN_OUTPUT_OPTION.test(argument))
|
|
5021
5289
|
continue;
|
|
5022
5290
|
const separator = argument.indexOf("=");
|
|
5023
5291
|
if (separator !== -1)
|
|
@@ -5038,12 +5306,16 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
5038
5306
|
renderedOutput = failureOutput.text();
|
|
5039
5307
|
}
|
|
5040
5308
|
let frameworkOutput = frameworkCapture.text();
|
|
5041
|
-
|
|
5309
|
+
const writeUpdateNotice = () => {
|
|
5310
|
+
if (notice === undefined || batchedVerification)
|
|
5311
|
+
return;
|
|
5042
5312
|
try {
|
|
5043
5313
|
errorOutput.write(formatUpdateNotice(notice));
|
|
5044
5314
|
}
|
|
5045
5315
|
catch { }
|
|
5046
|
-
}
|
|
5316
|
+
};
|
|
5317
|
+
if (deferredVerificationDiagnostic === undefined)
|
|
5318
|
+
writeUpdateNotice();
|
|
5047
5319
|
if (frameworkExit !== undefined) {
|
|
5048
5320
|
if (disabledImportInvocation && exitCode === 0) {
|
|
5049
5321
|
reportPublicationError(externalImportsDisabledMessage, undefined);
|
|
@@ -5056,7 +5328,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
5056
5328
|
else {
|
|
5057
5329
|
if (exitCode !== 0)
|
|
5058
5330
|
return exitCode;
|
|
5059
|
-
errorOutput.write(`codex-security: ${diagnosticLines(incurErrorMessage(frameworkOutput))}\n`);
|
|
5331
|
+
errorOutput.write(`codex-security: ${diagnosticLines(await incurErrorMessage(frameworkOutput))}\n`);
|
|
5060
5332
|
return 2;
|
|
5061
5333
|
}
|
|
5062
5334
|
}
|
|
@@ -5064,7 +5336,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
5064
5336
|
return exitCode;
|
|
5065
5337
|
if (frameworkOutput.length === 0 &&
|
|
5066
5338
|
streamedLogs === undefined &&
|
|
5067
|
-
filteredScanFailure === undefined
|
|
5339
|
+
filteredScanFailure === undefined &&
|
|
5340
|
+
deferredVerificationDiagnostic === undefined)
|
|
5068
5341
|
return exitCode;
|
|
5069
5342
|
try {
|
|
5070
5343
|
// Incur can add a stale-skills CTA after the logs handler returns.
|
|
@@ -5094,6 +5367,19 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
5094
5367
|
errorOutput.write(`codex-security: ${diagnosticLines(error)}\n`);
|
|
5095
5368
|
return 2;
|
|
5096
5369
|
}
|
|
5370
|
+
finally {
|
|
5371
|
+
if (deferredVerificationDiagnostic !== undefined) {
|
|
5372
|
+
// Token output can omit the diagnostic. Otherwise a buffered stderr
|
|
5373
|
+
// write is optional once the complete structured failure is on stdout.
|
|
5374
|
+
if (frameworkFlags.tokenOutput) {
|
|
5375
|
+
await writeCliOutput(errorOutput, deferredVerificationDiagnostic).catch(() => { });
|
|
5376
|
+
}
|
|
5377
|
+
else {
|
|
5378
|
+
writeOptionalVerificationDiagnostic(errorOutput, deferredVerificationDiagnostic);
|
|
5379
|
+
}
|
|
5380
|
+
writeUpdateNotice();
|
|
5381
|
+
}
|
|
5382
|
+
}
|
|
5097
5383
|
}
|
|
5098
5384
|
async function runScanImport(options, errorOutput, dependencies) {
|
|
5099
5385
|
const controller = new AbortController();
|
|
@@ -5129,7 +5415,7 @@ async function runScanImport(options, errorOutput, dependencies) {
|
|
|
5129
5415
|
removeSignals();
|
|
5130
5416
|
}
|
|
5131
5417
|
}
|
|
5132
|
-
async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, scanPromptFile, validationPromptFile, }, directory) {
|
|
5418
|
+
async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, scanPromptFile, validationPromptFile, }, directory, environment) {
|
|
5133
5419
|
if (recipe === undefined || !isJsonObject(recipe)) {
|
|
5134
5420
|
throw new CodexSecurityError("This scan does not have a saved launch recipe.");
|
|
5135
5421
|
}
|
|
@@ -5222,6 +5508,9 @@ async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, s
|
|
|
5222
5508
|
}
|
|
5223
5509
|
const safetyIdentifier = recipe["safetyIdentifier"];
|
|
5224
5510
|
const postScanPrompt = recipe["postScanPrompt"];
|
|
5511
|
+
const severityRubric = operation === "rerun"
|
|
5512
|
+
? severityRubricSchema.optional().parse(recipe["severityRubric"])
|
|
5513
|
+
: undefined;
|
|
5225
5514
|
if ((safetyIdentifier !== undefined && typeof safetyIdentifier !== "string") ||
|
|
5226
5515
|
(postScanPrompt !== undefined && typeof postScanPrompt !== "string")) {
|
|
5227
5516
|
throw new CodexSecurityError("The saved scan recipe contains invalid launch settings.");
|
|
@@ -5230,11 +5519,13 @@ async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, s
|
|
|
5230
5519
|
if (requiresRerunPrompt && !prompts.scanPrompt?.trim()) {
|
|
5231
5520
|
throw new CodexSecurityError("This scan used additional instructions. The --scan-prompt-file must not be empty.");
|
|
5232
5521
|
}
|
|
5522
|
+
const replayConfig = await restoreProviderProfile(config, recipe["providerProfile"], environment);
|
|
5233
5523
|
return {
|
|
5234
5524
|
repository,
|
|
5235
5525
|
auth: auth.data ?? DEFAULT_SCAN_AUTH,
|
|
5236
5526
|
cyberAccessProgram: cyberAccessProgram.data,
|
|
5237
5527
|
ownerSuggestions: ownerSuggestions.data,
|
|
5528
|
+
...(severityRubric === undefined ? {} : { severityRubric }),
|
|
5238
5529
|
// Saved scopes contain literal repository names, not home-relative inputs.
|
|
5239
5530
|
target: paths.length > 0
|
|
5240
5531
|
? paths.map((path) => path === "~" || path.startsWith("~/") || path.startsWith("~\\")
|
|
@@ -5252,9 +5543,9 @@ async function prepareScanArgumentsFromRecipe(recipe, operation, { scanPrompt, s
|
|
|
5252
5543
|
mode,
|
|
5253
5544
|
...deepScan.data,
|
|
5254
5545
|
archiveExisting: false,
|
|
5255
|
-
codexOverrides: Object.hasOwn(
|
|
5256
|
-
?
|
|
5257
|
-
: { ...
|
|
5546
|
+
codexOverrides: Object.hasOwn(replayConfig, "approval_policy")
|
|
5547
|
+
? replayConfig
|
|
5548
|
+
: { ...replayConfig, approval_policy: "never" },
|
|
5258
5549
|
failureSeverity: threshold.data,
|
|
5259
5550
|
maxCostUsd,
|
|
5260
5551
|
maxTimeMinutes: maxTimeMinutes.data,
|
|
@@ -5269,6 +5560,7 @@ function frameworkOutputFlags(argv) {
|
|
|
5269
5560
|
let hideDisabledRoute = false;
|
|
5270
5561
|
let fullOutput = false;
|
|
5271
5562
|
let rawCollector = false;
|
|
5563
|
+
let tokenOutput = false;
|
|
5272
5564
|
for (let index = 0; index < argv.length; index++) {
|
|
5273
5565
|
const value = argv[index];
|
|
5274
5566
|
if (FRAMEWORK_ACTIONS.has(value) ||
|
|
@@ -5280,6 +5572,8 @@ function frameworkOutputFlags(argv) {
|
|
|
5280
5572
|
fullOutput = true;
|
|
5281
5573
|
if (value === "--json")
|
|
5282
5574
|
rawCollector = true;
|
|
5575
|
+
if (TOKEN_OUTPUT_OPTION.test(value))
|
|
5576
|
+
tokenOutput = true;
|
|
5283
5577
|
if (FRAMEWORK_VALUE_OPTIONS.has(value)) {
|
|
5284
5578
|
const operand = argv[++index];
|
|
5285
5579
|
if (value === "--format")
|
|
@@ -5287,7 +5581,11 @@ function frameworkOutputFlags(argv) {
|
|
|
5287
5581
|
operand === "json" || operand === "jsonl" || operand === "yaml";
|
|
5288
5582
|
}
|
|
5289
5583
|
}
|
|
5290
|
-
return {
|
|
5584
|
+
return {
|
|
5585
|
+
hideDisabledRoute,
|
|
5586
|
+
rawCollector: rawCollector && !fullOutput,
|
|
5587
|
+
tokenOutput,
|
|
5588
|
+
};
|
|
5291
5589
|
}
|
|
5292
5590
|
function cliValueOptions(commands) {
|
|
5293
5591
|
const options = new Set(FRAMEWORK_VALUE_OPTIONS);
|
|
@@ -5385,6 +5683,26 @@ function staysWithinWindowsDeviceRoot(input, root) {
|
|
|
5385
5683
|
function isFindingIdentifier(value) {
|
|
5386
5684
|
return /^(?:occ|csf)_[A-Za-z0-9_-]+$/u.test(value);
|
|
5387
5685
|
}
|
|
5686
|
+
function resolveRemediationInputs({ scan, linearIssue: issues, linearProject: project, linearFilter: filter, linearApiKey: apiKey, }, positionals) {
|
|
5687
|
+
if (issues.length > 0 && project) {
|
|
5688
|
+
throw new CodexSecurityError("Use either --linear-issue or --linear-project, not both.");
|
|
5689
|
+
}
|
|
5690
|
+
if (filter && !project) {
|
|
5691
|
+
throw new CodexSecurityError("--linear-filter requires --linear-project.");
|
|
5692
|
+
}
|
|
5693
|
+
const linear = issues.length > 0 || project
|
|
5694
|
+
? { issues, project, filter, apiKey }
|
|
5695
|
+
: undefined;
|
|
5696
|
+
if (apiKey !== undefined && !linear) {
|
|
5697
|
+
throw new CodexSecurityError("--linear-api-key requires --linear-issue or --linear-project.");
|
|
5698
|
+
}
|
|
5699
|
+
const savedFindings = scan !== undefined ||
|
|
5700
|
+
(positionals.length > 0 && positionals.every(isFindingIdentifier));
|
|
5701
|
+
if (savedFindings && linear) {
|
|
5702
|
+
throw new CodexSecurityError("Saved findings cannot be combined with Linear issues or projects.");
|
|
5703
|
+
}
|
|
5704
|
+
return { savedFindings, linear };
|
|
5705
|
+
}
|
|
5388
5706
|
async function* workbenchFindings(arguments_, dependencies) {
|
|
5389
5707
|
let offset;
|
|
5390
5708
|
do {
|
|
@@ -5523,15 +5841,6 @@ function patchCommitKey(branch) {
|
|
|
5523
5841
|
function patchPullRequestBodyKey(branch) {
|
|
5524
5842
|
return `branch.${branch}.codexSecurityPatchPullRequestBody`;
|
|
5525
5843
|
}
|
|
5526
|
-
function patchPullRequestBody(patchRiskSummary, introduction = PATCH_PR_BODY) {
|
|
5527
|
-
if (patchRiskSummary === undefined)
|
|
5528
|
-
return introduction;
|
|
5529
|
-
const summary = safePatchReport(patchRiskSummary);
|
|
5530
|
-
if (!summary) {
|
|
5531
|
-
throw new CodexSecurityError("Patch risk assessment returned an empty pull request summary.");
|
|
5532
|
-
}
|
|
5533
|
-
return `${introduction}\n\n## Patch risk assessment\n\n${summary}`;
|
|
5534
|
-
}
|
|
5535
5844
|
function directPatchIdentifier(positionals, imports) {
|
|
5536
5845
|
if (imports.length === 1)
|
|
5537
5846
|
return imports[0].id;
|
|
@@ -5603,13 +5912,15 @@ function verifiedPatchFiles(selected, patches) {
|
|
|
5603
5912
|
return path;
|
|
5604
5913
|
});
|
|
5605
5914
|
}
|
|
5606
|
-
async function createPatchPullRequest(repository, patchId, files, stderr, dependencies,
|
|
5915
|
+
async function createPatchPullRequest(repository, patchId, files, stderr, dependencies, patchRisk, introduction = PATCH_PR_BODY) {
|
|
5607
5916
|
if (files.length === 0) {
|
|
5608
5917
|
stderr.write("No verified patch changes to publish.\n");
|
|
5609
5918
|
return;
|
|
5610
5919
|
}
|
|
5611
5920
|
const branch = `codex-security/patch-${patchId.replaceAll(/[^a-z\d._-]/giu, "-")}`;
|
|
5612
|
-
const body =
|
|
5921
|
+
const body = patchRisk === undefined
|
|
5922
|
+
? introduction
|
|
5923
|
+
: `${introduction}\n\n## Patch risk assessment\n\n${patchRisk.summary}`;
|
|
5613
5924
|
const run = (args) => dependencies.runRepositoryCommand("git", args, repository);
|
|
5614
5925
|
stderr.write("Creating a draft pull request or merge request for verified patches...\n");
|
|
5615
5926
|
await run(["switch", "-c", branch]);
|
|
@@ -5979,7 +6290,7 @@ async function runSkill(skill, inputs, configuration, stdout, stderr, dependenci
|
|
|
5979
6290
|
...(providerConfiguration === undefined
|
|
5980
6291
|
? {}
|
|
5981
6292
|
: { model_providers: { [provider]: providerConfiguration } }),
|
|
5982
|
-
}),
|
|
6293
|
+
}), scanCodexHome(options.environment ?? dependencies.environment));
|
|
5983
6294
|
const directory = options.directory ?? dependencies.currentDirectory();
|
|
5984
6295
|
const contextFile = options.contextFile === undefined
|
|
5985
6296
|
? undefined
|
|
@@ -6126,6 +6437,7 @@ async function runSkill(skill, inputs, configuration, stdout, stderr, dependenci
|
|
|
6126
6437
|
pluginVersion,
|
|
6127
6438
|
providerResolved: provider !== undefined || validate,
|
|
6128
6439
|
});
|
|
6440
|
+
options.signal?.throwIfAborted();
|
|
6129
6441
|
return dependencies.runCodex([
|
|
6130
6442
|
...(appServer
|
|
6131
6443
|
? ["app-server"]
|
|
@@ -6188,6 +6500,7 @@ async function runSkill(skill, inputs, configuration, stdout, stderr, dependenci
|
|
|
6188
6500
|
]),
|
|
6189
6501
|
], {
|
|
6190
6502
|
command: verify ? "verify-fix" : patch || assess ? "patch" : "validate",
|
|
6503
|
+
signal: options.signal,
|
|
6191
6504
|
auth: options.auth ?? "auto",
|
|
6192
6505
|
directory,
|
|
6193
6506
|
modelProvider: provider,
|
|
@@ -6524,11 +6837,12 @@ export function skillCommandFailure(command, status, detail, authentication = nu
|
|
|
6524
6837
|
}
|
|
6525
6838
|
return detail || `${command} failed with exit code ${status}.`;
|
|
6526
6839
|
}
|
|
6527
|
-
function incurErrorMessage(output) {
|
|
6840
|
+
async function incurErrorMessage(output) {
|
|
6528
6841
|
// YAML folds long strings across lines; JSON output keeps its serialized form.
|
|
6529
6842
|
if (!output.startsWith("{")) {
|
|
6843
|
+
const { parse } = await import("yaml");
|
|
6530
6844
|
try {
|
|
6531
|
-
const parsed =
|
|
6845
|
+
const parsed = parse(output);
|
|
6532
6846
|
if (isJsonObject(parsed) && typeof parsed["message"] === "string")
|
|
6533
6847
|
return parsed["message"];
|
|
6534
6848
|
}
|
|
@@ -6727,10 +7041,15 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6727
7041
|
codexOverrides: arguments_.codexOverrides,
|
|
6728
7042
|
};
|
|
6729
7043
|
const selectedProfileName = config.codexOverrides?.["profile"];
|
|
6730
|
-
const
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
7044
|
+
const inlineProfiles = config.codexOverrides?.["profiles"];
|
|
7045
|
+
// Saved recipes keep their existing validation path; file profiles need
|
|
7046
|
+
// an early merge so CLI reporting reflects the selected file.
|
|
7047
|
+
const effectiveConfiguration = typeof selectedProfileName === "string" &&
|
|
7048
|
+
(inlineProfiles === undefined ||
|
|
7049
|
+
!isJsonObject(inlineProfiles) ||
|
|
7050
|
+
!isJsonObject(inlineProfiles[selectedProfileName] ?? null))
|
|
7051
|
+
? await mergedCodexConfig(config, scanCodexHome(dependencies.environment))
|
|
7052
|
+
: { ...DEFAULT_CODEX_CONFIG, ...config.codexOverrides };
|
|
6734
7053
|
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
6735
7054
|
scanModelConfiguration(effectiveConfiguration));
|
|
6736
7055
|
const resolvedConfiguration = resolveCodexProfile(effectiveConfiguration);
|
|
@@ -6780,7 +7099,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6780
7099
|
}
|
|
6781
7100
|
selectedAuthentication = arguments_.mock
|
|
6782
7101
|
? null
|
|
6783
|
-
: scanAuthentication(dependencies.environment, auth, provider, hasCommandAuth(effectiveConfiguration), arguments_.dryRun);
|
|
7102
|
+
: scanAuthentication(dependencies.environment, auth, provider, hasCommandAuth(effectiveConfiguration), arguments_.dryRun, scanProviderEnvKey(effectiveConfiguration));
|
|
6784
7103
|
diagnostic("scan.configuration", {
|
|
6785
7104
|
cli_version: VERSION,
|
|
6786
7105
|
bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
|
|
@@ -6813,7 +7132,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6813
7132
|
repository: resolveCliPath(directory, repository),
|
|
6814
7133
|
mode: arguments_.mode,
|
|
6815
7134
|
showCost,
|
|
6816
|
-
model: scanModelConfiguration(
|
|
7135
|
+
model: scanModelConfiguration(effectiveConfiguration),
|
|
6817
7136
|
...(arguments_.maxCostUsd === undefined
|
|
6818
7137
|
? {}
|
|
6819
7138
|
: { maxCostUsd: arguments_.maxCostUsd }),
|
|
@@ -6876,6 +7195,12 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
6876
7195
|
}
|
|
6877
7196
|
const options = {
|
|
6878
7197
|
...pickScanSettings(arguments_),
|
|
7198
|
+
...(arguments_.rubricPath === undefined
|
|
7199
|
+
? {}
|
|
7200
|
+
: { rubricPath: arguments_.rubricPath }),
|
|
7201
|
+
...(arguments_.severityRubric === undefined
|
|
7202
|
+
? {}
|
|
7203
|
+
: { severityRubric: arguments_.severityRubric }),
|
|
6879
7204
|
knowledgeBaseSnapshot: arguments_.knowledgeBaseSnapshot,
|
|
6880
7205
|
...(arguments_.resumeScanId === undefined
|
|
6881
7206
|
? {}
|
|
@@ -7277,7 +7602,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7277
7602
|
validation = { ...validation, status: "failed", message };
|
|
7278
7603
|
errorOutput.write(`codex-security: Validation failed: ${diagnosticValue(message)}\n`);
|
|
7279
7604
|
if (validation["reportPath"] !== undefined) {
|
|
7280
|
-
errorOutput.write(`
|
|
7605
|
+
errorOutput.write(`Validation report opened at ${diagnosticValue(validation["reportPath"])}\n`);
|
|
7281
7606
|
}
|
|
7282
7607
|
}
|
|
7283
7608
|
}
|
|
@@ -7332,11 +7657,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7332
7657
|
if (requestedSignal !== null) {
|
|
7333
7658
|
diagnostic("scan.interrupted", {
|
|
7334
7659
|
signal: requestedSignal,
|
|
7335
|
-
partial_output: scanDir !== null,
|
|
7336
7660
|
});
|
|
7337
7661
|
if (result !== null && arguments_.validate) {
|
|
7338
7662
|
const exitCode = requestedSignal === "SIGINT" ? 130 : 143;
|
|
7339
|
-
const
|
|
7663
|
+
const scanId = quoteCliPath(diagnosticValue(result.manifest.scan.id));
|
|
7664
|
+
const message = `Validation interrupted. Original output directory: ${errorMessage(result.scanDir)}. Run codex-security scans show ${scanId} to inspect the completed scan.`;
|
|
7340
7665
|
errorOutput.write(`codex-security: ${message}\n`);
|
|
7341
7666
|
return {
|
|
7342
7667
|
exitCode,
|
|
@@ -7347,6 +7672,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7347
7672
|
},
|
|
7348
7673
|
};
|
|
7349
7674
|
}
|
|
7675
|
+
if (failure instanceof ScanInterruptedError)
|
|
7676
|
+
scanDir ??= failure.scanDir;
|
|
7350
7677
|
const exitCode = interruptedExit(requestedSignal, scanDir, errorOutput);
|
|
7351
7678
|
printFailedScanReference(registeredScan, phase, arguments_, errorOutput);
|
|
7352
7679
|
return {
|
|
@@ -7359,16 +7686,12 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7359
7686
|
}
|
|
7360
7687
|
if (failed) {
|
|
7361
7688
|
const costLimitFailure = failure instanceof ScanCostLimitExceededError ? failure : undefined;
|
|
7689
|
+
const classification = classifyScanFailure(failure);
|
|
7362
7690
|
const message = failure instanceof OutputInsideProtectedRootError
|
|
7363
7691
|
? errorMessage(protectedRootErrorMessage(failure))
|
|
7364
|
-
: scanFailureMessage(failure, selectedAuthentication, providerOptions.provider);
|
|
7692
|
+
: scanFailureMessage(failure, classification, selectedAuthentication, providerOptions.provider);
|
|
7365
7693
|
diagnostic("scan.failed", {
|
|
7366
|
-
classification: costLimitFailure !== undefined
|
|
7367
|
-
? "cost_limit_exceeded"
|
|
7368
|
-
: isLocalScanFailure(failure)
|
|
7369
|
-
? "local"
|
|
7370
|
-
: classifyConnectionFailure(failure),
|
|
7371
|
-
partial_output: scanDir !== null,
|
|
7694
|
+
classification: costLimitFailure !== undefined ? "cost_limit_exceeded" : classification,
|
|
7372
7695
|
max_cost_usd: costLimitFailure?.maxCostUsd,
|
|
7373
7696
|
estimated_usd: costLimitFailure?.cost.estimatedUsd,
|
|
7374
7697
|
cost_estimate: costLimitFailure === undefined
|
|
@@ -7377,7 +7700,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7377
7700
|
});
|
|
7378
7701
|
errorOutput.write(`${message}\n`);
|
|
7379
7702
|
if (!(failure instanceof ScanInterruptedError) && scanDir !== null) {
|
|
7380
|
-
errorOutput.write(`
|
|
7703
|
+
errorOutput.write(`Output directory: ${errorMessage(scanDir)}\n`);
|
|
7381
7704
|
}
|
|
7382
7705
|
printFailedScanReference(registeredScan, phase, arguments_, errorOutput);
|
|
7383
7706
|
return { exitCode: 2, error: message, data: failureData };
|
|
@@ -7488,7 +7811,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
7488
7811
|
(dependencies.patchEditor !== undefined || process.stdin.isTTY === true)) {
|
|
7489
7812
|
const confirmed = arguments_.patch ||
|
|
7490
7813
|
(await (dependencies.confirmPatchReview ??
|
|
7491
|
-
createTerminalPrompt(errorOutput).confirm)("
|
|
7814
|
+
createTerminalPrompt(errorOutput).confirm)("Open findings for review?"));
|
|
7492
7815
|
if (confirmed) {
|
|
7493
7816
|
const selectPatches = dependencies.patchEditor ??
|
|
7494
7817
|
(async (target, candidates) => {
|
|
@@ -7588,7 +7911,8 @@ function isLocalScanFailure(error) {
|
|
|
7588
7911
|
error instanceof OutputDirectoryError ||
|
|
7589
7912
|
error instanceof ConfigurationError ||
|
|
7590
7913
|
error instanceof LocalPluginBootstrapError ||
|
|
7591
|
-
error instanceof PluginPythonUnavailableError
|
|
7914
|
+
error instanceof PluginPythonUnavailableError ||
|
|
7915
|
+
error instanceof SandboxUnavailableError) {
|
|
7592
7916
|
return true;
|
|
7593
7917
|
}
|
|
7594
7918
|
return (typeof error === "object" &&
|
|
@@ -7597,6 +7921,15 @@ function isLocalScanFailure(error) {
|
|
|
7597
7921
|
typeof error.code === "string" &&
|
|
7598
7922
|
LOCAL_SYSCALL_CODES.has(error.code));
|
|
7599
7923
|
}
|
|
7924
|
+
function classifyScanFailure(error) {
|
|
7925
|
+
if (isLocalScanFailure(error))
|
|
7926
|
+
return "local";
|
|
7927
|
+
const classification = classifyConnectionFailure(error);
|
|
7928
|
+
// Installing the plugin can be denied filesystem access before any model request.
|
|
7929
|
+
if (classification === "forbidden" && error instanceof PluginBootstrapError)
|
|
7930
|
+
return "plugin_bootstrap";
|
|
7931
|
+
return classification;
|
|
7932
|
+
}
|
|
7600
7933
|
function authenticationFailureMessage(authentication) {
|
|
7601
7934
|
if (authentication?.method === "command") {
|
|
7602
7935
|
return "Native Codex command authentication failed. Check the configured provider auth command.";
|
|
@@ -7626,13 +7959,12 @@ function authenticationFailureMessage(authentication) {
|
|
|
7626
7959
|
}
|
|
7627
7960
|
return "Authentication failed. Check the selected provider's credentials and retry.";
|
|
7628
7961
|
}
|
|
7629
|
-
function scanFailureMessage(error, authentication, provider) {
|
|
7962
|
+
function scanFailureMessage(error, classification, authentication, provider) {
|
|
7630
7963
|
// A local failure keeps its own message. Classification matches bare words
|
|
7631
7964
|
// such as "permission denied" anywhere in the text, so an EACCES from a
|
|
7632
7965
|
// read-only TMPDIR would otherwise be reported as a credential problem.
|
|
7633
|
-
if (
|
|
7966
|
+
if (classification === "local")
|
|
7634
7967
|
return diagnosticValue(error);
|
|
7635
|
-
const classification = classifyConnectionFailure(error);
|
|
7636
7968
|
if (provider === "amazon-bedrock" ||
|
|
7637
7969
|
authentication?.method === "aws_credentials") {
|
|
7638
7970
|
const detail = diagnosticValue(error);
|
|
@@ -7690,6 +8022,7 @@ function scanFailureMessage(error, authentication, provider) {
|
|
|
7690
8022
|
case "rate_limited":
|
|
7691
8023
|
return `${detail}The configured account reached its rate limit. Wait and retry.`;
|
|
7692
8024
|
case "network_error":
|
|
8025
|
+
case "plugin_bootstrap":
|
|
7693
8026
|
case "timeout":
|
|
7694
8027
|
case "unknown":
|
|
7695
8028
|
return diagnosticValue(error);
|
|
@@ -7794,7 +8127,7 @@ function printFailedScanReference(scan, phase, arguments_, output) {
|
|
|
7794
8127
|
printScanReference(scan, output);
|
|
7795
8128
|
if (phase !== null)
|
|
7796
8129
|
output.write(`Last observed phase: ${diagnosticValue(phase)}\n`);
|
|
7797
|
-
output.write(`
|
|
8130
|
+
output.write(`Output directory: ${diagnosticValue(scan["scanDir"])}\n` +
|
|
7798
8131
|
"Inspect the saved scan status before choosing resume or rerun.\n");
|
|
7799
8132
|
const prompts = [
|
|
7800
8133
|
...(arguments_.scanPromptFile !== undefined ||
|
|
@@ -8037,6 +8370,35 @@ function resolveCliScope(configured, overrides) {
|
|
|
8037
8370
|
sources,
|
|
8038
8371
|
};
|
|
8039
8372
|
}
|
|
8373
|
+
async function parseScanCodexOverrides(values, model, effort, provider, defaults, profileHome) {
|
|
8374
|
+
if (!isExternalModelProvider(provider) && provider !== "amazon-bedrock") {
|
|
8375
|
+
return parseCodexOverrides(values, model, effort, provider, defaults);
|
|
8376
|
+
}
|
|
8377
|
+
const explicit = parseCodexOverrides(values, model, effort);
|
|
8378
|
+
const overrides = mergeCodexOverrides(defaults ?? {}, explicit);
|
|
8379
|
+
const profile = await readCodexFileProfile(overrides, profileHome);
|
|
8380
|
+
const result = parseCodexOverrides(values, model, effort, provider, mergeCodexOverrides(profile, defaults ?? {}));
|
|
8381
|
+
const providers = profile["model_providers"];
|
|
8382
|
+
if (isExternalModelProvider(provider) &&
|
|
8383
|
+
isJsonObject(providers) &&
|
|
8384
|
+
isJsonObject(providers[provider])) {
|
|
8385
|
+
// Fill missing defaults without replacing file settings or combining
|
|
8386
|
+
// native command auth with the generated env-key definition.
|
|
8387
|
+
const generated = { ...EXTERNAL_CODEX_PROVIDERS[provider] };
|
|
8388
|
+
for (const key of Object.keys(providers[provider]))
|
|
8389
|
+
delete generated[key];
|
|
8390
|
+
if (providers[provider]["auth"] !== undefined)
|
|
8391
|
+
delete generated["env_key"];
|
|
8392
|
+
delete result["model_providers"];
|
|
8393
|
+
if (Object.keys(generated).length > 0) {
|
|
8394
|
+
result["model_providers"] = { [provider]: generated };
|
|
8395
|
+
}
|
|
8396
|
+
if (explicit["model_providers"] !== undefined) {
|
|
8397
|
+
result["model_providers"] = mergeCodexOverrides(result["model_providers"] ?? {}, explicit["model_providers"]);
|
|
8398
|
+
}
|
|
8399
|
+
}
|
|
8400
|
+
return result;
|
|
8401
|
+
}
|
|
8040
8402
|
export function parseCodexOverrides(values, model, effort, provider, defaults) {
|
|
8041
8403
|
const result = Object.create(null);
|
|
8042
8404
|
if (model !== undefined)
|
|
@@ -8232,20 +8594,8 @@ export class Progress {
|
|
|
8232
8594
|
}
|
|
8233
8595
|
}
|
|
8234
8596
|
#renderTimer(message) {
|
|
8235
|
-
let line = this.#line(message);
|
|
8236
8597
|
const width = Math.max(0, (this.#stream.columns ?? 80) - 1);
|
|
8237
|
-
|
|
8238
|
-
let visible = "";
|
|
8239
|
-
let used = 0;
|
|
8240
|
-
for (const { segment } of PUBLICATION_GRAPHEME_SEGMENTER.segment(line)) {
|
|
8241
|
-
const segmentWidth = publicationDisplayWidth(segment);
|
|
8242
|
-
if (used + segmentWidth >= width)
|
|
8243
|
-
break;
|
|
8244
|
-
visible += segment;
|
|
8245
|
-
used += segmentWidth;
|
|
8246
|
-
}
|
|
8247
|
-
line = width > 0 ? `${visible}…` : "";
|
|
8248
|
-
}
|
|
8598
|
+
const line = fitProgressLine(this.#line(message), width);
|
|
8249
8599
|
this.#stream.write(`${this.#timerLineActive ? "\r\u001B[K" : ""}${line}`);
|
|
8250
8600
|
this.#timerLineActive = true;
|
|
8251
8601
|
}
|
|
@@ -8253,9 +8603,9 @@ export class Progress {
|
|
|
8253
8603
|
function interruptedExit(signal, scanDir, errorOutput) {
|
|
8254
8604
|
const ctrlC = signal === "SIGINT";
|
|
8255
8605
|
errorOutput.write(`codex-security: Scan ${ctrlC ? "canceled by Ctrl-C" : "terminated by SIGTERM"}.\n`);
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8606
|
+
if (scanDir) {
|
|
8607
|
+
errorOutput.write(`codex-security: Output directory: ${errorMessage(scanDir)}\n`);
|
|
8608
|
+
}
|
|
8259
8609
|
return ctrlC ? 130 : 143;
|
|
8260
8610
|
}
|
|
8261
8611
|
function invokedAsMain() {
|