@openai/codex-security 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -788
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +3 -0
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/references/access-advisory.md +1 -1
- 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/final-report.md +1 -1
- package/_bundled_plugin/references/focused-investigator.md +13 -0
- 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/threat-model.md +1 -0
- package/_bundled_plugin/references/validate-scan-findings.md +3 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +30 -12
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +47 -9
- package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
- package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
- package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
- package/_bundled_plugin/scripts/workbench/storage.py +25 -5
- package/_bundled_plugin/scripts/workbench_cli.py +24 -2
- package/_bundled_plugin/scripts/workbench_constants.py +2 -0
- package/_bundled_plugin/scripts/workbench_db.py +257 -268
- package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
- package/_bundled_plugin/scripts/workbench_progress.py +159 -3
- package/_bundled_plugin/scripts/workbench_publication.py +2 -3
- package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
- package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
- package/_bundled_plugin/scripts/workbench_scan_history.py +291 -134
- package/_bundled_plugin/scripts/workbench_scan_start.py +208 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
- package/_bundled_plugin/scripts/workbench_schema.py +220 -14
- package/_bundled_plugin/scripts/workbench_setup.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
- package/_bundled_plugin/scripts/workbench_target.py +486 -85
- package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
- package/_bundled_plugin/shared/workbench-history-repairs.json +64 -14
- package/_bundled_plugin/shared/workbench-migrations.json +66 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
- package/_bundled_plugin/skills/publish-findings/SKILL.md +26 -160
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
- 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/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +459 -157
- 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 +33 -12
- 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/blackduck-findings.d.ts +1 -1
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +5 -18
- package/dist/blackduck-findings.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/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-diagnostics.d.ts +10 -0
- package/dist/classify-severity-diagnostics.d.ts.map +1 -0
- package/dist/classify-severity-diagnostics.js +57 -0
- package/dist/classify-severity-diagnostics.js.map +1 -0
- package/dist/classify-severity-records.d.ts +4 -0
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +35 -8
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +9 -6
- 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 +8 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1860 -903
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +33 -31
- 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-plan.d.ts.map +1 -1
- package/dist/component-plan.js +3 -3
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +3 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +40 -7
- 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 +30 -1
- package/dist/config.js.map +1 -1
- package/dist/continuum-aws.d.ts +6 -0
- package/dist/continuum-aws.d.ts.map +1 -0
- package/dist/continuum-aws.js +202 -0
- package/dist/continuum-aws.js.map +1 -0
- package/dist/continuum-collector.d.ts +44 -0
- package/dist/continuum-collector.d.ts.map +1 -0
- package/dist/continuum-collector.js +266 -0
- package/dist/continuum-collector.js.map +1 -0
- package/dist/continuum-findings.d.ts +31 -2
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +497 -59
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -0
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +1 -45
- package/dist/cost.js.map +1 -1
- package/dist/crowdstrike-findings.d.ts +7 -0
- package/dist/crowdstrike-findings.d.ts.map +1 -0
- package/dist/crowdstrike-findings.js +210 -0
- package/dist/crowdstrike-findings.js.map +1 -0
- 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 +3 -1
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +8 -1
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +2 -1
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +2 -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-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +16 -15
- package/dist/deep-scan.js.map +1 -1
- package/dist/endor-findings.d.ts +2 -2
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +6 -23
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -3
- 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.map +1 -1
- package/dist/external-findings-import.js +12 -1
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +66 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +258 -59
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +6 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +330 -1633
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +11 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +56 -53
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +1 -1
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +12 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +6 -11
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +35 -177
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/finding-prompt.d.ts.map +1 -1
- package/dist/finding-prompt.js +2 -2
- package/dist/finding-prompt.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +3 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +19 -287
- package/dist/github-findings.js.map +1 -1
- package/dist/host-protocol.d.ts +6 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +11 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +2 -0
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +4 -0
- package/dist/host-records-protocol.js.map +1 -1
- 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/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +19 -35
- 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 +34 -27
- 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 -4
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +4 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +83 -39
- package/dist/multiscan.js.map +1 -1
- package/dist/opengrep-findings.d.ts +4 -2
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +39 -22
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/private-finding-import.d.ts +8 -13
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +69 -129
- package/dist/private-finding-import.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +56 -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.map +1 -1
- package/dist/provider-profile.js +4 -9
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication.d.ts +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.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.map +1 -1
- package/dist/remediation.js +3 -1
- package/dist/remediation.js.map +1 -1
- package/dist/runtime.d.ts +35 -7
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +782 -153
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +6 -1
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +267 -115
- package/dist/saved-scan-bootstrap.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 +20 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +26 -5
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +18 -2
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +4 -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 +25 -9
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +28 -4
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +5 -11
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +16 -89
- package/dist/scanner-import.js.map +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.map +1 -1
- package/dist/semgrep-findings.js +14 -48
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-platform-findings.d.ts +20 -70
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +116 -333
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +1 -0
- package/dist/severity-review.js.map +1 -1
- package/dist/snyk-findings.d.ts +2 -0
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +5 -8
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +3 -20
- package/dist/snyk-rest-findings.d.ts.map +1 -1
- package/dist/snyk-rest-findings.js +45 -217
- package/dist/snyk-rest-findings.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 +28 -30
- 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 +129 -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/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +103 -23
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +1 -4
- package/dist/tenable-findings.d.ts.map +1 -1
- package/dist/tenable-findings.js.map +1 -1
- package/dist/trivy-findings.d.ts.map +1 -1
- package/dist/trivy-findings.js +0 -11
- package/dist/trivy-findings.js.map +1 -1
- package/dist/trusted-executable.d.ts +7 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +148 -37
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.js +3 -1
- package/dist/value.js.map +1 -1
- package/dist/veracode-findings.d.ts +1 -3
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +13 -38
- 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/wiz-findings.d.ts +2 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +14 -92
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +30 -0
- package/docs/cli.md +537 -124
- package/docs/findings-service.md +22 -9
- package/docs/hosted-remediation.md +13 -4
- package/docs/sdk.md +918 -0
- package/package.json +15 -6
- package/schemas/external-findings.schema.json +2 -1
- package/schemas/project-config.schema.json +5 -0
- package/dist/hosted-scanner-v1.d.ts +0 -6
- package/dist/hosted-scanner-v1.d.ts.map +0 -1
- package/dist/hosted-scanner-v1.js +0 -60
- package/dist/hosted-scanner-v1.js.map +0 -1
- package/dist/reader-selection.d.ts +0 -15
- package/dist/reader-selection.d.ts.map +0 -1
- package/dist/reader-selection.js +0 -89
- package/dist/reader-selection.js.map +0 -1
- package/dist/semgrep-platform-v1.d.ts +0 -6
- package/dist/semgrep-platform-v1.d.ts.map +0 -1
- package/dist/semgrep-platform-v1.js +0 -83
- package/dist/semgrep-platform-v1.js.map +0 -1
- package/dist/snyk-rest-v1.d.ts +0 -28
- package/dist/snyk-rest-v1.d.ts.map +0 -1
- package/dist/snyk-rest-v1.js +0 -132
- package/dist/snyk-rest-v1.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,iBAAiB,EACjB,4BAA4B,GAM7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,GAG1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAuBtE,SAAS,SAAS,CAAC,EACjB,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,eAAe,G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AAC;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"]}
|
package/dist/targets.d.ts
CHANGED
|
@@ -32,8 +32,12 @@ export interface NormalizedTarget {
|
|
|
32
32
|
baseRef?: string;
|
|
33
33
|
headRef?: string;
|
|
34
34
|
}
|
|
35
|
+
/** Exclusions are literal repository-relative names and may be absent in a checkout. */
|
|
36
|
+
export declare function normalizeExcludedPaths(values: readonly string[] | undefined): string[];
|
|
35
37
|
export declare function normalizeRepository(repository: string, signal?: AbortSignal): Promise<string>;
|
|
36
|
-
export declare function resolveRepositoryPath(repository: string): string;
|
|
38
|
+
export declare function resolveRepositoryPath(repository: string, directory?: string): string;
|
|
39
|
+
/** Preserve filesystem resolution of symlink/.. paths on POSIX. */
|
|
40
|
+
export declare function resolveTargetPath(value: string, directory?: string): string;
|
|
37
41
|
type ReadWorktreeGit = (repository: string, args: readonly string[], signal?: AbortSignal) => Promise<string>;
|
|
38
42
|
export declare function enclosingGitWorktreeRoot(repository: string, signal?: AbortSignal, options?: {
|
|
39
43
|
requireIfPresent?: boolean;
|
|
@@ -58,11 +62,14 @@ export declare function repositoryRevision(repository: string, signal?: AbortSig
|
|
|
58
62
|
export declare function gitHistoryIdentity(repository: string, git: TrustedExecutable, signal?: AbortSignal): Promise<{
|
|
59
63
|
commonDirectory: string | null;
|
|
60
64
|
origin: string | null;
|
|
65
|
+
relativePath: string | null;
|
|
61
66
|
}>;
|
|
62
67
|
/** Resolve Git and its sanitized executable search path for a single selected checkout. */
|
|
63
68
|
export declare function trustedGitCommand(repository: string, preserveConfiguration: boolean, sourceEnvironment: NodeJS.ProcessEnv, protectedRoots: string | readonly string[], signal?: AbortSignal): Promise<TrustedExecutable>;
|
|
64
69
|
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>;
|
|
65
70
|
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>;
|
|
71
|
+
/** Bound repository-supplied document links to the selected checkout or directory. */
|
|
72
|
+
export declare function documentSourceRoot(repository: string, signal?: AbortSignal): Promise<string>;
|
|
66
73
|
export declare function gitMarkerRoot(repository: string, signal: AbortSignal | undefined, search: "nearest" | "outermost"): Promise<string | null>;
|
|
67
74
|
/** Protect both the stored path's checkout and its resolved destination. */
|
|
68
75
|
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,CAA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AAC,CAAC,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|
package/dist/targets.js
CHANGED
|
@@ -2,8 +2,8 @@ import { isNonEmptyString } from "./value.js";
|
|
|
2
2
|
import { isUtf8 } from "node:buffer";
|
|
3
3
|
import { execFile as execFileCallback } from "node:child_process";
|
|
4
4
|
import { realpathSync } from "node:fs";
|
|
5
|
-
import { lstat, readFile, realpath, stat } from "node:fs/promises";
|
|
6
|
-
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";
|
|
7
7
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
8
8
|
import { promisify } from "node:util";
|
|
9
9
|
import { InvalidTargetError, abortReason, errorMessage } from "./errors.js";
|
|
@@ -65,6 +65,33 @@ function requireValidDiffTarget(target) {
|
|
|
65
65
|
throw new InvalidTargetError("Working-tree targets cannot specify a head ref.");
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
/** Exclusions are literal repository-relative names and may be absent in a checkout. */
|
|
69
|
+
export function normalizeExcludedPaths(values) {
|
|
70
|
+
if (values === undefined)
|
|
71
|
+
return [];
|
|
72
|
+
if (!Array.isArray(values))
|
|
73
|
+
throw new InvalidTargetError("Excluded paths must be an array of paths.");
|
|
74
|
+
const paths = new Set();
|
|
75
|
+
for (const value of values) {
|
|
76
|
+
if (typeof value !== "string" ||
|
|
77
|
+
!value ||
|
|
78
|
+
!value.isWellFormed() ||
|
|
79
|
+
/[\u0000-\u001f]/u.test(value))
|
|
80
|
+
throw new InvalidTargetError("Excluded paths must be non-empty UTF-8 paths.");
|
|
81
|
+
const path = process.platform === "win32" ? value.replaceAll("\\", "/") : value;
|
|
82
|
+
if (isAbsolute(value) ||
|
|
83
|
+
path.startsWith("/") ||
|
|
84
|
+
/^[a-z]:/iu.test(path) ||
|
|
85
|
+
path.includes("\\") ||
|
|
86
|
+
path.split("/").includes(".."))
|
|
87
|
+
throw new InvalidTargetError(`Excluded path must be relative to the repository: ${value}`);
|
|
88
|
+
paths.add(path
|
|
89
|
+
.split("/")
|
|
90
|
+
.filter((part) => part && part !== ".")
|
|
91
|
+
.join("/") || ".");
|
|
92
|
+
}
|
|
93
|
+
return [...paths];
|
|
94
|
+
}
|
|
68
95
|
export async function normalizeRepository(repository, signal) {
|
|
69
96
|
const candidate = resolveRepositoryPath(repository);
|
|
70
97
|
requirePortableWindowsRepositoryPath(candidate);
|
|
@@ -86,9 +113,22 @@ export async function normalizeRepository(repository, signal) {
|
|
|
86
113
|
requirePortableWindowsRepositoryPath(canonical);
|
|
87
114
|
return canonical;
|
|
88
115
|
}
|
|
89
|
-
export function resolveRepositoryPath(repository) {
|
|
116
|
+
export function resolveRepositoryPath(repository, directory = process.cwd()) {
|
|
90
117
|
requireUtf8Path("Repository path", repository);
|
|
91
|
-
return
|
|
118
|
+
return resolveTargetPath(expandHome(repository), directory);
|
|
119
|
+
}
|
|
120
|
+
/** Preserve filesystem resolution of symlink/.. paths on POSIX. */
|
|
121
|
+
export function resolveTargetPath(value, directory = process.cwd()) {
|
|
122
|
+
if (sep === "\\")
|
|
123
|
+
return resolve(directory, value);
|
|
124
|
+
const base = isAbsolute(directory)
|
|
125
|
+
? directory
|
|
126
|
+
: `${process.cwd()}/${directory}`;
|
|
127
|
+
const absolute = isAbsolute(value) ? value : `${base}/${value}`;
|
|
128
|
+
const parts = absolute
|
|
129
|
+
.split("/")
|
|
130
|
+
.filter((part) => part !== "" && part !== ".");
|
|
131
|
+
return `/${parts.join("/")}`;
|
|
92
132
|
}
|
|
93
133
|
function requireUtf8Path(label, value, resolved) {
|
|
94
134
|
if (resolved === undefined ? !value.isWellFormed() : !isUtf8(resolved)) {
|
|
@@ -392,9 +432,7 @@ export async function normalizeTarget(repository, target, signal) {
|
|
|
392
432
|
throw new InvalidTargetError("Path scan targets must not contain an empty path.");
|
|
393
433
|
}
|
|
394
434
|
requireUtf8Path("Path target", value);
|
|
395
|
-
const candidate =
|
|
396
|
-
? resolve(expandHome(value))
|
|
397
|
-
: resolve(root, expandHome(value));
|
|
435
|
+
const candidate = resolveTargetPath(expandHome(value), root);
|
|
398
436
|
let canonical;
|
|
399
437
|
try {
|
|
400
438
|
// Some runtimes cannot canonicalize special files to filesystem paths.
|
|
@@ -444,10 +482,40 @@ export async function validateCommittedDiffCheckout(repository, target, signal)
|
|
|
444
482
|
if (status.length !== 0) {
|
|
445
483
|
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.");
|
|
446
484
|
}
|
|
447
|
-
const tracked = await gitOutput(repository, ["ls-files", "-
|
|
448
|
-
if (tracked.
|
|
485
|
+
const tracked = (await gitOutput(repository, ["ls-files", "-v", "-z"], signal)).split("\0");
|
|
486
|
+
if (tracked.some((entry) => /^[Ss] /u.test(entry))) {
|
|
449
487
|
throw new InvalidTargetError("Committed-diff scans require a full repository checkout. Sparse checkouts are not supported; materialize skipped tracked files and retry.");
|
|
450
488
|
}
|
|
489
|
+
if (tracked.some((entry) => entry.startsWith("h "))) {
|
|
490
|
+
await verifyAssumedUnchangedFiles(repository, signal);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async function verifyAssumedUnchangedFiles(repository, signal) {
|
|
494
|
+
const index = await gitOutput(repository, ["rev-parse", "--path-format=absolute", "--git-path", "index"], signal);
|
|
495
|
+
// Git changes to the repository before resolving GIT_INDEX_FILE, even when TMPDIR is relative.
|
|
496
|
+
const directory = await mkdtemp(join(await realpath(tmpdir()), "codex-security-git-index-"));
|
|
497
|
+
const copy = join(directory, "index");
|
|
498
|
+
try {
|
|
499
|
+
// Git refreshes stat data and flags. Keep that write and any hooks out of the checkout.
|
|
500
|
+
await copyFile(index, copy);
|
|
501
|
+
await gitOutput(repository, [
|
|
502
|
+
"-c",
|
|
503
|
+
`core.hooksPath=${directory}`,
|
|
504
|
+
"-c",
|
|
505
|
+
"core.splitIndex=false",
|
|
506
|
+
"update-index",
|
|
507
|
+
"--really-refresh",
|
|
508
|
+
], signal, { GIT_INDEX_FILE: copy });
|
|
509
|
+
}
|
|
510
|
+
catch (error) {
|
|
511
|
+
if (error instanceof Error && "code" in error && error.code === 1) {
|
|
512
|
+
throw new InvalidTargetError("Committed-diff scans require a clean repository checkout. A tracked file marked assume-unchanged has changed on disk.", { cause: error });
|
|
513
|
+
}
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
finally {
|
|
517
|
+
await rm(directory, { recursive: true, force: true });
|
|
518
|
+
}
|
|
451
519
|
}
|
|
452
520
|
export function validateMode(target, mode) {
|
|
453
521
|
if (mode !== "standard" && mode !== "deep") {
|
|
@@ -494,7 +562,7 @@ async function resolveGitRef(repository, ref, signal) {
|
|
|
494
562
|
}
|
|
495
563
|
/** Read-only identity for matching saved history with an already selected host Git. */
|
|
496
564
|
export async function gitHistoryIdentity(repository, git, signal) {
|
|
497
|
-
const read = async (args) => {
|
|
565
|
+
const read = async (args, allowEmpty = false) => {
|
|
498
566
|
try {
|
|
499
567
|
const { stdout } = await execFile(git.executable, ["-c", "core.fsmonitor=false", "-C", repository, ...args], {
|
|
500
568
|
encoding: "utf8",
|
|
@@ -502,19 +570,20 @@ export async function gitHistoryIdentity(repository, git, signal) {
|
|
|
502
570
|
env: isolatedGitEnvironment(true, git.environment),
|
|
503
571
|
maxBuffer: Infinity,
|
|
504
572
|
});
|
|
505
|
-
|
|
506
|
-
|
|
573
|
+
const value = stdout.replace(process.platform === "win32" ? /\r?\n$/u : /\n$/u, "");
|
|
574
|
+
return value || (allowEmpty ? "" : null);
|
|
507
575
|
}
|
|
508
576
|
catch {
|
|
509
577
|
throwIfAborted(signal);
|
|
510
578
|
return null;
|
|
511
579
|
}
|
|
512
580
|
};
|
|
513
|
-
const [commonDirectory, origin] = await Promise.all([
|
|
581
|
+
const [commonDirectory, origin, relativePath] = await Promise.all([
|
|
514
582
|
read(["rev-parse", "--path-format=absolute", "--git-common-dir"]),
|
|
515
583
|
read(["remote", "get-url", "origin"]),
|
|
584
|
+
read(["rev-parse", "--show-prefix"], true),
|
|
516
585
|
]);
|
|
517
|
-
return { commonDirectory, origin };
|
|
586
|
+
return { commonDirectory, origin, relativePath };
|
|
518
587
|
}
|
|
519
588
|
/** Resolve Git and its sanitized executable search path for a single selected checkout. */
|
|
520
589
|
export async function trustedGitCommand(repository, preserveConfiguration, sourceEnvironment, protectedRoots, signal) {
|
|
@@ -562,8 +631,20 @@ export async function gitOutput(repository, args, signal, environment = {}, work
|
|
|
562
631
|
const remoteUrl = args[0] === "remote" && args[1] === "get-url";
|
|
563
632
|
return stdout.replace(process.platform === "win32" && !remoteUrl ? /\r?\n$/u : /\n$/u, "");
|
|
564
633
|
}
|
|
634
|
+
function unavailableGitMarkerPath(error, search) {
|
|
635
|
+
const { code } = error;
|
|
636
|
+
return (code === "ENOENT" ||
|
|
637
|
+
code === "ENOTDIR" ||
|
|
638
|
+
(search === "outermost" &&
|
|
639
|
+
["EACCES", "EPERM", "ELOOP", "ENAMETOOLONG"].includes(code ?? "")));
|
|
640
|
+
}
|
|
641
|
+
/** Bound repository-supplied document links to the selected checkout or directory. */
|
|
642
|
+
export async function documentSourceRoot(repository, signal) {
|
|
643
|
+
return ((await gitMarkerRoot(repository, signal, "nearest")) ??
|
|
644
|
+
(await realpath(repository)));
|
|
645
|
+
}
|
|
565
646
|
export async function gitMarkerRoot(repository, signal, search) {
|
|
566
|
-
let candidate =
|
|
647
|
+
let candidate = resolveTargetPath(repository);
|
|
567
648
|
let current;
|
|
568
649
|
while (true) {
|
|
569
650
|
try {
|
|
@@ -576,9 +657,7 @@ export async function gitMarkerRoot(repository, signal, search) {
|
|
|
576
657
|
catch (error) {
|
|
577
658
|
// Stale or inaccessible descendants still belong to their accessible checkout ancestors.
|
|
578
659
|
throwIfAborted(signal);
|
|
579
|
-
|
|
580
|
-
if (search !== "outermost" ||
|
|
581
|
-
!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(code ?? ""))
|
|
660
|
+
if (search !== "outermost" || !unavailableGitMarkerPath(error, search))
|
|
582
661
|
throw error;
|
|
583
662
|
const parent = dirname(candidate);
|
|
584
663
|
if (parent === candidate)
|
|
@@ -608,10 +687,7 @@ async function walkGitMarkers(current, signal, search) {
|
|
|
608
687
|
}
|
|
609
688
|
catch (error) {
|
|
610
689
|
throwIfAborted(signal);
|
|
611
|
-
|
|
612
|
-
if (code !== "ENOENT" &&
|
|
613
|
-
code !== "ENOTDIR" &&
|
|
614
|
-
(search !== "outermost" || (code !== "EACCES" && code !== "EPERM")))
|
|
690
|
+
if (!unavailableGitMarkerPath(error, search))
|
|
615
691
|
throw error;
|
|
616
692
|
}
|
|
617
693
|
const parent = dirname(current);
|
|
@@ -662,7 +738,11 @@ function expandHome(value) {
|
|
|
662
738
|
}
|
|
663
739
|
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
664
740
|
const separators = sep === "/" && value.startsWith("~/") ? /^\/+/ : /^[/\\]+/;
|
|
665
|
-
|
|
741
|
+
const suffix = value.slice(2).replace(separators, "");
|
|
742
|
+
const home = homedir();
|
|
743
|
+
if (process.platform === "win32")
|
|
744
|
+
return resolve(home, suffix);
|
|
745
|
+
return home === "" ? resolveTargetPath(suffix) : `${home}${sep}${suffix}`;
|
|
666
746
|
}
|
|
667
747
|
return value;
|
|
668
748
|
}
|