@openai/codex-security 0.8.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -746
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +7 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- 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/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/baseline-auditor.md +18 -0
- package/_bundled_plugin/references/core-scan.md +5 -42
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/focused-investigator.md +13 -0
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/references/scan-prologue.md +2 -2
- package/_bundled_plugin/references/scan-runtime.md +4 -2
- package/_bundled_plugin/references/security-guidance.md +14 -1
- package/_bundled_plugin/references/validate-scan-findings.md +3 -0
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +192 -352
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +182 -230
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +55 -16
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +37 -1
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +9 -2
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +582 -20
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +100 -23
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +91 -7
- package/_bundled_plugin/scripts/workbench_cli.py +54 -14
- package/_bundled_plugin/scripts/workbench_constants.py +12 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +562 -303
- package/_bundled_plugin/scripts/workbench_feedback.py +57 -11
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +238 -41
- package/_bundled_plugin/scripts/workbench_progress.py +169 -4
- package/_bundled_plugin/scripts/workbench_publication.py +16 -13
- package/_bundled_plugin/scripts/workbench_remediation.py +155 -2
- package/_bundled_plugin/scripts/workbench_saved_results.py +176 -81
- package/_bundled_plugin/scripts/workbench_scan_history.py +398 -174
- package/_bundled_plugin/scripts/workbench_scan_start.py +224 -31
- package/_bundled_plugin/scripts/workbench_scan_usage.py +675 -73
- package/_bundled_plugin/scripts/workbench_schema.py +258 -63
- package/_bundled_plugin/scripts/workbench_setup.py +14 -2
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +594 -136
- package/_bundled_plugin/scripts/workbench_target_state.py +1110 -21
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +77 -35
- package/_bundled_plugin/shared/workbench-migrations.json +100 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +2 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -153
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +409 -0
- package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
- package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
- package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
- package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
- package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
- package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +45 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1192 -427
- package/dist/api.js.map +1 -1
- package/dist/armorcode-findings.d.ts +9 -0
- package/dist/armorcode-findings.d.ts.map +1 -0
- package/dist/armorcode-findings.js +145 -0
- package/dist/armorcode-findings.js.map +1 -0
- package/dist/artifact-export.d.ts +2 -0
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +29 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +6 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +37 -18
- package/dist/auth.js.map +1 -1
- package/dist/batch-cost.d.ts +18 -0
- package/dist/batch-cost.d.ts.map +1 -0
- package/dist/batch-cost.js +41 -0
- package/dist/batch-cost.js.map +1 -0
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts +1 -1
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +24 -22
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/bundled-plugin.d.ts +4 -0
- package/dist/bundled-plugin.d.ts.map +1 -0
- package/dist/bundled-plugin.js +23 -0
- package/dist/bundled-plugin.js.map +1 -0
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-scan-severity.d.ts +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +11 -3
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +11 -10
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-argument.d.ts +4 -0
- package/dist/cli-argument.d.ts.map +1 -0
- package/dist/cli-argument.js +17 -0
- package/dist/cli-argument.js.map +1 -0
- package/dist/cli-help.d.ts +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +71 -29
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-hook.d.ts +3 -0
- package/dist/cli-hook.d.ts.map +1 -0
- package/dist/cli-hook.js +87 -0
- package/dist/cli-hook.js.map +1 -0
- package/dist/cli-integrations.d.ts +13 -0
- package/dist/cli-integrations.d.ts.map +1 -0
- package/dist/cli-integrations.js +333 -0
- package/dist/cli-integrations.js.map +1 -0
- package/dist/cli-mcp.d.ts +15 -0
- package/dist/cli-mcp.d.ts.map +1 -0
- package/dist/cli-mcp.js +178 -0
- package/dist/cli-mcp.js.map +1 -0
- package/dist/cli-token-view.d.ts +10 -0
- package/dist/cli-token-view.d.ts.map +1 -0
- package/dist/cli-token-view.js +41 -0
- package/dist/cli-token-view.js.map +1 -0
- package/dist/cli.d.ts +16 -8
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3382 -2017
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +35 -33
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +6 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +19 -0
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/command-words.d.ts +3 -0
- package/dist/command-words.d.ts.map +1 -0
- package/dist/command-words.js +46 -0
- package/dist/command-words.js.map +1 -0
- package/dist/component-scan.d.ts +19 -4
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +67 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +130 -67
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +149 -19
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +484 -149
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.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 +29 -19
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/local.d.ts +4 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +9 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +26 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +5 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +24 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +44 -19
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +86 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +4 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -4
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +3 -0
- package/dist/executable-path.d.ts.map +1 -1
- package/dist/executable-path.js +26 -0
- package/dist/executable-path.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +19 -7
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +69 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +537 -108
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +13 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +895 -1142
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +21 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +130 -68
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +54 -2
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +8 -12
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +51 -184
- 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/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +18 -8
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +73 -316
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-remediation.d.ts +1 -0
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +23 -3
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +52 -86
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +102 -32
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts +11 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -2
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +8 -5
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +10 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +217 -102
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +5 -2
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +54 -33
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +99 -9
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +116 -152
- package/dist/private-finding-import.js.map +1 -1
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +53 -13
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +7 -2
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +42 -20
- package/dist/prompt-files.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +12 -10
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publication.d.ts +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +1 -5
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +3 -51
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +6 -8
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +54 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1084 -256
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +7 -1
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +269 -114
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-archive-path.d.ts +2 -0
- package/dist/scan-archive-path.d.ts.map +1 -0
- package/dist/scan-archive-path.js +5 -0
- package/dist/scan-archive-path.js.map +1 -0
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +66 -17
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +7 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +92 -43
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +24 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +34 -28
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +131 -78
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +25 -13
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +216 -97
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +26 -6
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +72 -42
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +157 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +766 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +9 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +90 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +59 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +879 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-findings.d.ts +1 -1
- package/dist/sonar-findings.d.ts.map +1 -1
- package/dist/sonar-findings.js +2 -4
- package/dist/sonar-findings.js.map +1 -1
- package/dist/sonar-import.d.ts +3 -0
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +30 -34
- package/dist/sonar-import.js.map +1 -1
- package/dist/stored-finding-projection.d.ts +6 -0
- package/dist/stored-finding-projection.d.ts.map +1 -0
- package/dist/stored-finding-projection.js +104 -0
- package/dist/stored-finding-projection.js.map +1 -0
- package/dist/stored-findings-publication.d.ts +23 -0
- package/dist/stored-findings-publication.d.ts.map +1 -0
- package/dist/stored-findings-publication.js +169 -0
- package/dist/stored-findings-publication.js.map +1 -0
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +131 -42
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +6 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +424 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/trusted-executable.d.ts +6 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +140 -37
- package/dist/trusted-executable.js.map +1 -1
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +1 -1
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +19 -6
- package/dist/veracode-findings.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +184 -32
- package/dist/version.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +6 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +65 -89
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +853 -639
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +84 -44
- package/docs/hosted-remediation.md +27 -11
- package/docs/hosted-scans.md +50 -42
- package/docs/sdk.md +903 -0
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +23 -16
- package/schemas/external-findings.schema.json +4 -1
- 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/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/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
- package/dist/reader-selection.d.ts +0 -13
- package/dist/reader-selection.d.ts.map +0 -1
- package/dist/reader-selection.js +0 -81
- package/dist/reader-selection.js.map +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { isRecord } from "./record.js";
|
|
2
|
+
import { requiredText, text } from "./scanner-import.js";
|
|
3
|
+
import { checkmarxOneId } from "./checkmarx-one.js";
|
|
4
|
+
import { checkmarxResultViewer, checkmarxXmlId, checkmarxXmlInstance, checkmarxXmlScope, } from "./checkmarx-xml.js";
|
|
5
|
+
import { declaredScannerRepositoryUrl, repositoryScopeValidator, } from "./scanner-repository-url.js";
|
|
6
|
+
const nativeId = /^checkmarx-(?:one|cxsast):[a-f0-9]{64}$/u;
|
|
7
|
+
function checkmarxFormat(value) {
|
|
8
|
+
return value === "cxsast-xml" || value === "checkmarx-one-json";
|
|
9
|
+
}
|
|
10
|
+
function scanKey(value, xml) {
|
|
11
|
+
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu;
|
|
12
|
+
return !xml && typeof value === "string" && uuid.test(value)
|
|
13
|
+
? value.toLowerCase()
|
|
14
|
+
: value;
|
|
15
|
+
}
|
|
16
|
+
/** A native payload can verify its occurrence ID. A projection can still identify its source. */
|
|
17
|
+
function checkmarxSource({ source_finding_id: id, evidence }, provider) {
|
|
18
|
+
const data = evidence.source_data;
|
|
19
|
+
const format = data?.["format"];
|
|
20
|
+
if (checkmarxFormat(format))
|
|
21
|
+
return format;
|
|
22
|
+
const scanner = evidence.details?.scanner_origin;
|
|
23
|
+
const projected = nativeId.test(id) ||
|
|
24
|
+
scanner === "CxSAST" ||
|
|
25
|
+
scanner === "Checkmarx One SAST" ||
|
|
26
|
+
Boolean(checkmarxResultViewer(data));
|
|
27
|
+
if (data &&
|
|
28
|
+
(provider === "checkmarx" || projected || "sourceRepositoryUrl" in data)) {
|
|
29
|
+
const row = data["row"];
|
|
30
|
+
if (isRecord(row) && row["type"] === "sast" && "similarityId" in row)
|
|
31
|
+
return "checkmarx-one-json";
|
|
32
|
+
const path = data["path"];
|
|
33
|
+
if ("projectId" in data && isRecord(path) && "SimilarityId" in path)
|
|
34
|
+
return "cxsast-xml";
|
|
35
|
+
}
|
|
36
|
+
if (projected)
|
|
37
|
+
return "projection";
|
|
38
|
+
}
|
|
39
|
+
const mismatch = "Checkmarx finding does not match the retained report format, scan or project.";
|
|
40
|
+
/** Compare the claims present across the whole batch, including projected SDK rows. */
|
|
41
|
+
function checkBatchScope(findings, formats, report) {
|
|
42
|
+
const claims = new Map();
|
|
43
|
+
function claim(key, value) {
|
|
44
|
+
if (value == null)
|
|
45
|
+
return;
|
|
46
|
+
if (claims.has(key) && claims.get(key) !== value)
|
|
47
|
+
throw new Error(report
|
|
48
|
+
? mismatch
|
|
49
|
+
: "Checkmarx occurrences must belong to the same product, project and scan.");
|
|
50
|
+
claims.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
for (const format of [report?.["format"], ...formats])
|
|
53
|
+
if (checkmarxFormat(format))
|
|
54
|
+
claim("scanner", format === "cxsast-xml" ? "CxSAST" : "Checkmarx One SAST");
|
|
55
|
+
const sources = [report];
|
|
56
|
+
for (const { evidence } of findings) {
|
|
57
|
+
claim("scanner", evidence.details?.scanner_origin);
|
|
58
|
+
if (evidence.source_data)
|
|
59
|
+
sources.push(evidence.source_data);
|
|
60
|
+
}
|
|
61
|
+
if (sources.some(checkmarxResultViewer))
|
|
62
|
+
claim("scanner", "CxSAST");
|
|
63
|
+
const xml = claims.get("scanner") === "CxSAST";
|
|
64
|
+
const named = xml || sources.some((data) => text(data?.["teamFullPathOnReportDate"]));
|
|
65
|
+
claim("scan", scanKey(report?.["scanId"], xml));
|
|
66
|
+
for (const { evidence } of findings)
|
|
67
|
+
claim("scan", scanKey(evidence.source_scan_id, xml));
|
|
68
|
+
let instance;
|
|
69
|
+
for (const data of sources) {
|
|
70
|
+
if (!data)
|
|
71
|
+
continue;
|
|
72
|
+
claim("project", data["projectId"]);
|
|
73
|
+
if (named) {
|
|
74
|
+
claim("project name", text(data["projectName"]));
|
|
75
|
+
claim("team", text(data["teamFullPathOnReportDate"])
|
|
76
|
+
?.replaceAll("\\", "/")
|
|
77
|
+
.replace(/^\/+|\/+$/gu, "")
|
|
78
|
+
.replace(/[A-Z]/gu, (c) => c.toLowerCase()));
|
|
79
|
+
}
|
|
80
|
+
// A URL identifies a deployment; other instance metadata in SDK rows is opaque.
|
|
81
|
+
const url = data["instance"];
|
|
82
|
+
if (xml ||
|
|
83
|
+
(typeof url === "string" &&
|
|
84
|
+
/^https?:$/u.test(URL.parse(url)?.protocol ?? ""))) {
|
|
85
|
+
const scope = checkmarxXmlScope(data);
|
|
86
|
+
instance = checkmarxXmlInstance(instance, scope.instance);
|
|
87
|
+
claim("project", scope.projectId);
|
|
88
|
+
claim("scan", scope.scanId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Identify report and row provenance once for both import destinations. */
|
|
93
|
+
export function checkmarxSelection(provider, findings, report, target, historical = false) {
|
|
94
|
+
const selected = provider === "checkmarx";
|
|
95
|
+
const replay = historical && !selected;
|
|
96
|
+
const format = report?.["format"];
|
|
97
|
+
const nativeReport = checkmarxFormat(format);
|
|
98
|
+
const formats = new Map();
|
|
99
|
+
for (const finding of findings) {
|
|
100
|
+
const kind = checkmarxSource(finding, provider);
|
|
101
|
+
if (kind)
|
|
102
|
+
formats.set(finding, kind);
|
|
103
|
+
}
|
|
104
|
+
const validateUrl = (value) => declaredScannerRepositoryUrl(value, "Checkmarx", target);
|
|
105
|
+
function requireProvider() {
|
|
106
|
+
if (!selected)
|
|
107
|
+
throw new Error("Retained Checkmarx evidence requires the checkmarx provider.");
|
|
108
|
+
}
|
|
109
|
+
if (selected)
|
|
110
|
+
checkBatchScope(findings, formats.values(), report);
|
|
111
|
+
let reportUrl;
|
|
112
|
+
if (report && nativeReport && !replay) {
|
|
113
|
+
requireProvider();
|
|
114
|
+
const xml = format === "cxsast-xml";
|
|
115
|
+
const scan = scanKey(requiredText(report["scanId"], "Checkmarx report scan ID"), xml);
|
|
116
|
+
const project = xml
|
|
117
|
+
? requiredText(report["projectId"], "CxSAST report project ID")
|
|
118
|
+
: undefined;
|
|
119
|
+
for (const finding of findings) {
|
|
120
|
+
const { evidence } = finding;
|
|
121
|
+
const data = evidence.source_data;
|
|
122
|
+
if ((data && "format" in data ? data["format"] : formats.get(finding)) !==
|
|
123
|
+
format ||
|
|
124
|
+
scanKey(evidence.source_scan_id, xml) !== scan ||
|
|
125
|
+
(xml && data?.["projectId"] !== project))
|
|
126
|
+
throw new Error(mismatch);
|
|
127
|
+
}
|
|
128
|
+
reportUrl = validateUrl(report["sourceRepositoryUrl"]);
|
|
129
|
+
}
|
|
130
|
+
else if (report) {
|
|
131
|
+
if (selected && "sourceRepositoryUrl" in report && "scanId" in report)
|
|
132
|
+
throw new Error("Expected the original Checkmarx report format.");
|
|
133
|
+
if (typeof report["sourceRepositoryUrl"] === "string" &&
|
|
134
|
+
(selected || nativeReport || formats.size))
|
|
135
|
+
reportUrl = validateUrl(report["sourceRepositoryUrl"]);
|
|
136
|
+
}
|
|
137
|
+
const marked = new Set(nativeReport || reportUrl ? findings : formats.keys());
|
|
138
|
+
function projectedRepository({ evidence }) {
|
|
139
|
+
const source = evidence.source_data?.["sourceRepositoryUrl"];
|
|
140
|
+
const url = typeof source === "string"
|
|
141
|
+
? validateUrl(source)
|
|
142
|
+
: evidence.details?.repository?.url;
|
|
143
|
+
return url ? { url } : undefined;
|
|
144
|
+
}
|
|
145
|
+
const validateRows = repositoryScopeValidator({
|
|
146
|
+
provider: "checkmarx",
|
|
147
|
+
label: "Checkmarx",
|
|
148
|
+
scope: "product, project and scan",
|
|
149
|
+
}, (_, finding) => {
|
|
150
|
+
const { source_finding_id: id, evidence } = finding;
|
|
151
|
+
const data = evidence.source_data;
|
|
152
|
+
const kind = formats.get(finding);
|
|
153
|
+
if (checkmarxFormat(kind) && data) {
|
|
154
|
+
requireProvider();
|
|
155
|
+
requiredText(evidence.source_scan_id, "Checkmarx source scan ID");
|
|
156
|
+
const expected = kind === "cxsast-xml"
|
|
157
|
+
? checkmarxXmlId(data)
|
|
158
|
+
: checkmarxOneId(data["row"]);
|
|
159
|
+
if (id !== expected)
|
|
160
|
+
throw new Error("Checkmarx source finding ID does not match the retained occurrence.");
|
|
161
|
+
return { url: validateUrl(data["sourceRepositoryUrl"]), scope: kind };
|
|
162
|
+
}
|
|
163
|
+
if (selected && nativeId.test(id))
|
|
164
|
+
throw new Error("Checkmarx source finding ID requires its original evidence.");
|
|
165
|
+
if (selected && data && "sourceRepositoryUrl" in data)
|
|
166
|
+
return { url: validateUrl(data["sourceRepositoryUrl"]) };
|
|
167
|
+
return kind ? projectedRepository(finding) : undefined;
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
reportUrl,
|
|
171
|
+
projections: selected ? new Set() : marked,
|
|
172
|
+
repositories(sameRepositories) {
|
|
173
|
+
const rows = replay || (!selected && !formats.size)
|
|
174
|
+
? undefined
|
|
175
|
+
: validateRows(provider, findings, target, sameRepositories);
|
|
176
|
+
return (finding) => rows?.get(finding.source_finding_id) ??
|
|
177
|
+
(marked.has(finding) ? projectedRepository(finding) : undefined);
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=checkmarx-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkmarx-repository.js","sourceRoot":"","sources":["../src/checkmarx-repository.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AAErC,MAAM,QAAQ,GAAG,0CAA0C,CAAC;AAE5D,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,oBAAoB,CAAC;AAClE,CAAC;AAED,SAAS,OAAO,CAAC,KAAc,EAAE,GAAY;IAC3C,MAAM,IAAI,GAAG,iDAAiD,CAAC;IAC/D,OAAO,CAAC,GAAG,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC1D,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE;QACrB,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC;AAED,iGAAiG;AACjG,SAAS,eAAe,CACtB,EAAE,iBAAiB,EAAE,EAAE,EAAE,QAAQ,EAAmB,EACpD,QAAmB;IAEnB,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,eAAe,CAAC,MAAM,CAAC;QAAE,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AAE,CAAC;QAC3D,OAAO,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,CAAC,CACF,CAAC;IACF,OAAO;QACL,SAAS;QACT,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAmB,CAAC,CAAC,CAAC,MAAM;QAC3D,YAAY,CAAC,gBAAsD;YACjE,MAAM,IAAI,GACR,MAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACpC,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACjE,OAAO,CAAC,OAAwB,EAAE,EAAE,CAClC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC;gBACpC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ExternalFinding, ExternalFindings } from \"./external-findings.js\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport { isRecord } from \"./record.js\";\nimport { requiredText, text } from \"./scanner-import.js\";\nimport { checkmarxOneId } from \"./checkmarx-one.js\";\nimport {\n checkmarxResultViewer,\n checkmarxXmlId,\n checkmarxXmlInstance,\n checkmarxXmlScope,\n} from \"./checkmarx-xml.js\";\nimport {\n declaredScannerRepositoryUrl,\n repositoryScopeValidator,\n} from \"./scanner-repository-url.js\";\n\nconst nativeId = /^checkmarx-(?:one|cxsast):[a-f0-9]{64}$/u;\n\nfunction checkmarxFormat(value: unknown) {\n return value === \"cxsast-xml\" || value === \"checkmarx-one-json\";\n}\n\nfunction scanKey(value: unknown, xml: boolean) {\n const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu;\n return !xml && typeof value === \"string\" && uuid.test(value)\n ? value.toLowerCase()\n : value;\n}\n\n/** A native payload can verify its occurrence ID. A projection can still identify its source. */\nfunction checkmarxSource(\n { source_finding_id: id, evidence }: ExternalFinding,\n provider?: Provider,\n) {\n const data = evidence.source_data;\n const format = data?.[\"format\"];\n if (checkmarxFormat(format)) return format;\n const scanner = evidence.details?.scanner_origin;\n const projected =\n nativeId.test(id) ||\n scanner === \"CxSAST\" ||\n scanner === \"Checkmarx One SAST\" ||\n Boolean(checkmarxResultViewer(data));\n if (\n data &&\n (provider === \"checkmarx\" || projected || \"sourceRepositoryUrl\" in data)\n ) {\n const row = data[\"row\"];\n if (isRecord(row) && row[\"type\"] === \"sast\" && \"similarityId\" in row)\n return \"checkmarx-one-json\";\n const path = data[\"path\"];\n if (\"projectId\" in data && isRecord(path) && \"SimilarityId\" in path)\n return \"cxsast-xml\";\n }\n if (projected) return \"projection\";\n}\n\nconst mismatch =\n \"Checkmarx finding does not match the retained report format, scan or project.\";\n\n/** Compare the claims present across the whole batch, including projected SDK rows. */\nfunction checkBatchScope(\n findings: readonly ExternalFinding[],\n formats: Iterable<string>,\n report: ExternalFindings[\"report\"],\n) {\n const claims = new Map<string, unknown>();\n function claim(key: string, value: unknown) {\n if (value == null) return;\n if (claims.has(key) && claims.get(key) !== value)\n throw new Error(\n report\n ? mismatch\n : \"Checkmarx occurrences must belong to the same product, project and scan.\",\n );\n claims.set(key, value);\n }\n\n for (const format of [report?.[\"format\"], ...formats])\n if (checkmarxFormat(format))\n claim(\n \"scanner\",\n format === \"cxsast-xml\" ? \"CxSAST\" : \"Checkmarx One SAST\",\n );\n const sources = [report];\n for (const { evidence } of findings) {\n claim(\"scanner\", evidence.details?.scanner_origin);\n if (evidence.source_data) sources.push(evidence.source_data);\n }\n if (sources.some(checkmarxResultViewer)) claim(\"scanner\", \"CxSAST\");\n const xml = claims.get(\"scanner\") === \"CxSAST\";\n const named =\n xml || sources.some((data) => text(data?.[\"teamFullPathOnReportDate\"]));\n claim(\"scan\", scanKey(report?.[\"scanId\"], xml));\n for (const { evidence } of findings)\n claim(\"scan\", scanKey(evidence.source_scan_id, xml));\n\n let instance: string | undefined;\n for (const data of sources) {\n if (!data) continue;\n claim(\"project\", data[\"projectId\"]);\n if (named) {\n claim(\"project name\", text(data[\"projectName\"]));\n claim(\n \"team\",\n text(data[\"teamFullPathOnReportDate\"])\n ?.replaceAll(\"\\\\\", \"/\")\n .replace(/^\\/+|\\/+$/gu, \"\")\n .replace(/[A-Z]/gu, (c) => c.toLowerCase()),\n );\n }\n // A URL identifies a deployment; other instance metadata in SDK rows is opaque.\n const url = data[\"instance\"];\n if (\n xml ||\n (typeof url === \"string\" &&\n /^https?:$/u.test(URL.parse(url)?.protocol ?? \"\"))\n ) {\n const scope = checkmarxXmlScope(data);\n instance = checkmarxXmlInstance(instance, scope.instance);\n claim(\"project\", scope.projectId);\n claim(\"scan\", scope.scanId);\n }\n }\n}\n\n/** Identify report and row provenance once for both import destinations. */\nexport function checkmarxSelection(\n provider: Provider,\n findings: ExternalFindings[\"findings\"],\n report: ExternalFindings[\"report\"],\n target: ExternalImportTarget,\n historical = false,\n) {\n const selected = provider === \"checkmarx\";\n const replay = historical && !selected;\n const format = report?.[\"format\"];\n const nativeReport = checkmarxFormat(format);\n const formats = new Map<ExternalFinding, string>();\n for (const finding of findings) {\n const kind = checkmarxSource(finding, provider);\n if (kind) formats.set(finding, kind);\n }\n const validateUrl = (value: unknown) =>\n declaredScannerRepositoryUrl(value, \"Checkmarx\", target);\n function requireProvider() {\n if (!selected)\n throw new Error(\n \"Retained Checkmarx evidence requires the checkmarx provider.\",\n );\n }\n if (selected) checkBatchScope(findings, formats.values(), report);\n let reportUrl: string | undefined;\n if (report && nativeReport && !replay) {\n requireProvider();\n const xml = format === \"cxsast-xml\";\n const scan = scanKey(\n requiredText(report[\"scanId\"], \"Checkmarx report scan ID\"),\n xml,\n );\n const project = xml\n ? requiredText(report[\"projectId\"], \"CxSAST report project ID\")\n : undefined;\n for (const finding of findings) {\n const { evidence } = finding;\n const data = evidence.source_data;\n if (\n (data && \"format\" in data ? data[\"format\"] : formats.get(finding)) !==\n format ||\n scanKey(evidence.source_scan_id, xml) !== scan ||\n (xml && data?.[\"projectId\"] !== project)\n )\n throw new Error(mismatch);\n }\n reportUrl = validateUrl(report[\"sourceRepositoryUrl\"]);\n } else if (report) {\n if (selected && \"sourceRepositoryUrl\" in report && \"scanId\" in report)\n throw new Error(\"Expected the original Checkmarx report format.\");\n if (\n typeof report[\"sourceRepositoryUrl\"] === \"string\" &&\n (selected || nativeReport || formats.size)\n )\n reportUrl = validateUrl(report[\"sourceRepositoryUrl\"]);\n }\n const marked = new Set(nativeReport || reportUrl ? findings : formats.keys());\n function projectedRepository({ evidence }: ExternalFinding) {\n const source = evidence.source_data?.[\"sourceRepositoryUrl\"];\n const url =\n typeof source === \"string\"\n ? validateUrl(source)\n : evidence.details?.repository?.url;\n return url ? { url } : undefined;\n }\n const validateRows = repositoryScopeValidator(\n {\n provider: \"checkmarx\",\n label: \"Checkmarx\",\n scope: \"product, project and scan\",\n },\n (_, finding) => {\n const { source_finding_id: id, evidence } = finding;\n const data = evidence.source_data;\n const kind = formats.get(finding);\n if (checkmarxFormat(kind) && data) {\n requireProvider();\n requiredText(evidence.source_scan_id, \"Checkmarx source scan ID\");\n const expected =\n kind === \"cxsast-xml\"\n ? checkmarxXmlId(data)\n : checkmarxOneId(data[\"row\"]);\n if (id !== expected)\n throw new Error(\n \"Checkmarx source finding ID does not match the retained occurrence.\",\n );\n return { url: validateUrl(data[\"sourceRepositoryUrl\"]), scope: kind };\n }\n if (selected && nativeId.test(id))\n throw new Error(\n \"Checkmarx source finding ID requires its original evidence.\",\n );\n if (selected && data && \"sourceRepositoryUrl\" in data)\n return { url: validateUrl(data[\"sourceRepositoryUrl\"]) };\n return kind ? projectedRepository(finding) : undefined;\n },\n );\n return {\n reportUrl,\n projections: selected ? new Set<ExternalFinding>() : marked,\n repositories(sameRepositories?: (urls: Iterable<string>) => boolean) {\n const rows =\n replay || (!selected && !formats.size)\n ? undefined\n : validateRows(provider, findings, target, sameRepositories);\n return (finding: ExternalFinding) =>\n rows?.get(finding.source_finding_id) ??\n (marked.has(finding) ? projectedRepository(finding) : undefined);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExternalImportTarget } from "./external-import-contract.js";
|
|
2
|
+
export declare function checkmarxXmlInstance(current: string | undefined, next: string | undefined): string | undefined;
|
|
3
|
+
export declare function checkmarxResultViewer(source: Record<string, unknown> | null | undefined): URL | undefined;
|
|
4
|
+
export declare function checkmarxXmlScope(source: Record<string, unknown>, scanId?: string, projectId?: string): {
|
|
5
|
+
instance: string | undefined;
|
|
6
|
+
scanId: string | undefined;
|
|
7
|
+
projectId: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** SimilarityId groups paths, including paths with different intermediate nodes. */
|
|
10
|
+
export declare function checkmarxXmlId(source: Record<string, unknown>): string;
|
|
11
|
+
export declare function normalizeCheckmarxXml(contents: string, repository: string, target: ExternalImportTarget): import("./external-findings.js").ExternalFindings;
|
|
12
|
+
//# sourceMappingURL=checkmarx-xml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkmarx-xml.d.ts","sourceRoot":"","sources":["../src/checkmarx-xml.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAiE1E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,sBAUzB;AAaD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,mBAGnD;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM;IAUhB,QAAQ;IAMR,MAAM;IACN,SAAS;EAEZ;AAgED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAkBtE;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,oBAAoB,qDA0D7B"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { SaxesParser } from "saxes";
|
|
2
|
+
import { asRecord } from "./record.js";
|
|
3
|
+
import { checkmarxEvidence } from "./checkmarx-evidence.js";
|
|
4
|
+
import { array, normalizeRecords, record, requiredText, stableId, text, } from "./scanner-import.js";
|
|
5
|
+
function fields(element) {
|
|
6
|
+
return Object.fromEntries(element.children
|
|
7
|
+
.filter((child) => !child.children.length)
|
|
8
|
+
.map((child) => [child.name, child.text]));
|
|
9
|
+
}
|
|
10
|
+
function pathNode(element) {
|
|
11
|
+
const node = fields(element);
|
|
12
|
+
const snippet = element.children.find((child) => child.name === "Snippet");
|
|
13
|
+
if (snippet)
|
|
14
|
+
node["Snippet"] = snippet.children
|
|
15
|
+
.filter((child) => child.name === "Line")
|
|
16
|
+
.map(fields);
|
|
17
|
+
return node;
|
|
18
|
+
}
|
|
19
|
+
const viewerPath = "/cxwebclient/viewermain.aspx";
|
|
20
|
+
function viewerLink(value) {
|
|
21
|
+
const url = typeof value === "string" ? URL.parse(value) : null;
|
|
22
|
+
if (url &&
|
|
23
|
+
/^https?:$/u.test(url.protocol) &&
|
|
24
|
+
url.pathname.toLowerCase().endsWith(viewerPath))
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
function viewerInstance(link) {
|
|
28
|
+
return link && link.origin + link.pathname.slice(0, -viewerPath.length);
|
|
29
|
+
}
|
|
30
|
+
function instanceKey(value) {
|
|
31
|
+
const url = URL.parse(value);
|
|
32
|
+
return url && /^https?:$/u.test(url.protocol) ? url.href : value;
|
|
33
|
+
}
|
|
34
|
+
export function checkmarxXmlInstance(current, next) {
|
|
35
|
+
if (current !== undefined &&
|
|
36
|
+
next !== undefined &&
|
|
37
|
+
current !== next &&
|
|
38
|
+
instanceKey(current) !== instanceKey(next))
|
|
39
|
+
throw new Error("CxSAST viewer links must identify the same instance.");
|
|
40
|
+
return current ?? next;
|
|
41
|
+
}
|
|
42
|
+
function viewerId(link, field, expected) {
|
|
43
|
+
let selected = expected;
|
|
44
|
+
for (const [key, id] of link?.searchParams ?? []) {
|
|
45
|
+
if (!id || key.toLowerCase() !== field)
|
|
46
|
+
continue;
|
|
47
|
+
if (selected !== undefined && selected !== id)
|
|
48
|
+
throw new Error(`CxSAST DeepLink ${field} does not match the report.`);
|
|
49
|
+
selected = id;
|
|
50
|
+
}
|
|
51
|
+
return selected;
|
|
52
|
+
}
|
|
53
|
+
export function checkmarxResultViewer(source) {
|
|
54
|
+
return viewerLink(asRecord(source?.["result"])?.["DeepLink"]);
|
|
55
|
+
}
|
|
56
|
+
export function checkmarxXmlScope(source, scanId, projectId) {
|
|
57
|
+
const link = checkmarxResultViewer(source);
|
|
58
|
+
viewerId(link, "pathid", text(asRecord(source["path"])?.["PathId"]) ?? undefined);
|
|
59
|
+
const instance = source["instance"];
|
|
60
|
+
return {
|
|
61
|
+
instance: checkmarxXmlInstance(instance === undefined
|
|
62
|
+
? undefined
|
|
63
|
+
: requiredText(instance, "CxSAST instance"), viewerInstance(link)),
|
|
64
|
+
scanId: viewerId(link, "scanid", scanId),
|
|
65
|
+
projectId: viewerId(link, "projectid", projectId),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function readReport(contents) {
|
|
69
|
+
const rows = [];
|
|
70
|
+
const stack = [];
|
|
71
|
+
const parser = new SaxesParser({ xmlns: false });
|
|
72
|
+
let scanId = "";
|
|
73
|
+
let rootInstance;
|
|
74
|
+
const project = { projectId: "" };
|
|
75
|
+
parser.on("opentag", ({ name, attributes }) => {
|
|
76
|
+
const element = { name, attributes, children: [], text: "" };
|
|
77
|
+
if (!stack.length) {
|
|
78
|
+
if (name !== "CxXMLResults")
|
|
79
|
+
throw new Error("Expected a Checkmarx CxSAST CxXMLResults report.");
|
|
80
|
+
project.projectId = requiredText(attributes["ProjectId"], "CxSAST ProjectId");
|
|
81
|
+
scanId = requiredText(attributes["ScanId"], "CxSAST ScanId");
|
|
82
|
+
const projectName = text(attributes["ProjectName"]);
|
|
83
|
+
const team = text(attributes["TeamFullPathOnReportDate"]);
|
|
84
|
+
if (projectName)
|
|
85
|
+
project["projectName"] = projectName;
|
|
86
|
+
if (team)
|
|
87
|
+
project["teamFullPathOnReportDate"] = team;
|
|
88
|
+
const link = viewerLink(attributes["DeepLink"]);
|
|
89
|
+
viewerId(link, "scanid", scanId);
|
|
90
|
+
viewerId(link, "projectid", project.projectId);
|
|
91
|
+
rootInstance = viewerInstance(link);
|
|
92
|
+
}
|
|
93
|
+
else if ((stack.length === 1 && name !== "Query") ||
|
|
94
|
+
(stack.length === 2 && name !== "Result")) {
|
|
95
|
+
throw new Error("Expected CxSAST results directly under their Query.");
|
|
96
|
+
}
|
|
97
|
+
// Only build subtrees within the current result, then release them.
|
|
98
|
+
if (stack.length >= 3)
|
|
99
|
+
stack.at(-1).children.push(element);
|
|
100
|
+
stack.push(element);
|
|
101
|
+
});
|
|
102
|
+
function appendText(value) {
|
|
103
|
+
const element = stack.at(-1);
|
|
104
|
+
if (element)
|
|
105
|
+
element.text += value;
|
|
106
|
+
}
|
|
107
|
+
parser.on("text", appendText);
|
|
108
|
+
parser.on("cdata", appendText);
|
|
109
|
+
parser.on("closetag", () => {
|
|
110
|
+
const element = stack.pop();
|
|
111
|
+
const parent = stack.at(-1);
|
|
112
|
+
if (parent?.name !== "Query" || stack.length !== 2)
|
|
113
|
+
return;
|
|
114
|
+
const paths = element.children.filter((child) => child.name === "Path");
|
|
115
|
+
const path = paths.length === 1 ? paths[0] : undefined;
|
|
116
|
+
rows.push({
|
|
117
|
+
...project,
|
|
118
|
+
query: parent.attributes,
|
|
119
|
+
result: element.attributes,
|
|
120
|
+
path: path?.attributes ?? null,
|
|
121
|
+
nodes: path?.children
|
|
122
|
+
.filter((child) => child.name === "PathNode")
|
|
123
|
+
.map(pathNode) ?? [],
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
parser.write(contents).close();
|
|
127
|
+
return { rows, project, scanId, rootInstance };
|
|
128
|
+
}
|
|
129
|
+
/** SimilarityId groups paths, including paths with different intermediate nodes. */
|
|
130
|
+
export function checkmarxXmlId(source) {
|
|
131
|
+
const projectId = requiredText(source["projectId"], "CxSAST ProjectId");
|
|
132
|
+
const query = record(source["query"], "CxSAST Query");
|
|
133
|
+
const result = record(source["result"], "CxSAST Result");
|
|
134
|
+
const path = record(source["path"], "CxSAST Path");
|
|
135
|
+
const nodes = array(source["nodes"], "CxSAST Path nodes");
|
|
136
|
+
const route = (nodes.length ? nodes : [result]).map((value) => {
|
|
137
|
+
const node = record(value, "CxSAST path node");
|
|
138
|
+
return ["FileName", "Line", "Column", "Name", "Type"].map((field) => text(node[field]));
|
|
139
|
+
});
|
|
140
|
+
return stableId("checkmarx-cxsast", [
|
|
141
|
+
projectId,
|
|
142
|
+
requiredText(query["id"], "CxSAST Query id"),
|
|
143
|
+
requiredText(path["SimilarityId"], "CxSAST SimilarityId"),
|
|
144
|
+
route,
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
export function normalizeCheckmarxXml(contents, repository, target) {
|
|
148
|
+
const { rows, project, scanId, rootInstance } = readReport(contents);
|
|
149
|
+
function normalize(instance) {
|
|
150
|
+
const report = {
|
|
151
|
+
format: "cxsast-xml",
|
|
152
|
+
scanId,
|
|
153
|
+
...project,
|
|
154
|
+
...(instance && { instance }),
|
|
155
|
+
sourceRepositoryUrl: repository,
|
|
156
|
+
};
|
|
157
|
+
return normalizeRecords(rows, (row) => {
|
|
158
|
+
const { query, result } = row;
|
|
159
|
+
return checkmarxEvidence(report, {
|
|
160
|
+
title: requiredText(query["name"], "CxSAST Query name"),
|
|
161
|
+
ruleId: query["id"],
|
|
162
|
+
severity: text(result["Severity"]) ?? query["Severity"],
|
|
163
|
+
description: result["Remark"],
|
|
164
|
+
status: result["Status"],
|
|
165
|
+
verdict: result["FalsePositive"]?.toLowerCase() === "true"
|
|
166
|
+
? "False positive"
|
|
167
|
+
: result["state"],
|
|
168
|
+
cwe: query["cweId"],
|
|
169
|
+
sourceData: !row["instance"] && instance ? { ...row, instance } : row,
|
|
170
|
+
}, target);
|
|
171
|
+
}, (row) => {
|
|
172
|
+
const scope = checkmarxXmlScope(row, scanId, project.projectId);
|
|
173
|
+
if (scope.instance)
|
|
174
|
+
row["instance"] = scope.instance;
|
|
175
|
+
return checkmarxXmlId(row);
|
|
176
|
+
}, target, { report });
|
|
177
|
+
}
|
|
178
|
+
const result = normalize(rootInstance);
|
|
179
|
+
let instance = rootInstance;
|
|
180
|
+
let hasUnboundRows = false;
|
|
181
|
+
for (const { evidence } of result.findings) {
|
|
182
|
+
const rowInstance = text(evidence.source_data?.["instance"]);
|
|
183
|
+
if (rowInstance)
|
|
184
|
+
instance = checkmarxXmlInstance(instance, rowInstance);
|
|
185
|
+
else
|
|
186
|
+
hasUnboundRows = true;
|
|
187
|
+
}
|
|
188
|
+
if (instance && !rootInstance) {
|
|
189
|
+
// Count inherited instance bytes before accepting linkless findings for Cloud.
|
|
190
|
+
if (hasUnboundRows)
|
|
191
|
+
return normalize(instance);
|
|
192
|
+
result.report["instance"] = instance;
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=checkmarx-xml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkmarx-xml.js","sourceRoot":"","sources":["../src/checkmarx-xml.ts"],"names":[],"mappings":"AAAA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G,QAAQ,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { SaxesParser } from \"saxes\";\nimport { asRecord } from \"./record.js\";\nimport { checkmarxEvidence } from \"./checkmarx-evidence.js\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport {\n array,\n normalizeRecords,\n record,\n requiredText,\n stableId,\n text,\n} from \"./scanner-import.js\";\n\ntype Attributes = Record<string, string>;\ninterface Element {\n name: string;\n attributes: Attributes;\n children: Element[];\n text: string;\n}\n\nfunction fields(element: Element): Attributes {\n return Object.fromEntries(\n element.children\n .filter((child) => !child.children.length)\n .map((child) => [child.name, child.text]),\n );\n}\n\nfunction pathNode(element: Element): Record<string, unknown> {\n const node: Record<string, unknown> = fields(element);\n const snippet = element.children.find((child) => child.name === \"Snippet\");\n if (snippet)\n node[\"Snippet\"] = snippet.children\n .filter((child) => child.name === \"Line\")\n .map(fields);\n return node;\n}\n\ninterface Row extends Record<string, unknown> {\n projectId: string;\n query: Attributes;\n result: Attributes;\n path: Attributes | null;\n nodes: Record<string, unknown>[];\n}\n\nconst viewerPath = \"/cxwebclient/viewermain.aspx\";\n\nfunction viewerLink(value: unknown) {\n const url = typeof value === \"string\" ? URL.parse(value) : null;\n if (\n url &&\n /^https?:$/u.test(url.protocol) &&\n url.pathname.toLowerCase().endsWith(viewerPath)\n )\n return url;\n}\n\nfunction viewerInstance(link: URL | undefined) {\n return link && link.origin + link.pathname.slice(0, -viewerPath.length);\n}\n\nfunction instanceKey(value: string) {\n const url = URL.parse(value);\n return url && /^https?:$/u.test(url.protocol) ? url.href : value;\n}\n\nexport function checkmarxXmlInstance(\n current: string | undefined,\n next: string | undefined,\n) {\n if (\n current !== undefined &&\n next !== undefined &&\n current !== next &&\n instanceKey(current) !== instanceKey(next)\n )\n throw new Error(\"CxSAST viewer links must identify the same instance.\");\n return current ?? next;\n}\n\nfunction viewerId(link: URL | undefined, field: string, expected?: string) {\n let selected = expected;\n for (const [key, id] of link?.searchParams ?? []) {\n if (!id || key.toLowerCase() !== field) continue;\n if (selected !== undefined && selected !== id)\n throw new Error(`CxSAST DeepLink ${field} does not match the report.`);\n selected = id;\n }\n return selected;\n}\n\nexport function checkmarxResultViewer(\n source: Record<string, unknown> | null | undefined,\n) {\n return viewerLink(asRecord(source?.[\"result\"])?.[\"DeepLink\"]);\n}\n\nexport function checkmarxXmlScope(\n source: Record<string, unknown>,\n scanId?: string,\n projectId?: string,\n) {\n const link = checkmarxResultViewer(source);\n viewerId(\n link,\n \"pathid\",\n text(asRecord(source[\"path\"])?.[\"PathId\"]) ?? undefined,\n );\n const instance = source[\"instance\"];\n return {\n instance: checkmarxXmlInstance(\n instance === undefined\n ? undefined\n : requiredText(instance, \"CxSAST instance\"),\n viewerInstance(link),\n ),\n scanId: viewerId(link, \"scanid\", scanId),\n projectId: viewerId(link, \"projectid\", projectId),\n };\n}\n\nfunction readReport(contents: string) {\n const rows: Row[] = [];\n const stack: Element[] = [];\n const parser = new SaxesParser({ xmlns: false });\n let scanId = \"\";\n let rootInstance: string | undefined;\n const project: Attributes & { projectId: string } = { projectId: \"\" };\n parser.on(\"opentag\", ({ name, attributes }) => {\n const element: Element = { name, attributes, children: [], text: \"\" };\n if (!stack.length) {\n if (name !== \"CxXMLResults\")\n throw new Error(\"Expected a Checkmarx CxSAST CxXMLResults report.\");\n project.projectId = requiredText(\n attributes[\"ProjectId\"],\n \"CxSAST ProjectId\",\n );\n scanId = requiredText(attributes[\"ScanId\"], \"CxSAST ScanId\");\n const projectName = text(attributes[\"ProjectName\"]);\n const team = text(attributes[\"TeamFullPathOnReportDate\"]);\n if (projectName) project[\"projectName\"] = projectName;\n if (team) project[\"teamFullPathOnReportDate\"] = team;\n const link = viewerLink(attributes[\"DeepLink\"]);\n viewerId(link, \"scanid\", scanId);\n viewerId(link, \"projectid\", project.projectId);\n rootInstance = viewerInstance(link);\n } else if (\n (stack.length === 1 && name !== \"Query\") ||\n (stack.length === 2 && name !== \"Result\")\n ) {\n throw new Error(\"Expected CxSAST results directly under their Query.\");\n }\n // Only build subtrees within the current result, then release them.\n if (stack.length >= 3) stack.at(-1)!.children.push(element);\n stack.push(element);\n });\n function appendText(value: string) {\n const element = stack.at(-1);\n if (element) element.text += value;\n }\n parser.on(\"text\", appendText);\n parser.on(\"cdata\", appendText);\n parser.on(\"closetag\", () => {\n const element = stack.pop()!;\n const parent = stack.at(-1);\n if (parent?.name !== \"Query\" || stack.length !== 2) return;\n const paths = element.children.filter((child) => child.name === \"Path\");\n const path = paths.length === 1 ? paths[0] : undefined;\n rows.push({\n ...project,\n query: parent.attributes,\n result: element.attributes,\n path: path?.attributes ?? null,\n nodes:\n path?.children\n .filter((child) => child.name === \"PathNode\")\n .map(pathNode) ?? [],\n });\n });\n parser.write(contents).close();\n return { rows, project, scanId, rootInstance };\n}\n\n/** SimilarityId groups paths, including paths with different intermediate nodes. */\nexport function checkmarxXmlId(source: Record<string, unknown>): string {\n const projectId = requiredText(source[\"projectId\"], \"CxSAST ProjectId\");\n const query = record(source[\"query\"], \"CxSAST Query\");\n const result = record(source[\"result\"], \"CxSAST Result\");\n const path = record(source[\"path\"], \"CxSAST Path\");\n const nodes = array(source[\"nodes\"], \"CxSAST Path nodes\");\n const route = (nodes.length ? nodes : [result]).map((value) => {\n const node = record(value, \"CxSAST path node\");\n return [\"FileName\", \"Line\", \"Column\", \"Name\", \"Type\"].map((field) =>\n text(node[field]),\n );\n });\n return stableId(\"checkmarx-cxsast\", [\n projectId,\n requiredText(query[\"id\"], \"CxSAST Query id\"),\n requiredText(path[\"SimilarityId\"], \"CxSAST SimilarityId\"),\n route,\n ]);\n}\n\nexport function normalizeCheckmarxXml(\n contents: string,\n repository: string,\n target: ExternalImportTarget,\n) {\n const { rows, project, scanId, rootInstance } = readReport(contents);\n function normalize(instance: string | undefined) {\n const report = {\n format: \"cxsast-xml\",\n scanId,\n ...project,\n ...(instance && { instance }),\n sourceRepositoryUrl: repository,\n } as const;\n return normalizeRecords(\n rows,\n (row) => {\n const { query, result } = row;\n return checkmarxEvidence(\n report,\n {\n title: requiredText(query[\"name\"], \"CxSAST Query name\"),\n ruleId: query[\"id\"],\n severity: text(result[\"Severity\"]) ?? query[\"Severity\"],\n description: result[\"Remark\"],\n status: result[\"Status\"],\n verdict:\n result[\"FalsePositive\"]?.toLowerCase() === \"true\"\n ? \"False positive\"\n : result[\"state\"],\n cwe: query[\"cweId\"],\n sourceData:\n !row[\"instance\"] && instance ? { ...row, instance } : row,\n },\n target,\n );\n },\n (row) => {\n const scope = checkmarxXmlScope(row, scanId, project.projectId);\n if (scope.instance) row[\"instance\"] = scope.instance;\n return checkmarxXmlId(row);\n },\n target,\n { report },\n );\n }\n\n const result = normalize(rootInstance);\n let instance = rootInstance;\n let hasUnboundRows = false;\n for (const { evidence } of result.findings) {\n const rowInstance = text(evidence.source_data?.[\"instance\"]);\n if (rowInstance) instance = checkmarxXmlInstance(instance, rowInstance);\n else hasUnboundRows = true;\n }\n if (instance && !rootInstance) {\n // Count inherited instance bytes before accepting linkless findings for Cloud.\n if (hasUnboundRows) return normalize(instance);\n result.report![\"instance\"] = instance;\n }\n return result;\n}\n"]}
|
|
@@ -3,7 +3,7 @@ export interface ScanSeverityClassification extends SeverityClassification {
|
|
|
3
3
|
scanId: string;
|
|
4
4
|
}
|
|
5
5
|
export interface ClassifyScanSeverityOptions extends ClassifySeverityOptions {
|
|
6
|
-
/** Exact selection, such as dedupe's
|
|
6
|
+
/** Exact selection, such as dedupe's scanRepresentativeFindingIds. Omit to classify all findings. */
|
|
7
7
|
findingIds?: readonly string[];
|
|
8
8
|
/** Reclassify selected findings even when their saved assessment matches the inputs. */
|
|
9
9
|
reprocess?: boolean;
|
|
@@ -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;AAehC,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,2BAA4B,SAAQ,uBAAuB;IAC1E,qGAAqG;IACrG,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;AAmDD,sGAAsG;AACtG,wBAAsB,6BAA6B,CACjD,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAErC"}
|
|
@@ -8,6 +8,7 @@ import { bundledPluginRoot } from "./runtime.js";
|
|
|
8
8
|
import { savedScanWorkbench } from "./saved-scan-bootstrap.js";
|
|
9
9
|
import { resolveCompletedScan, } from "./saved-scan.js";
|
|
10
10
|
import { SeverityStore } from "./severity-store.js";
|
|
11
|
+
import { documentSourceRoot, nullIfMissingPath } from "./targets.js";
|
|
11
12
|
const CLASSIFICATION_FILE = "severity-classification.json";
|
|
12
13
|
/** Resolve a saved scan ID, unique prefix, or latest and save its classification. */
|
|
13
14
|
export async function classifyScanSeverity(scanId, options = {}) {
|
|
@@ -35,14 +36,21 @@ export async function classifyScanSeverityInternal(scanId, options = {}, depende
|
|
|
35
36
|
options.expectedScanId !== scan.scanId) {
|
|
36
37
|
throw new CodexSecurityError("Saved scan does not match expectedScanId.");
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
const target = scan["targetPath"];
|
|
40
|
+
// The workbench enables remediation only for the recorded checkout and revision.
|
|
41
|
+
const sourceRoot = scan["remediationAvailable"] === true &&
|
|
42
|
+
typeof target === "string" &&
|
|
43
|
+
(options.rubricPath !== undefined || options.knowledgeBasePaths?.length)
|
|
44
|
+
? await documentSourceRoot(target, options.signal).catch(nullIfMissingPath)
|
|
45
|
+
: null;
|
|
46
|
+
return classifyScanDirectorySeverityInternal(scan.scanDir, { ...options, expectedScanId: scan.scanId }, surface, bootstrap?.protectedRoots, sourceRoot === null ? null : [sourceRoot]);
|
|
39
47
|
}
|
|
40
48
|
/** Classify a sealed scan directory and save a separate assessment without changing its artifacts. */
|
|
41
49
|
export async function classifyScanDirectorySeverity(scanDirectory, options = {}) {
|
|
42
50
|
return classifyScanDirectorySeverityInternal(scanDirectory, options);
|
|
43
51
|
}
|
|
44
52
|
/** @internal */
|
|
45
|
-
export async function classifyScanDirectorySeverityInternal(requestedDirectory, options = {}, surface = "sdk", protectedRoots = []) {
|
|
53
|
+
export async function classifyScanDirectorySeverityInternal(requestedDirectory, options = {}, surface = "sdk", protectedRoots = [], sourceRoots = []) {
|
|
46
54
|
const { contract, scanDirectory } = await loadContractWithScanDirectory(requestedDirectory, {
|
|
47
55
|
pluginRoot: await bundledPluginRoot(),
|
|
48
56
|
expectedScanId: options.expectedScanId,
|
|
@@ -51,7 +59,7 @@ export async function classifyScanDirectorySeverityInternal(requestedDirectory,
|
|
|
51
59
|
const findings = selectClassificationFindings(contract.findings.findings, options.findingIds);
|
|
52
60
|
const store = new SeverityStore(options.environment ?? process.env, scanDirectory, options.signal, protectedRoots);
|
|
53
61
|
const result = {
|
|
54
|
-
...(await classifySeverityInternal(findings, options, surface, store.checkpoint(contract.manifest.scan.id, findings.map(({ findingId }) => findingId), options.reprocess ?? false))),
|
|
62
|
+
...(await classifySeverityInternal(findings, options, surface, store.checkpoint(contract.manifest.scan.id, findings.map(({ findingId }) => findingId), options.reprocess ?? false), sourceRoots && [scanDirectory, ...sourceRoots])),
|
|
55
63
|
scanId: contract.manifest.scan.id,
|
|
56
64
|
};
|
|
57
65
|
options.signal?.throwIfAborted();
|
|
@@ -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,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,oBAAoB,GAErB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAa3D,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,OAAO,GAAgC,EAAE;IAEzC,OAAO,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,MAAc,EACd,OAAO,GAAgC,EAAE,EACzC,YAAY,GAAmC,EAAE,EACjD,OAAO,GAAkB,KAAK;IAE9B,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,C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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"]}
|
|
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;AAGjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,oBAAoB,GAErB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAa3D,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,OAAO,GAAgC,EA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EAC5B,UAA8B;IAE9B,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,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 type { DocumentRoots } from \"./prompt-files.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\";\nimport { documentSourceRoot, nullIfMissingPath } from \"./targets.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 scanRepresentativeFindingIds. 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 const target = scan[\"targetPath\"];\n // The workbench enables remediation only for the recorded checkout and revision.\n const sourceRoot =\n scan[\"remediationAvailable\"] === true &&\n typeof target === \"string\" &&\n (options.rubricPath !== undefined || options.knowledgeBasePaths?.length)\n ? await documentSourceRoot(target, options.signal).catch(\n nullIfMissingPath,\n )\n : null;\n return classifyScanDirectorySeverityInternal(\n scan.scanDir,\n { ...options, expectedScanId: scan.scanId },\n surface,\n bootstrap?.protectedRoots,\n sourceRoot === null ? null : [sourceRoot],\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 sourceRoots: DocumentRoots = [],\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 sourceRoots && [scanDirectory, ...sourceRoots],\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"]}
|
|
@@ -14,15 +14,7 @@ export declare const classifySeverityRecordsInputSchema: z.ZodObject<{
|
|
|
14
14
|
sha256: z.ZodString;
|
|
15
15
|
}, z.core.$strict>>;
|
|
16
16
|
model: z.ZodString;
|
|
17
|
-
effort: z.
|
|
18
|
-
high: "high";
|
|
19
|
-
low: "low";
|
|
20
|
-
max: "max";
|
|
21
|
-
medium: "medium";
|
|
22
|
-
minimal: "minimal";
|
|
23
|
-
ultra: "ultra";
|
|
24
|
-
xhigh: "xhigh";
|
|
25
|
-
}>;
|
|
17
|
+
effort: z.ZodString;
|
|
26
18
|
records: z.ZodArray<z.ZodObject<{
|
|
27
19
|
id: z.ZodString;
|
|
28
20
|
revision: z.ZodNumber;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify-severity-records.d.ts","sourceRoot":"","sources":["../src/classify-severity-records.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAO9B,eAAO,MAAM,4BAA4B;;;;kBAIvC,CAAC;AAmBH,+EAA+E;AAC/E,eAAO,MAAM,kCAAkC
|
|
1
|
+
{"version":3,"file":"classify-severity-records.d.ts","sourceRoot":"","sources":["../src/classify-severity-records.ts"],"names":[],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