@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,169 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import cloudSchema from "../schemas/external-findings.schema.json" with { type: "json" };
|
|
3
|
+
import { CodexSecurityError } from "./errors.js";
|
|
4
|
+
import { distinctSourceRepositories, recordExternalFindingPublications, selectLocalExternalFindings, } from "./external-findings-local.js";
|
|
5
|
+
import { cloudReviewDigest, prepareNormalizedPublication, } from "./external-findings-publish.js";
|
|
6
|
+
import { NoPublishableFindingsError, externalImportDisposition, } from "./external-findings.js";
|
|
7
|
+
import { projectStoredFinding } from "./stored-finding-projection.js";
|
|
8
|
+
function reference({ id, version, provider, sourceKey, sourceFindingId, }) {
|
|
9
|
+
return { id, version, provider, sourceKey, sourceFindingId };
|
|
10
|
+
}
|
|
11
|
+
function cloudProvider(provider) {
|
|
12
|
+
return cloudSchema.$defs.ImportSource.properties.provider.enum.includes(provider);
|
|
13
|
+
}
|
|
14
|
+
function cloudSelection(rows, sourceRepositories, inspectorMap, metadata) {
|
|
15
|
+
const selected = {
|
|
16
|
+
read: metadata?.excluded.length ?? 0,
|
|
17
|
+
findings: [],
|
|
18
|
+
excluded: [...(metadata?.excluded ?? [])],
|
|
19
|
+
report: metadata?.report,
|
|
20
|
+
};
|
|
21
|
+
const skipped = new Set(selected.excluded.map((item) => item.position));
|
|
22
|
+
let position = 0;
|
|
23
|
+
for (const row of rows) {
|
|
24
|
+
const projection = projectStoredFinding(row, sourceRepositories, inspectorMap);
|
|
25
|
+
selected.findings.push(...projection.findings);
|
|
26
|
+
selected.read += projection.read;
|
|
27
|
+
const positions = Array.from({ length: projection.read }, () => {
|
|
28
|
+
do {
|
|
29
|
+
position++;
|
|
30
|
+
} while (skipped.has(position));
|
|
31
|
+
return position;
|
|
32
|
+
});
|
|
33
|
+
for (const item of projection.excluded)
|
|
34
|
+
selected.excluded.push({
|
|
35
|
+
...item,
|
|
36
|
+
position: positions[item.position - 1],
|
|
37
|
+
source_finding_id: row.sourceFindingId,
|
|
38
|
+
...(projection.read > 1 && {
|
|
39
|
+
reason: `Retained trace ${item.position} in ${JSON.stringify(row.sourceFindingId)} (position in stored selection order): ${item.reason}`,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// A native source may account for additional input observations, and an agent
|
|
44
|
+
// report may count a grouped occurrence once before its traces are expanded.
|
|
45
|
+
selected.read = Math.max(selected.read, metadata?.read ?? 0);
|
|
46
|
+
selected.excluded.sort((a, b) => a.position - b.position);
|
|
47
|
+
return selected;
|
|
48
|
+
}
|
|
49
|
+
function receiptRecorder(rows, dependencies) {
|
|
50
|
+
const repository = rows[0].repository;
|
|
51
|
+
const pins = new Map(rows.map(({ id, version, sourceFindingId }) => [
|
|
52
|
+
sourceFindingId,
|
|
53
|
+
{ id, version },
|
|
54
|
+
]));
|
|
55
|
+
return async ({ accountId, cloudApiUrl, destination, requests, findings }, receipts, privateJobId) => {
|
|
56
|
+
const entries = [];
|
|
57
|
+
if (privateJobId) {
|
|
58
|
+
for (const finding of findings)
|
|
59
|
+
entries.push({
|
|
60
|
+
...pins.get(finding.source_finding_id),
|
|
61
|
+
receiptId: privateJobId,
|
|
62
|
+
outcome: "private_job",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
for (const [index, receipt] of receipts.entries()) {
|
|
66
|
+
const batch = new Map(requests[index].items.map((item) => [
|
|
67
|
+
item.client_id,
|
|
68
|
+
pins.get(item.source_finding_id),
|
|
69
|
+
]));
|
|
70
|
+
for (const item of receipt.results)
|
|
71
|
+
if (item.outcome !== "error")
|
|
72
|
+
entries.push({
|
|
73
|
+
...batch.get(item.client_id),
|
|
74
|
+
receiptId: receipt.id,
|
|
75
|
+
outcome: item.outcome,
|
|
76
|
+
cloudFindingId: item.canonical_finding_id ?? undefined,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (entries.length)
|
|
80
|
+
await recordExternalFindingPublications({
|
|
81
|
+
repository,
|
|
82
|
+
accountId,
|
|
83
|
+
cloudApiUrl,
|
|
84
|
+
destinationId: destination.id,
|
|
85
|
+
entries,
|
|
86
|
+
}, dependencies);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function prepareSource(rows, options, dependencies, workbench, metadata) {
|
|
90
|
+
const references = [...(dependencies.sourceRepositories ?? [])];
|
|
91
|
+
const inspectorProjectMap = new Map();
|
|
92
|
+
for (const row of rows) {
|
|
93
|
+
references.push(...(row.provenance?.sourceRepositories ?? []));
|
|
94
|
+
for (const [arn, url] of row.provenance?.inspectorProjectMap ?? []) {
|
|
95
|
+
if (inspectorProjectMap.has(arn) && inspectorProjectMap.get(arn) !== url)
|
|
96
|
+
throw new CodexSecurityError("The selected findings disagree on the Inspector project repository.");
|
|
97
|
+
inspectorProjectMap.set(arn, url);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const sourceRepositories = distinctSourceRepositories(references);
|
|
101
|
+
return prepareNormalizedPublication(cloudSelection(rows, sourceRepositories, inspectorProjectMap.size ? inspectorProjectMap : undefined, metadata), { ...options, ...(inspectorProjectMap.size && { inspectorProjectMap }) }, { ...dependencies, sourceRepositories }, workbench);
|
|
102
|
+
}
|
|
103
|
+
/** Preview each source once. Each group's approval can be resumed independently. */
|
|
104
|
+
export async function prepareStoredFindingsPublication(selection, options, dependencies = {}) {
|
|
105
|
+
const { importId } = selection;
|
|
106
|
+
const stored = await selectLocalExternalFindings(selection, dependencies);
|
|
107
|
+
const groups = [];
|
|
108
|
+
const excluded = [];
|
|
109
|
+
const bySource = Map.groupBy(stored.findings, ({ provider, sourceKey }) => JSON.stringify([provider, sourceKey]));
|
|
110
|
+
for (const rows of bySource.values()) {
|
|
111
|
+
const { provider, sourceKey, repository } = rows[0];
|
|
112
|
+
if (!cloudProvider(provider)) {
|
|
113
|
+
const reason = `The Cloud import contract does not support provider ${JSON.stringify(provider)}.`;
|
|
114
|
+
for (const row of rows)
|
|
115
|
+
excluded.push({ ...reference(row), reason });
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const findings = rows.map(({ id, version }) => ({ id, version }));
|
|
119
|
+
let prepared;
|
|
120
|
+
try {
|
|
121
|
+
prepared = await prepareSource(rows, { ...options, provider, sourceKey }, dependencies, {
|
|
122
|
+
checkout: repository,
|
|
123
|
+
findings,
|
|
124
|
+
record: receiptRecorder(rows, dependencies),
|
|
125
|
+
}, importId === undefined ? undefined : stored);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (!(error instanceof NoPublishableFindingsError) ||
|
|
129
|
+
externalImportDisposition(error.selection) === "failed")
|
|
130
|
+
throw error;
|
|
131
|
+
appendExclusions(rows, error.selection);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const { preview } = prepared;
|
|
135
|
+
appendExclusions(rows, preview);
|
|
136
|
+
const first = groups[0]?.preview;
|
|
137
|
+
if (first &&
|
|
138
|
+
(first.accountId !== preview.accountId ||
|
|
139
|
+
!isDeepStrictEqual(first.destination, preview.destination)))
|
|
140
|
+
throw new CodexSecurityError("The Cloud account or repository changed during publication preparation.");
|
|
141
|
+
const reviewId = cloudReviewDigest(preview, repository, findings);
|
|
142
|
+
groups.push({
|
|
143
|
+
selection: importId === undefined
|
|
144
|
+
? { repository, findings }
|
|
145
|
+
: { repository, importId },
|
|
146
|
+
preview,
|
|
147
|
+
reviewId,
|
|
148
|
+
async publish(approvedReviewId) {
|
|
149
|
+
if (approvedReviewId !== reviewId)
|
|
150
|
+
throw new CodexSecurityError("The stored findings publication has changed. Review the new preview before publishing.");
|
|
151
|
+
return prepared.publish();
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return { groups, excluded };
|
|
156
|
+
function appendExclusions(rows, projected) {
|
|
157
|
+
const accepted = new Set(projected.findings.map((f) => f.source_finding_id));
|
|
158
|
+
const reasons = new Map(projected.excluded.map((f) => [f.source_finding_id, f.reason]));
|
|
159
|
+
for (const row of rows) {
|
|
160
|
+
if (!accepted.has(row.sourceFindingId))
|
|
161
|
+
excluded.push({
|
|
162
|
+
...reference(row),
|
|
163
|
+
reason: reasons.get(row.sourceFindingId) ??
|
|
164
|
+
"Excluded by the Cloud publisher.",
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=stored-findings-publication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-findings-publication.js","sourceRoot":"","sources":["../src/stored-findings-publication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,WAAW,MAAM,0CAA0C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EACL,0BAA0B,EAC1B,iCAAiC,EACjC,2BAA2B,GAK5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,iBAA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E,QAAQ,EAAE;YAC9B,OAAO;YACP,QAAQ;YACR,KAAK,CAAC,OAAO,CAAC,gBAAgB;gBAC5B,IAAI,gBAAgB,KAAK,QAAQ;oBAC/B,MAAM,IAAI,kBAAkB,CAC1B,wFAAwF,CACzF,CAAC;gBACJ,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAE5B,SAAS,gBAAgB,CACvB,IAA6B,EAC7B,SAA2B;QAE3B,MAAM,QAAQ,GAAG,IAAI,GAAG,CACtB,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CACnD,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAC/D,CAAC;QACF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC;gBACpC,QAAQ,CAAC,IAAI,CAAC;oBACZ,GAAG,SAAS,CAAC,GAAG,CAAC;oBACjB,MAAM,EACJ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC;wBAChC,kCAAkC;iBACrC,CAAC,CAAC;QACP,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport cloudSchema from \"../schemas/external-findings.schema.json\" with { type: \"json\" };\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport {\n distinctSourceRepositories,\n recordExternalFindingPublications,\n selectLocalExternalFindings,\n type LocalExternalFindingSelection,\n type LocalFindingReceipt,\n type LocalExternalImportDependencies,\n type StoredExternalFinding,\n} from \"./external-findings-local.js\";\nimport {\n cloudReviewDigest,\n prepareNormalizedPublication,\n type WorkbenchPublication,\n type ExternalPublicationDependencies,\n type ExternalPublicationPreview,\n type ExternalPublicationResult,\n type PreparedExternalPublication,\n} from \"./external-findings-publish.js\";\nimport {\n NoPublishableFindingsError,\n externalImportDisposition,\n type ExternalFindings,\n type ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { projectStoredFinding } from \"./stored-finding-projection.js\";\n\ntype Dependencies = ExternalPublicationDependencies &\n LocalExternalImportDependencies;\ntype Reference = Pick<\n StoredExternalFinding,\n \"id\" | \"version\" | \"provider\" | \"sourceKey\" | \"sourceFindingId\"\n>;\ntype Metadata = Pick<ExternalFindings, \"read\" | \"excluded\" | \"report\">;\n\nexport interface StoredFindingsPublicationGroup {\n /** Prepare this selection again to resume the same reviewed source in another process. */\n selection: LocalExternalFindingSelection;\n preview: ExternalPublicationPreview;\n reviewId: string;\n publish(reviewId: string): Promise<ExternalPublicationResult>;\n}\n\nexport interface StoredFindingsPublication {\n groups: StoredFindingsPublicationGroup[];\n excluded: (Reference & { reason: string })[];\n}\n\nfunction reference({\n id,\n version,\n provider,\n sourceKey,\n sourceFindingId,\n}: StoredExternalFinding): Reference {\n return { id, version, provider, sourceKey, sourceFindingId };\n}\n\nfunction cloudProvider(provider: string): provider is Provider {\n return cloudSchema.$defs.ImportSource.properties.provider.enum.includes(\n provider,\n );\n}\n\nfunction cloudSelection(\n rows: StoredExternalFinding[],\n sourceRepositories: readonly ExternalSourceRepository[],\n inspectorMap: ReadonlyMap<string, string> | undefined,\n metadata?: Metadata,\n): ExternalFindings {\n const selected: ExternalFindings = {\n read: metadata?.excluded.length ?? 0,\n findings: [],\n excluded: [...(metadata?.excluded ?? [])],\n report: metadata?.report,\n };\n const skipped = new Set(selected.excluded.map((item) => item.position));\n let position = 0;\n for (const row of rows) {\n const projection = projectStoredFinding(\n row,\n sourceRepositories,\n inspectorMap,\n );\n selected.findings.push(...projection.findings);\n selected.read += projection.read;\n const positions = Array.from({ length: projection.read }, () => {\n do {\n position++;\n } while (skipped.has(position));\n return position;\n });\n for (const item of projection.excluded)\n selected.excluded.push({\n ...item,\n position: positions[item.position - 1]!,\n source_finding_id: row.sourceFindingId,\n ...(projection.read > 1 && {\n reason: `Retained trace ${item.position} in ${JSON.stringify(row.sourceFindingId)} (position in stored selection order): ${item.reason}`,\n }),\n });\n }\n // A native source may account for additional input observations, and an agent\n // report may count a grouped occurrence once before its traces are expanded.\n selected.read = Math.max(selected.read, metadata?.read ?? 0);\n selected.excluded.sort((a, b) => a.position - b.position);\n return selected;\n}\n\nfunction receiptRecorder(\n rows: StoredExternalFinding[],\n dependencies: Dependencies,\n): WorkbenchPublication[\"record\"] {\n const repository = rows[0]!.repository;\n const pins = new Map(\n rows.map(({ id, version, sourceFindingId }) => [\n sourceFindingId,\n { id, version },\n ]),\n );\n return async (\n { accountId, cloudApiUrl, destination, requests, findings },\n receipts,\n privateJobId,\n ) => {\n const entries: LocalFindingReceipt[] = [];\n if (privateJobId) {\n for (const finding of findings)\n entries.push({\n ...pins.get(finding.source_finding_id)!,\n receiptId: privateJobId,\n outcome: \"private_job\",\n });\n }\n for (const [index, receipt] of receipts.entries()) {\n const batch = new Map(\n requests[index]!.items.map((item) => [\n item.client_id,\n pins.get(item.source_finding_id)!,\n ]),\n );\n for (const item of receipt.results)\n if (item.outcome !== \"error\")\n entries.push({\n ...batch.get(item.client_id)!,\n receiptId: receipt.id,\n outcome: item.outcome,\n cloudFindingId: item.canonical_finding_id ?? undefined,\n });\n }\n if (entries.length)\n await recordExternalFindingPublications(\n {\n repository,\n accountId,\n cloudApiUrl,\n destinationId: destination.id,\n entries,\n },\n dependencies,\n );\n };\n}\n\nfunction prepareSource(\n rows: StoredExternalFinding[],\n options: { repository: string; provider: Provider; sourceKey: string },\n dependencies: Dependencies,\n workbench: WorkbenchPublication,\n metadata?: Metadata,\n) {\n const references = [...(dependencies.sourceRepositories ?? [])];\n const inspectorProjectMap = new Map<string, string>();\n for (const row of rows) {\n references.push(...(row.provenance?.sourceRepositories ?? []));\n for (const [arn, url] of row.provenance?.inspectorProjectMap ?? []) {\n if (inspectorProjectMap.has(arn) && inspectorProjectMap.get(arn) !== url)\n throw new CodexSecurityError(\n \"The selected findings disagree on the Inspector project repository.\",\n );\n inspectorProjectMap.set(arn, url);\n }\n }\n const sourceRepositories = distinctSourceRepositories(references);\n return prepareNormalizedPublication(\n cloudSelection(\n rows,\n sourceRepositories,\n inspectorProjectMap.size ? inspectorProjectMap : undefined,\n metadata,\n ),\n { ...options, ...(inspectorProjectMap.size && { inspectorProjectMap }) },\n { ...dependencies, sourceRepositories },\n workbench,\n );\n}\n\n/** Preview each source once. Each group's approval can be resumed independently. */\nexport async function prepareStoredFindingsPublication(\n selection: LocalExternalFindingSelection,\n options: { repository: string },\n dependencies: Dependencies = {},\n): Promise<StoredFindingsPublication> {\n const { importId } = selection;\n const stored = await selectLocalExternalFindings(selection, dependencies);\n const groups: StoredFindingsPublicationGroup[] = [];\n const excluded: StoredFindingsPublication[\"excluded\"] = [];\n const bySource = Map.groupBy(stored.findings, ({ provider, sourceKey }) =>\n JSON.stringify([provider, sourceKey]),\n );\n for (const rows of bySource.values()) {\n const { provider, sourceKey, repository } = rows[0]!;\n if (!cloudProvider(provider)) {\n const reason = `The Cloud import contract does not support provider ${JSON.stringify(provider)}.`;\n for (const row of rows) excluded.push({ ...reference(row), reason });\n continue;\n }\n const findings = rows.map(({ id, version }) => ({ id, version }));\n let prepared: PreparedExternalPublication;\n try {\n prepared = await prepareSource(\n rows,\n { ...options, provider, sourceKey },\n dependencies,\n {\n checkout: repository,\n findings,\n record: receiptRecorder(rows, dependencies),\n },\n importId === undefined ? undefined : stored,\n );\n } catch (error) {\n if (\n !(error instanceof NoPublishableFindingsError) ||\n externalImportDisposition(error.selection) === \"failed\"\n )\n throw error;\n appendExclusions(rows, error.selection);\n continue;\n }\n const { preview } = prepared;\n appendExclusions(rows, preview);\n const first = groups[0]?.preview;\n if (\n first &&\n (first.accountId !== preview.accountId ||\n !isDeepStrictEqual(first.destination, preview.destination))\n )\n throw new CodexSecurityError(\n \"The Cloud account or repository changed during publication preparation.\",\n );\n const reviewId = cloudReviewDigest(preview, repository, findings);\n groups.push({\n selection:\n importId === undefined\n ? { repository, findings }\n : { repository, importId },\n preview,\n reviewId,\n async publish(approvedReviewId) {\n if (approvedReviewId !== reviewId)\n throw new CodexSecurityError(\n \"The stored findings publication has changed. Review the new preview before publishing.\",\n );\n return prepared.publish();\n },\n });\n }\n return { groups, excluded };\n\n function appendExclusions(\n rows: StoredExternalFinding[],\n projected: ExternalFindings,\n ) {\n const accepted = new Set(\n projected.findings.map((f) => f.source_finding_id),\n );\n const reasons = new Map(\n projected.excluded.map((f) => [f.source_finding_id, f.reason]),\n );\n for (const row of rows) {\n if (!accepted.has(row.sourceFindingId))\n excluded.push({\n ...reference(row),\n reason:\n reasons.get(row.sourceFindingId) ??\n \"Excluded by the Cloud publisher.\",\n });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface HeadDriftMonitorOptions {
|
|
2
|
+
expectedRevision: string;
|
|
3
|
+
readRevision: (signal: AbortSignal) => Promise<string | null>;
|
|
4
|
+
signal: AbortSignal;
|
|
5
|
+
onDrift: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function startHeadDriftMonitor(options: HeadDriftMonitorOptions): () => void;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=target-drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target-drift.d.ts","sourceRoot":"","sources":["../src/target-drift.ts"],"names":[],"mappings":"AAAA,UAAU,uBAAuB;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9D,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,uBAAuB,GAC/B,MAAM,IAAI,CA0BZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function startHeadDriftMonitor(options) {
|
|
2
|
+
const controller = new AbortController();
|
|
3
|
+
const signal = AbortSignal.any([options.signal, controller.signal]);
|
|
4
|
+
let timer;
|
|
5
|
+
signal.addEventListener("abort", () => clearTimeout(timer), { once: true });
|
|
6
|
+
async function check() {
|
|
7
|
+
if (signal.aborted)
|
|
8
|
+
return;
|
|
9
|
+
try {
|
|
10
|
+
const revision = await options.readRevision(signal);
|
|
11
|
+
if (!signal.aborted &&
|
|
12
|
+
revision !== null &&
|
|
13
|
+
revision !== options.expectedRevision) {
|
|
14
|
+
controller.abort();
|
|
15
|
+
options.onDrift();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Failed reads and warning observers must not interrupt the scan.
|
|
20
|
+
}
|
|
21
|
+
if (!signal.aborted)
|
|
22
|
+
timer = setTimeout(check, 1_000).unref();
|
|
23
|
+
}
|
|
24
|
+
void check();
|
|
25
|
+
return () => controller.abort();
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=target-drift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target-drift.js","sourceRoot":"","sources":["../src/target-drift.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,qBAAqB,CACnC,OAAgC;IAEhC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,IAAI,KAAiC,CAAC;IACtC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5E,KAAK,UAAU,KAAK;QAClB,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO;QAC3B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YACpD,IACE,CAAC,MAAM,CAAC,OAAO;gBACf,QAAQ,KAAK,IAAI;gBACjB,QAAQ,KAAK,OAAO,CAAC,gBAAgB,EACrC,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;QACpE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;IAChE,CAAC;IAED,KAAK,KAAK,EAAE,CAAC;IACb,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC","sourcesContent":["interface HeadDriftMonitorOptions {\n expectedRevision: string;\n readRevision: (signal: AbortSignal) => Promise<string | null>;\n signal: AbortSignal;\n onDrift: () => void;\n}\n\nexport function startHeadDriftMonitor(\n options: HeadDriftMonitorOptions,\n): () => void {\n const controller = new AbortController();\n const signal = AbortSignal.any([options.signal, controller.signal]);\n let timer: NodeJS.Timeout | undefined;\n signal.addEventListener(\"abort\", () => clearTimeout(timer), { once: true });\n\n async function check(): Promise<void> {\n if (signal.aborted) return;\n try {\n const revision = await options.readRevision(signal);\n if (\n !signal.aborted &&\n revision !== null &&\n revision !== options.expectedRevision\n ) {\n controller.abort();\n options.onDrift();\n }\n } catch {\n // Failed reads and warning observers must not interrupt the scan.\n }\n if (!signal.aborted) timer = setTimeout(check, 1_000).unref();\n }\n\n void check();\n return () => controller.abort();\n}\n"]}
|
package/dist/targets.d.ts
CHANGED
|
@@ -33,7 +33,9 @@ export interface NormalizedTarget {
|
|
|
33
33
|
headRef?: string;
|
|
34
34
|
}
|
|
35
35
|
export declare function normalizeRepository(repository: string, signal?: AbortSignal): Promise<string>;
|
|
36
|
-
export declare function resolveRepositoryPath(repository: string): string;
|
|
36
|
+
export declare function resolveRepositoryPath(repository: string, directory?: string): string;
|
|
37
|
+
/** Preserve filesystem resolution of symlink/.. paths on POSIX. */
|
|
38
|
+
export declare function resolveTargetPath(value: string, directory?: string): string;
|
|
37
39
|
type ReadWorktreeGit = (repository: string, args: readonly string[], signal?: AbortSignal) => Promise<string>;
|
|
38
40
|
export declare function enclosingGitWorktreeRoot(repository: string, signal?: AbortSignal, options?: {
|
|
39
41
|
requireIfPresent?: boolean;
|
|
@@ -58,9 +60,14 @@ export declare function repositoryRevision(repository: string, signal?: AbortSig
|
|
|
58
60
|
export declare function gitHistoryIdentity(repository: string, git: TrustedExecutable, signal?: AbortSignal): Promise<{
|
|
59
61
|
commonDirectory: string | null;
|
|
60
62
|
origin: string | null;
|
|
63
|
+
relativePath: string | null;
|
|
61
64
|
}>;
|
|
65
|
+
/** Resolve Git and its sanitized executable search path for a single selected checkout. */
|
|
66
|
+
export declare function trustedGitCommand(repository: string, preserveConfiguration: boolean, sourceEnvironment: NodeJS.ProcessEnv, protectedRoots: string | readonly string[], signal?: AbortSignal): Promise<TrustedExecutable>;
|
|
62
67
|
export declare function gitOutput(repository: string, args: readonly string[], signal?: AbortSignal, environment?: NodeJS.ProcessEnv, workingDirectory?: string, encoding?: "utf8", protectedRoots?: string | readonly string[], sourceEnvironment?: NodeJS.ProcessEnv): Promise<string>;
|
|
63
68
|
export declare function gitOutput(repository: string, args: readonly string[], signal: AbortSignal | undefined, environment: NodeJS.ProcessEnv | undefined, workingDirectory: string | undefined, encoding: "buffer", protectedRoots?: string | readonly string[], sourceEnvironment?: NodeJS.ProcessEnv): Promise<Buffer>;
|
|
69
|
+
/** Bound repository-supplied document links to the selected checkout or directory. */
|
|
70
|
+
export declare function documentSourceRoot(repository: string, signal?: AbortSignal): Promise<string>;
|
|
64
71
|
export declare function gitMarkerRoot(repository: string, signal: AbortSignal | undefined, search: "nearest" | "outermost"): Promise<string | null>;
|
|
65
72
|
/** Protect both the stored path's checkout and its resolved destination. */
|
|
66
73
|
export declare function gitProtectionRoots(repository: string, signal?: AbortSignal): Promise<string[]>;
|
package/dist/targets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAyBA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAQ1D,CAAC;AAaH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,cAAc,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,UAAU;;IAErB,SAAgB,IAAI,EAAE,cAAc,CAAC;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAE9B,YAAmB,OAAO,EAAE,iBAAiB,EAO5C;IAED,OAAc,IAAI,CAAC,EACjB,IAAI,EACJ,IAAa,GACd,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,UAAU,CAEb;IAED,OAAc,WAAW,CAAC,EACxB,IAAa,GACd,GAAE;Q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,EAAE,MAAM,CAAC,UAAU,GACpC,OAAO,CAAC,MAAM,CAAC,CAAC;AAsEnB,sFAAsF;AACtF,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED,wBAAsB,aAAa,CACjC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,EAAE,SAAS,GAAG,WAAW,GAC9B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,4EAA4E;AAC5E,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,EAAE,CAAC,CAMnB;AA2CD,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|
package/dist/targets.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isNonEmptyString } from "./value.js";
|
|
2
|
+
import { isUtf8 } from "node:buffer";
|
|
2
3
|
import { execFile as execFileCallback } from "node:child_process";
|
|
3
4
|
import { realpathSync } from "node:fs";
|
|
4
|
-
import { lstat, readFile, realpath, stat } from "node:fs/promises";
|
|
5
|
-
import { homedir } from "node:os";
|
|
5
|
+
import { copyFile, lstat, mkdtemp, readFile, realpath, rm, stat, } from "node:fs/promises";
|
|
6
|
+
import { homedir, tmpdir } from "node:os";
|
|
6
7
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
7
8
|
import { promisify } from "node:util";
|
|
8
9
|
import { InvalidTargetError, abortReason, errorMessage } from "./errors.js";
|
|
@@ -67,10 +68,10 @@ function requireValidDiffTarget(target) {
|
|
|
67
68
|
export async function normalizeRepository(repository, signal) {
|
|
68
69
|
const candidate = resolveRepositoryPath(repository);
|
|
69
70
|
requirePortableWindowsRepositoryPath(candidate);
|
|
70
|
-
let
|
|
71
|
+
let resolved;
|
|
71
72
|
try {
|
|
72
|
-
|
|
73
|
-
if (!(await abortable(() =>
|
|
73
|
+
resolved = await abortable(() => realpath(candidate, { encoding: "buffer" }), signal);
|
|
74
|
+
if (!(await abortable(() => lstat(resolved), signal)).isDirectory()) {
|
|
74
75
|
throw new Error("not a directory");
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -80,11 +81,32 @@ export async function normalizeRepository(repository, signal) {
|
|
|
80
81
|
cause: error,
|
|
81
82
|
});
|
|
82
83
|
}
|
|
84
|
+
requireUtf8Path("Repository path", candidate, resolved);
|
|
85
|
+
const canonical = resolved.toString();
|
|
83
86
|
requirePortableWindowsRepositoryPath(canonical);
|
|
84
87
|
return canonical;
|
|
85
88
|
}
|
|
86
|
-
export function resolveRepositoryPath(repository) {
|
|
87
|
-
|
|
89
|
+
export function resolveRepositoryPath(repository, directory = process.cwd()) {
|
|
90
|
+
requireUtf8Path("Repository path", repository);
|
|
91
|
+
return resolveTargetPath(expandHome(repository), directory);
|
|
92
|
+
}
|
|
93
|
+
/** Preserve filesystem resolution of symlink/.. paths on POSIX. */
|
|
94
|
+
export function resolveTargetPath(value, directory = process.cwd()) {
|
|
95
|
+
if (sep === "\\")
|
|
96
|
+
return resolve(directory, value);
|
|
97
|
+
const base = isAbsolute(directory)
|
|
98
|
+
? directory
|
|
99
|
+
: `${process.cwd()}/${directory}`;
|
|
100
|
+
const absolute = isAbsolute(value) ? value : `${base}/${value}`;
|
|
101
|
+
const parts = absolute
|
|
102
|
+
.split("/")
|
|
103
|
+
.filter((part) => part !== "" && part !== ".");
|
|
104
|
+
return `/${parts.join("/")}`;
|
|
105
|
+
}
|
|
106
|
+
function requireUtf8Path(label, value, resolved) {
|
|
107
|
+
if (resolved === undefined ? !value.isWellFormed() : !isUtf8(resolved)) {
|
|
108
|
+
throw new InvalidTargetError(`${label} cannot be represented as UTF-8: ${value}`);
|
|
109
|
+
}
|
|
88
110
|
}
|
|
89
111
|
function requirePortableWindowsRepositoryPath(path) {
|
|
90
112
|
if (process.platform !== "win32")
|
|
@@ -382,25 +404,28 @@ export async function normalizeTarget(repository, target, signal) {
|
|
|
382
404
|
if (value.length === 0) {
|
|
383
405
|
throw new InvalidTargetError("Path scan targets must not contain an empty path.");
|
|
384
406
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
: resolve(root, expandHome(value));
|
|
388
|
-
let metadata;
|
|
407
|
+
requireUtf8Path("Path target", value);
|
|
408
|
+
const candidate = resolveTargetPath(expandHome(value), root);
|
|
389
409
|
let canonical;
|
|
390
410
|
try {
|
|
391
|
-
|
|
392
|
-
|
|
411
|
+
// Some runtimes cannot canonicalize special files to filesystem paths.
|
|
412
|
+
requireScanPathType(value, await abortable(() => stat(candidate), signal));
|
|
413
|
+
const resolved = await abortable(() => realpath(candidate, { encoding: "buffer" }), signal);
|
|
414
|
+
canonical = resolved.toString();
|
|
415
|
+
if (!isAbsolute(canonical)) {
|
|
416
|
+
throw new InvalidTargetError(`Could not resolve path target: ${value}`);
|
|
417
|
+
}
|
|
418
|
+
requireScanPathType(value, await abortable(() => lstat(resolved), signal));
|
|
419
|
+
requireUtf8Path("Path target", value, resolved);
|
|
393
420
|
}
|
|
394
421
|
catch (error) {
|
|
395
422
|
throwIfAborted(signal);
|
|
423
|
+
if (error instanceof InvalidTargetError)
|
|
424
|
+
throw error;
|
|
396
425
|
throw new InvalidTargetError(`Path target does not exist: ${value}`, {
|
|
397
426
|
cause: error,
|
|
398
427
|
});
|
|
399
428
|
}
|
|
400
|
-
// Match the bundled scan scope resolver's supported filesystem types.
|
|
401
|
-
if (!metadata.isFile() && !metadata.isDirectory()) {
|
|
402
|
-
throw new InvalidTargetError(`Path target is not a regular file or directory: ${value}`);
|
|
403
|
-
}
|
|
404
429
|
const relativePath = relative(root, canonical);
|
|
405
430
|
if (relativePathIsOutside(relativePath)) {
|
|
406
431
|
throw new InvalidTargetError(`Path target is outside the repository: ${value}`);
|
|
@@ -414,6 +439,11 @@ export async function normalizeTarget(repository, target, signal) {
|
|
|
414
439
|
}
|
|
415
440
|
return { kind: "paths", paths: [...paths] };
|
|
416
441
|
}
|
|
442
|
+
function requireScanPathType(value, metadata) {
|
|
443
|
+
if (!metadata.isFile() && !metadata.isDirectory()) {
|
|
444
|
+
throw new InvalidTargetError(`Path target is not a regular file or directory: ${value}`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
417
447
|
export async function validateCommittedDiffCheckout(repository, target, signal) {
|
|
418
448
|
if (target.kind !== "refs")
|
|
419
449
|
return;
|
|
@@ -425,10 +455,40 @@ export async function validateCommittedDiffCheckout(repository, target, signal)
|
|
|
425
455
|
if (status.length !== 0) {
|
|
426
456
|
throw new InvalidTargetError("Committed-diff scans require a clean repository checkout. Commit, stash, or remove local changes and retry. Use `git stash --include-untracked` to stash untracked files.");
|
|
427
457
|
}
|
|
428
|
-
const tracked = await gitOutput(repository, ["ls-files", "-
|
|
429
|
-
if (tracked.
|
|
458
|
+
const tracked = (await gitOutput(repository, ["ls-files", "-v", "-z"], signal)).split("\0");
|
|
459
|
+
if (tracked.some((entry) => /^[Ss] /u.test(entry))) {
|
|
430
460
|
throw new InvalidTargetError("Committed-diff scans require a full repository checkout. Sparse checkouts are not supported; materialize skipped tracked files and retry.");
|
|
431
461
|
}
|
|
462
|
+
if (tracked.some((entry) => entry.startsWith("h "))) {
|
|
463
|
+
await verifyAssumedUnchangedFiles(repository, signal);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function verifyAssumedUnchangedFiles(repository, signal) {
|
|
467
|
+
const index = await gitOutput(repository, ["rev-parse", "--path-format=absolute", "--git-path", "index"], signal);
|
|
468
|
+
// Git changes to the repository before resolving GIT_INDEX_FILE, even when TMPDIR is relative.
|
|
469
|
+
const directory = await mkdtemp(join(await realpath(tmpdir()), "codex-security-git-index-"));
|
|
470
|
+
const copy = join(directory, "index");
|
|
471
|
+
try {
|
|
472
|
+
// Git refreshes stat data and flags. Keep that write and any hooks out of the checkout.
|
|
473
|
+
await copyFile(index, copy);
|
|
474
|
+
await gitOutput(repository, [
|
|
475
|
+
"-c",
|
|
476
|
+
`core.hooksPath=${directory}`,
|
|
477
|
+
"-c",
|
|
478
|
+
"core.splitIndex=false",
|
|
479
|
+
"update-index",
|
|
480
|
+
"--really-refresh",
|
|
481
|
+
], signal, { GIT_INDEX_FILE: copy });
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
if (error instanceof Error && "code" in error && error.code === 1) {
|
|
485
|
+
throw new InvalidTargetError("Committed-diff scans require a clean repository checkout. A tracked file marked assume-unchanged has changed on disk.", { cause: error });
|
|
486
|
+
}
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
await rm(directory, { recursive: true, force: true });
|
|
491
|
+
}
|
|
432
492
|
}
|
|
433
493
|
export function validateMode(target, mode) {
|
|
434
494
|
if (mode !== "standard" && mode !== "deep") {
|
|
@@ -475,7 +535,7 @@ async function resolveGitRef(repository, ref, signal) {
|
|
|
475
535
|
}
|
|
476
536
|
/** Read-only identity for matching saved history with an already selected host Git. */
|
|
477
537
|
export async function gitHistoryIdentity(repository, git, signal) {
|
|
478
|
-
const read = async (args) => {
|
|
538
|
+
const read = async (args, allowEmpty = false) => {
|
|
479
539
|
try {
|
|
480
540
|
const { stdout } = await execFile(git.executable, ["-c", "core.fsmonitor=false", "-C", repository, ...args], {
|
|
481
541
|
encoding: "utf8",
|
|
@@ -483,36 +543,53 @@ export async function gitHistoryIdentity(repository, git, signal) {
|
|
|
483
543
|
env: isolatedGitEnvironment(true, git.environment),
|
|
484
544
|
maxBuffer: Infinity,
|
|
485
545
|
});
|
|
486
|
-
|
|
487
|
-
|
|
546
|
+
const value = stdout.replace(process.platform === "win32" ? /\r?\n$/u : /\n$/u, "");
|
|
547
|
+
return value || (allowEmpty ? "" : null);
|
|
488
548
|
}
|
|
489
549
|
catch {
|
|
490
550
|
throwIfAborted(signal);
|
|
491
551
|
return null;
|
|
492
552
|
}
|
|
493
553
|
};
|
|
494
|
-
const [commonDirectory, origin] = await Promise.all([
|
|
554
|
+
const [commonDirectory, origin, relativePath] = await Promise.all([
|
|
495
555
|
read(["rev-parse", "--path-format=absolute", "--git-common-dir"]),
|
|
496
556
|
read(["remote", "get-url", "origin"]),
|
|
557
|
+
read(["rev-parse", "--show-prefix"], true),
|
|
558
|
+
]);
|
|
559
|
+
return { commonDirectory, origin, relativePath };
|
|
560
|
+
}
|
|
561
|
+
/** Resolve Git and its sanitized executable search path for a single selected checkout. */
|
|
562
|
+
export async function trustedGitCommand(repository, preserveConfiguration, sourceEnvironment, protectedRoots, signal) {
|
|
563
|
+
const command = await resolveTrustedExecutable("git", isolatedGitEnvironment(preserveConfiguration, sourceEnvironment), [
|
|
564
|
+
(await gitMarkerRoot(repository, signal, "outermost")) ?? repository,
|
|
565
|
+
...(typeof protectedRoots === "string"
|
|
566
|
+
? [protectedRoots]
|
|
567
|
+
: protectedRoots),
|
|
497
568
|
]);
|
|
498
|
-
|
|
569
|
+
if (!command)
|
|
570
|
+
throw new Error("Git is not available on a trusted PATH.");
|
|
571
|
+
return command;
|
|
499
572
|
}
|
|
500
573
|
export async function gitOutput(repository, args, signal, environment = {}, workingDirectory = repository, encoding = "utf8", protectedRoots = [], sourceEnvironment = process.env) {
|
|
501
574
|
throwIfAborted(signal);
|
|
502
|
-
const command = await
|
|
575
|
+
const command = await trustedGitCommand(repository, args[0] === "rev-parse" ||
|
|
576
|
+
(args[0] === "symbolic-ref" &&
|
|
577
|
+
args[1] === "--quiet" &&
|
|
578
|
+
args[2] === "HEAD" &&
|
|
579
|
+
args.length === 3) ||
|
|
580
|
+
(args[0] === "--exec-path" && args.length === 1) ||
|
|
503
581
|
args[0] === "config" ||
|
|
582
|
+
(args[0] === "fetch-pack" &&
|
|
583
|
+
args[1] === "--diag-url" &&
|
|
584
|
+
args.length === 3) ||
|
|
585
|
+
(args[0] === "ls-remote" &&
|
|
586
|
+
args[1] === "--get-url" &&
|
|
587
|
+
(args.length === 2 || (args[2] === "--" && args.length === 4))) ||
|
|
504
588
|
args[0] === "ls-files" ||
|
|
505
589
|
(args[0] === "remote" &&
|
|
506
590
|
(args.length === 1 ||
|
|
507
591
|
(args[1] === "get-url" &&
|
|
508
|
-
(args[2] === "--all" || args[2] === "--")))), sourceEnvironment
|
|
509
|
-
(await gitMarkerRoot(repository, signal, "outermost")) ?? repository,
|
|
510
|
-
...(typeof protectedRoots === "string"
|
|
511
|
-
? [protectedRoots]
|
|
512
|
-
: protectedRoots),
|
|
513
|
-
]);
|
|
514
|
-
if (command === null)
|
|
515
|
-
throw new Error("Git is not available on a trusted PATH.");
|
|
592
|
+
(args[2] === "--all" || args[2] === "--")))), sourceEnvironment, protectedRoots, signal);
|
|
516
593
|
throwIfAborted(signal);
|
|
517
594
|
const { stdout } = await execFile(command.executable, ["-c", "core.fsmonitor=false", "-C", workingDirectory, ...args], {
|
|
518
595
|
encoding,
|
|
@@ -527,8 +604,20 @@ export async function gitOutput(repository, args, signal, environment = {}, work
|
|
|
527
604
|
const remoteUrl = args[0] === "remote" && args[1] === "get-url";
|
|
528
605
|
return stdout.replace(process.platform === "win32" && !remoteUrl ? /\r?\n$/u : /\n$/u, "");
|
|
529
606
|
}
|
|
607
|
+
function unavailableGitMarkerPath(error, search) {
|
|
608
|
+
const { code } = error;
|
|
609
|
+
return (code === "ENOENT" ||
|
|
610
|
+
code === "ENOTDIR" ||
|
|
611
|
+
(search === "outermost" &&
|
|
612
|
+
["EACCES", "EPERM", "ELOOP", "ENAMETOOLONG"].includes(code ?? "")));
|
|
613
|
+
}
|
|
614
|
+
/** Bound repository-supplied document links to the selected checkout or directory. */
|
|
615
|
+
export async function documentSourceRoot(repository, signal) {
|
|
616
|
+
return ((await gitMarkerRoot(repository, signal, "nearest")) ??
|
|
617
|
+
(await realpath(repository)));
|
|
618
|
+
}
|
|
530
619
|
export async function gitMarkerRoot(repository, signal, search) {
|
|
531
|
-
let candidate =
|
|
620
|
+
let candidate = resolveTargetPath(repository);
|
|
532
621
|
let current;
|
|
533
622
|
while (true) {
|
|
534
623
|
try {
|
|
@@ -541,9 +630,7 @@ export async function gitMarkerRoot(repository, signal, search) {
|
|
|
541
630
|
catch (error) {
|
|
542
631
|
// Stale or inaccessible descendants still belong to their accessible checkout ancestors.
|
|
543
632
|
throwIfAborted(signal);
|
|
544
|
-
|
|
545
|
-
if (search !== "outermost" ||
|
|
546
|
-
!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(code ?? ""))
|
|
633
|
+
if (search !== "outermost" || !unavailableGitMarkerPath(error, search))
|
|
547
634
|
throw error;
|
|
548
635
|
const parent = dirname(candidate);
|
|
549
636
|
if (parent === candidate)
|
|
@@ -573,10 +660,7 @@ async function walkGitMarkers(current, signal, search) {
|
|
|
573
660
|
}
|
|
574
661
|
catch (error) {
|
|
575
662
|
throwIfAborted(signal);
|
|
576
|
-
|
|
577
|
-
if (code !== "ENOENT" &&
|
|
578
|
-
code !== "ENOTDIR" &&
|
|
579
|
-
(search !== "outermost" || (code !== "EACCES" && code !== "EPERM")))
|
|
663
|
+
if (!unavailableGitMarkerPath(error, search))
|
|
580
664
|
throw error;
|
|
581
665
|
}
|
|
582
666
|
const parent = dirname(current);
|
|
@@ -626,7 +710,12 @@ function expandHome(value) {
|
|
|
626
710
|
return homedir();
|
|
627
711
|
}
|
|
628
712
|
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
629
|
-
|
|
713
|
+
const separators = sep === "/" && value.startsWith("~/") ? /^\/+/ : /^[/\\]+/;
|
|
714
|
+
const suffix = value.slice(2).replace(separators, "");
|
|
715
|
+
const home = homedir();
|
|
716
|
+
if (process.platform === "win32")
|
|
717
|
+
return resolve(home, suffix);
|
|
718
|
+
return home === "" ? resolveTargetPath(suffix) : `${home}${sep}${suffix}`;
|
|
630
719
|
}
|
|
631
720
|
return value;
|
|
632
721
|
}
|