@openai/codex-security 0.4.0 → 0.5.1
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 +52 -9
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +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 +60 -9
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/core-scan.md +2 -0
- package/_bundled_plugin/references/final-report.md +5 -1
- package/_bundled_plugin/references/investigation-time-budget.md +11 -0
- package/_bundled_plugin/references/sarif-adapter.md +1 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -6
- package/_bundled_plugin/references/scan-runtime.md +15 -0
- package/_bundled_plugin/references/threat-model.md +2 -0
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +6 -2
- package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +92 -44
- package/_bundled_plugin/scripts/finding_preview.py +5 -3
- package/_bundled_plugin/scripts/generate_in_scope_files.py +6 -6
- package/_bundled_plugin/scripts/generate_rank_input.py +13 -6
- package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
- package/_bundled_plugin/scripts/report_projection.py +2 -1
- package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +234 -0
- package/_bundled_plugin/scripts/workbench_cli.py +5 -10
- package/_bundled_plugin/scripts/workbench_constants.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +68 -39
- package/_bundled_plugin/scripts/workbench_native_indexes.py +10 -7
- package/_bundled_plugin/scripts/workbench_progress.py +0 -50
- package/_bundled_plugin/scripts/workbench_publication.py +4 -3
- package/_bundled_plugin/scripts/workbench_remediation.py +5 -1
- package/_bundled_plugin/scripts/workbench_saved_results.py +542 -148
- package/_bundled_plugin/scripts/workbench_scan_history.py +82 -80
- package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
- package/_bundled_plugin/scripts/workbench_scan_usage.py +246 -38
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
- package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
- package/_bundled_plugin/scripts/workbench_target.py +28 -12
- package/_bundled_plugin/scripts/workbench_validation.py +52 -13
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
- package/_bundled_plugin/shared/workbench-migrations.json +15 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/dist/api.d.ts +4 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +215 -93
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +2 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +38 -23
- package/dist/artifact-export.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +16 -18
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity-records.d.ts +76 -0
- package/dist/classify-severity-records.d.ts.map +1 -0
- package/dist/classify-severity-records.js +141 -0
- package/dist/classify-severity-records.js.map +1 -0
- package/dist/classify-severity.d.ts +1 -23
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -24
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-daybreak.d.ts +5 -0
- package/dist/cli-daybreak.d.ts.map +1 -0
- package/dist/cli-daybreak.js +89 -0
- package/dist/cli-daybreak.js.map +1 -0
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +2 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +9 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +957 -738
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +1 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codeowners.js +2 -2
- package/dist/codeowners.js.map +1 -1
- package/dist/codex-sdk-environment.js +1 -1
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +3 -2
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.js +2 -2
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -5
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +65 -17
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +7 -2
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +2 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +17 -8
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +2 -5
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +8 -6
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +1 -1
- 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/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +5 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.js +1 -1
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/retry.d.ts.map +1 -1
- package/dist/deduplication/retry.js +5 -0
- package/dist/deduplication/retry.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +15 -10
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +4 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +21 -1
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan.d.ts +6 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +8 -6
- package/dist/deep-scan.js.map +1 -1
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +26 -6
- package/dist/findings-import.js.map +1 -1
- package/dist/git-remote.d.ts +10 -0
- package/dist/git-remote.d.ts.map +1 -0
- package/dist/git-remote.js +24 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +5 -7
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +1 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +2 -2
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +15 -0
- package/dist/host-records-protocol.d.ts.map +1 -0
- package/dist/host-records-protocol.js +15 -0
- package/dist/host-records-protocol.js.map +1 -0
- package/dist/hosted-remediation-protocol.d.ts +5 -0
- package/dist/hosted-remediation-protocol.d.ts.map +1 -0
- package/dist/hosted-remediation-protocol.js +26 -0
- package/dist/hosted-remediation-protocol.js.map +1 -0
- package/dist/hosted-remediation.d.ts +89 -0
- package/dist/hosted-remediation.d.ts.map +1 -0
- package/dist/hosted-remediation.js +122 -0
- package/dist/hosted-remediation.js.map +1 -0
- package/dist/hosted-scan.d.ts +1 -6
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +2 -2
- package/dist/hosted-scan.js.map +1 -1
- package/dist/import-scan.d.ts +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +5 -1
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +87 -7
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +65 -29
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-publication.d.ts +26 -0
- package/dist/patch-publication.d.ts.map +1 -0
- package/dist/patch-publication.js +105 -0
- package/dist/patch-publication.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +29 -15
- package/dist/project-config.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +135 -19
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +2 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +48 -25
- package/dist/publish.js.map +1 -1
- package/dist/remediation.d.ts +63 -0
- package/dist/remediation.d.ts.map +1 -0
- package/dist/remediation.js +110 -0
- package/dist/remediation.js.map +1 -0
- package/dist/request-metadata.d.ts +17 -7
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +43 -8
- package/dist/request-metadata.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +104 -36
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +16 -4
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.js +8 -8
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +15 -9
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +12 -6
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +5 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +9 -8
- package/dist/scan-executor.js.map +1 -1
- package/dist/{deep-progress.d.ts → scan-progress.d.ts} +15 -7
- package/dist/scan-progress.d.ts.map +1 -0
- package/dist/scan-progress.js +138 -0
- package/dist/scan-progress.js.map +1 -0
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +7 -1
- package/dist/scan-settings.js.map +1 -1
- package/dist/scan-time-budget.d.ts +9 -0
- package/dist/scan-time-budget.d.ts.map +1 -0
- package/dist/scan-time-budget.js +16 -0
- package/dist/scan-time-budget.js.map +1 -0
- package/dist/security-policy.js +1 -1
- package/dist/security-policy.js.map +1 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +4 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +14 -2
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-review.d.ts +29 -0
- package/dist/severity-review.d.ts.map +1 -0
- package/dist/severity-review.js +47 -0
- package/dist/severity-review.js.map +1 -0
- package/dist/severity-store.js +4 -1
- package/dist/severity-store.js.map +1 -1
- package/dist/timestamps.d.ts +3 -0
- package/dist/timestamps.d.ts.map +1 -0
- package/dist/timestamps.js +14 -0
- package/dist/timestamps.js.map +1 -0
- package/dist/validation-records.d.ts +38 -0
- package/dist/validation-records.d.ts.map +1 -0
- package/dist/validation-records.js +76 -0
- package/dist/validation-records.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +17 -4
- package/dist/version.js.map +1 -1
- package/dist/workbench-arguments.d.ts.map +1 -1
- package/dist/workbench-arguments.js +9 -3
- package/dist/workbench-arguments.js.map +1 -1
- package/dist/worker-progress.d.ts +13 -7
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +12 -44
- package/dist/worker-progress.js.map +1 -1
- package/docs/classify-severity-records.md +89 -0
- package/docs/cli.md +352 -45
- package/docs/findings-service.md +7 -2
- package/docs/hosted-remediation.md +117 -0
- package/docs/hosted-scans.md +8 -3
- package/docs/validate-records.md +69 -0
- package/package.json +13 -10
- package/schemas/project-config.schema.json +7 -1
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
- package/_bundled_plugin/references/config-preflight.md +0 -93
- package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
- package/_bundled_plugin/scripts/config_preflight.py +0 -911
- package/dist/deep-progress.d.ts.map +0 -1
- package/dist/deep-progress.js +0 -92
- package/dist/deep-progress.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JsonObject } from "./config.js";
|
|
2
|
+
import { type PluginPythonOptions } from "./runtime.js";
|
|
2
3
|
export type ArtifactOutput = Pick<NodeJS.WriteStream, "write">;
|
|
3
4
|
export declare const ARTIFACT_EXPORT_FILENAMES: {
|
|
4
5
|
readonly csv: "findings.csv";
|
|
@@ -44,7 +45,7 @@ export interface ArtifactExportResult {
|
|
|
44
45
|
}
|
|
45
46
|
interface HelperOptions {
|
|
46
47
|
pythonPath?: string;
|
|
47
|
-
protectedRoot?:
|
|
48
|
+
protectedRoot?: PluginPythonOptions["protectedRoot"];
|
|
48
49
|
pluginRoot?: string;
|
|
49
50
|
signal?: AbortSignal;
|
|
50
51
|
output?: ArtifactOutput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifact-export.d.ts","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"artifact-export.d.ts","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EACL,KAAK,mBAAmB,EAOzB,MAAM,cAAc,CAAC;AAKtB,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAE/D,eAAO,MAAM,yBAAyB;aACpC,GAAG,EAAE,cAAc;aACnB,IAAI,EAAE,eAAe;aACrB,KAAK,EAAE,eAAe;aACtB,EAAE,EAAE,gBAAgB;CACZ,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,yBAAyB,CAAC;AAClE,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE7D,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EACF;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,CAAA;KAAE,GACrC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IAC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sB,iBAAiB,CACrC,UAAU,EAAE,uBAAuB,EACnC,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAoC7B;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,uBAAuB,EACnC,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,uBAAuB,CAAC,CAqFlC;AAED,qFAAqF;AACrF,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,GAC1D,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,uEAAuE;AACvE,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAkE/B;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,GACrD,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,GAAE,MAAM,CAAC,UAAwB,GAC3C,MAAM,CAAC,UAAU,CAuBnB"}
|
package/dist/artifact-export.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { workbenchArgs } from "./workbench-arguments.js";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
+
import { realpath as callbackRealpath } from "node:fs";
|
|
3
4
|
import { lstat, realpath } from "node:fs/promises";
|
|
4
5
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
6
|
import { Writable as NodeWritable } from "node:stream";
|
|
6
7
|
import { pipeline } from "node:stream/promises";
|
|
8
|
+
import { promisify } from "node:util";
|
|
7
9
|
import { CodexSecurityError } from "./errors.js";
|
|
8
10
|
import { relativePathIsOutside as isOutsidePath } from "./targets.js";
|
|
9
11
|
import { bundledPluginRoot, codexSecurityStateDirectory, expandHome, pythonUtf8Environment, resolvePluginPython, runWorkbench, } from "./runtime.js";
|
|
12
|
+
// Bun's promise-based realpath can return drive-relative Windows roots.
|
|
13
|
+
const nativeRealpath = promisify(callbackRealpath.native);
|
|
10
14
|
export const ARTIFACT_EXPORT_FILENAMES = {
|
|
11
15
|
csv: "findings.csv",
|
|
12
16
|
json: "findings.json",
|
|
@@ -114,6 +118,9 @@ export async function runArtifactExport(arguments_, output) {
|
|
|
114
118
|
...(arguments_.includeMetadata ? ["--export-metadata"] : []),
|
|
115
119
|
], {
|
|
116
120
|
pythonPath: arguments_.pythonPath,
|
|
121
|
+
protectedRoot: arguments_.sourceRoot === undefined
|
|
122
|
+
? undefined
|
|
123
|
+
: [process.cwd(), arguments_.sourceRoot],
|
|
117
124
|
signal: arguments_.signal,
|
|
118
125
|
failureMessage: artifact === "findings"
|
|
119
126
|
? `Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`
|
|
@@ -144,29 +151,35 @@ export async function resolveArtifactExportOutput(arguments_, currentDirectory)
|
|
|
144
151
|
throw error;
|
|
145
152
|
}), basename(arguments_.output));
|
|
146
153
|
if (arguments_.output !== "-") {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
const canonicalCurrent = await realpath(currentDirectory).catch(() => currentDirectory);
|
|
155
|
+
let traversedSymlink = false;
|
|
156
|
+
let expectedOutput;
|
|
157
|
+
for (let directory = dirname(arguments_.output);; directory = dirname(directory)) {
|
|
158
|
+
const metadata = await lstat(directory).catch((error) => {
|
|
159
|
+
if (error.code === "ENOENT")
|
|
160
|
+
return undefined;
|
|
161
|
+
throw error;
|
|
162
|
+
});
|
|
163
|
+
const canonicalDirectory = relative(currentDirectory, directory) === ""
|
|
164
|
+
? canonicalCurrent
|
|
165
|
+
: metadata === undefined
|
|
166
|
+
? undefined
|
|
167
|
+
: await nativeRealpath(directory);
|
|
168
|
+
if (canonicalDirectory !== undefined) {
|
|
169
|
+
expectedOutput ??= resolve(canonicalDirectory, relative(directory, arguments_.output));
|
|
170
|
+
if (!isOutsidePath(relative(canonicalCurrent, canonicalDirectory)) &&
|
|
171
|
+
(traversedSymlink ||
|
|
172
|
+
isOutsidePath(relative(canonicalCurrent, outputPath)) ||
|
|
173
|
+
relative(expectedOutput, outputPath) !== "")) {
|
|
157
174
|
throw new CodexSecurityError("The export output path cannot traverse a repository symlink.");
|
|
158
175
|
}
|
|
159
|
-
if (metadata !== undefined)
|
|
160
|
-
existingParent ??= directory;
|
|
161
|
-
}
|
|
162
|
-
const canonicalCurrent = await realpath(currentDirectory).catch(() => currentDirectory);
|
|
163
|
-
const expectedOutput = existingParent === undefined
|
|
164
|
-
? resolve(canonicalCurrent, outputFromCurrent)
|
|
165
|
-
: resolve(await realpath(existingParent), relative(existingParent, arguments_.output));
|
|
166
|
-
if (isOutsidePath(relative(canonicalCurrent, outputPath)) ||
|
|
167
|
-
relative(expectedOutput, outputPath) !== "") {
|
|
168
|
-
throw new CodexSecurityError("The export output path cannot traverse a repository symlink.");
|
|
169
176
|
}
|
|
177
|
+
// An external alias may select the repository, but links below it are
|
|
178
|
+
// repository-owned. Check ancestors before counting the current link.
|
|
179
|
+
traversedSymlink ||= metadata?.isSymbolicLink() ?? false;
|
|
180
|
+
if (relative(currentDirectory, directory) === "" ||
|
|
181
|
+
dirname(directory) === directory)
|
|
182
|
+
break;
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
185
|
return { ...arguments_, scanDir: canonicalScan, output: outputPath };
|
|
@@ -190,6 +203,9 @@ export async function resolveSavedArtifactDirectory(scanId, artifact, format, wo
|
|
|
190
203
|
export async function exportArtifact(options) {
|
|
191
204
|
const artifact = options.artifact ?? "findings";
|
|
192
205
|
const format = resolveArtifactFormat(artifact, options.format);
|
|
206
|
+
const sourceRoot = options.sourceRoot === undefined
|
|
207
|
+
? undefined
|
|
208
|
+
: resolve(expandHome(options.sourceRoot));
|
|
193
209
|
const environment = {
|
|
194
210
|
...exportEnvironment(),
|
|
195
211
|
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
|
|
@@ -202,6 +218,7 @@ export async function exportArtifact(options) {
|
|
|
202
218
|
const python = await resolvePluginPython({
|
|
203
219
|
configuredPath: options.pythonPath,
|
|
204
220
|
environment,
|
|
221
|
+
protectedRoot: sourceRoot === undefined ? undefined : [process.cwd(), sourceRoot],
|
|
205
222
|
signal: options.signal,
|
|
206
223
|
});
|
|
207
224
|
const pluginRoot = await bundledPluginRoot();
|
|
@@ -221,9 +238,7 @@ export async function exportArtifact(options) {
|
|
|
221
238
|
pythonPath: options.pythonPath,
|
|
222
239
|
signal: options.signal,
|
|
223
240
|
includeMetadata: artifact === "threat-model" && options.output !== "-",
|
|
224
|
-
...(
|
|
225
|
-
? {}
|
|
226
|
-
: { sourceRoot: resolve(expandHome(options.sourceRoot)) }),
|
|
241
|
+
...(sourceRoot === undefined ? {} : { sourceRoot }),
|
|
227
242
|
}, process.cwd());
|
|
228
243
|
const metadata = await runArtifactExport(arguments_, options.output === "-" ? process.stdout : undefined);
|
|
229
244
|
const description = metadata === undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifact-export.js","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,O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S,CAAC;SAC/C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CACzC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { workbenchArgs } from \"./workbench-arguments.js\";\nimport { spawn } from \"node:child_process\";\nimport { lstat, realpath } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { Writable as NodeWritable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { relativePathIsOutside as isOutsidePath } from \"./targets.js\";\nimport {\n bundledPluginRoot,\n codexSecurityStateDirectory,\n expandHome,\n pythonUtf8Environment,\n resolvePluginPython,\n runWorkbench,\n} from \"./runtime.js\";\n\nexport type ArtifactOutput = Pick<NodeJS.WriteStream, \"write\">;\n\nexport const ARTIFACT_EXPORT_FILENAMES = {\n csv: \"findings.csv\",\n json: \"findings.json\",\n sarif: \"results.sarif\",\n md: \"threatmodel.md\",\n} as const;\nexport type ExportFormat = keyof typeof ARTIFACT_EXPORT_FILENAMES;\nexport type ExportArtifactKind = \"findings\" | \"threat-model\";\n\nexport interface ArtifactExportArguments {\n scanDir: string;\n artifact?: ExportArtifactKind;\n format: ExportFormat;\n output: string;\n sourceRoot?: string;\n pythonPath?: string;\n signal?: AbortSignal;\n includeMetadata?: boolean;\n}\n\nexport type ExportArtifactOptions = {\n source:\n | { directory: string; scanId?: never }\n | { scanId: string; directory?: never };\n output: string;\n pythonPath?: string;\n signal?: AbortSignal;\n} & (\n | { artifact: \"threat-model\"; format?: \"md\"; sourceRoot?: never }\n | {\n artifact?: \"findings\";\n format?: \"csv\" | \"json\" | \"sarif\";\n sourceRoot?: string;\n }\n);\n\nexport interface ArtifactExportResult {\n path: string | null;\n provenance: JsonObject | null;\n}\n\ninterface HelperOptions {\n pythonPath?: string;\n protectedRoot?: string;\n pluginRoot?: string;\n signal?: AbortSignal;\n output?: ArtifactOutput;\n failureMessage?: string;\n}\n\nexport function resolveArtifactFormat(\n artifact: ExportArtifactKind,\n format?: ExportFormat,\n): ExportFormat {\n const selected = format ?? (artifact === \"threat-model\" ? \"md\" : \"sarif\");\n if ((artifact === \"threat-model\") !== (selected === \"md\")) {\n throw new CodexSecurityError(\n artifact === \"threat-model\"\n ? \"Threat-model exports only support --export-format md.\"\n : \"Findings exports support --export-format csv, json, or sarif.\",\n );\n }\n return selected;\n}\n\nexport async function runArtifactHelper(\n args: readonly string[],\n options: HelperOptions = {},\n): Promise<{ stdout: string; stderr: string }> {\n const environment = exportEnvironment();\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n protectedRoot: options.protectedRoot,\n signal: options.signal,\n });\n const plugin = options.pluginRoot ?? (await bundledPluginRoot());\n const invocation = spawn(\n python,\n [\n \"-I\",\n \"-X\",\n \"utf8\",\n \"-B\",\n join(plugin, \"scripts\", \"finalize_scan_contract.py\"),\n ...args,\n ],\n {\n env: environment,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n let stderr = \"\";\n let stdout = \"\";\n invocation.stderr.setEncoding(\"utf8\");\n invocation.stderr.on(\"data\", (chunk: string) => {\n stderr = `${stderr}${chunk}`.slice(-64 * 1024);\n });\n const forwarded =\n options.output === undefined\n ? (async () => {\n invocation.stdout.setEncoding(\"utf8\");\n for await (const chunk of invocation.stdout) stdout += chunk;\n })()\n : writeArtifactOutput(options.output, invocation.stdout);\n let status: number;\n try {\n [status] = await Promise.all([\n new Promise<number>((resolve, reject) => {\n invocation.once(\"error\", reject);\n invocation.once(\"close\", (code, signal) =>\n resolve(signal === null ? (code ?? 1) : 1),\n );\n }),\n forwarded,\n ]);\n } catch (error) {\n invocation.stdout.destroy();\n invocation.kill();\n throw error;\n }\n if (status !== 0) {\n const detail = stderr.trim().split(\"\\n\").at(-1);\n throw new CodexSecurityError(\n detail?.replace(/^finalize_scan_contract\\.py: error: /, \"\") ||\n options.failureMessage ||\n \"Could not export Codex Security artifacts.\",\n );\n }\n return { stdout, stderr };\n}\n\nexport async function writeThreatModel(\n directory: string,\n options: HelperOptions = {},\n): Promise<string> {\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--write-threat-model\"],\n options,\n );\n return result.stderr.trim().replace(/^codex-security: warning: /u, \"\");\n}\n\n/** Read the current document path without making an optional projection required. */\nexport async function readThreatModelPath(\n directory: string,\n options: HelperOptions = {},\n): Promise<string | null> {\n try {\n options.signal?.throwIfAborted();\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--describe-threat-model\"],\n options,\n );\n return (JSON.parse(result.stdout) as ArtifactExportResult).path;\n } catch {\n options.signal?.throwIfAborted();\n return null;\n }\n}\n\nexport async function runArtifactExport(\n arguments_: ArtifactExportArguments,\n output?: ArtifactOutput,\n): Promise<string | undefined> {\n const artifact = arguments_.artifact ?? \"findings\";\n resolveArtifactFormat(artifact, arguments_.format);\n const result = await runArtifactHelper(\n [\n \"--scan-dir\",\n arguments_.scanDir,\n ...(artifact === \"findings\" ? [] : [\"--export-artifact\", artifact]),\n \"--export-format\",\n arguments_.format,\n ...(arguments_.output === \"-\"\n ? []\n : [\"--export-output\", arguments_.output]),\n ...(arguments_.sourceRoot === undefined\n ? []\n : [\"--source-root\", arguments_.sourceRoot]),\n ...(arguments_.includeMetadata ? [\"--export-metadata\"] : []),\n ],\n {\n pythonPath: arguments_.pythonPath,\n signal: arguments_.signal,\n failureMessage:\n artifact === \"findings\"\n ? `Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`\n : \"Could not export the saved threat model as Markdown.\",\n ...(arguments_.output === \"-\" && output !== undefined ? { output } : {}),\n },\n );\n return (arguments_.output === \"-\" && output === undefined) ||\n arguments_.includeMetadata\n ? result.stdout\n : undefined;\n}\n\nexport async function resolveArtifactExportOutput(\n arguments_: ArtifactExportArguments,\n currentDirectory: string,\n): Promise<ArtifactExportArguments> {\n const canonicalScan = await realpath(arguments_.scanDir).catch(\n () => arguments_.scanDir,\n );\n const scanRelativeOutput = relative(arguments_.scanDir, arguments_.output);\n const scanLocalOutput = join(\n \"exports\",\n ARTIFACT_EXPORT_FILENAMES[arguments_.format],\n );\n if (\n arguments_.output !== \"-\" &&\n !isOutsidePath(scanRelativeOutput) &&\n scanRelativeOutput !== scanLocalOutput\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot overwrite a scan artifact.\",\n );\n }\n const outputPath =\n arguments_.output === \"-\"\n ? \"-\"\n : !isOutsidePath(scanRelativeOutput)\n ? join(canonicalScan, scanRelativeOutput)\n : join(\n await realpath(dirname(arguments_.output)).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\")\n throw new CodexSecurityError(\n `Export output directory does not exist: ${dirname(arguments_.output)}. Create the directory and retry.`,\n );\n throw error;\n },\n ),\n basename(arguments_.output),\n );\n if (arguments_.output !== \"-\") {\n const outputFromCurrent = relative(currentDirectory, arguments_.output);\n if (outputFromCurrent !== \"\" && !isOutsidePath(outputFromCurrent)) {\n let existingParent: string | undefined;\n for (\n let directory = dirname(arguments_.output);\n relative(currentDirectory, directory) !== \"\";\n directory = dirname(directory)\n ) {\n const metadata = await lstat(directory).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n },\n );\n if (metadata?.isSymbolicLink()) {\n throw new CodexSecurityError(\n \"The export output path cannot traverse a repository symlink.\",\n );\n }\n if (metadata !== undefined) existingParent ??= directory;\n }\n const canonicalCurrent = await realpath(currentDirectory).catch(\n () => currentDirectory,\n );\n const expectedOutput =\n existingParent === undefined\n ? resolve(canonicalCurrent, outputFromCurrent)\n : resolve(\n await realpath(existingParent),\n relative(existingParent, arguments_.output),\n );\n if (\n isOutsidePath(relative(canonicalCurrent, outputPath)) ||\n relative(expectedOutput, outputPath) !== \"\"\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot traverse a repository symlink.\",\n );\n }\n }\n }\n return { ...arguments_, scanDir: canonicalScan, output: outputPath };\n}\n\n/** Resolve saved artifacts after the workbench validates their recorded identity. */\nexport async function resolveSavedArtifactDirectory(\n scanId: string,\n artifact: ExportArtifactKind,\n format: ExportFormat,\n workbench: (args: readonly string[]) => Promise<JsonObject>,\n): Promise<string> {\n // Reuse the workbench's recorded digest and scan binding checks without\n // requiring a writable saved-scan directory for stdout or external exports.\n const context = await workbench(\n workbenchArgs(\"export-findings\", {\n scanId,\n artifact,\n format,\n validateOnly: true,\n }),\n );\n const scan = context[\"scan\"] as JsonObject | undefined;\n if (typeof scan?.[\"scanDir\"] !== \"string\")\n throw new CodexSecurityError(\n `Artifacts for scan ${scanId} are unavailable.`,\n );\n return resolve(expandHome(scan[\"scanDir\"]));\n}\n\n/** Export saved artifacts without authenticating or starting Codex. */\nexport async function exportArtifact(\n options: ExportArtifactOptions,\n): Promise<ArtifactExportResult> {\n const artifact = options.artifact ?? \"findings\";\n const format = resolveArtifactFormat(artifact, options.format);\n const environment = {\n ...exportEnvironment(),\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),\n };\n let directory: string;\n if (options.source.directory !== undefined) {\n directory = resolve(expandHome(options.source.directory));\n } else {\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n signal: options.signal,\n });\n const pluginRoot = await bundledPluginRoot();\n directory = await resolveSavedArtifactDirectory(\n options.source.scanId,\n artifact,\n format,\n (args) =>\n runWorkbench(\n {\n python,\n pluginRoot,\n environment,\n signal: options.signal,\n failureMessage: \"Could not export Codex Security scan artifacts\",\n },\n args,\n ),\n );\n }\n const arguments_ = await resolveArtifactExportOutput(\n {\n scanDir: directory,\n artifact,\n format,\n output:\n options.output === \"-\" ? \"-\" : resolve(expandHome(options.output)),\n pythonPath: options.pythonPath,\n signal: options.signal,\n includeMetadata: artifact === \"threat-model\" && options.output !== \"-\",\n ...(options.sourceRoot === undefined\n ? {}\n : { sourceRoot: resolve(expandHome(options.sourceRoot)) }),\n },\n process.cwd(),\n );\n const metadata = await runArtifactExport(\n arguments_,\n options.output === \"-\" ? process.stdout : undefined,\n );\n const description =\n metadata === undefined\n ? null\n : (JSON.parse(metadata) as ArtifactExportResult);\n return {\n path: arguments_.output === \"-\" ? null : arguments_.output,\n provenance: description?.provenance ?? null,\n };\n}\n\nexport async function writeArtifactOutput(\n output: ArtifactOutput,\n value: string | Uint8Array | AsyncIterable<Uint8Array>,\n): Promise<void> {\n const destination = new NodeWritable({\n write(chunk, _encoding, callback) {\n try {\n if (output instanceof NodeWritable) {\n output.write(chunk, callback);\n } else if (output.write(chunk)) {\n callback();\n } else {\n callback(\n new CodexSecurityError(\n \"The export stdout stream cannot report backpressure safely.\",\n ),\n );\n }\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n },\n });\n const forwardError = (error: Error): void => {\n destination.destroy(error);\n };\n if (output instanceof NodeWritable) output.once(\"error\", forwardError);\n try {\n await pipeline(\n typeof value === \"string\" || value instanceof Uint8Array\n ? [value]\n : value,\n destination,\n );\n } finally {\n if (output instanceof NodeWritable) {\n output.removeListener(\"error\", forwardError);\n }\n }\n}\n\nexport function exportEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n): NodeJS.ProcessEnv {\n return pythonUtf8Environment(\n Object.fromEntries(\n [\n \"PATH\",\n \"Path\",\n \"PATHEXT\",\n \"SystemRoot\",\n \"SYSTEMROOT\",\n \"WINDIR\",\n \"TMP\",\n \"TEMP\",\n \"TMPDIR\",\n \"PYTHON\",\n \"XDG_CACHE_HOME\",\n \"LANG\",\n \"LC_ALL\",\n \"LC_CTYPE\",\n ]\n .filter((key) => environment[key] !== undefined)\n .map((key) => [key, environment[key]]),\n ),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"artifact-export.js","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MA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Y,GAAG,CAAC,KAAY,EAAQ,EAAE;QAC1C,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,IAAI,MAAM,YAAY,YAAY;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACvE,IAAI,CAAC;QACH,MAAM,QAAQ,CACZ,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,UAAU;YACtD,CAAC,CAAC,CAAC,KAAK,CAAC;YACT,CAAC,CAAC,KAAK,EACT,WAAW,CACZ,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,YAAY,YAAY,EAAE,CAAC;YACnC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,WAAW,GAAsB,OAAO,CAAC,GAAG;IAE5C,OAAO,qBAAqB,CAC1B,MAAM,CAAC,WAAW,CAChB;QACE,MAAM;QACN,MAAM;QACN,SAAS;QACT,YAAY;QACZ,YAAY;QACZ,QAAQ;QACR,KAAK;QACL,MAAM;QACN,QAAQ;QACR,QAAQ;QACR,gBAAgB;QAChB,MAAM;QACN,QAAQ;QACR,UAAU;KACX;SACE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;SAC/C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CACzC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { workbenchArgs } from \"./workbench-arguments.js\";\nimport { spawn } from \"node:child_process\";\nimport { realpath as callbackRealpath } from \"node:fs\";\nimport { lstat, realpath } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { Writable as NodeWritable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport { promisify } from \"node:util\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { relativePathIsOutside as isOutsidePath } from \"./targets.js\";\nimport {\n type PluginPythonOptions,\n bundledPluginRoot,\n codexSecurityStateDirectory,\n expandHome,\n pythonUtf8Environment,\n resolvePluginPython,\n runWorkbench,\n} from \"./runtime.js\";\n\n// Bun's promise-based realpath can return drive-relative Windows roots.\nconst nativeRealpath = promisify(callbackRealpath.native);\n\nexport type ArtifactOutput = Pick<NodeJS.WriteStream, \"write\">;\n\nexport const ARTIFACT_EXPORT_FILENAMES = {\n csv: \"findings.csv\",\n json: \"findings.json\",\n sarif: \"results.sarif\",\n md: \"threatmodel.md\",\n} as const;\nexport type ExportFormat = keyof typeof ARTIFACT_EXPORT_FILENAMES;\nexport type ExportArtifactKind = \"findings\" | \"threat-model\";\n\nexport interface ArtifactExportArguments {\n scanDir: string;\n artifact?: ExportArtifactKind;\n format: ExportFormat;\n output: string;\n sourceRoot?: string;\n pythonPath?: string;\n signal?: AbortSignal;\n includeMetadata?: boolean;\n}\n\nexport type ExportArtifactOptions = {\n source:\n | { directory: string; scanId?: never }\n | { scanId: string; directory?: never };\n output: string;\n pythonPath?: string;\n signal?: AbortSignal;\n} & (\n | { artifact: \"threat-model\"; format?: \"md\"; sourceRoot?: never }\n | {\n artifact?: \"findings\";\n format?: \"csv\" | \"json\" | \"sarif\";\n sourceRoot?: string;\n }\n);\n\nexport interface ArtifactExportResult {\n path: string | null;\n provenance: JsonObject | null;\n}\n\ninterface HelperOptions {\n pythonPath?: string;\n protectedRoot?: PluginPythonOptions[\"protectedRoot\"];\n pluginRoot?: string;\n signal?: AbortSignal;\n output?: ArtifactOutput;\n failureMessage?: string;\n}\n\nexport function resolveArtifactFormat(\n artifact: ExportArtifactKind,\n format?: ExportFormat,\n): ExportFormat {\n const selected = format ?? (artifact === \"threat-model\" ? \"md\" : \"sarif\");\n if ((artifact === \"threat-model\") !== (selected === \"md\")) {\n throw new CodexSecurityError(\n artifact === \"threat-model\"\n ? \"Threat-model exports only support --export-format md.\"\n : \"Findings exports support --export-format csv, json, or sarif.\",\n );\n }\n return selected;\n}\n\nexport async function runArtifactHelper(\n args: readonly string[],\n options: HelperOptions = {},\n): Promise<{ stdout: string; stderr: string }> {\n const environment = exportEnvironment();\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n protectedRoot: options.protectedRoot,\n signal: options.signal,\n });\n const plugin = options.pluginRoot ?? (await bundledPluginRoot());\n const invocation = spawn(\n python,\n [\n \"-I\",\n \"-X\",\n \"utf8\",\n \"-B\",\n join(plugin, \"scripts\", \"finalize_scan_contract.py\"),\n ...args,\n ],\n {\n env: environment,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n let stderr = \"\";\n let stdout = \"\";\n invocation.stderr.setEncoding(\"utf8\");\n invocation.stderr.on(\"data\", (chunk: string) => {\n stderr = `${stderr}${chunk}`.slice(-64 * 1024);\n });\n const forwarded =\n options.output === undefined\n ? (async () => {\n invocation.stdout.setEncoding(\"utf8\");\n for await (const chunk of invocation.stdout) stdout += chunk;\n })()\n : writeArtifactOutput(options.output, invocation.stdout);\n let status: number;\n try {\n [status] = await Promise.all([\n new Promise<number>((resolve, reject) => {\n invocation.once(\"error\", reject);\n invocation.once(\"close\", (code, signal) =>\n resolve(signal === null ? (code ?? 1) : 1),\n );\n }),\n forwarded,\n ]);\n } catch (error) {\n invocation.stdout.destroy();\n invocation.kill();\n throw error;\n }\n if (status !== 0) {\n const detail = stderr.trim().split(\"\\n\").at(-1);\n throw new CodexSecurityError(\n detail?.replace(/^finalize_scan_contract\\.py: error: /, \"\") ||\n options.failureMessage ||\n \"Could not export Codex Security artifacts.\",\n );\n }\n return { stdout, stderr };\n}\n\nexport async function writeThreatModel(\n directory: string,\n options: HelperOptions = {},\n): Promise<string> {\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--write-threat-model\"],\n options,\n );\n return result.stderr.trim().replace(/^codex-security: warning: /u, \"\");\n}\n\n/** Read the current document path without making an optional projection required. */\nexport async function readThreatModelPath(\n directory: string,\n options: HelperOptions = {},\n): Promise<string | null> {\n try {\n options.signal?.throwIfAborted();\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--describe-threat-model\"],\n options,\n );\n return (JSON.parse(result.stdout) as ArtifactExportResult).path;\n } catch {\n options.signal?.throwIfAborted();\n return null;\n }\n}\n\nexport async function runArtifactExport(\n arguments_: ArtifactExportArguments,\n output?: ArtifactOutput,\n): Promise<string | undefined> {\n const artifact = arguments_.artifact ?? \"findings\";\n resolveArtifactFormat(artifact, arguments_.format);\n const result = await runArtifactHelper(\n [\n \"--scan-dir\",\n arguments_.scanDir,\n ...(artifact === \"findings\" ? [] : [\"--export-artifact\", artifact]),\n \"--export-format\",\n arguments_.format,\n ...(arguments_.output === \"-\"\n ? []\n : [\"--export-output\", arguments_.output]),\n ...(arguments_.sourceRoot === undefined\n ? []\n : [\"--source-root\", arguments_.sourceRoot]),\n ...(arguments_.includeMetadata ? [\"--export-metadata\"] : []),\n ],\n {\n pythonPath: arguments_.pythonPath,\n protectedRoot:\n arguments_.sourceRoot === undefined\n ? undefined\n : [process.cwd(), arguments_.sourceRoot],\n signal: arguments_.signal,\n failureMessage:\n artifact === \"findings\"\n ? `Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`\n : \"Could not export the saved threat model as Markdown.\",\n ...(arguments_.output === \"-\" && output !== undefined ? { output } : {}),\n },\n );\n return (arguments_.output === \"-\" && output === undefined) ||\n arguments_.includeMetadata\n ? result.stdout\n : undefined;\n}\n\nexport async function resolveArtifactExportOutput(\n arguments_: ArtifactExportArguments,\n currentDirectory: string,\n): Promise<ArtifactExportArguments> {\n const canonicalScan = await realpath(arguments_.scanDir).catch(\n () => arguments_.scanDir,\n );\n const scanRelativeOutput = relative(arguments_.scanDir, arguments_.output);\n const scanLocalOutput = join(\n \"exports\",\n ARTIFACT_EXPORT_FILENAMES[arguments_.format],\n );\n if (\n arguments_.output !== \"-\" &&\n !isOutsidePath(scanRelativeOutput) &&\n scanRelativeOutput !== scanLocalOutput\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot overwrite a scan artifact.\",\n );\n }\n const outputPath =\n arguments_.output === \"-\"\n ? \"-\"\n : !isOutsidePath(scanRelativeOutput)\n ? join(canonicalScan, scanRelativeOutput)\n : join(\n await realpath(dirname(arguments_.output)).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\")\n throw new CodexSecurityError(\n `Export output directory does not exist: ${dirname(arguments_.output)}. Create the directory and retry.`,\n );\n throw error;\n },\n ),\n basename(arguments_.output),\n );\n if (arguments_.output !== \"-\") {\n const canonicalCurrent = await realpath(currentDirectory).catch(\n () => currentDirectory,\n );\n let traversedSymlink = false;\n let expectedOutput: string | undefined;\n for (\n let directory = dirname(arguments_.output);\n ;\n directory = dirname(directory)\n ) {\n const metadata = await lstat(directory).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n },\n );\n const canonicalDirectory =\n relative(currentDirectory, directory) === \"\"\n ? canonicalCurrent\n : metadata === undefined\n ? undefined\n : await nativeRealpath(directory);\n if (canonicalDirectory !== undefined) {\n expectedOutput ??= resolve(\n canonicalDirectory,\n relative(directory, arguments_.output),\n );\n if (\n !isOutsidePath(relative(canonicalCurrent, canonicalDirectory)) &&\n (traversedSymlink ||\n isOutsidePath(relative(canonicalCurrent, outputPath)) ||\n relative(expectedOutput, outputPath) !== \"\")\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot traverse a repository symlink.\",\n );\n }\n }\n // An external alias may select the repository, but links below it are\n // repository-owned. Check ancestors before counting the current link.\n traversedSymlink ||= metadata?.isSymbolicLink() ?? false;\n if (\n relative(currentDirectory, directory) === \"\" ||\n dirname(directory) === directory\n )\n break;\n }\n }\n return { ...arguments_, scanDir: canonicalScan, output: outputPath };\n}\n\n/** Resolve saved artifacts after the workbench validates their recorded identity. */\nexport async function resolveSavedArtifactDirectory(\n scanId: string,\n artifact: ExportArtifactKind,\n format: ExportFormat,\n workbench: (args: readonly string[]) => Promise<JsonObject>,\n): Promise<string> {\n // Reuse the workbench's recorded digest and scan binding checks without\n // requiring a writable saved-scan directory for stdout or external exports.\n const context = await workbench(\n workbenchArgs(\"export-findings\", {\n scanId,\n artifact,\n format,\n validateOnly: true,\n }),\n );\n const scan = context[\"scan\"] as JsonObject | undefined;\n if (typeof scan?.[\"scanDir\"] !== \"string\")\n throw new CodexSecurityError(\n `Artifacts for scan ${scanId} are unavailable.`,\n );\n return resolve(expandHome(scan[\"scanDir\"]));\n}\n\n/** Export saved artifacts without authenticating or starting Codex. */\nexport async function exportArtifact(\n options: ExportArtifactOptions,\n): Promise<ArtifactExportResult> {\n const artifact = options.artifact ?? \"findings\";\n const format = resolveArtifactFormat(artifact, options.format);\n const sourceRoot =\n options.sourceRoot === undefined\n ? undefined\n : resolve(expandHome(options.sourceRoot));\n const environment = {\n ...exportEnvironment(),\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),\n };\n let directory: string;\n if (options.source.directory !== undefined) {\n directory = resolve(expandHome(options.source.directory));\n } else {\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n protectedRoot:\n sourceRoot === undefined ? undefined : [process.cwd(), sourceRoot],\n signal: options.signal,\n });\n const pluginRoot = await bundledPluginRoot();\n directory = await resolveSavedArtifactDirectory(\n options.source.scanId,\n artifact,\n format,\n (args) =>\n runWorkbench(\n {\n python,\n pluginRoot,\n environment,\n signal: options.signal,\n failureMessage: \"Could not export Codex Security scan artifacts\",\n },\n args,\n ),\n );\n }\n const arguments_ = await resolveArtifactExportOutput(\n {\n scanDir: directory,\n artifact,\n format,\n output:\n options.output === \"-\" ? \"-\" : resolve(expandHome(options.output)),\n pythonPath: options.pythonPath,\n signal: options.signal,\n includeMetadata: artifact === \"threat-model\" && options.output !== \"-\",\n ...(sourceRoot === undefined ? {} : { sourceRoot }),\n },\n process.cwd(),\n );\n const metadata = await runArtifactExport(\n arguments_,\n options.output === \"-\" ? process.stdout : undefined,\n );\n const description =\n metadata === undefined\n ? null\n : (JSON.parse(metadata) as ArtifactExportResult);\n return {\n path: arguments_.output === \"-\" ? null : arguments_.output,\n provenance: description?.provenance ?? null,\n };\n}\n\nexport async function writeArtifactOutput(\n output: ArtifactOutput,\n value: string | Uint8Array | AsyncIterable<Uint8Array>,\n): Promise<void> {\n const destination = new NodeWritable({\n write(chunk, _encoding, callback) {\n try {\n if (output instanceof NodeWritable) {\n output.write(chunk, callback);\n } else if (output.write(chunk)) {\n callback();\n } else {\n callback(\n new CodexSecurityError(\n \"The export stdout stream cannot report backpressure safely.\",\n ),\n );\n }\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n },\n });\n const forwardError = (error: Error): void => {\n destination.destroy(error);\n };\n if (output instanceof NodeWritable) output.once(\"error\", forwardError);\n try {\n await pipeline(\n typeof value === \"string\" || value instanceof Uint8Array\n ? [value]\n : value,\n destination,\n );\n } finally {\n if (output instanceof NodeWritable) {\n output.removeListener(\"error\", forwardError);\n }\n }\n}\n\nexport function exportEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n): NodeJS.ProcessEnv {\n return pythonUtf8Environment(\n Object.fromEntries(\n [\n \"PATH\",\n \"Path\",\n \"PATHEXT\",\n \"SystemRoot\",\n \"SYSTEMROOT\",\n \"WINDIR\",\n \"TMP\",\n \"TEMP\",\n \"TMPDIR\",\n \"PYTHON\",\n \"XDG_CACHE_HOME\",\n \"LANG\",\n \"LC_ALL\",\n \"LC_CTYPE\",\n ]\n .filter((key) => environment[key] !== undefined)\n .map((key) => [key, environment[key]]),\n ),\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify-scan-severity.d.ts","sourceRoot":"","sources":["../src/classify-scan-severity.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"classify-scan-severity.d.ts","sourceRoot":"","sources":["../src/classify-scan-severity.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAahC,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,2BAA4B,SAAQ,uBAAuB;IAC1E,yFAAyF;IACzF,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,wFAAwF;IACxF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qFAAqF;AACrF,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAErC;AAwCD,sGAAsG;AACtG,wBAAsB,6BAA6B,CACjD,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAErC"}
|
|
@@ -4,7 +4,8 @@ import { join } from "node:path";
|
|
|
4
4
|
import { classifySeverityInternal, validateSeverityClassification, } from "./classify-severity.js";
|
|
5
5
|
import { loadContractWithScanDirectory } from "./contract.js";
|
|
6
6
|
import { CodexSecurityError } from "./errors.js";
|
|
7
|
-
import { bundledPluginRoot
|
|
7
|
+
import { bundledPluginRoot } from "./runtime.js";
|
|
8
|
+
import { savedScanWorkbench } from "./saved-scan-bootstrap.js";
|
|
8
9
|
import { resolveCompletedScan, } from "./saved-scan.js";
|
|
9
10
|
import { SeverityStore } from "./severity-store.js";
|
|
10
11
|
const CLASSIFICATION_FILE = "severity-classification.json";
|
|
@@ -17,41 +18,38 @@ export async function classifyScanSeverityInternal(scanId, options = {}, depende
|
|
|
17
18
|
options.signal?.throwIfAborted();
|
|
18
19
|
const environment = options.environment ?? process.env;
|
|
19
20
|
const pluginRoot = await bundledPluginRoot();
|
|
21
|
+
const currentDirectory = dependencies.currentDirectory?.() ?? process.cwd();
|
|
22
|
+
const bootstrap = dependencies.runWorkbench
|
|
23
|
+
? undefined
|
|
24
|
+
: await savedScanWorkbench(scanId, {
|
|
25
|
+
environment,
|
|
26
|
+
pluginRoot,
|
|
27
|
+
currentDirectory,
|
|
28
|
+
signal: options.signal,
|
|
29
|
+
});
|
|
20
30
|
const scan = await resolveCompletedScan(scanId, {
|
|
21
|
-
currentDirectory:
|
|
22
|
-
runWorkbench: dependencies.runWorkbench ??
|
|
23
|
-
(async (args) => {
|
|
24
|
-
const stateEnvironment = workbenchEnvironment(environment);
|
|
25
|
-
return runWorkbench({
|
|
26
|
-
environment: stateEnvironment,
|
|
27
|
-
pluginRoot,
|
|
28
|
-
python: await resolvePluginPython({
|
|
29
|
-
environment: stateEnvironment,
|
|
30
|
-
}),
|
|
31
|
-
signal: options.signal,
|
|
32
|
-
failureMessage: "Could not read Codex Security scan history",
|
|
33
|
-
}, args);
|
|
34
|
-
}),
|
|
31
|
+
currentDirectory: () => currentDirectory,
|
|
32
|
+
runWorkbench: (args, input) => (dependencies.runWorkbench ?? bootstrap)(args, input, options.signal),
|
|
35
33
|
});
|
|
36
34
|
if (options.expectedScanId !== undefined &&
|
|
37
35
|
options.expectedScanId !== scan.scanId) {
|
|
38
36
|
throw new CodexSecurityError("Saved scan does not match expectedScanId.");
|
|
39
37
|
}
|
|
40
|
-
return classifyScanDirectorySeverityInternal(scan.scanDir, { ...options, expectedScanId: scan.scanId }, surface);
|
|
38
|
+
return classifyScanDirectorySeverityInternal(scan.scanDir, { ...options, expectedScanId: scan.scanId }, surface, bootstrap?.protectedRoots);
|
|
41
39
|
}
|
|
42
40
|
/** Classify a sealed scan directory and save a separate assessment without changing its artifacts. */
|
|
43
41
|
export async function classifyScanDirectorySeverity(scanDirectory, options = {}) {
|
|
44
42
|
return classifyScanDirectorySeverityInternal(scanDirectory, options);
|
|
45
43
|
}
|
|
46
44
|
/** @internal */
|
|
47
|
-
export async function classifyScanDirectorySeverityInternal(requestedDirectory, options = {}, surface = "sdk") {
|
|
45
|
+
export async function classifyScanDirectorySeverityInternal(requestedDirectory, options = {}, surface = "sdk", protectedRoots = []) {
|
|
48
46
|
const { contract, scanDirectory } = await loadContractWithScanDirectory(requestedDirectory, {
|
|
49
47
|
pluginRoot: await bundledPluginRoot(),
|
|
50
48
|
expectedScanId: options.expectedScanId,
|
|
51
49
|
signal: options.signal,
|
|
52
50
|
});
|
|
53
51
|
const findings = selectClassificationFindings(contract.findings.findings, options.findingIds);
|
|
54
|
-
const store = new SeverityStore(options.environment ?? process.env, scanDirectory, options.signal);
|
|
52
|
+
const store = new SeverityStore(options.environment ?? process.env, scanDirectory, options.signal, protectedRoots);
|
|
55
53
|
const result = {
|
|
56
54
|
...(await classifySeverityInternal(findings, options, surface, store.checkpoint(contract.manifest.scan.id, findings.map(({ findingId }) => findingId), options.reprocess ?? false))),
|
|
57
55
|
scanId: contract.manifest.scan.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify-scan-severity.js","sourceRoot":"","sources":["../src/classify-scan-severity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,8BAA8B,GAG/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,GACb,MAA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wDAAwD,CACzD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,aAAqB,EACrB,MAAc,EACd,QAA4B,EAC5B,MAAoB,EACpB,WAAW,GAAsB,OAAO,CAAC,GAAG;IAE5C,MAAM,cAAc,GAAG,MAAM,IAAI,aAAa,CAC5C,WAAW,EACX,aAAa,EACb,MAAM,CACP,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACf,OAAO,cAAc,KAAK,SAAS;QACjC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,8BAA8B,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { rename, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n classifySeverityInternal,\n validateSeverityClassification,\n type ClassifySeverityOptions,\n type SeverityClassification,\n} from \"./classify-severity.js\";\nimport { loadContractWithScanDirectory } from \"./contract.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { Finding } from \"./models.js\";\nimport {\n bundledPluginRoot,\n workbenchEnvironment,\n resolvePluginPython,\n runWorkbench,\n} from \"./runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"./saved-scan.js\";\nimport { SeverityStore } from \"./severity-store.js\";\n\nconst CLASSIFICATION_FILE = \"severity-classification.json\";\nexport interface ScanSeverityClassification extends SeverityClassification {\n scanId: string;\n}\n\nexport interface ClassifyScanSeverityOptions extends ClassifySeverityOptions {\n /** Exact selection, such as dedupe's uniqueFindingIds. Omit to classify all findings. */\n findingIds?: readonly string[];\n /** Reclassify selected findings even when their saved assessment matches the inputs. */\n reprocess?: boolean;\n expectedScanId?: string;\n}\n\n/** Resolve a saved scan ID, unique prefix, or latest and save its classification. */\nexport async function classifyScanSeverity(\n scanId: string,\n options: ClassifyScanSeverityOptions = {},\n): Promise<ScanSeverityClassification> {\n return classifyScanSeverityInternal(scanId, options);\n}\n\n/** @internal */\nexport async function classifyScanSeverityInternal(\n scanId: string,\n options: ClassifyScanSeverityOptions = {},\n dependencies: Partial<SavedScanDependencies> = {},\n surface: \"sdk\" | \"cli\" = \"sdk\",\n): Promise<ScanSeverityClassification> {\n options.signal?.throwIfAborted();\n const environment = options.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n dependencies.runWorkbench ??\n (async (args) => {\n const stateEnvironment = workbenchEnvironment(environment);\n return runWorkbench(\n {\n environment: stateEnvironment,\n pluginRoot,\n python: await resolvePluginPython({\n environment: stateEnvironment,\n }),\n signal: options.signal,\n failureMessage: \"Could not read Codex Security scan history\",\n },\n args,\n );\n }),\n });\n if (\n options.expectedScanId !== undefined &&\n options.expectedScanId !== scan.scanId\n ) {\n throw new CodexSecurityError(\"Saved scan does not match expectedScanId.\");\n }\n return classifyScanDirectorySeverityInternal(\n scan.scanDir,\n { ...options, expectedScanId: scan.scanId },\n surface,\n );\n}\n\n/** Classify a sealed scan directory and save a separate assessment without changing its artifacts. */\nexport async function classifyScanDirectorySeverity(\n scanDirectory: string,\n options: ClassifyScanSeverityOptions = {},\n): Promise<ScanSeverityClassification> {\n return classifyScanDirectorySeverityInternal(scanDirectory, options);\n}\n\n/** @internal */\nexport async function classifyScanDirectorySeverityInternal(\n requestedDirectory: string,\n options: ClassifyScanSeverityOptions = {},\n surface: \"sdk\" | \"cli\" = \"sdk\",\n): Promise<ScanSeverityClassification> {\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n requestedDirectory,\n {\n pluginRoot: await bundledPluginRoot(),\n expectedScanId: options.expectedScanId,\n signal: options.signal,\n },\n );\n const findings = selectClassificationFindings(\n contract.findings.findings,\n options.findingIds,\n );\n const store = new SeverityStore(\n options.environment ?? process.env,\n scanDirectory,\n options.signal,\n );\n const result: ScanSeverityClassification = {\n ...(await classifySeverityInternal(\n findings,\n options,\n surface,\n store.checkpoint(\n contract.manifest.scan.id,\n findings.map(({ findingId }) => findingId),\n options.reprocess ?? false,\n ),\n )),\n scanId: contract.manifest.scan.id,\n };\n options.signal?.throwIfAborted();\n const temporary = join(\n scanDirectory,\n `.severity-classification-${randomUUID()}.json`,\n );\n try {\n await writeFile(temporary, `${JSON.stringify(result, null, 2)}\\n`, {\n flag: \"wx\",\n mode: 0o600,\n signal: options.signal,\n });\n options.signal?.throwIfAborted();\n await rename(temporary, join(scanDirectory, CLASSIFICATION_FILE));\n } finally {\n await rm(temporary, { force: true });\n }\n return result;\n}\n\n/** @internal */\nexport function selectClassificationFindings(\n findings: readonly Finding[],\n findingIds?: readonly string[],\n): readonly Finding[] {\n if (findingIds === undefined) return findings;\n const selected = new Set(findingIds);\n const result = findings.filter((finding) => selected.has(finding.findingId));\n if (result.length !== selected.size) {\n throw new CodexSecurityError(\n \"Selected finding IDs must belong to the supplied scan.\",\n );\n }\n return result;\n}\n\n/** @internal */\nexport async function readScanSeverityClassification(\n scanDirectory: string,\n scanId: string,\n findings: readonly Finding[],\n signal?: AbortSignal,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<SeverityClassification | undefined> {\n const classification = await new SeverityStore(\n environment,\n scanDirectory,\n signal,\n ).read(scanId);\n return classification === undefined\n ? undefined\n : validateSeverityClassification(classification, findings);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"classify-scan-severity.js","sourceRoot":"","sources":["../src/classify-scan-severity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,8BAA8B,GAG/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,6BAA6B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ACrC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7E,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,kBAAkB,CAC1B,wDAAwD,CACzD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,aAAqB,EACrB,MAAc,EACd,QAA4B,EAC5B,MAAoB,EACpB,WAAW,GAAsB,OAAO,CAAC,GAAG;IAE5C,MAAM,cAAc,GAAG,MAAM,IAAI,aAAa,CAC5C,WAAW,EACX,aAAa,EACb,MAAM,CACP,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACf,OAAO,cAAc,KAAK,SAAS;QACjC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,8BAA8B,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { rename, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n classifySeverityInternal,\n validateSeverityClassification,\n type ClassifySeverityOptions,\n type SeverityClassification,\n} from \"./classify-severity.js\";\nimport { loadContractWithScanDirectory } from \"./contract.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { Finding } from \"./models.js\";\nimport { bundledPluginRoot } from \"./runtime.js\";\nimport { savedScanWorkbench } from \"./saved-scan-bootstrap.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"./saved-scan.js\";\nimport { SeverityStore } from \"./severity-store.js\";\n\nconst CLASSIFICATION_FILE = \"severity-classification.json\";\nexport interface ScanSeverityClassification extends SeverityClassification {\n scanId: string;\n}\n\nexport interface ClassifyScanSeverityOptions extends ClassifySeverityOptions {\n /** Exact selection, such as dedupe's uniqueFindingIds. Omit to classify all findings. */\n findingIds?: readonly string[];\n /** Reclassify selected findings even when their saved assessment matches the inputs. */\n reprocess?: boolean;\n expectedScanId?: string;\n}\n\n/** Resolve a saved scan ID, unique prefix, or latest and save its classification. */\nexport async function classifyScanSeverity(\n scanId: string,\n options: ClassifyScanSeverityOptions = {},\n): Promise<ScanSeverityClassification> {\n return classifyScanSeverityInternal(scanId, options);\n}\n\n/** @internal */\nexport async function classifyScanSeverityInternal(\n scanId: string,\n options: ClassifyScanSeverityOptions = {},\n dependencies: Partial<SavedScanDependencies> = {},\n surface: \"sdk\" | \"cli\" = \"sdk\",\n): Promise<ScanSeverityClassification> {\n options.signal?.throwIfAborted();\n const environment = options.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const currentDirectory = dependencies.currentDirectory?.() ?? process.cwd();\n const bootstrap = dependencies.runWorkbench\n ? undefined\n : await savedScanWorkbench(scanId, {\n environment,\n pluginRoot,\n currentDirectory,\n signal: options.signal,\n });\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: () => currentDirectory,\n runWorkbench: (args, input) =>\n (dependencies.runWorkbench ?? bootstrap!)(args, input, options.signal),\n });\n if (\n options.expectedScanId !== undefined &&\n options.expectedScanId !== scan.scanId\n ) {\n throw new CodexSecurityError(\"Saved scan does not match expectedScanId.\");\n }\n return classifyScanDirectorySeverityInternal(\n scan.scanDir,\n { ...options, expectedScanId: scan.scanId },\n surface,\n bootstrap?.protectedRoots,\n );\n}\n\n/** Classify a sealed scan directory and save a separate assessment without changing its artifacts. */\nexport async function classifyScanDirectorySeverity(\n scanDirectory: string,\n options: ClassifyScanSeverityOptions = {},\n): Promise<ScanSeverityClassification> {\n return classifyScanDirectorySeverityInternal(scanDirectory, options);\n}\n\n/** @internal */\nexport async function classifyScanDirectorySeverityInternal(\n requestedDirectory: string,\n options: ClassifyScanSeverityOptions = {},\n surface: \"sdk\" | \"cli\" = \"sdk\",\n protectedRoots: readonly string[] = [],\n): Promise<ScanSeverityClassification> {\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n requestedDirectory,\n {\n pluginRoot: await bundledPluginRoot(),\n expectedScanId: options.expectedScanId,\n signal: options.signal,\n },\n );\n const findings = selectClassificationFindings(\n contract.findings.findings,\n options.findingIds,\n );\n const store = new SeverityStore(\n options.environment ?? process.env,\n scanDirectory,\n options.signal,\n protectedRoots,\n );\n const result: ScanSeverityClassification = {\n ...(await classifySeverityInternal(\n findings,\n options,\n surface,\n store.checkpoint(\n contract.manifest.scan.id,\n findings.map(({ findingId }) => findingId),\n options.reprocess ?? false,\n ),\n )),\n scanId: contract.manifest.scan.id,\n };\n options.signal?.throwIfAborted();\n const temporary = join(\n scanDirectory,\n `.severity-classification-${randomUUID()}.json`,\n );\n try {\n await writeFile(temporary, `${JSON.stringify(result, null, 2)}\\n`, {\n flag: \"wx\",\n mode: 0o600,\n signal: options.signal,\n });\n options.signal?.throwIfAborted();\n await rename(temporary, join(scanDirectory, CLASSIFICATION_FILE));\n } finally {\n await rm(temporary, { force: true });\n }\n return result;\n}\n\n/** @internal */\nexport function selectClassificationFindings(\n findings: readonly Finding[],\n findingIds?: readonly string[],\n): readonly Finding[] {\n if (findingIds === undefined) return findings;\n const selected = new Set(findingIds);\n const result = findings.filter((finding) => selected.has(finding.findingId));\n if (result.length !== selected.size) {\n throw new CodexSecurityError(\n \"Selected finding IDs must belong to the supplied scan.\",\n );\n }\n return result;\n}\n\n/** @internal */\nexport async function readScanSeverityClassification(\n scanDirectory: string,\n scanId: string,\n findings: readonly Finding[],\n signal?: AbortSignal,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<SeverityClassification | undefined> {\n const classification = await new SeverityStore(\n environment,\n scanDirectory,\n signal,\n ).read(scanId);\n return classification === undefined\n ? undefined\n : validateSeverityClassification(classification, findings);\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type SeverityDecision } from "./severity-review.js";
|
|
3
|
+
/** Versioned input for repository-free classification of canonical records. */
|
|
4
|
+
export declare const classifySeverityRecordsInputSchema: z.ZodObject<{
|
|
5
|
+
version: z.ZodLiteral<1>;
|
|
6
|
+
rubric: z.ZodObject<{
|
|
7
|
+
revision: z.ZodNumber;
|
|
8
|
+
markdown: z.ZodString;
|
|
9
|
+
sha256: z.ZodString;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
model: z.ZodString;
|
|
12
|
+
effort: z.ZodEnum<{
|
|
13
|
+
high: "high";
|
|
14
|
+
low: "low";
|
|
15
|
+
max: "max";
|
|
16
|
+
medium: "medium";
|
|
17
|
+
minimal: "minimal";
|
|
18
|
+
ultra: "ultra";
|
|
19
|
+
xhigh: "xhigh";
|
|
20
|
+
}>;
|
|
21
|
+
records: z.ZodArray<z.ZodObject<{
|
|
22
|
+
id: z.ZodString;
|
|
23
|
+
revision: z.ZodNumber;
|
|
24
|
+
findingJson: z.ZodString;
|
|
25
|
+
inputSha256: z.ZodString;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type ClassifySeverityRecordsInput = z.infer<typeof classifySeverityRecordsInputSchema>;
|
|
29
|
+
export interface SeverityClassificationReviewRequest {
|
|
30
|
+
requestId: string;
|
|
31
|
+
stage: "severity-classification";
|
|
32
|
+
model: string;
|
|
33
|
+
effort: ClassifySeverityRecordsInput["effort"];
|
|
34
|
+
trustedInstructions: string;
|
|
35
|
+
prompt: string;
|
|
36
|
+
schema: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface ClassifySeverityRecordsOptions {
|
|
39
|
+
reviewRunner: {
|
|
40
|
+
run(request: SeverityClassificationReviewRequest, options?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
};
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
export type CanonicalSeverityAssessment = Omit<SeverityDecision, "findingId"> & {
|
|
47
|
+
id: string;
|
|
48
|
+
revision: number;
|
|
49
|
+
inputSha256: string;
|
|
50
|
+
};
|
|
51
|
+
interface RecordsResultBinding {
|
|
52
|
+
version: 1;
|
|
53
|
+
rubric: {
|
|
54
|
+
revision: number;
|
|
55
|
+
sha256: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export type ClassifySeverityRecordsResult = RecordsResultBinding & ({
|
|
59
|
+
status: "completed";
|
|
60
|
+
assessments: CanonicalSeverityAssessment[];
|
|
61
|
+
} | {
|
|
62
|
+
status: "unresolved";
|
|
63
|
+
assessments: [];
|
|
64
|
+
error: {
|
|
65
|
+
recordId: string;
|
|
66
|
+
code: "review_failed" | "invalid_assessment";
|
|
67
|
+
message: string;
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Classify immutable host-provided reports. No filesystem, auth, local model,
|
|
72
|
+
* repository access, retries, or persistence. The host owns those lifecycles.
|
|
73
|
+
*/
|
|
74
|
+
export declare function classifySeverityRecords(input: ClassifySeverityRecordsInput, options: ClassifySeverityRecordsOptions): Promise<ClassifySeverityRecordsResult>;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=classify-severity-records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify-severity-records.d.ts","sourceRoot":"","sources":["../src/classify-severity-records.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAwB9B,+EAA+E;AAC/E,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;kBA+BpC,CAAC;AAEZ,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,kCAAkC,CAC1C,CAAC;AAEF,MAAM,WAAW,mCAAmC;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,yB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C"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { SCAN_SEVERITIES } from "./scan-settings.js";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { abortable } from "./targets.js";
|
|
5
|
+
import { parseSeverityDecision, severityDecisionSchema, severityReviewInstructions, } from "./severity-review.js";
|
|
6
|
+
const text = z
|
|
7
|
+
.string()
|
|
8
|
+
.refine((value) => value.trim().length > 0, "Must not be blank.");
|
|
9
|
+
const digest = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
10
|
+
const revision = z.number().int().nonnegative();
|
|
11
|
+
const reportSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
findingId: text,
|
|
14
|
+
title: text,
|
|
15
|
+
summary: text,
|
|
16
|
+
occurrenceId: text.optional(),
|
|
17
|
+
severity: z
|
|
18
|
+
.object({
|
|
19
|
+
level: z.enum(SCAN_SEVERITIES),
|
|
20
|
+
rationale: z.string().optional(),
|
|
21
|
+
changeConditions: z.string().optional(),
|
|
22
|
+
})
|
|
23
|
+
.passthrough()
|
|
24
|
+
.optional(),
|
|
25
|
+
})
|
|
26
|
+
.passthrough();
|
|
27
|
+
/** Versioned input for repository-free classification of canonical records. */
|
|
28
|
+
export const classifySeverityRecordsInputSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
version: z.literal(1),
|
|
31
|
+
rubric: z
|
|
32
|
+
.object({
|
|
33
|
+
revision: revision.positive(),
|
|
34
|
+
markdown: text,
|
|
35
|
+
sha256: digest,
|
|
36
|
+
})
|
|
37
|
+
.strict(),
|
|
38
|
+
model: text,
|
|
39
|
+
effort: z.enum([
|
|
40
|
+
"minimal",
|
|
41
|
+
"low",
|
|
42
|
+
"medium",
|
|
43
|
+
"high",
|
|
44
|
+
"xhigh",
|
|
45
|
+
"max",
|
|
46
|
+
"ultra",
|
|
47
|
+
]),
|
|
48
|
+
records: z.array(z
|
|
49
|
+
.object({
|
|
50
|
+
id: text,
|
|
51
|
+
revision,
|
|
52
|
+
findingJson: text,
|
|
53
|
+
inputSha256: digest,
|
|
54
|
+
})
|
|
55
|
+
.strict()),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
function sha256(value) {
|
|
59
|
+
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Classify immutable host-provided reports. No filesystem, auth, local model,
|
|
63
|
+
* repository access, retries, or persistence. The host owns those lifecycles.
|
|
64
|
+
*/
|
|
65
|
+
export async function classifySeverityRecords(input, options) {
|
|
66
|
+
options.signal?.throwIfAborted();
|
|
67
|
+
const data = classifySeverityRecordsInputSchema.parse(structuredClone(input));
|
|
68
|
+
if (sha256(data.rubric.markdown) !== data.rubric.sha256)
|
|
69
|
+
throw new Error("Rubric SHA-256 does not match its exact UTF-8 Markdown.");
|
|
70
|
+
const ids = new Set();
|
|
71
|
+
for (const record of data.records) {
|
|
72
|
+
if (ids.has(record.id))
|
|
73
|
+
throw new Error("Canonical record IDs must be unique.");
|
|
74
|
+
ids.add(record.id);
|
|
75
|
+
if (sha256(record.findingJson) !== record.inputSha256)
|
|
76
|
+
throw new Error("Finding SHA-256 does not match its exact UTF-8 JSON.");
|
|
77
|
+
const report = reportSchema.parse(JSON.parse(record.findingJson));
|
|
78
|
+
if (report.findingId !== record.id)
|
|
79
|
+
throw new Error("The report findingId must equal its canonical record ID.");
|
|
80
|
+
}
|
|
81
|
+
const binding = {
|
|
82
|
+
version: 1,
|
|
83
|
+
rubric: { revision: data.rubric.revision, sha256: data.rubric.sha256 },
|
|
84
|
+
};
|
|
85
|
+
const assessments = [];
|
|
86
|
+
for (const record of data.records) {
|
|
87
|
+
options.signal?.throwIfAborted();
|
|
88
|
+
let response;
|
|
89
|
+
try {
|
|
90
|
+
response = await abortable(() => {
|
|
91
|
+
options.signal?.throwIfAborted();
|
|
92
|
+
return options.reviewRunner.run({
|
|
93
|
+
requestId: randomUUID(),
|
|
94
|
+
stage: "severity-classification",
|
|
95
|
+
model: data.model,
|
|
96
|
+
effort: data.effort,
|
|
97
|
+
trustedInstructions: severityReviewInstructions,
|
|
98
|
+
prompt: `{"rubric":${JSON.stringify([data.rubric.markdown])},"knowledgeBase":null,"finding":${record.findingJson}}`,
|
|
99
|
+
schema: z.toJSONSchema(severityDecisionSchema),
|
|
100
|
+
}, { signal: options.signal });
|
|
101
|
+
}, options.signal);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
options.signal?.throwIfAborted();
|
|
105
|
+
return {
|
|
106
|
+
...binding,
|
|
107
|
+
status: "unresolved",
|
|
108
|
+
assessments: [],
|
|
109
|
+
error: {
|
|
110
|
+
recordId: record.id,
|
|
111
|
+
code: "review_failed",
|
|
112
|
+
message: error instanceof Error ? error.message : "Host review failed.",
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
options.signal?.throwIfAborted();
|
|
117
|
+
try {
|
|
118
|
+
const { findingId: _findingId, ...decision } = parseSeverityDecision(response, record.id);
|
|
119
|
+
assessments.push({
|
|
120
|
+
...decision,
|
|
121
|
+
id: record.id,
|
|
122
|
+
revision: record.revision,
|
|
123
|
+
inputSha256: record.inputSha256,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
...binding,
|
|
129
|
+
status: "unresolved",
|
|
130
|
+
assessments: [],
|
|
131
|
+
error: {
|
|
132
|
+
recordId: record.id,
|
|
133
|
+
code: "invalid_assessment",
|
|
134
|
+
message: error instanceof Error ? error.message : "Invalid assessment.",
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { ...binding, status: "completed", assessments };
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=classify-severity-records.js.map
|