@openai/codex-security 0.9.1 → 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 +37 -788
- package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
- package/_bundled_plugin/.mcp.json +2 -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/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/validate-scan-findings.md +3 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +29 -12
- package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -3
- package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
- 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 +244 -217
- 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 +281 -119
- package/_bundled_plugin/scripts/workbench_scan_start.py +143 -9
- 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_target.py +471 -84
- package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
- package/_bundled_plugin/shared/workbench-history-repairs.json +60 -14
- package/_bundled_plugin/shared/workbench-migrations.json +66 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
- package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -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/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/bin/codex-security.mjs +2 -2
- package/dist/api.d.ts +6 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +437 -154
- 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.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 +5 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1763 -894
- 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-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-findings.d.ts +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +93 -31
- package/dist/continuum-findings.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/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 +234 -53
- 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 +326 -1633
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +1 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +31 -51
- 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 +3 -11
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +29 -176
- 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/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 +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -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 +79 -37
- 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.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.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 +778 -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.map +1 -1
- package/dist/scan-comparison.js +6 -2
- 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/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/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 +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/targets.d.ts +6 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +76 -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 +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/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/cli.md +373 -106
- package/docs/findings-service.md +22 -9
- package/docs/hosted-remediation.md +13 -4
- package/docs/sdk.md +903 -0
- package/package.json +10 -6
- package/schemas/external-findings.schema.json +2 -1
- 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-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C,CAAC;QACnD,MAAM,YAAY,GAAG,WAAW,IAAI,OAAO,CAAC;QAC5C,OAAO,QAAQ,CAAC,OAAO,EAAE;YACvB,MAAM,CAAC,IAAI;YACX,QAAQ;YACR,QAAQ;YACR,IAAI;YACJ,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY;YAC/C,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,WAAW,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC,CAAC;IACL,CAAC,EACD,MAAM,CACP,CAAC;IACF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM;QAAE,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IACxD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,MAAM,GAAyB,OAAO,EACtC,QAAiB;IAEjB,OAAO,sBAAsB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { posix, sep } from \"node:path\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isGitHubCloudHost, isGitSsh, parseGitRemote } from \"./git-remote.js\";\nimport {\n hostedRepositoryUrlKey,\n normalizeHostedGitRepositoryUrl,\n} from \"./hosted-git-repository.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n reportableScannerSeverity,\n requiredText,\n stableId,\n strings,\n text,\n} from \"./scanner-import.js\";\n\ntype NativeRecord = Record<string, unknown>;\n\nconst urlScheme = /^[a-z][a-z\\d+.-]*:\\/\\//iu;\nconst javaArchiveAncestor = /\\.(?:jar|war|ear|par)\\//iu;\nconst cloudLocationLimit = 100;\n\nconst curlUrlPrefix = /^(?:(?:https?|ftps?)::)?(?:https?|ftps?):\\/{1,3}/iu;\nconst unsafeRepositoryUrl =\n \"Use a Trivy repository URL without credentials, a query, or a fragment.\";\n\nfunction hasHttpUserinfo(\n value: string | null,\n allowImplicitHttps: boolean,\n): boolean {\n if (!value) return false;\n const prefix = curlUrlPrefix.exec(value)?.[0];\n if (!prefix && (!allowImplicitHttps || /^[a-z]:[\\\\/]/iu.test(value)))\n return false;\n // Git's HTTP transport treats backslashes before @ as part of userinfo.\n const authority = value.slice(prefix?.length ?? 0).split(/[/?#]/u, 1)[0]!;\n const at = authority.lastIndexOf(\"@\");\n const colon = authority.indexOf(\":\");\n const scp = colon > authority.indexOf(\"@\");\n // A bare user@host:path is Git's SSH form. Trivy reads user@host/path as HTTPS.\n return at > 0 && (!!prefix || (!scp && !authority.includes(\"\\\\\", at + 1)));\n}\n\nfunction networkRepository(value: unknown): string | null {\n const source = text(value);\n if (!source || /^(?:[a-z]:|[./\\\\])/iu.test(source)) return null;\n const remote = parseGitRemote(source);\n if (!remote) return null;\n const { url } = remote;\n const ssh = isGitSsh(url.protocol);\n if (url.password || (!ssh && url.username) || /[?#\\t\\r\\n]/u.test(source))\n throw new Error(unsafeRepositoryUrl);\n if (url.protocol === \"file:\") return null;\n if (\n !url.hostname ||\n !remote.path ||\n (!ssh &&\n ![\"http:\", \"https:\", \"git:\", \"ftp:\", \"ftps:\"].includes(url.protocol))\n )\n throw new Error(\"Unsupported Trivy repository URL.\");\n return source;\n}\n\nfunction comparableGitHubRemote(\n remote: string,\n cloudRepositoryUrl?: string,\n): string | undefined {\n if (/[?#\\t\\r\\n]/u.test(remote)) return undefined;\n let parsed;\n try {\n parsed = parseGitRemote(remote);\n } catch {\n // A checkout can have unrelated remotes with no comparable URL.\n return undefined;\n }\n if (!parsed) return undefined;\n const prefix = `${parsed.url.protocol}//`;\n // Git dispatches mixed-case schemes to distinct remote helpers.\n if (!parsed.scpStyle && !remote.startsWith(prefix)) return undefined;\n const host = parsed.url.hostname.toLowerCase();\n const githubUrl =\n cloudRepositoryUrl ??\n (isGitHubCloudHost(host) ? `https://${host}` : undefined);\n const normalized = normalizeHostedGitRepositoryUrl(\n remote,\n githubUrl,\n githubUrl !== undefined,\n );\n if (!/^https?:\\/\\//iu.test(normalized)) return undefined;\n if (\n !isGitHubCloudHost(new URL(normalized).hostname) &&\n (!cloudRepositoryUrl || new URL(cloudRepositoryUrl).hostname !== host)\n )\n return undefined;\n return normalized;\n}\n\nexport function trivyRemoteKey(\n remote: string,\n cloudRepositoryUrl?: string,\n checkout = false,\n): string {\n const normalized = comparableGitHubRemote(remote, cloudRepositoryUrl);\n if (!normalized) return remote;\n // GitHub identifies an HTTPS repository by host and path. Other Git servers\n // may use the HTTP username to select the repository.\n const url = checkout\n ? normalized.replace(/^(https?:\\/\\/)[^/\\\\?#]*@/iu, \"$1\")\n : normalized;\n return hostedRepositoryUrlKey(\n url,\n true,\n false,\n cloudRepositoryUrl ? \"cloud\" : \"local\",\n );\n}\n\nconst sshScheme = /^(?:ssh|git\\+ssh|ssh\\+git):\\/\\//u;\n\nexport function trivyRemoteOmitsSshUser(url: string): boolean {\n return sshScheme.test(url) && !new URL(url).username;\n}\n\nexport const trivyHeaderFields = [\n \"SchemaVersion\",\n \"ArtifactType\",\n \"ArtifactID\",\n \"ReportID\",\n \"CreatedAt\",\n];\n\n// Go may rewrite escaped separators or unreserved bytes in mixed Unicode paths.\n// Only escape spaces and non-ASCII bytes when existing escapes are unambiguous.\nfunction escapedHttpTarget(target: string): string {\n return target.replace(\n /^(https?:\\/\\/[^/]+)(\\/(?:[^%]|%(?:2[05]|[89A-F][\\dA-F]))*)$/u,\n (_, authority: string, path: string) =>\n authority + path.replace(/[ \\P{ASCII}]+/gu, encodeURIComponent),\n );\n}\n\nexport function trivyReportRemotes(report: unknown) {\n if (!isRecord(report)) return { urls: [] };\n const metadata = report[\"Metadata\"];\n const repoUrl = text(isRecord(metadata) && metadata[\"RepoURL\"]);\n const name = text(report[\"ArtifactName\"]);\n if (\n hasHttpUserinfo(repoUrl, true) ||\n hasHttpUserinfo(name, report[\"ArtifactType\"] !== \"filesystem\")\n )\n throw new Error(unsafeRepositoryUrl);\n const repository = networkRepository(repoUrl);\n let artifact = name && urlScheme.test(name) ? networkRepository(name) : null;\n if (report[\"SchemaVersion\"] !== 2) return { urls: [] };\n // A filesystem display label is validated but never identifies the repository.\n if (report[\"ArtifactType\"] === \"filesystem\")\n return { urls: repository ? [repository] : [] };\n // Trivy accepts scheme-less HTTPS targets and relative checkout paths.\n // A scheme-less name identifies a remote only when Git metadata corroborates it.\n const target =\n artifact ??\n (name && /^[^./:\\\\][^/:\\\\]*\\//u.test(name) ? `https://${name}` : null);\n if (\n target &&\n repository &&\n report[\"ArtifactType\"] === \"repository\" &&\n (target === repository || escapedHttpTarget(target) === repository)\n )\n artifact = repository;\n // A checkout-supplied label cannot restore an omitted SSH user. Keep any\n // other difference visible when validating the report's repository claims.\n if (\n repository &&\n trivyRemoteOmitsSshUser(repository) &&\n artifact?.replace(/^([^:]+:\\/\\/)[^/@]+@/u, \"$1\") === repository\n )\n return { urls: [repository] };\n return {\n urls: [repository, artifact].filter((url) => url !== null),\n uncorroboratedTarget: repository ? null : artifact,\n };\n}\n\nfunction matchingTrivyRemotes(\n [repository, artifact]: readonly string[],\n githubUrl?: string,\n): boolean {\n return (\n !!repository &&\n !!artifact &&\n trivyRemoteKey(repository, githubUrl) ===\n trivyRemoteKey(artifact, githubUrl)\n );\n}\n\n/** Compare the report's claims using the authenticated host when available. */\nexport function trivyRepositoryUrl(\n report: unknown,\n cloudRepositoryUrl?: string,\n): string | null {\n const { urls } = trivyReportRemotes(report);\n if (urls.length > 1 && !matchingTrivyRemotes(urls, cloudRepositoryUrl))\n throw new Error(\"Trivy source URLs identify different repositories.\");\n const remote = urls[0];\n return remote && cloudRepositoryUrl\n ? (comparableGitHubRemote(remote, cloudRepositoryUrl) ?? remote)\n : (remote ?? null);\n}\n\nfunction repositoryPath(value: unknown, directory = false): string | null {\n const raw = text(value);\n if (!raw || !relativePath(raw)) return null;\n // Check the emitted spelling across platforms while retaining literal POSIX backslashes.\n const path = posix.normalize(raw);\n const portable = posix.normalize(path.replaceAll(\"\\\\\", \"/\"));\n const firstComponent = portable.split(\"/\", 1)[0]!;\n const at = firstComponent.indexOf(\"@\", 1);\n const scpStyle = at !== -1 && firstComponent.indexOf(\":\", at + 2) !== -1;\n return relativePath(portable) &&\n (directory || (portable !== \".\" && !portable.endsWith(\"/\"))) &&\n !scpStyle &&\n !/^[a-z][a-z\\d+.-]*:\\//iu.test(portable)\n ? path\n : null;\n}\n\nconst aggregateTargets = new Map([\n [\"python-pkg\", \"Python\"],\n [\"conda-pkg\", \"Conda\"],\n [\"gemspec\", \"Ruby\"],\n [\"node-pkg\", \"Node.js\"],\n [\"jar\", \"Java\"],\n [\"kubernetes\", \"Kubernetes\"],\n]);\nconst nonManifestTypes = new Set([\n \"gobinary\",\n \"rustbinary\",\n \"jar\",\n \"javascript\",\n]);\n\nfunction resolveScanRoot(\n scanRoot: string | undefined,\n remoteRepository: boolean,\n): string {\n if (scanRoot === undefined) {\n if (remoteRepository) return \".\";\n throw new Error(\n \"Specify --trivy-scan-root relative to the repository; use . for a whole-checkout scan.\",\n );\n }\n const root = repositoryPath(scanRoot.split(sep).join(\"/\"), true)?.replace(\n /\\/$/u,\n \"\",\n );\n if (!root)\n throw new Error(\n \"--trivy-scan-root must be a repository-relative directory without traversal.\",\n );\n if (remoteRepository && root !== \".\")\n throw new Error(\n \"A remote Trivy repository scan starts at the checkout root; --trivy-scan-root must be .\",\n );\n return root;\n}\n\nfunction scopedPath(root: string, value: unknown): string | null {\n const path = repositoryPath(value);\n return path === null ? null : posix.join(root, path);\n}\n\nfunction pick(source: NativeRecord, fields: string[]): NativeRecord {\n return Object.fromEntries(\n fields\n .filter((field) => Object.hasOwn(source, field))\n .map((field) => [field, source[field]]),\n );\n}\n\nfunction packageKeys(row: NativeRecord, inventory: boolean) {\n const path = row[inventory ? \"FilePath\" : \"PkgPath\"];\n const identifier = row[inventory ? \"Identifier\" : \"PkgIdentifier\"];\n const name = row[inventory ? \"Name\" : \"PkgName\"];\n const version = row[inventory ? \"Version\" : \"InstalledVersion\"];\n const file = repositoryPath(path) ?? text(path);\n const key = (kind: string, value: unknown) =>\n text(value) && JSON.stringify([kind, value, file]);\n const native = isRecord(identifier) ? identifier : {};\n return {\n id: key(\"id\", row[inventory ? \"ID\" : \"PkgID\"]),\n uid: key(\"uid\", native[\"UID\"]),\n purl: key(\"purl\", native[\"PURL\"]),\n bomRef: key(\"bomRef\", native[\"BOMRef\"]),\n nameVersion:\n text(name) &&\n text(version) &&\n JSON.stringify([\"name-version\", name, version, file]),\n };\n}\n\ntype PackageIndex = Map<\n string,\n { pkg: NativeRecord; keys: ReturnType<typeof packageKeys> } | null\n>;\n\nfunction indexPackages(packages: unknown): PackageIndex {\n const index: PackageIndex = new Map();\n for (const value of array(packages ?? [], \"Trivy Packages\")) {\n const pkg = record(value, \"Trivy package\");\n const keys = packageKeys(pkg, true);\n const match = { pkg, keys };\n for (const key of Object.values(keys))\n if (key) index.set(key, index.has(key) ? null : match);\n }\n return index;\n}\n\nfunction matchingPackage(vulnerability: NativeRecord, index: PackageIndex) {\n const keys = packageKeys(vulnerability, false);\n const supplied = ([\"uid\", \"id\", \"purl\", \"bomRef\"] as const).filter(\n (field) => keys[field],\n );\n for (const field of supplied.length ? supplied : ([\"nameVersion\"] as const)) {\n const key = keys[field];\n const match = key && index.get(key);\n if (\n match &&\n agreesWhenPresent(vulnerability[\"PkgName\"], match.pkg[\"Name\"]) &&\n agreesWhenPresent(\n vulnerability[\"InstalledVersion\"],\n match.pkg[\"Version\"],\n ) &&\n supplied.every((id) => !match.keys[id] || keys[id] === match.keys[id])\n )\n return match.pkg;\n }\n return null;\n}\n\nfunction agreesWhenPresent(detected: unknown, inventoried: unknown): boolean {\n return !text(detected) || !text(inventoried) || detected === inventoried;\n}\n\ninterface Entry {\n result: { Target?: string; Type: string; Class: string };\n packages: PackageIndex;\n value: unknown;\n}\n\nfunction occurrence(entry: Entry | string, root: string) {\n if (typeof entry === \"string\") throw new Error(entry);\n const vulnerability = record(entry.value, \"Trivy vulnerability\");\n const { Target, Type } = entry.result;\n return {\n ...entry,\n vulnerability,\n advisory: requiredText(\n vulnerability[\"VulnerabilityID\"],\n \"Trivy VulnerabilityID\",\n ),\n name: requiredText(vulnerability[\"PkgName\"], \"Trivy PkgName\"),\n pkgPath: text(vulnerability[\"PkgPath\"]),\n targetPath:\n aggregateTargets.get(Type) === Target ? null : scopedPath(root, Target),\n packagePath: scopedPath(root, vulnerability[\"PkgPath\"]),\n };\n}\n\n/** Import native Trivy dependency occurrences. Local scans require their checkout-relative\n * scan root. The package ecosystem is the PURL type when supplied, otherwise the analyzer. */\nexport function normalizeTrivyFindings(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n scanRoot?: string,\n): ExternalFindings {\n const locationLimit = target === \"cloud\" ? cloudLocationLimit : Infinity;\n return normalizeReport(input, target, scanRoot, locationLimit);\n}\n\n/** @internal Only a finding at the Cloud location limit can have a different prior selection. */\nexport function needsPreviousTrivyProjection({ findings }: ExternalFindings) {\n return findings.some(\n ({ evidence }) => evidence.locations?.length === cloudLocationLimit,\n );\n}\n\n/** @internal Reconstruct the original selection for an interrupted Cloud request. */\nexport function normalizePreviousTrivyFindings(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n scanRoot?: string,\n): ExternalFindings {\n return normalizeReport(input, target, scanRoot, Infinity);\n}\n\nfunction normalizeReport(\n input: unknown,\n target: ExternalImportTarget,\n scanRoot: string | undefined,\n locationLimit: number,\n): ExternalFindings {\n const document = record(input, \"Trivy report\");\n if (document[\"SchemaVersion\"] !== 2)\n throw new Error(\n \"Expected a native Trivy JSON report with SchemaVersion 2.\",\n );\n if (\n document[\"ArtifactType\"] !== \"repository\" &&\n document[\"ArtifactType\"] !== \"filesystem\"\n )\n throw new Error(\n \"Only Trivy repository and filesystem reports are supported.\",\n );\n const metadata = record(document[\"Metadata\"] ?? {}, \"Trivy Metadata\");\n const { urls } = trivyReportRemotes(document);\n const report = {\n ...pick(document, trivyHeaderFields),\n ...(isRecord(document[\"Trivy\"])\n ? { Trivy: pick(document[\"Trivy\"], [\"Version\"]) }\n : {}),\n ...(typeof document[\"ArtifactName\"] === \"string\"\n ? { ArtifactName: document[\"ArtifactName\"] }\n : {}),\n Metadata: pick(metadata, [\"RepoURL\", \"Branch\", \"Commit\"]),\n };\n // A scan root requires corroboration. Explicit-root readers can inspect a report\n // whose declarations still have to agree with the destination at import.\n const root = resolveScanRoot(scanRoot, matchingTrivyRemotes(urls));\n\n const entries: (Entry | string)[] = [];\n for (const group of array(document[\"Results\"] ?? [], \"Trivy Results\")) {\n const result = record(group, \"Trivy result\");\n if (result[\"Class\"] !== \"lang-pkgs\") {\n entries.push(\n `Unsupported Trivy result class: ${text(result[\"Class\"]) ?? \"(missing)\"}. Only lang-pkgs vulnerabilities are imported.`,\n );\n continue;\n }\n for (const field of [\n \"Misconfigurations\",\n \"Secrets\",\n \"Licenses\",\n \"CryptoAssets\",\n \"CustomResources\",\n \"ExperimentalModifiedFindings\",\n ])\n if (array(result[field] ?? [], `Trivy ${field}`).length)\n entries.push(`Unsupported Trivy ${field} in lang-pkgs result.`);\n\n const vulnerabilities = array(\n result[\"Vulnerabilities\"] ?? [],\n \"Trivy Vulnerabilities\",\n );\n if (!vulnerabilities.length) continue;\n const reportedTarget = result[\"Target\"];\n if (reportedTarget != null && typeof reportedTarget !== \"string\")\n throw new Error(\"Trivy result Target must be text.\");\n const context = {\n ...(reportedTarget == null ? {} : { Target: reportedTarget }),\n Type: requiredText(result[\"Type\"], \"Trivy result Type\"),\n Class: result[\"Class\"],\n };\n const packages = indexPackages(result[\"Packages\"]);\n for (const value of vulnerabilities)\n entries.push({ result: context, packages, value });\n }\n\n const findings = normalizeRecords(\n entries,\n (entry) => {\n const row = occurrence(entry, root);\n const { result, packages, vulnerability, advisory, name, targetPath } =\n row;\n const identifier = vulnerability[\"PkgIdentifier\"];\n const purl = isRecord(identifier) ? text(identifier[\"PURL\"]) : null;\n const ecosystem =\n purl?.match(/^pkg:([a-z][a-z\\d.+-]*)\\//iu)?.[1]?.toLowerCase() ??\n result.Type;\n const pkg = matchingPackage(vulnerability, packages);\n const manifest = nonManifestTypes.has(result.Type) ? null : targetPath;\n // Trivy uses the same spelling for archive members and files in exploded archives.\n let declaration = row.pkgPath ? row.packagePath : manifest;\n if (\n result.Type === \"jar\" &&\n row.pkgPath !== null &&\n javaArchiveAncestor.test(row.pkgPath) &&\n /\\.(?:jar|ear|war)$/u.test(row.pkgPath)\n )\n declaration = null;\n const locations: { path: string; line: number | null }[] = [];\n if (targetPath && targetPath !== declaration)\n locations.push({ path: targetPath, line: null });\n if (declaration) {\n // The scan target already consumes a slot when it differs from this declaration.\n const lineLimit = locationLimit - locations.length;\n const lines = new Set<number>();\n for (const range of array(\n pkg?.[\"Locations\"] ?? [],\n \"Trivy package Locations\",\n )) {\n const start = isRecord(range) && range[\"StartLine\"];\n if (\n typeof start === \"number\" &&\n Number.isSafeInteger(start) &&\n start > 0 &&\n lines.size < lineLimit\n )\n lines.add(start);\n }\n if (!lines.size) locations.push({ path: declaration, line: null });\n for (const line of lines) locations.push({ path: declaration, line });\n }\n return validateExternalEvidence(\n {\n title: text(vulnerability[\"Title\"]) ?? `${advisory} in ${name}`,\n severity: reportableScannerSeverity(vulnerability[\"Severity\"]),\n description: text(vulnerability[\"Description\"]),\n url: text(vulnerability[\"PrimaryURL\"]),\n advisory_ids: [\n ...new Set([advisory, ...strings(vulnerability[\"VendorIDs\"])]),\n ],\n packages: [\n {\n name,\n ecosystem,\n manifest_path: manifest,\n installed_version: text(vulnerability[\"InstalledVersion\"]),\n fixed_versions:\n text(vulnerability[\"FixedVersion\"])\n ?.split(\",\")\n .map((version) => version.trim())\n .filter(Boolean) ?? [],\n },\n ],\n locations,\n branch: text(metadata[\"Branch\"]),\n source_scan_id: text(document[\"ReportID\"]),\n source_data: structuredClone({\n scanRoot: root,\n report,\n result,\n vulnerability,\n ...(pkg\n ? {\n package: pick(pkg, [\n \"ID\",\n \"Name\",\n \"Version\",\n \"Identifier\",\n \"FilePath\",\n \"Relationship\",\n \"Locations\",\n ]),\n }\n : {}),\n }),\n },\n target,\n );\n },\n (entry) => {\n const { result, advisory, name, pkgPath, targetPath, packagePath } =\n occurrence(entry, root);\n const manifest = targetPath ?? text(result.Target);\n const concretePath = packagePath ?? pkgPath;\n return stableId(\"trivy\", [\n result.Type,\n manifest,\n advisory,\n name,\n concretePath === manifest ? null : concretePath,\n ...(!targetPath && !packagePath && root !== \".\" ? [root] : []),\n ]);\n },\n target,\n );\n if (!findings.findings.length) findings.report = report;\n return findings;\n}\n\nexport async function readTrivyFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n scanRoot?: string,\n): Promise<ExternalFindings> {\n return normalizeTrivyFindings(await readScannerJson(path), target, scanRoot);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"trivy-findings.js","sourceRoot":"","sources":["../src/trivy-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,+BAA+B,GAChC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,yBAAyB,EACzB,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,IAAI,GACL,MAAM,qBAAqB,CAAC;AAI7B,MAAM,SAAS,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1B,MAAM,QAAQ,GAAG,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,WAAW,IAAI,OAAO,CAAC;QAC5C,OAAO,QAAQ,CAAC,OAAO,EAAE;YACvB,MAAM,CAAC,IAAI;YACX,QAAQ;YACR,QAAQ;YACR,IAAI;YACJ,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY;YAC/C,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,WAAW,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC,CAAC;IACL,CAAC,EACD,MAAM,CACP,CAAC;IACF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM;QAAE,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IACxD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,MAAM,GAAyB,OAAO,EACtC,QAAiB;IAEjB,OAAO,sBAAsB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { posix, sep } from \"node:path\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isGitHubCloudHost, isGitSsh, parseGitRemote } from \"./git-remote.js\";\nimport {\n hostedRepositoryUrlKey,\n normalizeHostedGitRepositoryUrl,\n} from \"./hosted-git-repository.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n reportableScannerSeverity,\n requiredText,\n stableId,\n strings,\n text,\n} from \"./scanner-import.js\";\n\ntype NativeRecord = Record<string, unknown>;\n\nconst urlScheme = /^[a-z][a-z\\d+.-]*:\\/\\//iu;\nconst javaArchiveAncestor = /\\.(?:jar|war|ear|par)\\//iu;\nconst cloudLocationLimit = 100;\n\nconst curlUrlPrefix = /^(?:(?:https?|ftps?)::)?(?:https?|ftps?):\\/{1,3}/iu;\nconst unsafeRepositoryUrl =\n \"Use a Trivy repository URL without credentials, a query, or a fragment.\";\n\nfunction hasHttpUserinfo(\n value: string | null,\n allowImplicitHttps: boolean,\n): boolean {\n if (!value) return false;\n const prefix = curlUrlPrefix.exec(value)?.[0];\n if (!prefix && (!allowImplicitHttps || /^[a-z]:[\\\\/]/iu.test(value)))\n return false;\n // Git's HTTP transport treats backslashes before @ as part of userinfo.\n const authority = value.slice(prefix?.length ?? 0).split(/[/?#]/u, 1)[0]!;\n const at = authority.lastIndexOf(\"@\");\n const colon = authority.indexOf(\":\");\n const scp = colon > authority.indexOf(\"@\");\n // A bare user@host:path is Git's SSH form. Trivy reads user@host/path as HTTPS.\n return at > 0 && (!!prefix || (!scp && !authority.includes(\"\\\\\", at + 1)));\n}\n\nfunction networkRepository(value: unknown): string | null {\n const source = text(value);\n if (!source || /^(?:[a-z]:|[./\\\\])/iu.test(source)) return null;\n const remote = parseGitRemote(source);\n if (!remote) return null;\n const { url } = remote;\n const ssh = isGitSsh(url.protocol);\n if (url.password || (!ssh && url.username) || /[?#\\t\\r\\n]/u.test(source))\n throw new Error(unsafeRepositoryUrl);\n if (url.protocol === \"file:\") return null;\n if (\n !url.hostname ||\n !remote.path ||\n (!ssh &&\n ![\"http:\", \"https:\", \"git:\", \"ftp:\", \"ftps:\"].includes(url.protocol))\n )\n throw new Error(\"Unsupported Trivy repository URL.\");\n return source;\n}\n\nfunction comparableGitHubRemote(\n remote: string,\n cloudRepositoryUrl?: string,\n): string | undefined {\n if (/[?#\\t\\r\\n]/u.test(remote)) return undefined;\n let parsed;\n try {\n parsed = parseGitRemote(remote);\n } catch {\n // A checkout can have unrelated remotes with no comparable URL.\n return undefined;\n }\n if (!parsed) return undefined;\n const prefix = `${parsed.url.protocol}//`;\n // Git dispatches mixed-case schemes to distinct remote helpers.\n if (!parsed.scpStyle && !remote.startsWith(prefix)) return undefined;\n const host = parsed.url.hostname.toLowerCase();\n const githubUrl =\n cloudRepositoryUrl ??\n (isGitHubCloudHost(host) ? `https://${host}` : undefined);\n const normalized = normalizeHostedGitRepositoryUrl(\n remote,\n githubUrl,\n githubUrl !== undefined,\n );\n if (!/^https?:\\/\\//iu.test(normalized)) return undefined;\n if (\n !isGitHubCloudHost(new URL(normalized).hostname) &&\n (!cloudRepositoryUrl || new URL(cloudRepositoryUrl).hostname !== host)\n )\n return undefined;\n return normalized;\n}\n\nexport function trivyRemoteKey(\n remote: string,\n cloudRepositoryUrl?: string,\n checkout = false,\n): string {\n const normalized = comparableGitHubRemote(remote, cloudRepositoryUrl);\n if (!normalized) return remote;\n // GitHub identifies an HTTPS repository by host and path. Other Git servers\n // may use the HTTP username to select the repository.\n const url = checkout\n ? normalized.replace(/^(https?:\\/\\/)[^/\\\\?#]*@/iu, \"$1\")\n : normalized;\n return hostedRepositoryUrlKey(\n url,\n true,\n false,\n cloudRepositoryUrl ? \"cloud\" : \"local\",\n );\n}\n\nconst sshScheme = /^(?:ssh|git\\+ssh|ssh\\+git):\\/\\//u;\n\nexport function trivyRemoteOmitsSshUser(url: string): boolean {\n return sshScheme.test(url) && !new URL(url).username;\n}\n\nexport const trivyHeaderFields = [\n \"SchemaVersion\",\n \"ArtifactType\",\n \"ArtifactID\",\n \"ReportID\",\n \"CreatedAt\",\n];\n\n// Go may rewrite escaped separators or unreserved bytes in mixed Unicode paths.\n// Only escape spaces and non-ASCII bytes when existing escapes are unambiguous.\nfunction escapedHttpTarget(target: string): string {\n return target.replace(\n /^(https?:\\/\\/[^/]+)(\\/(?:[^%]|%(?:2[05]|[89A-F][\\dA-F]))*)$/u,\n (_, authority: string, path: string) =>\n authority + path.replace(/[ \\P{ASCII}]+/gu, encodeURIComponent),\n );\n}\n\nexport function trivyReportRemotes(report: unknown) {\n if (!isRecord(report)) return { urls: [] };\n const metadata = report[\"Metadata\"];\n const repoUrl = text(isRecord(metadata) && metadata[\"RepoURL\"]);\n const name = text(report[\"ArtifactName\"]);\n if (\n hasHttpUserinfo(repoUrl, true) ||\n hasHttpUserinfo(name, report[\"ArtifactType\"] !== \"filesystem\")\n )\n throw new Error(unsafeRepositoryUrl);\n const repository = networkRepository(repoUrl);\n let artifact = name && urlScheme.test(name) ? networkRepository(name) : null;\n if (report[\"SchemaVersion\"] !== 2) return { urls: [] };\n // A filesystem display label is validated but never identifies the repository.\n if (report[\"ArtifactType\"] === \"filesystem\")\n return { urls: repository ? [repository] : [] };\n // Trivy accepts scheme-less HTTPS targets and relative checkout paths.\n // A scheme-less name identifies a remote only when Git metadata corroborates it.\n const target =\n artifact ??\n (name && /^[^./:\\\\][^/:\\\\]*\\//u.test(name) ? `https://${name}` : null);\n if (\n target &&\n repository &&\n report[\"ArtifactType\"] === \"repository\" &&\n (target === repository || escapedHttpTarget(target) === repository)\n )\n artifact = repository;\n // A checkout-supplied label cannot restore an omitted SSH user. Keep any\n // other difference visible when validating the report's repository claims.\n if (\n repository &&\n trivyRemoteOmitsSshUser(repository) &&\n artifact?.replace(/^([^:]+:\\/\\/)[^/@]+@/u, \"$1\") === repository\n )\n return { urls: [repository] };\n return {\n urls: [repository, artifact].filter((url) => url !== null),\n uncorroboratedTarget: repository ? null : artifact,\n };\n}\n\nfunction matchingTrivyRemotes(\n [repository, artifact]: readonly string[],\n githubUrl?: string,\n): boolean {\n return (\n !!repository &&\n !!artifact &&\n trivyRemoteKey(repository, githubUrl) ===\n trivyRemoteKey(artifact, githubUrl)\n );\n}\n\n/** Compare the report's claims using the authenticated host when available. */\nexport function trivyRepositoryUrl(\n report: unknown,\n cloudRepositoryUrl?: string,\n): string | null {\n const { urls } = trivyReportRemotes(report);\n if (urls.length > 1 && !matchingTrivyRemotes(urls, cloudRepositoryUrl))\n throw new Error(\"Trivy source URLs identify different repositories.\");\n const remote = urls[0];\n return remote && cloudRepositoryUrl\n ? (comparableGitHubRemote(remote, cloudRepositoryUrl) ?? remote)\n : (remote ?? null);\n}\n\nfunction repositoryPath(value: unknown, directory = false): string | null {\n const raw = text(value);\n if (!raw || !relativePath(raw)) return null;\n // Check the emitted spelling across platforms while retaining literal POSIX backslashes.\n const path = posix.normalize(raw);\n const portable = posix.normalize(path.replaceAll(\"\\\\\", \"/\"));\n const firstComponent = portable.split(\"/\", 1)[0]!;\n const at = firstComponent.indexOf(\"@\", 1);\n const scpStyle = at !== -1 && firstComponent.indexOf(\":\", at + 2) !== -1;\n return relativePath(portable) &&\n (directory || (portable !== \".\" && !portable.endsWith(\"/\"))) &&\n !scpStyle &&\n !/^[a-z][a-z\\d+.-]*:\\//iu.test(portable)\n ? path\n : null;\n}\n\nconst aggregateTargets = new Map([\n [\"python-pkg\", \"Python\"],\n [\"conda-pkg\", \"Conda\"],\n [\"gemspec\", \"Ruby\"],\n [\"node-pkg\", \"Node.js\"],\n [\"jar\", \"Java\"],\n [\"kubernetes\", \"Kubernetes\"],\n]);\nconst nonManifestTypes = new Set([\n \"gobinary\",\n \"rustbinary\",\n \"jar\",\n \"javascript\",\n]);\n\nfunction resolveScanRoot(\n scanRoot: string | undefined,\n remoteRepository: boolean,\n): string {\n if (scanRoot === undefined) {\n if (remoteRepository) return \".\";\n throw new Error(\n \"Specify --trivy-scan-root relative to the repository; use . for a whole-checkout scan.\",\n );\n }\n const root = repositoryPath(scanRoot.split(sep).join(\"/\"), true)?.replace(\n /\\/$/u,\n \"\",\n );\n if (!root)\n throw new Error(\n \"--trivy-scan-root must be a repository-relative directory without traversal.\",\n );\n if (remoteRepository && root !== \".\")\n throw new Error(\n \"A remote Trivy repository scan starts at the checkout root; --trivy-scan-root must be .\",\n );\n return root;\n}\n\nfunction scopedPath(root: string, value: unknown): string | null {\n const path = repositoryPath(value);\n return path === null ? null : posix.join(root, path);\n}\n\nfunction pick(source: NativeRecord, fields: string[]): NativeRecord {\n return Object.fromEntries(\n fields\n .filter((field) => Object.hasOwn(source, field))\n .map((field) => [field, source[field]]),\n );\n}\n\nfunction packageKeys(row: NativeRecord, inventory: boolean) {\n const path = row[inventory ? \"FilePath\" : \"PkgPath\"];\n const identifier = row[inventory ? \"Identifier\" : \"PkgIdentifier\"];\n const name = row[inventory ? \"Name\" : \"PkgName\"];\n const version = row[inventory ? \"Version\" : \"InstalledVersion\"];\n const file = repositoryPath(path) ?? text(path);\n const key = (kind: string, value: unknown) =>\n text(value) && JSON.stringify([kind, value, file]);\n const native = isRecord(identifier) ? identifier : {};\n return {\n id: key(\"id\", row[inventory ? \"ID\" : \"PkgID\"]),\n uid: key(\"uid\", native[\"UID\"]),\n purl: key(\"purl\", native[\"PURL\"]),\n bomRef: key(\"bomRef\", native[\"BOMRef\"]),\n nameVersion:\n text(name) &&\n text(version) &&\n JSON.stringify([\"name-version\", name, version, file]),\n };\n}\n\ntype PackageIndex = Map<\n string,\n { pkg: NativeRecord; keys: ReturnType<typeof packageKeys> } | null\n>;\n\nfunction indexPackages(packages: unknown): PackageIndex {\n const index: PackageIndex = new Map();\n for (const value of array(packages ?? [], \"Trivy Packages\")) {\n const pkg = record(value, \"Trivy package\");\n const keys = packageKeys(pkg, true);\n const match = { pkg, keys };\n for (const key of Object.values(keys))\n if (key) index.set(key, index.has(key) ? null : match);\n }\n return index;\n}\n\nfunction matchingPackage(vulnerability: NativeRecord, index: PackageIndex) {\n const keys = packageKeys(vulnerability, false);\n const supplied = ([\"uid\", \"id\", \"purl\", \"bomRef\"] as const).filter(\n (field) => keys[field],\n );\n for (const field of supplied.length ? supplied : ([\"nameVersion\"] as const)) {\n const key = keys[field];\n const match = key && index.get(key);\n if (\n match &&\n agreesWhenPresent(vulnerability[\"PkgName\"], match.pkg[\"Name\"]) &&\n agreesWhenPresent(\n vulnerability[\"InstalledVersion\"],\n match.pkg[\"Version\"],\n ) &&\n supplied.every((id) => !match.keys[id] || keys[id] === match.keys[id])\n )\n return match.pkg;\n }\n return null;\n}\n\nfunction agreesWhenPresent(detected: unknown, inventoried: unknown): boolean {\n return !text(detected) || !text(inventoried) || detected === inventoried;\n}\n\ninterface Entry {\n result: { Target?: string; Type: string; Class: string };\n packages: PackageIndex;\n value: unknown;\n}\n\nfunction occurrence(entry: Entry | string, root: string) {\n if (typeof entry === \"string\") throw new Error(entry);\n const vulnerability = record(entry.value, \"Trivy vulnerability\");\n const { Target, Type } = entry.result;\n return {\n ...entry,\n vulnerability,\n advisory: requiredText(\n vulnerability[\"VulnerabilityID\"],\n \"Trivy VulnerabilityID\",\n ),\n name: requiredText(vulnerability[\"PkgName\"], \"Trivy PkgName\"),\n pkgPath: text(vulnerability[\"PkgPath\"]),\n targetPath:\n aggregateTargets.get(Type) === Target ? null : scopedPath(root, Target),\n packagePath: scopedPath(root, vulnerability[\"PkgPath\"]),\n };\n}\n\n/** Import native Trivy dependency occurrences. Local scans require their checkout-relative\n * scan root. The package ecosystem is the PURL type when supplied, otherwise the analyzer. */\nexport function normalizeTrivyFindings(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n scanRoot?: string,\n): ExternalFindings {\n const locationLimit = target === \"cloud\" ? cloudLocationLimit : Infinity;\n const document = record(input, \"Trivy report\");\n if (document[\"SchemaVersion\"] !== 2)\n throw new Error(\n \"Expected a native Trivy JSON report with SchemaVersion 2.\",\n );\n if (\n document[\"ArtifactType\"] !== \"repository\" &&\n document[\"ArtifactType\"] !== \"filesystem\"\n )\n throw new Error(\n \"Only Trivy repository and filesystem reports are supported.\",\n );\n const metadata = record(document[\"Metadata\"] ?? {}, \"Trivy Metadata\");\n const { urls } = trivyReportRemotes(document);\n const report = {\n ...pick(document, trivyHeaderFields),\n ...(isRecord(document[\"Trivy\"])\n ? { Trivy: pick(document[\"Trivy\"], [\"Version\"]) }\n : {}),\n ...(typeof document[\"ArtifactName\"] === \"string\"\n ? { ArtifactName: document[\"ArtifactName\"] }\n : {}),\n Metadata: pick(metadata, [\"RepoURL\", \"Branch\", \"Commit\"]),\n };\n // A scan root requires corroboration. Explicit-root readers can inspect a report\n // whose declarations still have to agree with the destination at import.\n const root = resolveScanRoot(scanRoot, matchingTrivyRemotes(urls));\n\n const entries: (Entry | string)[] = [];\n for (const group of array(document[\"Results\"] ?? [], \"Trivy Results\")) {\n const result = record(group, \"Trivy result\");\n if (result[\"Class\"] !== \"lang-pkgs\") {\n entries.push(\n `Unsupported Trivy result class: ${text(result[\"Class\"]) ?? \"(missing)\"}. Only lang-pkgs vulnerabilities are imported.`,\n );\n continue;\n }\n for (const field of [\n \"Misconfigurations\",\n \"Secrets\",\n \"Licenses\",\n \"CryptoAssets\",\n \"CustomResources\",\n \"ExperimentalModifiedFindings\",\n ])\n if (array(result[field] ?? [], `Trivy ${field}`).length)\n entries.push(`Unsupported Trivy ${field} in lang-pkgs result.`);\n\n const vulnerabilities = array(\n result[\"Vulnerabilities\"] ?? [],\n \"Trivy Vulnerabilities\",\n );\n if (!vulnerabilities.length) continue;\n const reportedTarget = result[\"Target\"];\n if (reportedTarget != null && typeof reportedTarget !== \"string\")\n throw new Error(\"Trivy result Target must be text.\");\n const context = {\n ...(reportedTarget == null ? {} : { Target: reportedTarget }),\n Type: requiredText(result[\"Type\"], \"Trivy result Type\"),\n Class: result[\"Class\"],\n };\n const packages = indexPackages(result[\"Packages\"]);\n for (const value of vulnerabilities)\n entries.push({ result: context, packages, value });\n }\n\n const findings = normalizeRecords(\n entries,\n (entry) => {\n const row = occurrence(entry, root);\n const { result, packages, vulnerability, advisory, name, targetPath } =\n row;\n const identifier = vulnerability[\"PkgIdentifier\"];\n const purl = isRecord(identifier) ? text(identifier[\"PURL\"]) : null;\n const ecosystem =\n purl?.match(/^pkg:([a-z][a-z\\d.+-]*)\\//iu)?.[1]?.toLowerCase() ??\n result.Type;\n const pkg = matchingPackage(vulnerability, packages);\n const manifest = nonManifestTypes.has(result.Type) ? null : targetPath;\n // Trivy uses the same spelling for archive members and files in exploded archives.\n let declaration = row.pkgPath ? row.packagePath : manifest;\n if (\n result.Type === \"jar\" &&\n row.pkgPath !== null &&\n javaArchiveAncestor.test(row.pkgPath) &&\n /\\.(?:jar|ear|war)$/u.test(row.pkgPath)\n )\n declaration = null;\n const locations: { path: string; line: number | null }[] = [];\n if (targetPath && targetPath !== declaration)\n locations.push({ path: targetPath, line: null });\n if (declaration) {\n // The scan target already consumes a slot when it differs from this declaration.\n const lineLimit = locationLimit - locations.length;\n const lines = new Set<number>();\n for (const range of array(\n pkg?.[\"Locations\"] ?? [],\n \"Trivy package Locations\",\n )) {\n const start = isRecord(range) && range[\"StartLine\"];\n if (\n typeof start === \"number\" &&\n Number.isSafeInteger(start) &&\n start > 0 &&\n lines.size < lineLimit\n )\n lines.add(start);\n }\n if (!lines.size) locations.push({ path: declaration, line: null });\n for (const line of lines) locations.push({ path: declaration, line });\n }\n return validateExternalEvidence(\n {\n title: text(vulnerability[\"Title\"]) ?? `${advisory} in ${name}`,\n severity: reportableScannerSeverity(vulnerability[\"Severity\"]),\n description: text(vulnerability[\"Description\"]),\n url: text(vulnerability[\"PrimaryURL\"]),\n advisory_ids: [\n ...new Set([advisory, ...strings(vulnerability[\"VendorIDs\"])]),\n ],\n packages: [\n {\n name,\n ecosystem,\n manifest_path: manifest,\n installed_version: text(vulnerability[\"InstalledVersion\"]),\n fixed_versions:\n text(vulnerability[\"FixedVersion\"])\n ?.split(\",\")\n .map((version) => version.trim())\n .filter(Boolean) ?? [],\n },\n ],\n locations,\n branch: text(metadata[\"Branch\"]),\n source_scan_id: text(document[\"ReportID\"]),\n source_data: structuredClone({\n scanRoot: root,\n report,\n result,\n vulnerability,\n ...(pkg\n ? {\n package: pick(pkg, [\n \"ID\",\n \"Name\",\n \"Version\",\n \"Identifier\",\n \"FilePath\",\n \"Relationship\",\n \"Locations\",\n ]),\n }\n : {}),\n }),\n },\n target,\n );\n },\n (entry) => {\n const { result, advisory, name, pkgPath, targetPath, packagePath } =\n occurrence(entry, root);\n const manifest = targetPath ?? text(result.Target);\n const concretePath = packagePath ?? pkgPath;\n return stableId(\"trivy\", [\n result.Type,\n manifest,\n advisory,\n name,\n concretePath === manifest ? null : concretePath,\n ...(!targetPath && !packagePath && root !== \".\" ? [root] : []),\n ]);\n },\n target,\n );\n if (!findings.findings.length) findings.report = report;\n return findings;\n}\n\nexport async function readTrivyFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n scanRoot?: string,\n): Promise<ExternalFindings> {\n return normalizeTrivyFindings(await readScannerJson(path), target, scanRoot);\n}\n"]}
|
|
@@ -6,6 +6,12 @@ export interface InspectedExecutable {
|
|
|
6
6
|
executable: string | null;
|
|
7
7
|
environment: Record<string, string | undefined>;
|
|
8
8
|
}
|
|
9
|
+
/** Include every selected source when a campaign launches tools from a new checkout. */
|
|
10
|
+
export declare function withProtectedExecutableRoots<T>(roots: readonly string[], run: () => Promise<T>): Promise<T>;
|
|
11
|
+
/** Bind an actual host launcher and its environment within this campaign. */
|
|
12
|
+
export declare function campaignExecutable(candidate: string, environment: Readonly<NodeJS.ProcessEnv> | (() => Readonly<NodeJS.ProcessEnv>)): Promise<TrustedExecutable> | undefined;
|
|
13
|
+
/** Host launchers and the workbench inherit the same Git search path as checkout. */
|
|
14
|
+
export declare function campaignCommandEnvironment(environment: Record<string, string | undefined>): Promise<Record<string, string | undefined>> | undefined;
|
|
9
15
|
export declare function resolveTrustedExecutable(candidate: string, environment: Readonly<Record<string, string | undefined>>, protectedRoot: string | readonly string[]): Promise<TrustedExecutable | null>;
|
|
10
16
|
export declare function inspectTrustedExecutable(candidate: string, environment: Readonly<Record<string, string | undefined>>, protectedRoot: string | readonly string[]): Promise<InspectedExecutable>;
|
|
11
17
|
//# sourceMappingURL=trusted-executable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted-executable.d.ts","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trusted-executable.d.ts","sourceRoot":"","sources":["../src/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EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACzD,aAAa,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GACxC,OAAO,CAAC,mBAAmB,CAAC,CAqJ9B"}
|
|
@@ -1,6 +1,71 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
10
|
import { constants } from "node:fs";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
2
12
|
import { access, realpath, stat } from "node:fs/promises";
|
|
3
13
|
import { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
14
|
+
const campaignScope = new AsyncLocalStorage();
|
|
15
|
+
function canonicalRoot(root) {
|
|
16
|
+
return realpath(root).catch(() => resolve(root));
|
|
17
|
+
}
|
|
18
|
+
async function campaignPathHelper() {
|
|
19
|
+
const { bundledPluginRoot } = await import("./bundled-plugin.js");
|
|
20
|
+
const path = join(await bundledPluginRoot(), "mcp/helpers.mjs");
|
|
21
|
+
const project = (await import(__rewriteRelativeImportExtension(pathToFileURL(path).href))).default
|
|
22
|
+
.inventoryToolPath;
|
|
23
|
+
if (typeof project !== "function")
|
|
24
|
+
throw new Error("The bundled plugin is missing campaign tool lookup.");
|
|
25
|
+
return project;
|
|
26
|
+
}
|
|
27
|
+
/** Include every selected source when a campaign launches tools from a new checkout. */
|
|
28
|
+
export async function withProtectedExecutableRoots(roots, run) {
|
|
29
|
+
const canonical = await Promise.all(roots.map(canonicalRoot));
|
|
30
|
+
const scope = {
|
|
31
|
+
roots: [
|
|
32
|
+
...new Set([...(campaignScope.getStore()?.roots ?? []), ...canonical]),
|
|
33
|
+
],
|
|
34
|
+
views: new Map(),
|
|
35
|
+
project: await campaignPathHelper(),
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
return await campaignScope.run(scope, run);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
for (const view of scope.views.values())
|
|
42
|
+
view.cleanup();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Bind an actual host launcher and its environment within this campaign. */
|
|
46
|
+
export function campaignExecutable(candidate, environment) {
|
|
47
|
+
if (!campaignScope.getStore())
|
|
48
|
+
return;
|
|
49
|
+
const env = typeof environment === "function" ? environment() : environment;
|
|
50
|
+
return resolveTrustedExecutable(candidate, env, []).then(async (command) => {
|
|
51
|
+
if (!command)
|
|
52
|
+
throw new Error(`Campaign executable is unavailable on a trusted PATH: ${candidate}`);
|
|
53
|
+
// Windows launchers inherit the same filtered PATH as checkout.
|
|
54
|
+
if (process.platform === "win32" && candidate !== "git")
|
|
55
|
+
command.environment = (await inspectTrustedExecutable("git", command.environment, [])).environment;
|
|
56
|
+
return command;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** Host launchers and the workbench inherit the same Git search path as checkout. */
|
|
60
|
+
export function campaignCommandEnvironment(environment) {
|
|
61
|
+
if (!campaignScope.getStore())
|
|
62
|
+
return undefined;
|
|
63
|
+
return inspectTrustedExecutable("git", environment, []).then((command) => command.environment);
|
|
64
|
+
}
|
|
65
|
+
function searchPath(environment) {
|
|
66
|
+
return (environment["PATH"] ??
|
|
67
|
+
Object.entries(environment).find(([name, value]) => value !== undefined && name.toUpperCase() === "PATH")?.[1]);
|
|
68
|
+
}
|
|
4
69
|
export async function resolveTrustedExecutable(candidate, environment, protectedRoot) {
|
|
5
70
|
const inspected = await inspectTrustedExecutable(candidate, environment, protectedRoot);
|
|
6
71
|
return inspected.executable === null
|
|
@@ -8,10 +73,19 @@ export async function resolveTrustedExecutable(candidate, environment, protected
|
|
|
8
73
|
: { executable: inspected.executable, environment: inspected.environment };
|
|
9
74
|
}
|
|
10
75
|
export async function inspectTrustedExecutable(candidate, environment, protectedRoot) {
|
|
11
|
-
const
|
|
76
|
+
const selectedRoots = await Promise.all((typeof protectedRoot === "string" ? [protectedRoot] : protectedRoot).map(canonicalRoot));
|
|
77
|
+
const campaign = campaignScope.getStore();
|
|
78
|
+
const extra = campaign
|
|
79
|
+
? selectedRoots.filter((root) => !campaign.roots.some((base) => isWithin(base, root)))
|
|
80
|
+
: selectedRoots;
|
|
81
|
+
const roots = campaign ? [...campaign.roots, ...extra] : selectedRoots;
|
|
12
82
|
const isProtected = (path) => roots.some((root) => isWithin(root, path));
|
|
13
|
-
const path = environment
|
|
14
|
-
|
|
83
|
+
const path = searchPath(environment) ??
|
|
84
|
+
(campaign
|
|
85
|
+
? process.platform === "win32"
|
|
86
|
+
? searchPath(process.env)
|
|
87
|
+
: "/usr/bin:/bin"
|
|
88
|
+
: undefined);
|
|
15
89
|
const entries = [];
|
|
16
90
|
for (let entry of path?.split(delimiter) ?? []) {
|
|
17
91
|
if (process.platform === "win32" &&
|
|
@@ -24,48 +98,70 @@ export async function inspectTrustedExecutable(candidate, environment, protected
|
|
|
24
98
|
const canonical = await realpath(entry).catch(() => null);
|
|
25
99
|
if (canonical === null || isProtected(canonical))
|
|
26
100
|
continue;
|
|
27
|
-
|
|
28
|
-
|
|
101
|
+
// A directory containing the separator can be on PATH through a safe alias.
|
|
102
|
+
// Keep that absolute spelling so joining the entries cannot split its name.
|
|
103
|
+
const directory = canonical.includes(delimiter)
|
|
104
|
+
? isAbsolute(entry)
|
|
105
|
+
? entry
|
|
106
|
+
: `${process.cwd()}${sep}${entry}`
|
|
107
|
+
: canonical;
|
|
108
|
+
if (!directory.includes(delimiter) &&
|
|
109
|
+
!isProtected(directory) &&
|
|
110
|
+
!entries.includes(directory))
|
|
111
|
+
entries.push(directory);
|
|
112
|
+
}
|
|
113
|
+
let view;
|
|
114
|
+
if (campaign) {
|
|
115
|
+
// Workers inherit this PATH across process boundaries. Keep the links until
|
|
116
|
+
// every row, including its pending child processes, has settled.
|
|
117
|
+
const path = entries.join(delimiter);
|
|
118
|
+
const cwd = process.cwd();
|
|
119
|
+
const key = JSON.stringify([cwd, extra, path]);
|
|
120
|
+
view = campaign.views.get(key);
|
|
121
|
+
if (!view) {
|
|
122
|
+
view = campaign.project(path || "/dev/null", cwd, roots, "campaign");
|
|
123
|
+
campaign.views.set(key, view);
|
|
124
|
+
}
|
|
29
125
|
}
|
|
30
126
|
const pathLike = candidate.includes("/") || candidate.includes("\\");
|
|
31
127
|
// execFile cannot launch batch files, but their symlink targets still affect PATH trust.
|
|
32
128
|
// CreateProcess appends .exe to an extensionless explicit path, so inspect the file that
|
|
33
129
|
// will actually run instead of rejecting an otherwise valid Windows configuration.
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? extensions.map((extension) => ({
|
|
51
|
-
entry: null,
|
|
52
|
-
path: process.platform === "win32"
|
|
53
|
-
? resolve(`${candidate}${extension.suffix}`)
|
|
54
|
-
: candidate,
|
|
55
|
-
runnable: extension.runnable,
|
|
56
|
-
}))
|
|
57
|
-
: entries.flatMap((entry) => extensions.map((extension) => ({
|
|
130
|
+
const windows = process.platform === "win32";
|
|
131
|
+
const suffixes = !windows || /\.(?:exe|com)$/iu.test(candidate)
|
|
132
|
+
? [""]
|
|
133
|
+
: pathLike
|
|
134
|
+
? [extname(candidate) === "" ? ".exe" : ""]
|
|
135
|
+
: [".exe", ".com", ".bat", ".cmd", ""];
|
|
136
|
+
const primary = suffixes.map((suffix) => candidate + suffix);
|
|
137
|
+
// The Windows MCP launcher and inventory look up Node and ripgrep on this PATH.
|
|
138
|
+
const names = campaign && windows && candidate === "git"
|
|
139
|
+
? [...primary, "node.exe", "rg.exe", "rg.com"]
|
|
140
|
+
: primary;
|
|
141
|
+
const candidates = (pathLike ? [null] : entries).flatMap((entry) => {
|
|
142
|
+
// PATH lookup traverses links before "..". join() would collapse it first.
|
|
143
|
+
const directory = entry ?? "";
|
|
144
|
+
const prefix = directory && !directory.endsWith(sep) ? directory + sep : directory;
|
|
145
|
+
return names.map((name) => ({
|
|
58
146
|
entry,
|
|
59
|
-
path:
|
|
60
|
-
runnable:
|
|
61
|
-
}))
|
|
147
|
+
path: entry === null && windows ? resolve(name) : prefix + name,
|
|
148
|
+
runnable: primary.includes(name) && (!windows || /\.(?:exe|com)$/iu.test(name)),
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
62
151
|
const unsafeEntries = new Set();
|
|
63
152
|
let executable = null;
|
|
64
153
|
for (const current of candidates) {
|
|
154
|
+
const crossesSource = view !== undefined && !view.allows(current.path);
|
|
155
|
+
if (!pathLike && crossesSource) {
|
|
156
|
+
if (current.entry !== null)
|
|
157
|
+
unsafeEntries.add(current.entry);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
65
160
|
const canonical = await realpath(current.path).catch(() => null);
|
|
66
161
|
if (canonical === null)
|
|
67
162
|
continue;
|
|
68
|
-
if (isProtected(canonical)
|
|
163
|
+
if (isProtected(canonical) ||
|
|
164
|
+
(pathLike && view && crossesSource && !view.allows(canonical))) {
|
|
69
165
|
if (current.entry !== null)
|
|
70
166
|
unsafeEntries.add(current.entry);
|
|
71
167
|
continue;
|
|
@@ -85,7 +181,10 @@ export async function inspectTrustedExecutable(candidate, environment, protected
|
|
|
85
181
|
? join(await realpath(dirname(current.path)), basename(current.path))
|
|
86
182
|
: current.path;
|
|
87
183
|
executable ??=
|
|
88
|
-
pathLike &&
|
|
184
|
+
pathLike &&
|
|
185
|
+
(crossesSource ||
|
|
186
|
+
isProtected(current.path) ||
|
|
187
|
+
isProtected(invocationPath))
|
|
89
188
|
? canonical
|
|
90
189
|
: invocationPath;
|
|
91
190
|
}
|
|
@@ -98,9 +197,13 @@ export async function inspectTrustedExecutable(candidate, environment, protected
|
|
|
98
197
|
if (name.toUpperCase() === "PATH")
|
|
99
198
|
delete sanitizedEnvironment[name];
|
|
100
199
|
}
|
|
101
|
-
|
|
102
|
-
.filter((entry) => !unsafeEntries.has(entry))
|
|
103
|
-
|
|
200
|
+
const filteredPath = (windows ? undefined : view?.path) ??
|
|
201
|
+
entries.filter((entry) => !unsafeEntries.has(entry)).join(delimiter);
|
|
202
|
+
// An empty POSIX PATH searches the current directory.
|
|
203
|
+
sanitizedEnvironment["PATH"] =
|
|
204
|
+
campaign && process.platform !== "win32" && !filteredPath
|
|
205
|
+
? "/dev/null"
|
|
206
|
+
: filteredPath;
|
|
104
207
|
return { executable, environment: sanitizedEnvironment };
|
|
105
208
|
}
|
|
106
209
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted-executable.js","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,SAAS,EACT,OAAO,EACP,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAYnB,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,SAAiB,EACjB,WAAyD,EACzD,aAAyC;IAEzC,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAC9C,SAAS,EACT,WAAW,EACX,aAAa,CACd,CAAC;IACF,OAAO,SAAS,CAAC,UAAU,KAAK,IAAI;QAClC,CA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MAAM,CAAC,GAAG,OAAO;SACnC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,IAAI,CAAC,SAAS,CAAC,CAAC;IACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;AAC3D,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,SAAiB;IACtD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CACL,IAAI,KAAK,EAAE;QACX,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access, realpath, stat } from \"node:fs/promises\";\nimport {\n basename,\n delimiter,\n dirname,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\n\nexport interface TrustedExecutable {\n executable: string;\n environment: Record<string, string | undefined>;\n}\n\nexport interface InspectedExecutable {\n executable: string | null;\n environment: Record<string, string | undefined>;\n}\n\nexport async function resolveTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string | readonly string[],\n): Promise<TrustedExecutable | null> {\n const inspected = await inspectTrustedExecutable(\n candidate,\n environment,\n protectedRoot,\n );\n return inspected.executable === null\n ? null\n : { executable: inspected.executable, environment: inspected.environment };\n}\n\nexport async function inspectTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string | readonly string[],\n): Promise<InspectedExecutable> {\n const roots = await Promise.all(\n (typeof protectedRoot === \"string\" ? [protectedRoot] : protectedRoot).map(\n (root) => realpath(root).catch(() => resolve(root)),\n ),\n );\n const isProtected = (path: string) =>\n roots.some((root) => isWithin(root, path));\n const path =\n environment[\"PATH\"] ??\n Object.entries(environment).find(\n ([name]) => name.toUpperCase() === \"PATH\",\n )?.[1];\n const entries: string[] = [];\n for (let entry of path?.split(delimiter) ?? []) {\n if (\n process.platform === \"win32\" &&\n entry.startsWith('\"') &&\n entry.endsWith('\"')\n ) {\n entry = entry.slice(1, -1);\n }\n if (entry.length === 0) continue;\n const canonical = await realpath(entry).catch(() => null);\n if (canonical === null || isProtected(canonical)) continue;\n if (!entries.includes(canonical)) entries.push(canonical);\n }\n\n const pathLike = candidate.includes(\"/\") || candidate.includes(\"\\\\\");\n // execFile cannot launch batch files, but their symlink targets still affect PATH trust.\n // CreateProcess appends .exe to an extensionless explicit path, so inspect the file that\n // will actually run instead of rejecting an otherwise valid Windows configuration.\n const extensions =\n process.platform === \"win32\"\n ? /\\.(?:exe|com)$/iu.test(candidate)\n ? [{ suffix: \"\", runnable: true }]\n : pathLike\n ? extname(candidate) === \"\"\n ? [{ suffix: \".exe\", runnable: true }]\n : [{ suffix: \"\", runnable: false }]\n : [\n { suffix: \".exe\", runnable: true },\n { suffix: \".com\", runnable: true },\n { suffix: \".bat\", runnable: false },\n { suffix: \".cmd\", runnable: false },\n { suffix: \"\", runnable: false },\n ]\n : [{ suffix: \"\", runnable: true }];\n const candidates = pathLike\n ? extensions.map((extension) => ({\n entry: null,\n path:\n process.platform === \"win32\"\n ? resolve(`${candidate}${extension.suffix}`)\n : candidate,\n runnable: extension.runnable,\n }))\n : entries.flatMap((entry) =>\n extensions.map((extension) => ({\n entry,\n path: join(entry, `${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n })),\n );\n const unsafeEntries = new Set<string>();\n let executable: string | null = null;\n for (const current of candidates) {\n const canonical = await realpath(current.path).catch(() => null);\n if (canonical === null) continue;\n if (isProtected(canonical)) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n if (process.platform === \"win32\" && /\\.(?:bat|cmd)$/iu.test(canonical)) {\n continue;\n }\n if (!current.runnable) continue;\n try {\n await access(\n canonical,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n if (!(await stat(canonical)).isFile()) continue;\n // Keep explicit virtualenv launchers, but resolve repository-local aliases\n // to the trusted target instead of invoking them from the repository.\n const invocationPath = pathLike\n ? join(await realpath(dirname(current.path)), basename(current.path))\n : current.path;\n executable ??=\n pathLike && (isProtected(current.path) || isProtected(invocationPath))\n ? canonical\n : invocationPath;\n } catch {\n continue;\n }\n }\n\n const sanitizedEnvironment = { ...environment };\n for (const name of Object.keys(sanitizedEnvironment)) {\n if (name.toUpperCase() === \"PATH\") delete sanitizedEnvironment[name];\n }\n sanitizedEnvironment[\"PATH\"] = entries\n .filter((entry) => !unsafeEntries.has(entry))\n .join(delimiter);\n return { executable, environment: sanitizedEnvironment };\n}\n\n/** @internal */\nexport function isWithin(root: string, candidate: string): boolean {\n const path = relative(root, candidate);\n return (\n path === \"\" ||\n (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"trusted-executable.js","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,SAAS,EACT,OAAO,EACP,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAkBnB,MAAM,aAAa,GAAG,IAAI,iBAAiB,EASvC,CAAC;AAEL,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC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C;IACvC,OAAO,CACL,IAAI,KAAK,EAAE;QACX,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { constants } from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport { access, realpath, stat } from \"node:fs/promises\";\nimport {\n basename,\n delimiter,\n dirname,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\n\nexport interface TrustedExecutable {\n executable: string;\n environment: Record<string, string | undefined>;\n}\n\nexport interface InspectedExecutable {\n executable: string | null;\n environment: Record<string, string | undefined>;\n}\n\ninterface ToolPathView {\n path: string;\n cleanup(): void;\n allows: (path: string) => boolean;\n}\n\nconst campaignScope = new AsyncLocalStorage<{\n roots: readonly string[];\n views: Map<string, ToolPathView>;\n project: (\n path: string,\n cwd: string,\n roots: readonly string[],\n mode: \"campaign\",\n ) => ToolPathView;\n}>();\n\nfunction canonicalRoot(root: string): Promise<string> {\n return realpath(root).catch(() => resolve(root));\n}\n\nasync function campaignPathHelper() {\n const { bundledPluginRoot } = await import(\"./bundled-plugin.js\");\n const path = join(await bundledPluginRoot(), \"mcp/helpers.mjs\");\n const project = (await import(pathToFileURL(path).href)).default\n .inventoryToolPath;\n if (typeof project !== \"function\")\n throw new Error(\"The bundled plugin is missing campaign tool lookup.\");\n return project;\n}\n\n/** Include every selected source when a campaign launches tools from a new checkout. */\nexport async function withProtectedExecutableRoots<T>(\n roots: readonly string[],\n run: () => Promise<T>,\n): Promise<T> {\n const canonical = await Promise.all(roots.map(canonicalRoot));\n const scope = {\n roots: [\n ...new Set([...(campaignScope.getStore()?.roots ?? []), ...canonical]),\n ],\n views: new Map<string, ToolPathView>(),\n project: await campaignPathHelper(),\n };\n try {\n return await campaignScope.run(scope, run);\n } finally {\n for (const view of scope.views.values()) view.cleanup();\n }\n}\n\n/** Bind an actual host launcher and its environment within this campaign. */\nexport function campaignExecutable(\n candidate: string,\n environment:\n Readonly<NodeJS.ProcessEnv> | (() => Readonly<NodeJS.ProcessEnv>),\n): Promise<TrustedExecutable> | undefined {\n if (!campaignScope.getStore()) return;\n const env = typeof environment === \"function\" ? environment() : environment;\n return resolveTrustedExecutable(candidate, env, []).then(async (command) => {\n if (!command)\n throw new Error(\n `Campaign executable is unavailable on a trusted PATH: ${candidate}`,\n );\n // Windows launchers inherit the same filtered PATH as checkout.\n if (process.platform === \"win32\" && candidate !== \"git\")\n command.environment = (\n await inspectTrustedExecutable(\"git\", command.environment, [])\n ).environment;\n return command;\n });\n}\n\n/** Host launchers and the workbench inherit the same Git search path as checkout. */\nexport function campaignCommandEnvironment(\n environment: Record<string, string | undefined>,\n): Promise<Record<string, string | undefined>> | undefined {\n if (!campaignScope.getStore()) return undefined;\n return inspectTrustedExecutable(\"git\", environment, []).then(\n (command) => command.environment,\n );\n}\n\nfunction searchPath(\n environment: Readonly<NodeJS.ProcessEnv>,\n): string | undefined {\n return (\n environment[\"PATH\"] ??\n Object.entries(environment).find(\n ([name, value]) => value !== undefined && name.toUpperCase() === \"PATH\",\n )?.[1]\n );\n}\n\nexport async function resolveTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string | readonly string[],\n): Promise<TrustedExecutable | null> {\n const inspected = await inspectTrustedExecutable(\n candidate,\n environment,\n protectedRoot,\n );\n return inspected.executable === null\n ? null\n : { executable: inspected.executable, environment: inspected.environment };\n}\n\nexport async function inspectTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string | readonly string[],\n): Promise<InspectedExecutable> {\n const selectedRoots = await Promise.all(\n (typeof protectedRoot === \"string\" ? [protectedRoot] : protectedRoot).map(\n canonicalRoot,\n ),\n );\n const campaign = campaignScope.getStore();\n const extra = campaign\n ? selectedRoots.filter(\n (root) => !campaign.roots.some((base) => isWithin(base, root)),\n )\n : selectedRoots;\n const roots = campaign ? [...campaign.roots, ...extra] : selectedRoots;\n const isProtected = (path: string) =>\n roots.some((root) => isWithin(root, path));\n const path =\n searchPath(environment) ??\n (campaign\n ? process.platform === \"win32\"\n ? searchPath(process.env)\n : \"/usr/bin:/bin\"\n : undefined);\n const entries: string[] = [];\n for (let entry of path?.split(delimiter) ?? []) {\n if (\n process.platform === \"win32\" &&\n entry.startsWith('\"') &&\n entry.endsWith('\"')\n ) {\n entry = entry.slice(1, -1);\n }\n if (entry.length === 0) continue;\n const canonical = await realpath(entry).catch(() => null);\n if (canonical === null || isProtected(canonical)) continue;\n // A directory containing the separator can be on PATH through a safe alias.\n // Keep that absolute spelling so joining the entries cannot split its name.\n const directory = canonical.includes(delimiter)\n ? isAbsolute(entry)\n ? entry\n : `${process.cwd()}${sep}${entry}`\n : canonical;\n if (\n !directory.includes(delimiter) &&\n !isProtected(directory) &&\n !entries.includes(directory)\n )\n entries.push(directory);\n }\n\n let view: ToolPathView | undefined;\n if (campaign) {\n // Workers inherit this PATH across process boundaries. Keep the links until\n // every row, including its pending child processes, has settled.\n const path = entries.join(delimiter);\n const cwd = process.cwd();\n const key = JSON.stringify([cwd, extra, path]);\n view = campaign.views.get(key);\n if (!view) {\n view = campaign.project(path || \"/dev/null\", cwd, roots, \"campaign\");\n campaign.views.set(key, view);\n }\n }\n\n const pathLike = candidate.includes(\"/\") || candidate.includes(\"\\\\\");\n // execFile cannot launch batch files, but their symlink targets still affect PATH trust.\n // CreateProcess appends .exe to an extensionless explicit path, so inspect the file that\n // will actually run instead of rejecting an otherwise valid Windows configuration.\n const windows = process.platform === \"win32\";\n const suffixes =\n !windows || /\\.(?:exe|com)$/iu.test(candidate)\n ? [\"\"]\n : pathLike\n ? [extname(candidate) === \"\" ? \".exe\" : \"\"]\n : [\".exe\", \".com\", \".bat\", \".cmd\", \"\"];\n const primary = suffixes.map((suffix) => candidate + suffix);\n // The Windows MCP launcher and inventory look up Node and ripgrep on this PATH.\n const names =\n campaign && windows && candidate === \"git\"\n ? [...primary, \"node.exe\", \"rg.exe\", \"rg.com\"]\n : primary;\n const candidates = (pathLike ? [null] : entries).flatMap((entry) => {\n // PATH lookup traverses links before \"..\". join() would collapse it first.\n const directory = entry ?? \"\";\n const prefix =\n directory && !directory.endsWith(sep) ? directory + sep : directory;\n return names.map((name) => ({\n entry,\n path: entry === null && windows ? resolve(name) : prefix + name,\n runnable:\n primary.includes(name) && (!windows || /\\.(?:exe|com)$/iu.test(name)),\n }));\n });\n const unsafeEntries = new Set<string>();\n let executable: string | null = null;\n for (const current of candidates) {\n const crossesSource = view !== undefined && !view.allows(current.path);\n if (!pathLike && crossesSource) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n const canonical = await realpath(current.path).catch(() => null);\n if (canonical === null) continue;\n if (\n isProtected(canonical) ||\n (pathLike && view && crossesSource && !view.allows(canonical))\n ) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n if (process.platform === \"win32\" && /\\.(?:bat|cmd)$/iu.test(canonical)) {\n continue;\n }\n if (!current.runnable) continue;\n try {\n await access(\n canonical,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n if (!(await stat(canonical)).isFile()) continue;\n // Keep explicit virtualenv launchers, but resolve repository-local aliases\n // to the trusted target instead of invoking them from the repository.\n const invocationPath = pathLike\n ? join(await realpath(dirname(current.path)), basename(current.path))\n : current.path;\n executable ??=\n pathLike &&\n (crossesSource ||\n isProtected(current.path) ||\n isProtected(invocationPath))\n ? canonical\n : invocationPath;\n } catch {\n continue;\n }\n }\n\n const sanitizedEnvironment = { ...environment };\n for (const name of Object.keys(sanitizedEnvironment)) {\n if (name.toUpperCase() === \"PATH\") delete sanitizedEnvironment[name];\n }\n const filteredPath =\n (windows ? undefined : view?.path) ??\n entries.filter((entry) => !unsafeEntries.has(entry)).join(delimiter);\n // An empty POSIX PATH searches the current directory.\n sanitizedEnvironment[\"PATH\"] =\n campaign && process.platform !== \"win32\" && !filteredPath\n ? \"/dev/null\"\n : filteredPath;\n return { executable, environment: sanitizedEnvironment };\n}\n\n/** @internal */\nexport function isWithin(root: string, candidate: string): boolean {\n const path = relative(root, candidate);\n return (\n path === \"\" ||\n (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n );\n}\n"]}
|
|
@@ -3,7 +3,5 @@ import { type ExternalImportTarget } from "./external-import-contract.js";
|
|
|
3
3
|
import type { ExternalFinding, ExternalFindings } from "./external-findings.js";
|
|
4
4
|
export declare const veracodeReportRepositories: (provider: Provider, findings: readonly ExternalFinding[], target: ExternalImportTarget, sameRepositories?: (urls: Iterable<string>) => boolean) => Map<string, import("./external-findings.js").ExternalSourceRepository>;
|
|
5
5
|
export declare function normalizeVeracodeFindings(input: unknown, sourceRepositoryUrl: string, target?: ExternalImportTarget): ExternalFindings;
|
|
6
|
-
|
|
7
|
-
export declare function normalizePreviousVeracodeFindings(input: unknown, sourceRepositoryUrl: string, target?: ExternalImportTarget): ExternalFindings;
|
|
8
|
-
export declare function readVeracodeFindings(path: string, sourceRepositoryUrl: string, target?: ExternalImportTarget): Promise<ExternalFindings>;
|
|
6
|
+
export declare const readVeracodeFindings: (path: string, sourceRepositoryUrl: string, target?: ExternalImportTarget | undefined) => Promise<ExternalFindings>;
|
|
9
7
|
//# sourceMappingURL=veracode-findings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"veracode-findings.d.ts","sourceRoot":"","sources":["../src/veracode-findings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"veracode-findings.d.ts","sourceRoot":"","sources":["../src/veracode-findings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAsLhF,eAAO,MAAM,0BAA0B,4NAGtC,CAAC;AAuTF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,mBAAmB,EAAE,MAAM,EAC3B,MAAM,GAAE,oBAA8B,GACrC,gBAAgB,CAgDlB;AAED,eAAO,MAAM,oBAAoB,qHAEhC,CAAC"}
|