@openai/codex-security 0.8.1 → 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 +45 -57
- 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/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/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_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +187 -363
- 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_saved_results.py +0 -66
- 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 +120 -35
- 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 +68 -35
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
- 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 +414 -163
- package/dist/api.js.map +1 -1
- package/dist/auth.js +7 -2
- 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 +635 -266
- 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 +6 -2
- 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 +12 -5
- 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 +11 -3
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +48 -16
- 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 +44 -89
- 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 +11 -15
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +12 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +411 -184
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +15 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1238 -226
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +10 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +71 -51
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +13 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +124 -1
- 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 +7 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- 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 +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +512 -0
- package/dist/inspector-findings.js.map +1 -0
- 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 +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +94 -36
- 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 +5 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +110 -57
- 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 +37 -48
- 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 +48 -3
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +214 -39
- 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 +50 -88
- 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 +97 -106
- 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 +320 -481
- package/docs/dedupe-records.md +27 -4
- package/docs/findings-service.md +21 -8
- package/docs/hosted-scans.md +16 -1
- package/package.json +9 -10
- 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 -35
- package/dist/deduplication/records-protocol.js.map +0 -1
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CodexSecurityError } from "./errors.js";
|
|
3
|
+
import type { ExternalFinding, ExternalFindings } from "./external-findings.js";
|
|
4
|
+
import type { ImportSource } from "./external-import-models.js";
|
|
5
|
+
declare const privateFormat: z.ZodEnum<{
|
|
6
|
+
"endor.findings_json.v1": "endor.findings_json.v1";
|
|
7
|
+
"security.findings.v1": "security.findings.v1";
|
|
8
|
+
"wiz.vulnerability_json.v1": "wiz.vulnerability_json.v1";
|
|
9
|
+
}>;
|
|
10
|
+
export type PrivateImportFormat = z.infer<typeof privateFormat>;
|
|
11
|
+
declare const contextSchema: z.ZodObject<{
|
|
12
|
+
object: z.ZodLiteral<"security.finding_import_context">;
|
|
13
|
+
context_version: z.ZodString;
|
|
14
|
+
can_upload: z.ZodBoolean;
|
|
15
|
+
can_create_import_jobs: z.ZodBoolean;
|
|
16
|
+
can_read: z.ZodBoolean;
|
|
17
|
+
formats: z.ZodArray<z.ZodString>;
|
|
18
|
+
limits: z.ZodObject<{
|
|
19
|
+
max_direct_file_bytes: z.ZodInt;
|
|
20
|
+
max_record_bytes: z.ZodInt;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
declare const jobSchema: z.ZodObject<{
|
|
24
|
+
object: z.ZodLiteral<"security.finding_import_job">;
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
request_id: z.ZodUUID;
|
|
27
|
+
source: z.ZodObject<{
|
|
28
|
+
provider: z.ZodString;
|
|
29
|
+
source_key: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
input: z.ZodObject<{
|
|
32
|
+
type: z.ZodLiteral<"file">;
|
|
33
|
+
file_id: z.ZodString;
|
|
34
|
+
format: z.ZodEnum<{
|
|
35
|
+
"endor.findings_json.v1": "endor.findings_json.v1";
|
|
36
|
+
"security.findings.v1": "security.findings.v1";
|
|
37
|
+
"wiz.vulnerability_json.v1": "wiz.vulnerability_json.v1";
|
|
38
|
+
}>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
default_targets: z.ZodArray<z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"repository">;
|
|
42
|
+
repo_id: z.ZodString;
|
|
43
|
+
repo_connector_id: z.ZodString;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
status: z.ZodEnum<{
|
|
46
|
+
cancelled: "cancelled";
|
|
47
|
+
cancelling: "cancelling";
|
|
48
|
+
completed: "completed";
|
|
49
|
+
failed: "failed";
|
|
50
|
+
in_progress: "in_progress";
|
|
51
|
+
queued: "queued";
|
|
52
|
+
}>;
|
|
53
|
+
counts: z.ZodObject<{
|
|
54
|
+
total: z.ZodNullable<z.ZodInt>;
|
|
55
|
+
discovered: z.ZodInt;
|
|
56
|
+
created: z.ZodInt;
|
|
57
|
+
updated: z.ZodInt;
|
|
58
|
+
unchanged: z.ZodInt;
|
|
59
|
+
error: z.ZodInt;
|
|
60
|
+
unprocessed: z.ZodInt;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
poll_after_seconds: z.ZodNullable<z.ZodInt>;
|
|
63
|
+
error: z.ZodNullable<z.ZodObject<{
|
|
64
|
+
message: z.ZodString;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export type PrivateImportContext = z.infer<typeof contextSchema>;
|
|
68
|
+
export type PrivateImportJob = z.infer<typeof jobSchema>;
|
|
69
|
+
export declare function privateReport(findings: ExternalFinding[], limits: PrivateImportContext["limits"]): {
|
|
70
|
+
format: PrivateImportFormat;
|
|
71
|
+
bytes: string;
|
|
72
|
+
digest: string;
|
|
73
|
+
};
|
|
74
|
+
export declare function selectPrivateReport(selection: ExternalFindings, provider: string, path: string | undefined, context: PrivateImportContext, saved: string | undefined): Promise<ReturnType<typeof privateReport>>;
|
|
75
|
+
export declare function unsuccessfulJob(job: PrivateImportJob | undefined): boolean;
|
|
76
|
+
export declare function readPrivateCheckpoint(serialized: string, expected: {
|
|
77
|
+
format: PrivateImportFormat;
|
|
78
|
+
apiBaseUrl: string;
|
|
79
|
+
accountId: string;
|
|
80
|
+
contextVersion: string;
|
|
81
|
+
sha256: string;
|
|
82
|
+
source: ImportSource;
|
|
83
|
+
repository: {
|
|
84
|
+
id: string;
|
|
85
|
+
repo_connector_id: string;
|
|
86
|
+
};
|
|
87
|
+
}): {
|
|
88
|
+
format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
|
|
89
|
+
apiBaseUrl: string;
|
|
90
|
+
accountId: string;
|
|
91
|
+
contextVersion: string;
|
|
92
|
+
sha256: string;
|
|
93
|
+
source: {
|
|
94
|
+
provider: string;
|
|
95
|
+
source_key: string;
|
|
96
|
+
};
|
|
97
|
+
repository: {
|
|
98
|
+
id: string;
|
|
99
|
+
repo_connector_id: string;
|
|
100
|
+
};
|
|
101
|
+
uploadRequestId: string;
|
|
102
|
+
jobRequestId: string;
|
|
103
|
+
fileId?: string | undefined;
|
|
104
|
+
jobId?: string | undefined;
|
|
105
|
+
receipt?: {
|
|
106
|
+
object: "security.finding_import_job";
|
|
107
|
+
id: string;
|
|
108
|
+
request_id: string;
|
|
109
|
+
source: {
|
|
110
|
+
provider: string;
|
|
111
|
+
source_key: string;
|
|
112
|
+
};
|
|
113
|
+
input: {
|
|
114
|
+
type: "file";
|
|
115
|
+
file_id: string;
|
|
116
|
+
format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
|
|
117
|
+
};
|
|
118
|
+
default_targets: {
|
|
119
|
+
type: "repository";
|
|
120
|
+
repo_id: string;
|
|
121
|
+
repo_connector_id: string;
|
|
122
|
+
}[];
|
|
123
|
+
status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
|
|
124
|
+
counts: {
|
|
125
|
+
total: number | null;
|
|
126
|
+
discovered: number;
|
|
127
|
+
created: number;
|
|
128
|
+
updated: number;
|
|
129
|
+
unchanged: number;
|
|
130
|
+
error: number;
|
|
131
|
+
unprocessed: number;
|
|
132
|
+
};
|
|
133
|
+
poll_after_seconds: number | null;
|
|
134
|
+
error: {
|
|
135
|
+
message: string;
|
|
136
|
+
} | null;
|
|
137
|
+
} | undefined;
|
|
138
|
+
previousReceipt?: {
|
|
139
|
+
object: "security.finding_import_job";
|
|
140
|
+
id: string;
|
|
141
|
+
request_id: string;
|
|
142
|
+
source: {
|
|
143
|
+
provider: string;
|
|
144
|
+
source_key: string;
|
|
145
|
+
};
|
|
146
|
+
input: {
|
|
147
|
+
type: "file";
|
|
148
|
+
file_id: string;
|
|
149
|
+
format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
|
|
150
|
+
};
|
|
151
|
+
default_targets: {
|
|
152
|
+
type: "repository";
|
|
153
|
+
repo_id: string;
|
|
154
|
+
repo_connector_id: string;
|
|
155
|
+
}[];
|
|
156
|
+
status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
|
|
157
|
+
counts: {
|
|
158
|
+
total: number | null;
|
|
159
|
+
discovered: number;
|
|
160
|
+
created: number;
|
|
161
|
+
updated: number;
|
|
162
|
+
unchanged: number;
|
|
163
|
+
error: number;
|
|
164
|
+
unprocessed: number;
|
|
165
|
+
};
|
|
166
|
+
poll_after_seconds: number | null;
|
|
167
|
+
error: {
|
|
168
|
+
message: string;
|
|
169
|
+
} | null;
|
|
170
|
+
} | undefined;
|
|
171
|
+
} | undefined;
|
|
172
|
+
export declare class PrivateImportRequestError extends CodexSecurityError {
|
|
173
|
+
readonly status: number;
|
|
174
|
+
readonly code: string | undefined;
|
|
175
|
+
constructor(status: number, code: string | undefined, message: string);
|
|
176
|
+
}
|
|
177
|
+
export declare function privateImportClient(base: string, credentials: {
|
|
178
|
+
access_token: string;
|
|
179
|
+
account_id: string;
|
|
180
|
+
}, fetch: (url: string, options: RequestInit) => Promise<Response>, signal?: AbortSignal): {
|
|
181
|
+
context(): Promise<{
|
|
182
|
+
object: "security.finding_import_context";
|
|
183
|
+
context_version: string;
|
|
184
|
+
can_upload: boolean;
|
|
185
|
+
can_create_import_jobs: boolean;
|
|
186
|
+
can_read: boolean;
|
|
187
|
+
formats: string[];
|
|
188
|
+
limits: {
|
|
189
|
+
max_direct_file_bytes: number;
|
|
190
|
+
max_record_bytes: number;
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
upload(input: {
|
|
194
|
+
requestId: string;
|
|
195
|
+
contextVersion: string;
|
|
196
|
+
bytes: string;
|
|
197
|
+
digest: string;
|
|
198
|
+
recovering: boolean;
|
|
199
|
+
}): Promise<string>;
|
|
200
|
+
job(input: {
|
|
201
|
+
requestId: string;
|
|
202
|
+
contextVersion: string;
|
|
203
|
+
fileId: string;
|
|
204
|
+
format: PrivateImportFormat;
|
|
205
|
+
source: ImportSource;
|
|
206
|
+
repository: {
|
|
207
|
+
id: string;
|
|
208
|
+
repo_connector_id: string;
|
|
209
|
+
};
|
|
210
|
+
jobId?: string;
|
|
211
|
+
}, accepted: (id: string) => Promise<void>): Promise<{
|
|
212
|
+
object: "security.finding_import_job";
|
|
213
|
+
id: string;
|
|
214
|
+
request_id: string;
|
|
215
|
+
source: {
|
|
216
|
+
provider: string;
|
|
217
|
+
source_key: string;
|
|
218
|
+
};
|
|
219
|
+
input: {
|
|
220
|
+
type: "file";
|
|
221
|
+
file_id: string;
|
|
222
|
+
format: "endor.findings_json.v1" | "security.findings.v1" | "wiz.vulnerability_json.v1";
|
|
223
|
+
};
|
|
224
|
+
default_targets: {
|
|
225
|
+
type: "repository";
|
|
226
|
+
repo_id: string;
|
|
227
|
+
repo_connector_id: string;
|
|
228
|
+
}[];
|
|
229
|
+
status: "cancelled" | "cancelling" | "completed" | "failed" | "in_progress" | "queued";
|
|
230
|
+
counts: {
|
|
231
|
+
total: number | null;
|
|
232
|
+
discovered: number;
|
|
233
|
+
created: number;
|
|
234
|
+
updated: number;
|
|
235
|
+
unchanged: number;
|
|
236
|
+
error: number;
|
|
237
|
+
unprocessed: number;
|
|
238
|
+
};
|
|
239
|
+
poll_after_seconds: number | null;
|
|
240
|
+
error: {
|
|
241
|
+
message: string;
|
|
242
|
+
} | null;
|
|
243
|
+
}>;
|
|
244
|
+
};
|
|
245
|
+
export {};
|
|
246
|
+
//# sourceMappingURL=private-finding-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-finding-import.d.ts","sourceRoot":"","sources":["../src/private-finding-import.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { hash } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { open } from "node:fs/promises";
|
|
4
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { CodexSecurityError } from "./errors.js";
|
|
7
|
+
import { canonicalJson, isRecord } from "./record.js";
|
|
8
|
+
const structuredFormat = "security.findings.v1";
|
|
9
|
+
const privateFormat = z.enum([
|
|
10
|
+
structuredFormat,
|
|
11
|
+
"endor.findings_json.v1",
|
|
12
|
+
"wiz.vulnerability_json.v1",
|
|
13
|
+
]);
|
|
14
|
+
const fileId = z.string().regex(/^aifile_[0-9a-f]{32}$/u);
|
|
15
|
+
const contextSchema = z.object({
|
|
16
|
+
object: z.literal("security.finding_import_context"),
|
|
17
|
+
context_version: z.string().min(1),
|
|
18
|
+
can_upload: z.boolean(),
|
|
19
|
+
can_create_import_jobs: z.boolean(),
|
|
20
|
+
can_read: z.boolean(),
|
|
21
|
+
formats: z.array(z.string()),
|
|
22
|
+
limits: z.object({
|
|
23
|
+
max_direct_file_bytes: z.int().positive(),
|
|
24
|
+
max_record_bytes: z.int().positive(),
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
const fileSchema = z.object({
|
|
28
|
+
id: fileId,
|
|
29
|
+
object: z.literal("security.finding_import_file"),
|
|
30
|
+
purpose: z.literal("report"),
|
|
31
|
+
sha256: z.string(),
|
|
32
|
+
bytes: z.int().positive(),
|
|
33
|
+
});
|
|
34
|
+
const jobSchema = z.object({
|
|
35
|
+
object: z.literal("security.finding_import_job"),
|
|
36
|
+
id: z.string().regex(/^import_[0-9a-f]{32}$/u),
|
|
37
|
+
request_id: z.uuid(),
|
|
38
|
+
source: z.object({ provider: z.string(), source_key: z.string() }),
|
|
39
|
+
input: z.object({
|
|
40
|
+
type: z.literal("file"),
|
|
41
|
+
file_id: fileId,
|
|
42
|
+
format: privateFormat,
|
|
43
|
+
}),
|
|
44
|
+
default_targets: z.array(z.object({
|
|
45
|
+
type: z.literal("repository"),
|
|
46
|
+
repo_id: z.string(),
|
|
47
|
+
repo_connector_id: z.string(),
|
|
48
|
+
})),
|
|
49
|
+
status: z.enum([
|
|
50
|
+
"queued",
|
|
51
|
+
"in_progress",
|
|
52
|
+
"cancelling",
|
|
53
|
+
"completed",
|
|
54
|
+
"failed",
|
|
55
|
+
"cancelled",
|
|
56
|
+
]),
|
|
57
|
+
counts: z.object({
|
|
58
|
+
total: z.int().nonnegative().nullable(),
|
|
59
|
+
discovered: z.int().nonnegative(),
|
|
60
|
+
created: z.int().nonnegative(),
|
|
61
|
+
updated: z.int().nonnegative(),
|
|
62
|
+
unchanged: z.int().nonnegative(),
|
|
63
|
+
error: z.int().nonnegative(),
|
|
64
|
+
unprocessed: z.int().nonnegative(),
|
|
65
|
+
}),
|
|
66
|
+
poll_after_seconds: z.int().positive().nullable(),
|
|
67
|
+
error: z.object({ message: z.string() }).nullable(),
|
|
68
|
+
});
|
|
69
|
+
export function privateReport(findings, limits) {
|
|
70
|
+
if (findings.length > 10_000)
|
|
71
|
+
throw new CodexSecurityError("A structured report accepts up to 10,000 findings. Split this selection.");
|
|
72
|
+
const records = findings.map(({ source_finding_id, evidence }) => {
|
|
73
|
+
if (source_finding_id !== source_finding_id.trim())
|
|
74
|
+
throw new CodexSecurityError("A private source finding ID cannot have leading or trailing whitespace.");
|
|
75
|
+
const record = {
|
|
76
|
+
source_finding_id,
|
|
77
|
+
evidence: {
|
|
78
|
+
...evidence,
|
|
79
|
+
severity: evidence.severity === "unknown" ? null : evidence.severity,
|
|
80
|
+
locations: evidence.locations?.map(({ path, line }, index) => ({
|
|
81
|
+
path,
|
|
82
|
+
start_line: line,
|
|
83
|
+
...(index === 0 && evidence.details?.code?.end_line != null
|
|
84
|
+
? { end_line: evidence.details.code.end_line }
|
|
85
|
+
: {}),
|
|
86
|
+
})),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
if (Buffer.byteLength(canonicalJson(record)) > limits.max_record_bytes)
|
|
90
|
+
throw new CodexSecurityError(`Finding ${JSON.stringify(source_finding_id)} exceeds the private import record limit.`);
|
|
91
|
+
return record;
|
|
92
|
+
});
|
|
93
|
+
const bytes = canonicalJson({ format: structuredFormat, findings: records });
|
|
94
|
+
if (Buffer.byteLength(bytes) > limits.max_direct_file_bytes)
|
|
95
|
+
throw new CodexSecurityError("The selected report exceeds the Cloud direct-upload limit. Split this selection.");
|
|
96
|
+
return {
|
|
97
|
+
format: structuredFormat,
|
|
98
|
+
bytes,
|
|
99
|
+
digest: hash("sha256", bytes),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const endorExport = z.strictObject({
|
|
103
|
+
list: z.strictObject({
|
|
104
|
+
objects: z.array(z.unknown()),
|
|
105
|
+
response: z
|
|
106
|
+
.strictObject({
|
|
107
|
+
next_page_id: z.literal(["", null]).optional(),
|
|
108
|
+
next_page_token: z.literal(["", "0", 0, null]).optional(),
|
|
109
|
+
total_size: z.union([z.string(), z.number()]).optional(),
|
|
110
|
+
})
|
|
111
|
+
.optional(),
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
const wizExport = z.strictObject({
|
|
115
|
+
vulnerabilityFindings: z.strictObject({
|
|
116
|
+
nodes: z.array(z.unknown()),
|
|
117
|
+
pageInfo: z
|
|
118
|
+
.strictObject({
|
|
119
|
+
hasNextPage: z.literal(false).optional(),
|
|
120
|
+
hasPreviousPage: z.literal(false).optional(),
|
|
121
|
+
startCursor: z.string().nullable().optional(),
|
|
122
|
+
endCursor: z.string().nullable().optional(),
|
|
123
|
+
})
|
|
124
|
+
.optional(),
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
// Only complete, known envelopes can be sent byte for byte. Unreviewed sibling
|
|
128
|
+
// collections, metadata or partial pages keep the normalized projection.
|
|
129
|
+
function nativeRecords(payload, provider) {
|
|
130
|
+
if (provider === "wiz" && Array.isArray(payload))
|
|
131
|
+
return payload;
|
|
132
|
+
if (!isRecord(payload))
|
|
133
|
+
return;
|
|
134
|
+
if (provider === "endor") {
|
|
135
|
+
if (isRecord(payload["spec"]))
|
|
136
|
+
return [payload];
|
|
137
|
+
return endorExport.safeParse(payload).data?.list.objects;
|
|
138
|
+
}
|
|
139
|
+
if (typeof payload["id"] === "string")
|
|
140
|
+
return [payload];
|
|
141
|
+
const data = Object.keys(payload).length === 1 && "data" in payload
|
|
142
|
+
? payload["data"]
|
|
143
|
+
: payload;
|
|
144
|
+
return wizExport.safeParse(data).data?.vulnerabilityFindings.nodes;
|
|
145
|
+
}
|
|
146
|
+
export async function selectPrivateReport(selection, provider, path, context, saved) {
|
|
147
|
+
const checkpoint = saved === undefined ? undefined : checkpointSchema.parse(JSON.parse(saved));
|
|
148
|
+
const originalFormat = checkpoint?.contextVersion === context.context_version
|
|
149
|
+
? checkpoint.format
|
|
150
|
+
: undefined;
|
|
151
|
+
const format = provider === "endor"
|
|
152
|
+
? "endor.findings_json.v1"
|
|
153
|
+
: provider === "wiz"
|
|
154
|
+
? "wiz.vulnerability_json.v1"
|
|
155
|
+
: undefined;
|
|
156
|
+
if (format &&
|
|
157
|
+
path &&
|
|
158
|
+
selection.excluded.length === 0 &&
|
|
159
|
+
selection.read <= 10_000 &&
|
|
160
|
+
selection.findings.length === selection.read &&
|
|
161
|
+
(originalFormat
|
|
162
|
+
? originalFormat === format
|
|
163
|
+
: context.formats.includes(format))) {
|
|
164
|
+
const handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
165
|
+
let bytes;
|
|
166
|
+
try {
|
|
167
|
+
const info = await handle.stat();
|
|
168
|
+
if (info.isFile() &&
|
|
169
|
+
info.size > 0 &&
|
|
170
|
+
info.size <= context.limits.max_direct_file_bytes) {
|
|
171
|
+
const buffer = Buffer.alloc(info.size + 1);
|
|
172
|
+
let count = 0;
|
|
173
|
+
while (count < buffer.length) {
|
|
174
|
+
const { bytesRead } = await handle.read(buffer, count, buffer.length - count);
|
|
175
|
+
if (bytesRead === 0)
|
|
176
|
+
break;
|
|
177
|
+
count += bytesRead;
|
|
178
|
+
}
|
|
179
|
+
if (count === info.size) {
|
|
180
|
+
try {
|
|
181
|
+
bytes = new TextDecoder("utf-8", {
|
|
182
|
+
fatal: true,
|
|
183
|
+
ignoreBOM: true,
|
|
184
|
+
}).decode(buffer.subarray(0, count));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
/* Binary exports use the normalized selection. */
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
await handle.close();
|
|
194
|
+
}
|
|
195
|
+
if (bytes !== undefined) {
|
|
196
|
+
let payload;
|
|
197
|
+
try {
|
|
198
|
+
payload = JSON.parse(bytes.replace(/^\uFEFF/u, ""));
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
/* JSONL and other exports use the normalized selection. */
|
|
202
|
+
}
|
|
203
|
+
const records = nativeRecords(payload, provider);
|
|
204
|
+
if (records &&
|
|
205
|
+
records.length === selection.findings.length &&
|
|
206
|
+
records.every((raw, index) => {
|
|
207
|
+
const reviewed = selection.findings[index];
|
|
208
|
+
if (!isRecord(raw))
|
|
209
|
+
return false;
|
|
210
|
+
const record = canonicalJson(raw);
|
|
211
|
+
return (raw[provider === "endor" ? "uuid" : "id"] ===
|
|
212
|
+
reviewed.source_finding_id &&
|
|
213
|
+
reviewed.source_finding_id === reviewed.source_finding_id.trim() &&
|
|
214
|
+
reviewed.evidence.source_data != null &&
|
|
215
|
+
record === canonicalJson(reviewed.evidence.source_data) &&
|
|
216
|
+
Buffer.byteLength(record) <= context.limits.max_record_bytes);
|
|
217
|
+
}))
|
|
218
|
+
return { format, bytes, digest: hash("sha256", bytes) };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (originalFormat && originalFormat !== structuredFormat)
|
|
222
|
+
throw new CodexSecurityError("The original native report is required to resume this private import.");
|
|
223
|
+
return privateReport(selection.findings, context.limits);
|
|
224
|
+
}
|
|
225
|
+
const checkpointSchema = z.object({
|
|
226
|
+
format: privateFormat.default(structuredFormat),
|
|
227
|
+
apiBaseUrl: z.string(),
|
|
228
|
+
accountId: z.string(),
|
|
229
|
+
contextVersion: z.string(),
|
|
230
|
+
sha256: z.string(),
|
|
231
|
+
source: z.object({ provider: z.string(), source_key: z.string() }),
|
|
232
|
+
repository: z.object({ id: z.string(), repo_connector_id: z.string() }),
|
|
233
|
+
uploadRequestId: z.uuid(),
|
|
234
|
+
jobRequestId: z.uuid(),
|
|
235
|
+
fileId: fileId.optional(),
|
|
236
|
+
jobId: jobSchema.shape.id.optional(),
|
|
237
|
+
receipt: jobSchema
|
|
238
|
+
.refine((job) => job.status === "completed" || unsuccessfulJob(job))
|
|
239
|
+
.optional(),
|
|
240
|
+
previousReceipt: jobSchema.refine(unsuccessfulJob).optional(),
|
|
241
|
+
});
|
|
242
|
+
export function unsuccessfulJob(job) {
|
|
243
|
+
return job?.status === "failed" || job?.status === "cancelled";
|
|
244
|
+
}
|
|
245
|
+
export function readPrivateCheckpoint(serialized, expected) {
|
|
246
|
+
const checkpoint = checkpointSchema.parse(JSON.parse(serialized));
|
|
247
|
+
const { uploadRequestId, jobRequestId, fileId, jobId, receipt, previousReceipt, contextVersion, format, sha256, ...scope } = checkpoint;
|
|
248
|
+
const { contextVersion: currentContext, format: selectedFormat, sha256: selectedDigest, ...selectedScope } = expected;
|
|
249
|
+
const sameContext = contextVersion === currentContext;
|
|
250
|
+
if (canonicalJson(scope) !== canonicalJson(selectedScope) ||
|
|
251
|
+
(sameContext && (format !== selectedFormat || sha256 !== selectedDigest)) ||
|
|
252
|
+
(jobId && !fileId) ||
|
|
253
|
+
[receipt, previousReceipt].some((job) => job &&
|
|
254
|
+
(job.input.format !== format ||
|
|
255
|
+
canonicalJson(job.source) !== canonicalJson(scope.source) ||
|
|
256
|
+
job.default_targets.length !== 1 ||
|
|
257
|
+
job.default_targets[0]?.repo_id !== scope.repository.id ||
|
|
258
|
+
job.default_targets[0]?.repo_connector_id !==
|
|
259
|
+
scope.repository.repo_connector_id)) ||
|
|
260
|
+
(receipt &&
|
|
261
|
+
(receipt.id !== jobId ||
|
|
262
|
+
receipt.request_id !== jobRequestId ||
|
|
263
|
+
receipt.input.file_id !== fileId)) ||
|
|
264
|
+
uploadRequestId === jobRequestId)
|
|
265
|
+
throw new CodexSecurityError("Saved private import does not match this account, repository or report.");
|
|
266
|
+
return sameContext ? checkpoint : undefined;
|
|
267
|
+
}
|
|
268
|
+
export class PrivateImportRequestError extends CodexSecurityError {
|
|
269
|
+
status;
|
|
270
|
+
code;
|
|
271
|
+
constructor(status, code, message) {
|
|
272
|
+
super(message);
|
|
273
|
+
this.status = status;
|
|
274
|
+
this.code = code;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
export function privateImportClient(base, credentials, fetch, signal) {
|
|
278
|
+
async function request(path, body) {
|
|
279
|
+
const timeout = AbortSignal.timeout(body === undefined ? 30_000 : 60_000);
|
|
280
|
+
const response = await fetch(`${base}/finding-imports/${path}`, {
|
|
281
|
+
method: body === undefined ? "GET" : "POST",
|
|
282
|
+
body,
|
|
283
|
+
redirect: "error",
|
|
284
|
+
headers: {
|
|
285
|
+
Authorization: `Bearer ${credentials.access_token}`,
|
|
286
|
+
"ChatGPT-Account-ID": credentials.account_id,
|
|
287
|
+
Accept: "application/json",
|
|
288
|
+
...(typeof body === "string"
|
|
289
|
+
? { "Content-Type": "application/json" }
|
|
290
|
+
: {}),
|
|
291
|
+
},
|
|
292
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
293
|
+
});
|
|
294
|
+
if (!response.ok) {
|
|
295
|
+
const payload = await response.json().catch(() => undefined);
|
|
296
|
+
const error = z
|
|
297
|
+
.object({
|
|
298
|
+
error: z.object({ code: z.string(), message: z.string().optional() }),
|
|
299
|
+
})
|
|
300
|
+
.safeParse(payload);
|
|
301
|
+
const detail = error.data?.error;
|
|
302
|
+
throw new PrivateImportRequestError(response.status, detail?.code, `Private import failed (HTTP ${response.status}): ${detail?.message ?? detail?.code ?? response.statusText}`);
|
|
303
|
+
}
|
|
304
|
+
return response;
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
async context() {
|
|
308
|
+
return contextSchema.parse(await (await request("context")).json());
|
|
309
|
+
},
|
|
310
|
+
async upload(input) {
|
|
311
|
+
let response;
|
|
312
|
+
if (input.recovering) {
|
|
313
|
+
try {
|
|
314
|
+
response = await request(`file-requests/${input.requestId}`);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
if (!(error instanceof PrivateImportRequestError) ||
|
|
318
|
+
(error.status !== 404 &&
|
|
319
|
+
!(error.status === 409 && error.code === "upload_retryable")))
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!response) {
|
|
324
|
+
const form = new FormData();
|
|
325
|
+
form.set("request_id", input.requestId);
|
|
326
|
+
form.set("context_version", input.contextVersion);
|
|
327
|
+
form.set("purpose", "report");
|
|
328
|
+
form.set("file", new Blob([input.bytes], { type: "application/json" }), "findings.json");
|
|
329
|
+
response = await request("files", form);
|
|
330
|
+
}
|
|
331
|
+
const file = fileSchema.parse(await response.json());
|
|
332
|
+
if (file.sha256 !== input.digest ||
|
|
333
|
+
file.bytes !== Buffer.byteLength(input.bytes))
|
|
334
|
+
throw new CodexSecurityError("The uploaded file does not match the reviewed report.");
|
|
335
|
+
return file.id;
|
|
336
|
+
},
|
|
337
|
+
async job(input, accepted) {
|
|
338
|
+
let id = input.jobId;
|
|
339
|
+
let response = id
|
|
340
|
+
? await request(`jobs/${id}`)
|
|
341
|
+
: await request("jobs", JSON.stringify({
|
|
342
|
+
request_id: input.requestId,
|
|
343
|
+
context_version: input.contextVersion,
|
|
344
|
+
source: input.source,
|
|
345
|
+
input: {
|
|
346
|
+
type: "file",
|
|
347
|
+
file_id: input.fileId,
|
|
348
|
+
format: input.format,
|
|
349
|
+
},
|
|
350
|
+
default_targets: [
|
|
351
|
+
{
|
|
352
|
+
type: "repository",
|
|
353
|
+
repo_id: input.repository.id,
|
|
354
|
+
repo_connector_id: input.repository.repo_connector_id,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
}));
|
|
358
|
+
for (;;) {
|
|
359
|
+
const job = jobSchema.parse(await response.json());
|
|
360
|
+
if ((id !== undefined && job.id !== id) ||
|
|
361
|
+
job.request_id !== input.requestId ||
|
|
362
|
+
job.input.file_id !== input.fileId ||
|
|
363
|
+
job.input.format !== input.format ||
|
|
364
|
+
job.source.provider !== input.source.provider ||
|
|
365
|
+
job.source.source_key !== input.source.source_key ||
|
|
366
|
+
job.default_targets.length !== 1 ||
|
|
367
|
+
job.default_targets[0]?.repo_id !== input.repository.id ||
|
|
368
|
+
job.default_targets[0]?.repo_connector_id !==
|
|
369
|
+
input.repository.repo_connector_id)
|
|
370
|
+
throw new CodexSecurityError("Cloud returned a job for a different private import.");
|
|
371
|
+
if (job.status === "completed" ||
|
|
372
|
+
job.status === "failed" ||
|
|
373
|
+
job.status === "cancelled")
|
|
374
|
+
return job;
|
|
375
|
+
if (!id) {
|
|
376
|
+
id = job.id;
|
|
377
|
+
await accepted(id);
|
|
378
|
+
}
|
|
379
|
+
const retry = response.headers.get("Retry-After");
|
|
380
|
+
const seconds = retry === null ? 0 : Number(retry);
|
|
381
|
+
await delay(Math.max(Number.isFinite(seconds) ? seconds : 0, job.poll_after_seconds ?? 1) * 1000, undefined, { signal });
|
|
382
|
+
response = await request(`jobs/${id}`);
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=private-finding-import.js.map
|