@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 @@
|
|
|
1
|
+
{"version":3,"file":"continuum-aws.d.ts","sourceRoot":"","sources":["../src/continuum-aws.ts"],"names":[],"mappings":"AAiIA,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,MAAM,CAAC,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,MAAM;;;;GA8HpB"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { readdir, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { environmentEntry } from "./auth.js";
|
|
5
|
+
import { CodexSecurityError } from "./errors.js";
|
|
6
|
+
import { commandGitProtectionRoots } from "./local-git-metadata.js";
|
|
7
|
+
import { isWithin, resolveTrustedExecutable, trustedHostPathResolver, } from "./trusted-executable.js";
|
|
8
|
+
const windows = process.platform === "win32";
|
|
9
|
+
const accountDirectories = [
|
|
10
|
+
"APPDATA",
|
|
11
|
+
"HOME",
|
|
12
|
+
"LOCALAPPDATA",
|
|
13
|
+
"USERPROFILE",
|
|
14
|
+
"XDG_CONFIG_HOME",
|
|
15
|
+
];
|
|
16
|
+
const hostSettings = new Set([
|
|
17
|
+
...accountDirectories,
|
|
18
|
+
"ALL_PROXY",
|
|
19
|
+
"CURL_CA_BUNDLE",
|
|
20
|
+
"HOMEDRIVE",
|
|
21
|
+
"HOMEPATH",
|
|
22
|
+
"HTTPS_PROXY",
|
|
23
|
+
"HTTP_PROXY",
|
|
24
|
+
"LANG",
|
|
25
|
+
"LANGUAGE",
|
|
26
|
+
"LOGNAME",
|
|
27
|
+
"NO_PROXY",
|
|
28
|
+
"REQUESTS_CA_BUNDLE",
|
|
29
|
+
"SSH_AUTH_SOCK",
|
|
30
|
+
"SSL_CERT_DIR",
|
|
31
|
+
"SSL_CERT_FILE",
|
|
32
|
+
"SYSTEMROOT",
|
|
33
|
+
"TEMP",
|
|
34
|
+
"TMP",
|
|
35
|
+
"TMPDIR",
|
|
36
|
+
"TZ",
|
|
37
|
+
"USER",
|
|
38
|
+
"USERNAME",
|
|
39
|
+
"WINDIR",
|
|
40
|
+
]);
|
|
41
|
+
function expandVariables(path, environment) {
|
|
42
|
+
// AWS uses Python's platform-specific expandvars for configuration paths.
|
|
43
|
+
const variables = windows
|
|
44
|
+
? /'[^']*'?|%(%|[^%]*%?)|\$(\$|[-\w]+|\{[^}]*\}?)/gu
|
|
45
|
+
: /\$(\w+|\{[^}]*\}?)/gu;
|
|
46
|
+
return path.replace(variables, (match) => {
|
|
47
|
+
if (match.startsWith("'"))
|
|
48
|
+
return match;
|
|
49
|
+
const token = match.slice(1);
|
|
50
|
+
if (token === "%" || token === "$")
|
|
51
|
+
return token;
|
|
52
|
+
let name = token;
|
|
53
|
+
if (match.startsWith("%")) {
|
|
54
|
+
if (!token.endsWith("%"))
|
|
55
|
+
return match;
|
|
56
|
+
name = token.slice(0, -1);
|
|
57
|
+
}
|
|
58
|
+
else if (token.startsWith("{")) {
|
|
59
|
+
if (!token.endsWith("}"))
|
|
60
|
+
return match;
|
|
61
|
+
name = token.slice(1, -1);
|
|
62
|
+
}
|
|
63
|
+
return environmentEntry(environment, name) ?? match;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function expandedSetting(name, value, home, environment) {
|
|
67
|
+
const path = expandVariables(value, environment);
|
|
68
|
+
if (path === "~" ||
|
|
69
|
+
path.startsWith("~/") ||
|
|
70
|
+
(windows && path.startsWith("~\\")))
|
|
71
|
+
return home + path.slice(1);
|
|
72
|
+
if (path.startsWith("~"))
|
|
73
|
+
throw new CodexSecurityError(`Use a fully expanded file path for ${name}.`);
|
|
74
|
+
return path;
|
|
75
|
+
}
|
|
76
|
+
function pinSetting(name, path, environment) {
|
|
77
|
+
if (expandVariables(path, environment) !== path ||
|
|
78
|
+
(name === "AWS_DATA_PATH" && path.includes(delimiter)))
|
|
79
|
+
throw new CodexSecurityError(`Use a fully expanded file path for ${name}.`);
|
|
80
|
+
return path;
|
|
81
|
+
}
|
|
82
|
+
function missingPath(error) {
|
|
83
|
+
if (error.code !== "ENOENT" && error.code !== "ENOTDIR")
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
async function checkModelPath(path, resolvePath, roots, signal, levels = 3) {
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
const safe = resolvePath(path);
|
|
89
|
+
if (safe === null || roots.some((root) => isWithin(safe, root)))
|
|
90
|
+
throw new CodexSecurityError(`Use an AWS model path separate from the selected checkout: ${path}`);
|
|
91
|
+
if (levels === 0)
|
|
92
|
+
return safe;
|
|
93
|
+
const entries = await readdir(safe).catch(missingPath);
|
|
94
|
+
// AWS loads global models and service/version/*.json[.gz].
|
|
95
|
+
for (const entry of entries ?? []) {
|
|
96
|
+
const child = join(safe, entry);
|
|
97
|
+
if (/\.json(?:\.gz)?$/iu.test(entry) ||
|
|
98
|
+
(levels > 1 && (await stat(child).catch(missingPath))?.isDirectory()))
|
|
99
|
+
await checkModelPath(child, resolvePath, roots, signal, levels - 1);
|
|
100
|
+
}
|
|
101
|
+
return safe;
|
|
102
|
+
}
|
|
103
|
+
export async function prepareContinuumAws(cwd, environment, signal, sourceRoot) {
|
|
104
|
+
const caller = await realpath(cwd);
|
|
105
|
+
const source = sourceRoot ?? cwd;
|
|
106
|
+
if (sourceRoot !== undefined &&
|
|
107
|
+
(!isAbsolute(sourceRoot) ||
|
|
108
|
+
!(await stat(sourceRoot).catch(missingPath))?.isDirectory()))
|
|
109
|
+
throw new CodexSecurityError("Select an existing absolute directory with --source-root.");
|
|
110
|
+
const roots = [
|
|
111
|
+
...new Set([
|
|
112
|
+
resolve(source),
|
|
113
|
+
source === cwd ? caller : await realpath(source),
|
|
114
|
+
...(await commandGitProtectionRoots(source, environment, signal, {
|
|
115
|
+
cwd,
|
|
116
|
+
})),
|
|
117
|
+
]),
|
|
118
|
+
];
|
|
119
|
+
const resolvePath = await trustedHostPathResolver(caller, roots);
|
|
120
|
+
const name = windows ? "aws.exe" : "aws";
|
|
121
|
+
const directories = [];
|
|
122
|
+
for (let entry of (environmentEntry(environment, "PATH") ?? "").split(delimiter)) {
|
|
123
|
+
if (windows && entry.startsWith('"') && entry.endsWith('"'))
|
|
124
|
+
entry = entry.slice(1, -1);
|
|
125
|
+
if (!isAbsolute(entry))
|
|
126
|
+
continue;
|
|
127
|
+
const path = resolvePath(entry);
|
|
128
|
+
if (path === null || path.includes(delimiter))
|
|
129
|
+
continue;
|
|
130
|
+
const candidate = resolvePath(join(path, name));
|
|
131
|
+
if (candidate !== null && (!windows || /\.exe$/iu.test(candidate)))
|
|
132
|
+
directories.push(path);
|
|
133
|
+
}
|
|
134
|
+
const aws = await resolveTrustedExecutable(name, { PATH: directories.join(delimiter) }, roots);
|
|
135
|
+
const executable = aws ? resolvePath(aws.executable) : null;
|
|
136
|
+
if (!aws || executable === null)
|
|
137
|
+
throw new CodexSecurityError("Could not find an installed AWS CLI outside the selected checkout.");
|
|
138
|
+
// Credential helpers can use any interpreter. Only forward AWS and host settings.
|
|
139
|
+
const child = {};
|
|
140
|
+
for (const [name, value] of Object.entries(environment)) {
|
|
141
|
+
const key = windows ? name.toUpperCase() : name;
|
|
142
|
+
if (value !== undefined &&
|
|
143
|
+
(key.startsWith("AWS_") ||
|
|
144
|
+
key.startsWith("LC_") ||
|
|
145
|
+
hostSettings.has(key.toUpperCase())))
|
|
146
|
+
child[key] = value;
|
|
147
|
+
}
|
|
148
|
+
child["PATH"] = aws.environment["PATH"];
|
|
149
|
+
function trustedSetting(path, label) {
|
|
150
|
+
const safe = resolvePath(path);
|
|
151
|
+
if (safe === null)
|
|
152
|
+
throw new CodexSecurityError(`Use ${label} outside the selected checkout.`);
|
|
153
|
+
return safe;
|
|
154
|
+
}
|
|
155
|
+
for (const name of accountDirectories) {
|
|
156
|
+
const path = child[name];
|
|
157
|
+
if (path)
|
|
158
|
+
child[name] = trustedSetting(path, `an account ${name} directory`);
|
|
159
|
+
}
|
|
160
|
+
const configuredHome = windows
|
|
161
|
+
? (child["USERPROFILE"] ??
|
|
162
|
+
(child["HOMEPATH"]
|
|
163
|
+
? (child["HOMEDRIVE"] ?? "") + child["HOMEPATH"]
|
|
164
|
+
: undefined))
|
|
165
|
+
: child["HOME"];
|
|
166
|
+
const home = trustedSetting(configuredHome ?? homedir(), "an account home directory");
|
|
167
|
+
child[windows ? "USERPROFILE" : "HOME"] = home;
|
|
168
|
+
// AWS can run credential helpers from profiles and commands from aliases.
|
|
169
|
+
const awsDirectory = join(home, ".aws");
|
|
170
|
+
for (const [name, filename] of [
|
|
171
|
+
["AWS_CONFIG_FILE", "config"],
|
|
172
|
+
["AWS_SHARED_CREDENTIALS_FILE", "credentials"],
|
|
173
|
+
]) {
|
|
174
|
+
const value = child[name];
|
|
175
|
+
const path = value === undefined
|
|
176
|
+
? join(awsDirectory, filename)
|
|
177
|
+
: expandedSetting(name, value, home, environment);
|
|
178
|
+
const safe = trustedSetting(path, `an ${name} file`);
|
|
179
|
+
if (value !== undefined)
|
|
180
|
+
child[name] = pinSetting(name, safe, child);
|
|
181
|
+
}
|
|
182
|
+
trustedSetting(join(awsDirectory, "cli", "alias"), "an AWS CLI alias file");
|
|
183
|
+
await checkModelPath(join(awsDirectory, "models"), resolvePath, roots, signal);
|
|
184
|
+
if (child["AWS_DATA_PATH"] !== undefined) {
|
|
185
|
+
const paths = [];
|
|
186
|
+
for (const entry of child["AWS_DATA_PATH"].split(delimiter)) {
|
|
187
|
+
const path = expandedSetting("AWS_DATA_PATH", entry, home, environment);
|
|
188
|
+
if (!path)
|
|
189
|
+
continue;
|
|
190
|
+
const safe = await checkModelPath(path, resolvePath, roots, signal);
|
|
191
|
+
paths.push(pinSetting("AWS_DATA_PATH", safe, child));
|
|
192
|
+
}
|
|
193
|
+
child["AWS_DATA_PATH"] = paths.join(delimiter);
|
|
194
|
+
}
|
|
195
|
+
// Windows may search the current directory for a bare credential helper name.
|
|
196
|
+
return {
|
|
197
|
+
executable,
|
|
198
|
+
cwd: dirname(executable),
|
|
199
|
+
environment: child,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=continuum-aws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuum-aws.js","sourceRoot":"","sources":["../src/continuum-aws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EACL,QAAQ,EACR,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAC7C,MAAM,kBAAkB,GAAG;IACzB,SAAS;IACT,MAAM;IACN,cAAc;IACd,aAAa;IACb,iBAAiB;CAClB,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Ac,CAAC,IAAI,EAAE,MAAM,IAAI,OAAO,CAAC,CAAC;QACrD,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;IACD,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,uBAAuB,CAAC,CAAC;IAC5E,MAAM,cAAc,CAClB,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,EAC5B,WAAW,EACX,KAAK,EACL,MAAM,CACP,CAAC;IACF,IAAI,KAAK,CAAC,eAAe,CAAC,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,GAAG,eAAe,CAAC,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;YACxE,IAAI,CAAC,IAAI;gBAAE,SAAS;YACpB,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACpE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAED,8EAA8E;IAC9E,OAAO;QACL,UAAU;QACV,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC;QACxB,WAAW,EAAE,KAAK;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import { readdir, realpath, stat } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { delimiter, dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { environmentEntry } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { commandGitProtectionRoots } from \"./local-git-metadata.js\";\nimport {\n isWithin,\n resolveTrustedExecutable,\n trustedHostPathResolver,\n} from \"./trusted-executable.js\";\n\nconst windows = process.platform === \"win32\";\nconst accountDirectories = [\n \"APPDATA\",\n \"HOME\",\n \"LOCALAPPDATA\",\n \"USERPROFILE\",\n \"XDG_CONFIG_HOME\",\n];\nconst hostSettings = new Set([\n ...accountDirectories,\n \"ALL_PROXY\",\n \"CURL_CA_BUNDLE\",\n \"HOMEDRIVE\",\n \"HOMEPATH\",\n \"HTTPS_PROXY\",\n \"HTTP_PROXY\",\n \"LANG\",\n \"LANGUAGE\",\n \"LOGNAME\",\n \"NO_PROXY\",\n \"REQUESTS_CA_BUNDLE\",\n \"SSH_AUTH_SOCK\",\n \"SSL_CERT_DIR\",\n \"SSL_CERT_FILE\",\n \"SYSTEMROOT\",\n \"TEMP\",\n \"TMP\",\n \"TMPDIR\",\n \"TZ\",\n \"USER\",\n \"USERNAME\",\n \"WINDIR\",\n]);\n\nfunction expandVariables(path: string, environment: NodeJS.ProcessEnv): string {\n // AWS uses Python's platform-specific expandvars for configuration paths.\n const variables = windows\n ? /'[^']*'?|%(%|[^%]*%?)|\\$(\\$|[-\\w]+|\\{[^}]*\\}?)/gu\n : /\\$(\\w+|\\{[^}]*\\}?)/gu;\n return path.replace(variables, (match) => {\n if (match.startsWith(\"'\")) return match;\n const token = match.slice(1);\n if (token === \"%\" || token === \"$\") return token;\n let name = token;\n if (match.startsWith(\"%\")) {\n if (!token.endsWith(\"%\")) return match;\n name = token.slice(0, -1);\n } else if (token.startsWith(\"{\")) {\n if (!token.endsWith(\"}\")) return match;\n name = token.slice(1, -1);\n }\n return environmentEntry(environment, name) ?? match;\n });\n}\n\nfunction expandedSetting(\n name: string,\n value: string,\n home: string,\n environment: NodeJS.ProcessEnv,\n): string {\n const path = expandVariables(value, environment);\n if (\n path === \"~\" ||\n path.startsWith(\"~/\") ||\n (windows && path.startsWith(\"~\\\\\"))\n )\n return home + path.slice(1);\n if (path.startsWith(\"~\"))\n throw new CodexSecurityError(`Use a fully expanded file path for ${name}.`);\n return path;\n}\n\nfunction pinSetting(\n name: string,\n path: string,\n environment: NodeJS.ProcessEnv,\n): string {\n if (\n expandVariables(path, environment) !== path ||\n (name === \"AWS_DATA_PATH\" && path.includes(delimiter))\n )\n throw new CodexSecurityError(`Use a fully expanded file path for ${name}.`);\n return path;\n}\n\nfunction missingPath(error: NodeJS.ErrnoException) {\n if (error.code !== \"ENOENT\" && error.code !== \"ENOTDIR\") throw error;\n}\n\nasync function checkModelPath(\n path: string,\n resolvePath: (path: string) => string | null,\n roots: readonly string[],\n signal: AbortSignal | undefined,\n levels = 3,\n): Promise<string> {\n signal?.throwIfAborted();\n const safe = resolvePath(path);\n if (safe === null || roots.some((root) => isWithin(safe, root)))\n throw new CodexSecurityError(\n `Use an AWS model path separate from the selected checkout: ${path}`,\n );\n if (levels === 0) return safe;\n const entries = await readdir(safe).catch(missingPath);\n // AWS loads global models and service/version/*.json[.gz].\n for (const entry of entries ?? []) {\n const child = join(safe, entry);\n if (\n /\\.json(?:\\.gz)?$/iu.test(entry) ||\n (levels > 1 && (await stat(child).catch(missingPath))?.isDirectory())\n )\n await checkModelPath(child, resolvePath, roots, signal, levels - 1);\n }\n return safe;\n}\n\nexport async function prepareContinuumAws(\n cwd: string,\n environment: NodeJS.ProcessEnv,\n signal?: AbortSignal,\n sourceRoot?: string,\n) {\n const caller = await realpath(cwd);\n const source = sourceRoot ?? cwd;\n if (\n sourceRoot !== undefined &&\n (!isAbsolute(sourceRoot) ||\n !(await stat(sourceRoot).catch(missingPath))?.isDirectory())\n )\n throw new CodexSecurityError(\n \"Select an existing absolute directory with --source-root.\",\n );\n const roots = [\n ...new Set([\n resolve(source),\n source === cwd ? caller : await realpath(source),\n ...(await commandGitProtectionRoots(source, environment, signal, {\n cwd,\n })),\n ]),\n ];\n const resolvePath = await trustedHostPathResolver(caller, roots);\n\n const name = windows ? \"aws.exe\" : \"aws\";\n const directories: string[] = [];\n for (let entry of (environmentEntry(environment, \"PATH\") ?? \"\").split(\n delimiter,\n )) {\n if (windows && entry.startsWith('\"') && entry.endsWith('\"'))\n entry = entry.slice(1, -1);\n if (!isAbsolute(entry)) continue;\n const path = resolvePath(entry);\n if (path === null || path.includes(delimiter)) continue;\n const candidate = resolvePath(join(path, name));\n if (candidate !== null && (!windows || /\\.exe$/iu.test(candidate)))\n directories.push(path);\n }\n const aws = await resolveTrustedExecutable(\n name,\n { PATH: directories.join(delimiter) },\n roots,\n );\n const executable = aws ? resolvePath(aws.executable) : null;\n if (!aws || executable === null)\n throw new CodexSecurityError(\n \"Could not find an installed AWS CLI outside the selected checkout.\",\n );\n\n // Credential helpers can use any interpreter. Only forward AWS and host settings.\n const child: NodeJS.ProcessEnv = {};\n for (const [name, value] of Object.entries(environment)) {\n const key = windows ? name.toUpperCase() : name;\n if (\n value !== undefined &&\n (key.startsWith(\"AWS_\") ||\n key.startsWith(\"LC_\") ||\n hostSettings.has(key.toUpperCase()))\n )\n child[key] = value;\n }\n child[\"PATH\"] = aws.environment[\"PATH\"];\n\n function trustedSetting(path: string, label: string) {\n const safe = resolvePath(path);\n if (safe === null)\n throw new CodexSecurityError(\n `Use ${label} outside the selected checkout.`,\n );\n return safe;\n }\n\n for (const name of accountDirectories) {\n const path = child[name];\n if (path)\n child[name] = trustedSetting(path, `an account ${name} directory`);\n }\n const configuredHome = windows\n ? (child[\"USERPROFILE\"] ??\n (child[\"HOMEPATH\"]\n ? (child[\"HOMEDRIVE\"] ?? \"\") + child[\"HOMEPATH\"]\n : undefined))\n : child[\"HOME\"];\n const home = trustedSetting(\n configuredHome ?? homedir(),\n \"an account home directory\",\n );\n child[windows ? \"USERPROFILE\" : \"HOME\"] = home;\n\n // AWS can run credential helpers from profiles and commands from aliases.\n const awsDirectory = join(home, \".aws\");\n for (const [name, filename] of [\n [\"AWS_CONFIG_FILE\", \"config\"],\n [\"AWS_SHARED_CREDENTIALS_FILE\", \"credentials\"],\n ] as const) {\n const value = child[name];\n const path =\n value === undefined\n ? join(awsDirectory, filename)\n : expandedSetting(name, value, home, environment);\n const safe = trustedSetting(path, `an ${name} file`);\n if (value !== undefined) child[name] = pinSetting(name, safe, child);\n }\n trustedSetting(join(awsDirectory, \"cli\", \"alias\"), \"an AWS CLI alias file\");\n await checkModelPath(\n join(awsDirectory, \"models\"),\n resolvePath,\n roots,\n signal,\n );\n if (child[\"AWS_DATA_PATH\"] !== undefined) {\n const paths: string[] = [];\n for (const entry of child[\"AWS_DATA_PATH\"].split(delimiter)) {\n const path = expandedSetting(\"AWS_DATA_PATH\", entry, home, environment);\n if (!path) continue;\n const safe = await checkModelPath(path, resolvePath, roots, signal);\n paths.push(pinSetting(\"AWS_DATA_PATH\", safe, child));\n }\n child[\"AWS_DATA_PATH\"] = paths.join(delimiter);\n }\n\n // Windows may search the current directory for a bare credential helper name.\n return {\n executable,\n cwd: dirname(executable),\n environment: child,\n };\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const continuumEnvironmentId: z.ZodString;
|
|
3
|
+
export declare const continuumFindingId: z.ZodString;
|
|
4
|
+
declare const continuumIssueExport: z.ZodObject<{
|
|
5
|
+
format: z.ZodLiteral<"aws-continuum-code-issues/v1">;
|
|
6
|
+
environmentId: z.ZodString;
|
|
7
|
+
sourceRepositoryUrl: z.ZodString;
|
|
8
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
9
|
+
issue: z.ZodObject<{
|
|
10
|
+
artifacts: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
11
|
+
}, z.core.$loose>;
|
|
12
|
+
findings: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export declare const continuumImportOutput: z.ZodUnion<readonly [z.ZodObject<{
|
|
16
|
+
format: z.ZodLiteral<"aws-continuum-code-issues/v1">;
|
|
17
|
+
environmentId: z.ZodString;
|
|
18
|
+
sourceRepositoryUrl: z.ZodString;
|
|
19
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
20
|
+
issue: z.ZodObject<{
|
|
21
|
+
artifacts: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
|
+
}, z.core.$loose>;
|
|
23
|
+
findings: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
26
|
+
interface ContinuumCollectionOptions {
|
|
27
|
+
environmentId: string;
|
|
28
|
+
profile?: string;
|
|
29
|
+
region?: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
sourceRoot?: string;
|
|
32
|
+
environment: NodeJS.ProcessEnv;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
type AwsCommand = (args: string[]) => Promise<Record<string, unknown>>;
|
|
36
|
+
export declare function collectContinuumFinding(options: ContinuumCollectionOptions & {
|
|
37
|
+
findingId: string;
|
|
38
|
+
sourceRoot: string;
|
|
39
|
+
repositoryName?: string;
|
|
40
|
+
warn?: (message: string) => void;
|
|
41
|
+
}, runAws?: AwsCommand): Promise<Record<string, unknown>>;
|
|
42
|
+
export declare function collectContinuumIssues(options: ContinuumCollectionOptions, runAws?: AwsCommand): Promise<z.infer<typeof continuumIssueExport>>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=continuum-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuum-collector.d.ts","sourceRoot":"","sources":["../src/continuum-collector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,eAAO,MAAM,sBAAsB,aAElC,CAAC;AACF,eAAO,MAAM,kBAAkB,aAE9B,CAAC;AAEF,QAAA,MAAM,oBAAoB;;;;;;;;;;iBAUxB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;2DAGhC,CAAC;AAEH,UAAU,0BAA0B;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AA8JvE,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,0BAA0B,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,EACD,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAwGlC;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,0BAA0B,EACnC,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC,CA+G/C"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { prepareContinuumAws } from "./continuum-aws.js";
|
|
5
|
+
import { continuumIssueFormat, findingIdentity, issueIdentity, readPatch, selectFindingValidationArtifact, singleFindingValidationIssue, } from "./continuum-findings.js";
|
|
6
|
+
import { CodexSecurityError } from "./errors.js";
|
|
7
|
+
import { array, record } from "./scanner-import.js";
|
|
8
|
+
import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
|
|
9
|
+
const execFile = promisify(execFileCallback);
|
|
10
|
+
const continuumId = z
|
|
11
|
+
.string()
|
|
12
|
+
.regex(/^[a-z0-9]{1,64}$/u, "Use a short Continuum ID with lowercase letters and digits.");
|
|
13
|
+
export const continuumEnvironmentId = continuumId.describe("Short Continuum environment ID.");
|
|
14
|
+
export const continuumFindingId = continuumId.describe("Short Continuum finding ID.");
|
|
15
|
+
const nativeRecord = z.record(z.string(), z.unknown());
|
|
16
|
+
const continuumIssueExport = z.object({
|
|
17
|
+
format: z.literal(continuumIssueFormat),
|
|
18
|
+
environmentId: continuumEnvironmentId,
|
|
19
|
+
sourceRepositoryUrl: z.string(),
|
|
20
|
+
issues: z.array(z.object({
|
|
21
|
+
issue: z.looseObject({ artifacts: z.array(nativeRecord) }),
|
|
22
|
+
findings: z.array(nativeRecord),
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
25
|
+
export const continuumImportOutput = z.union([
|
|
26
|
+
continuumIssueExport,
|
|
27
|
+
nativeRecord,
|
|
28
|
+
]);
|
|
29
|
+
const environmentSources = z.object({
|
|
30
|
+
configuration: z
|
|
31
|
+
.object({
|
|
32
|
+
codeConfiguration: z
|
|
33
|
+
.object({
|
|
34
|
+
sourceConfiguration: z
|
|
35
|
+
.object({
|
|
36
|
+
repositorySources: z.array(z.unknown()).optional(),
|
|
37
|
+
s3Sources: z.array(z.unknown()).optional(),
|
|
38
|
+
})
|
|
39
|
+
.optional(),
|
|
40
|
+
})
|
|
41
|
+
.optional(),
|
|
42
|
+
})
|
|
43
|
+
.optional(),
|
|
44
|
+
});
|
|
45
|
+
const repositorySource = z.object({
|
|
46
|
+
integrationId: continuumId,
|
|
47
|
+
repository: z.string().regex(/^[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)+$/iu),
|
|
48
|
+
});
|
|
49
|
+
const gitLabIntegration = z.object({
|
|
50
|
+
providerDetails: z.object({
|
|
51
|
+
gitlab: z.object({ instanceUrl: z.string().startsWith("https://") }),
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
function configuredSources(environment) {
|
|
55
|
+
const { configuration } = environmentSources.parse(environment);
|
|
56
|
+
const sources = configuration?.codeConfiguration?.sourceConfiguration;
|
|
57
|
+
return {
|
|
58
|
+
repositories: sources?.repositorySources ?? [],
|
|
59
|
+
s3Sources: sources?.s3Sources ?? [],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function singleRepositorySource(environment, getIntegration) {
|
|
63
|
+
const { repositories, s3Sources } = configuredSources(environment);
|
|
64
|
+
if (repositories.length !== 1)
|
|
65
|
+
throw new CodexSecurityError(`Continuum collection requires exactly one configured Git repository. This environment has ${repositories.length}.`);
|
|
66
|
+
const { integrationId, repository } = repositorySource.parse(repositories[0]);
|
|
67
|
+
const integration = await getIntegration(integrationId);
|
|
68
|
+
const type = integration["integrationType"];
|
|
69
|
+
if (type !== "GITHUB" && type !== "GITLAB")
|
|
70
|
+
throw new CodexSecurityError("Expected a GitHub or GitLab integration for the Continuum repository.");
|
|
71
|
+
const base = type === "GITHUB"
|
|
72
|
+
? "https://github.com"
|
|
73
|
+
: gitLabIntegration.parse(integration).providerDetails.gitlab.instanceUrl;
|
|
74
|
+
return {
|
|
75
|
+
url: declaredScannerRepositoryUrl(`${base.replace(/\/$/u, "")}/${repository}`, "Continuum"),
|
|
76
|
+
// Mixed environments do not identify the Git source by the patch's AWS source name.
|
|
77
|
+
includePatches: s3Sources.length === 0,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function awsCommand({ cwd, environment, signal, sourceRoot, }) {
|
|
81
|
+
const aws = await prepareContinuumAws(cwd, environment, signal, sourceRoot);
|
|
82
|
+
return async (args) => {
|
|
83
|
+
const command = execFile(aws.executable, args, {
|
|
84
|
+
cwd: aws.cwd,
|
|
85
|
+
env: aws.environment,
|
|
86
|
+
signal,
|
|
87
|
+
maxBuffer: Infinity,
|
|
88
|
+
windowsHide: true,
|
|
89
|
+
});
|
|
90
|
+
command.child.stdin?.end();
|
|
91
|
+
const { stdout } = await command;
|
|
92
|
+
return record(JSON.parse(stdout), `AWS Continuum ${args[1]} response`);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function continuumRequests(options, runAws) {
|
|
96
|
+
const { profile, region, signal } = options;
|
|
97
|
+
signal?.throwIfAborted();
|
|
98
|
+
const run = runAws ?? (await awsCommand(options));
|
|
99
|
+
const awsArgs = [
|
|
100
|
+
"--output",
|
|
101
|
+
"json",
|
|
102
|
+
"--no-cli-pager",
|
|
103
|
+
...(profile === undefined ? [] : ["--profile", profile]),
|
|
104
|
+
...(region === undefined ? [] : ["--region", region]),
|
|
105
|
+
];
|
|
106
|
+
return (operation, scope, ...args) => {
|
|
107
|
+
signal?.throwIfAborted();
|
|
108
|
+
return run(["continuum", operation, ...scope, ...awsArgs, ...args]);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function getIssueArtifact(request, scope, issueId, artifactId, artifactType) {
|
|
112
|
+
const artifact = await request("get-code-issue-artifact", scope, "--issue-id", issueId, "--artifact-id", artifactId);
|
|
113
|
+
if (artifact["artifactId"] !== artifactId ||
|
|
114
|
+
artifact["artifactType"] !== artifactType)
|
|
115
|
+
throw new CodexSecurityError(`Unexpected Continuum artifact ${artifactId} for issue ${issueId}.`);
|
|
116
|
+
return artifact;
|
|
117
|
+
}
|
|
118
|
+
function requireCompleteList(response, name) {
|
|
119
|
+
if (Object.hasOwn(response, "nextToken") ||
|
|
120
|
+
Object.hasOwn(response, "NextToken"))
|
|
121
|
+
throw new CodexSecurityError(`Expected a complete Continuum ${name} list.`);
|
|
122
|
+
}
|
|
123
|
+
async function getFindingValidationIssue(request, scope, issueId, identity) {
|
|
124
|
+
const issue = await request("get-code-issue", scope, "--issue-id", issueId);
|
|
125
|
+
const selected = issueIdentity(issue);
|
|
126
|
+
if (selected.scope !== identity.scope || selected.id !== issueId)
|
|
127
|
+
throw new CodexSecurityError(`Unexpected detail for Continuum issue ${issueId}.`);
|
|
128
|
+
return singleFindingValidationIssue(issue, issueId, identity);
|
|
129
|
+
}
|
|
130
|
+
export async function collectContinuumFinding(options, runAws) {
|
|
131
|
+
const { environmentId, findingId, repositoryName, warn, signal } = options;
|
|
132
|
+
const request = await continuumRequests(options, runAws);
|
|
133
|
+
const scope = ["--environment-id", environmentId];
|
|
134
|
+
if (repositoryName === undefined) {
|
|
135
|
+
const { repositories, s3Sources } = configuredSources(await request("get-environment", scope));
|
|
136
|
+
if (repositories.length !== 1 ||
|
|
137
|
+
s3Sources.length !== 0 ||
|
|
138
|
+
!repositorySource.safeParse(repositories[0]).success)
|
|
139
|
+
throw new CodexSecurityError("Pass --repository-name with the exact AWS source name. Omitting it requires exactly one configured Git repository and no S3 sources.");
|
|
140
|
+
}
|
|
141
|
+
const finding = await request("get-code-finding", scope, "--finding-id", findingId);
|
|
142
|
+
const identity = findingIdentity(finding);
|
|
143
|
+
if (finding["environmentId"] !== environmentId || identity.id !== findingId)
|
|
144
|
+
throw new CodexSecurityError(`Unexpected detail for Continuum finding ${findingId}.`);
|
|
145
|
+
const linkedIssue = finding["createdIssueId"] || finding["duplicateOfIssueId"];
|
|
146
|
+
if (!linkedIssue)
|
|
147
|
+
return finding;
|
|
148
|
+
const issueId = continuumId.parse(linkedIssue);
|
|
149
|
+
const list = await request("list-code-issue-artifacts", scope, "--issue-id", issueId);
|
|
150
|
+
requireCompleteList(list, "issue artifact");
|
|
151
|
+
const artifacts = array(list["items"], "Continuum issue artifacts")
|
|
152
|
+
.flatMap((item) => {
|
|
153
|
+
const summary = record(item, "Continuum issue artifact summary");
|
|
154
|
+
const type = summary["artifactType"];
|
|
155
|
+
if (type !== "PATCH" && type !== "VALIDATION_EVIDENCE")
|
|
156
|
+
return [];
|
|
157
|
+
return [{ id: continuumId.parse(summary["artifactId"]), type }];
|
|
158
|
+
})
|
|
159
|
+
.sort((left, right) => left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
160
|
+
const patches = [];
|
|
161
|
+
const evidenceArtifacts = [];
|
|
162
|
+
let validationIssue;
|
|
163
|
+
for (const { id: artifactId, type } of artifacts) {
|
|
164
|
+
const artifact = await getIssueArtifact(request, scope, issueId, artifactId, type);
|
|
165
|
+
if (type === "VALIDATION_EVIDENCE") {
|
|
166
|
+
const selected = selectFindingValidationArtifact(artifact, findingId);
|
|
167
|
+
if (!selected)
|
|
168
|
+
continue;
|
|
169
|
+
if (selected.scope === "issue") {
|
|
170
|
+
if (validationIssue === undefined)
|
|
171
|
+
validationIssue = await getFindingValidationIssue(request, scope, issueId, identity);
|
|
172
|
+
if (!validationIssue)
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
evidenceArtifacts.push(selected.artifact);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const body = record(artifact["body"], "Continuum artifact body");
|
|
179
|
+
const patch = record(body["patch"], `Continuum artifact ${artifactId} patch body`);
|
|
180
|
+
if (repositoryName !== undefined &&
|
|
181
|
+
patch["repositoryName"] !== repositoryName) {
|
|
182
|
+
if (!patch["repositoryName"])
|
|
183
|
+
warn?.(`Skipped Continuum patch ${artifactId}: AWS did not identify its repository.`);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
patches.push(readPatch({ ...patch, artifactId }));
|
|
187
|
+
}
|
|
188
|
+
signal?.throwIfAborted();
|
|
189
|
+
if (!patches.length && !evidenceArtifacts.length)
|
|
190
|
+
return finding;
|
|
191
|
+
return {
|
|
192
|
+
finding,
|
|
193
|
+
...(patches.length && { patches }),
|
|
194
|
+
...(validationIssue && { validationIssue }),
|
|
195
|
+
...(evidenceArtifacts.length && { evidenceArtifacts }),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
export async function collectContinuumIssues(options, runAws) {
|
|
199
|
+
const { environmentId, signal } = options;
|
|
200
|
+
const request = await continuumRequests(options, runAws);
|
|
201
|
+
const environmentArgs = ["--environment-id", environmentId];
|
|
202
|
+
const { url: sourceRepositoryUrl, includePatches } = await singleRepositorySource(await request("get-environment", environmentArgs), (id) => request("get-integration", ["--integration-id", id]));
|
|
203
|
+
// Let the AWS CLI assemble every page. A continuation token means the
|
|
204
|
+
// capture is incomplete and cannot be published as the environment's report.
|
|
205
|
+
const list = await request("list-code-issues", environmentArgs);
|
|
206
|
+
requireCompleteList(list, "issue");
|
|
207
|
+
const issues = [];
|
|
208
|
+
const seenIssues = new Set();
|
|
209
|
+
const fetchedFindings = new Map();
|
|
210
|
+
let environmentScope;
|
|
211
|
+
for (const summary of array(list["items"], "Continuum issue list")) {
|
|
212
|
+
const selected = issueIdentity(summary);
|
|
213
|
+
if (selected.environmentId !== environmentId ||
|
|
214
|
+
(environmentScope !== undefined && environmentScope !== selected.scope) ||
|
|
215
|
+
seenIssues.has(selected.id))
|
|
216
|
+
throw new CodexSecurityError("The Continuum issue list contains a duplicate issue or an issue from another environment.");
|
|
217
|
+
environmentScope = selected.scope;
|
|
218
|
+
seenIssues.add(selected.id);
|
|
219
|
+
const issue = await request("get-code-issue", environmentArgs, "--issue-id", selected.id);
|
|
220
|
+
if (issueIdentity(issue).arn !== selected.arn)
|
|
221
|
+
throw new CodexSecurityError(`Unexpected detail for Continuum issue ${selected.id}.`);
|
|
222
|
+
const ids = z.array(continuumId).nonempty().parse(issue["findingIds"]);
|
|
223
|
+
if (new Set(ids).size !== ids.length)
|
|
224
|
+
throw new CodexSecurityError(`Duplicate finding IDs on Continuum issue ${selected.id}.`);
|
|
225
|
+
const findings = [];
|
|
226
|
+
for (const id of ids) {
|
|
227
|
+
let finding = fetchedFindings.get(id);
|
|
228
|
+
if (!finding) {
|
|
229
|
+
finding = await request("get-code-finding", environmentArgs, "--finding-id", id);
|
|
230
|
+
const identity = findingIdentity(finding);
|
|
231
|
+
if (identity.id !== id || identity.scope !== selected.scope)
|
|
232
|
+
throw new CodexSecurityError(`Unexpected detail for Continuum finding ${id}.`);
|
|
233
|
+
fetchedFindings.set(id, finding);
|
|
234
|
+
}
|
|
235
|
+
findings.push(finding);
|
|
236
|
+
}
|
|
237
|
+
const issueArtifacts = [];
|
|
238
|
+
if (issue["evidenceAvailability"] !== "NONE") {
|
|
239
|
+
const issueArgs = ["--issue-id", selected.id];
|
|
240
|
+
const artifacts = await request("list-code-issue-artifacts", environmentArgs, ...issueArgs);
|
|
241
|
+
requireCompleteList(artifacts, "issue artifact");
|
|
242
|
+
for (const item of array(artifacts["items"], "Continuum issue artifacts")) {
|
|
243
|
+
const summary = record(item, "Continuum issue artifact summary");
|
|
244
|
+
const type = summary["artifactType"];
|
|
245
|
+
if (type !== "EVIDENCE" &&
|
|
246
|
+
type !== "VALIDATION_EVIDENCE" &&
|
|
247
|
+
!(includePatches && type === "PATCH"))
|
|
248
|
+
continue;
|
|
249
|
+
const artifactId = continuumId.parse(summary["artifactId"]);
|
|
250
|
+
issueArtifacts.push(await getIssueArtifact(request, environmentArgs, selected.id, artifactId, type));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
issues.push({
|
|
254
|
+
issue: { ...issue, artifacts: issueArtifacts },
|
|
255
|
+
findings,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
signal?.throwIfAborted();
|
|
259
|
+
return {
|
|
260
|
+
format: continuumIssueFormat,
|
|
261
|
+
environmentId,
|
|
262
|
+
sourceRepositoryUrl,
|
|
263
|
+
issues,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=continuum-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuum-collector.js","sourceRoot":"","sources":["../src/continuum-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAA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QAC5B,aAAa;QACb,mBAAmB;QACnB,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { z } from \"zod\";\nimport { prepareContinuumAws } from \"./continuum-aws.js\";\nimport {\n continuumIssueFormat,\n findingIdentity,\n issueIdentity,\n readPatch,\n selectFindingValidationArtifact,\n singleFindingValidationIssue,\n} from \"./continuum-findings.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { array, record } from \"./scanner-import.js\";\nimport { declaredScannerRepositoryUrl } from \"./scanner-repository-url.js\";\n\nconst execFile = promisify(execFileCallback);\nconst continuumId = z\n .string()\n .regex(\n /^[a-z0-9]{1,64}$/u,\n \"Use a short Continuum ID with lowercase letters and digits.\",\n );\nexport const continuumEnvironmentId = continuumId.describe(\n \"Short Continuum environment ID.\",\n);\nexport const continuumFindingId = continuumId.describe(\n \"Short Continuum finding ID.\",\n);\nconst nativeRecord = z.record(z.string(), z.unknown());\nconst continuumIssueExport = z.object({\n format: z.literal(continuumIssueFormat),\n environmentId: continuumEnvironmentId,\n sourceRepositoryUrl: z.string(),\n issues: z.array(\n z.object({\n issue: z.looseObject({ artifacts: z.array(nativeRecord) }),\n findings: z.array(nativeRecord),\n }),\n ),\n});\n\nexport const continuumImportOutput = z.union([\n continuumIssueExport,\n nativeRecord,\n]);\n\ninterface ContinuumCollectionOptions {\n environmentId: string;\n profile?: string;\n region?: string;\n cwd: string;\n sourceRoot?: string;\n environment: NodeJS.ProcessEnv;\n signal?: AbortSignal;\n}\n\ntype AwsCommand = (args: string[]) => Promise<Record<string, unknown>>;\n\nconst environmentSources = z.object({\n configuration: z\n .object({\n codeConfiguration: z\n .object({\n sourceConfiguration: z\n .object({\n repositorySources: z.array(z.unknown()).optional(),\n s3Sources: z.array(z.unknown()).optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional(),\n});\nconst repositorySource = z.object({\n integrationId: continuumId,\n repository: z.string().regex(/^[a-z0-9_.-]+(?:\\/[a-z0-9_.-]+)+$/iu),\n});\nconst gitLabIntegration = z.object({\n providerDetails: z.object({\n gitlab: z.object({ instanceUrl: z.string().startsWith(\"https://\") }),\n }),\n});\n\nfunction configuredSources(environment: Record<string, unknown>) {\n const { configuration } = environmentSources.parse(environment);\n const sources = configuration?.codeConfiguration?.sourceConfiguration;\n return {\n repositories: sources?.repositorySources ?? [],\n s3Sources: sources?.s3Sources ?? [],\n };\n}\n\nasync function singleRepositorySource(\n environment: Record<string, unknown>,\n getIntegration: (id: string) => Promise<Record<string, unknown>>,\n) {\n const { repositories, s3Sources } = configuredSources(environment);\n if (repositories.length !== 1)\n throw new CodexSecurityError(\n `Continuum collection requires exactly one configured Git repository. This environment has ${repositories.length}.`,\n );\n const { integrationId, repository } = repositorySource.parse(repositories[0]);\n const integration = await getIntegration(integrationId);\n const type = integration[\"integrationType\"];\n if (type !== \"GITHUB\" && type !== \"GITLAB\")\n throw new CodexSecurityError(\n \"Expected a GitHub or GitLab integration for the Continuum repository.\",\n );\n const base =\n type === \"GITHUB\"\n ? \"https://github.com\"\n : gitLabIntegration.parse(integration).providerDetails.gitlab.instanceUrl;\n return {\n url: declaredScannerRepositoryUrl(\n `${base.replace(/\\/$/u, \"\")}/${repository}`,\n \"Continuum\",\n ),\n // Mixed environments do not identify the Git source by the patch's AWS source name.\n includePatches: s3Sources.length === 0,\n };\n}\n\nasync function awsCommand({\n cwd,\n environment,\n signal,\n sourceRoot,\n}: ContinuumCollectionOptions): Promise<AwsCommand> {\n const aws = await prepareContinuumAws(cwd, environment, signal, sourceRoot);\n return async (args) => {\n const command = execFile(aws.executable, args, {\n cwd: aws.cwd,\n env: aws.environment,\n signal,\n maxBuffer: Infinity,\n windowsHide: true,\n });\n command.child.stdin?.end();\n const { stdout } = await command;\n return record(JSON.parse(stdout), `AWS Continuum ${args[1]} response`);\n };\n}\n\nasync function continuumRequests(\n options: ContinuumCollectionOptions,\n runAws?: AwsCommand,\n) {\n const { profile, region, signal } = options;\n signal?.throwIfAborted();\n const run = runAws ?? (await awsCommand(options));\n const awsArgs = [\n \"--output\",\n \"json\",\n \"--no-cli-pager\",\n ...(profile === undefined ? [] : [\"--profile\", profile]),\n ...(region === undefined ? [] : [\"--region\", region]),\n ];\n return (operation: string, scope: string[], ...args: string[]) => {\n signal?.throwIfAborted();\n return run([\"continuum\", operation, ...scope, ...awsArgs, ...args]);\n };\n}\n\ntype ContinuumRequest = Awaited<ReturnType<typeof continuumRequests>>;\n\nasync function getIssueArtifact(\n request: ContinuumRequest,\n scope: string[],\n issueId: string,\n artifactId: string,\n artifactType: string,\n) {\n const artifact = await request(\n \"get-code-issue-artifact\",\n scope,\n \"--issue-id\",\n issueId,\n \"--artifact-id\",\n artifactId,\n );\n if (\n artifact[\"artifactId\"] !== artifactId ||\n artifact[\"artifactType\"] !== artifactType\n )\n throw new CodexSecurityError(\n `Unexpected Continuum artifact ${artifactId} for issue ${issueId}.`,\n );\n return artifact;\n}\n\nfunction requireCompleteList(response: Record<string, unknown>, name: string) {\n if (\n Object.hasOwn(response, \"nextToken\") ||\n Object.hasOwn(response, \"NextToken\")\n )\n throw new CodexSecurityError(`Expected a complete Continuum ${name} list.`);\n}\n\nasync function getFindingValidationIssue(\n request: ContinuumRequest,\n scope: string[],\n issueId: string,\n identity: ReturnType<typeof findingIdentity>,\n) {\n const issue = await request(\"get-code-issue\", scope, \"--issue-id\", issueId);\n const selected = issueIdentity(issue);\n if (selected.scope !== identity.scope || selected.id !== issueId)\n throw new CodexSecurityError(\n `Unexpected detail for Continuum issue ${issueId}.`,\n );\n return singleFindingValidationIssue(issue, issueId, identity);\n}\n\nexport async function collectContinuumFinding(\n options: ContinuumCollectionOptions & {\n findingId: string;\n sourceRoot: string;\n repositoryName?: string;\n warn?: (message: string) => void;\n },\n runAws?: AwsCommand,\n): Promise<Record<string, unknown>> {\n const { environmentId, findingId, repositoryName, warn, signal } = options;\n const request = await continuumRequests(options, runAws);\n const scope = [\"--environment-id\", environmentId];\n if (repositoryName === undefined) {\n const { repositories, s3Sources } = configuredSources(\n await request(\"get-environment\", scope),\n );\n if (\n repositories.length !== 1 ||\n s3Sources.length !== 0 ||\n !repositorySource.safeParse(repositories[0]).success\n )\n throw new CodexSecurityError(\n \"Pass --repository-name with the exact AWS source name. Omitting it requires exactly one configured Git repository and no S3 sources.\",\n );\n }\n\n const finding = await request(\n \"get-code-finding\",\n scope,\n \"--finding-id\",\n findingId,\n );\n const identity = findingIdentity(finding);\n if (finding[\"environmentId\"] !== environmentId || identity.id !== findingId)\n throw new CodexSecurityError(\n `Unexpected detail for Continuum finding ${findingId}.`,\n );\n\n const linkedIssue =\n finding[\"createdIssueId\"] || finding[\"duplicateOfIssueId\"];\n if (!linkedIssue) return finding;\n const issueId = continuumId.parse(linkedIssue);\n const list = await request(\n \"list-code-issue-artifacts\",\n scope,\n \"--issue-id\",\n issueId,\n );\n requireCompleteList(list, \"issue artifact\");\n const artifacts = array(list[\"items\"], \"Continuum issue artifacts\")\n .flatMap((item) => {\n const summary = record(item, \"Continuum issue artifact summary\");\n const type = summary[\"artifactType\"];\n if (type !== \"PATCH\" && type !== \"VALIDATION_EVIDENCE\") return [];\n return [{ id: continuumId.parse(summary[\"artifactId\"]), type }];\n })\n .sort((left, right) =>\n left.id < right.id ? -1 : left.id > right.id ? 1 : 0,\n );\n const patches = [];\n const evidenceArtifacts = [];\n let validationIssue:\n ReturnType<typeof singleFindingValidationIssue> | undefined;\n for (const { id: artifactId, type } of artifacts) {\n const artifact = await getIssueArtifact(\n request,\n scope,\n issueId,\n artifactId,\n type,\n );\n if (type === \"VALIDATION_EVIDENCE\") {\n const selected = selectFindingValidationArtifact(artifact, findingId);\n if (!selected) continue;\n if (selected.scope === \"issue\") {\n if (validationIssue === undefined)\n validationIssue = await getFindingValidationIssue(\n request,\n scope,\n issueId,\n identity,\n );\n if (!validationIssue) continue;\n }\n evidenceArtifacts.push(selected.artifact);\n continue;\n }\n const body = record(artifact[\"body\"], \"Continuum artifact body\");\n const patch = record(\n body[\"patch\"],\n `Continuum artifact ${artifactId} patch body`,\n );\n if (\n repositoryName !== undefined &&\n patch[\"repositoryName\"] !== repositoryName\n ) {\n if (!patch[\"repositoryName\"])\n warn?.(\n `Skipped Continuum patch ${artifactId}: AWS did not identify its repository.`,\n );\n continue;\n }\n patches.push(readPatch({ ...patch, artifactId }));\n }\n signal?.throwIfAborted();\n if (!patches.length && !evidenceArtifacts.length) return finding;\n return {\n finding,\n ...(patches.length && { patches }),\n ...(validationIssue && { validationIssue }),\n ...(evidenceArtifacts.length && { evidenceArtifacts }),\n };\n}\n\nexport async function collectContinuumIssues(\n options: ContinuumCollectionOptions,\n runAws?: AwsCommand,\n): Promise<z.infer<typeof continuumIssueExport>> {\n const { environmentId, signal } = options;\n const request = await continuumRequests(options, runAws);\n const environmentArgs = [\"--environment-id\", environmentId];\n const { url: sourceRepositoryUrl, includePatches } =\n await singleRepositorySource(\n await request(\"get-environment\", environmentArgs),\n (id) => request(\"get-integration\", [\"--integration-id\", id]),\n );\n\n // Let the AWS CLI assemble every page. A continuation token means the\n // capture is incomplete and cannot be published as the environment's report.\n const list = await request(\"list-code-issues\", environmentArgs);\n requireCompleteList(list, \"issue\");\n\n const issues: z.infer<typeof continuumIssueExport>[\"issues\"] = [];\n const seenIssues = new Set<string>();\n const fetchedFindings = new Map<string, Record<string, unknown>>();\n let environmentScope: string | undefined;\n for (const summary of array(list[\"items\"], \"Continuum issue list\")) {\n const selected = issueIdentity(summary);\n if (\n selected.environmentId !== environmentId ||\n (environmentScope !== undefined && environmentScope !== selected.scope) ||\n seenIssues.has(selected.id)\n )\n throw new CodexSecurityError(\n \"The Continuum issue list contains a duplicate issue or an issue from another environment.\",\n );\n environmentScope = selected.scope;\n seenIssues.add(selected.id);\n const issue = await request(\n \"get-code-issue\",\n environmentArgs,\n \"--issue-id\",\n selected.id,\n );\n if (issueIdentity(issue).arn !== selected.arn)\n throw new CodexSecurityError(\n `Unexpected detail for Continuum issue ${selected.id}.`,\n );\n\n const ids = z.array(continuumId).nonempty().parse(issue[\"findingIds\"]);\n if (new Set(ids).size !== ids.length)\n throw new CodexSecurityError(\n `Duplicate finding IDs on Continuum issue ${selected.id}.`,\n );\n const findings: Record<string, unknown>[] = [];\n for (const id of ids) {\n let finding = fetchedFindings.get(id);\n if (!finding) {\n finding = await request(\n \"get-code-finding\",\n environmentArgs,\n \"--finding-id\",\n id,\n );\n const identity = findingIdentity(finding);\n if (identity.id !== id || identity.scope !== selected.scope)\n throw new CodexSecurityError(\n `Unexpected detail for Continuum finding ${id}.`,\n );\n fetchedFindings.set(id, finding);\n }\n findings.push(finding);\n }\n const issueArtifacts: Record<string, unknown>[] = [];\n if (issue[\"evidenceAvailability\"] !== \"NONE\") {\n const issueArgs = [\"--issue-id\", selected.id];\n const artifacts = await request(\n \"list-code-issue-artifacts\",\n environmentArgs,\n ...issueArgs,\n );\n requireCompleteList(artifacts, \"issue artifact\");\n for (const item of array(\n artifacts[\"items\"],\n \"Continuum issue artifacts\",\n )) {\n const summary = record(item, \"Continuum issue artifact summary\");\n const type = summary[\"artifactType\"];\n if (\n type !== \"EVIDENCE\" &&\n type !== \"VALIDATION_EVIDENCE\" &&\n !(includePatches && type === \"PATCH\")\n )\n continue;\n const artifactId = continuumId.parse(summary[\"artifactId\"]);\n issueArtifacts.push(\n await getIssueArtifact(\n request,\n environmentArgs,\n selected.id,\n artifactId,\n type,\n ),\n );\n }\n }\n issues.push({\n issue: { ...issue, artifacts: issueArtifacts },\n findings,\n });\n }\n signal?.throwIfAborted();\n return {\n format: continuumIssueFormat,\n environmentId,\n sourceRepositoryUrl,\n issues,\n };\n}\n"]}
|