@openai/codex-security 0.8.3 → 0.9.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 +192 -151
- package/_bundled_plugin/.mcp.json +5 -1
- package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
- package/_bundled_plugin/examples/completed-scan/report.md +11 -8
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
- package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
- package/_bundled_plugin/mcp/helpers.mjs +2 -11
- package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/package.json +1 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/default-severity-rubric.md +9 -4
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +18 -18
- package/_bundled_plugin/references/sarif-adapter.md +8 -2
- package/_bundled_plugin/references/scan-artifacts.md +21 -12
- package/_bundled_plugin/references/scan-contract.md +27 -33
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
- package/_bundled_plugin/scripts/finding_preview.py +20 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
- package/_bundled_plugin/scripts/legacy_findings.py +148 -0
- package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +81 -43
- package/_bundled_plugin/scripts/review_state.py +8 -2
- package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
- package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
- package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
- package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
- package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
- package/_bundled_plugin/scripts/workbench/storage.py +71 -7
- package/_bundled_plugin/scripts/workbench_cli.py +30 -12
- package/_bundled_plugin/scripts/workbench_constants.py +10 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +369 -137
- package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
- package/_bundled_plugin/scripts/workbench_progress.py +10 -1
- package/_bundled_plugin/scripts/workbench_publication.py +14 -10
- package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
- package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
- package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +13 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
- package/_bundled_plugin/scripts/workbench_target.py +127 -56
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +43 -3
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
- package/_bundled_plugin/shared/workbench-migrations.json +34 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
- package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
- package/dist/api.d.ts +39 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +774 -292
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -6
- package/dist/auth.js.map +1 -1
- package/dist/bedrock-oss-pricing.d.ts +6 -0
- package/dist/bedrock-oss-pricing.d.ts.map +1 -0
- package/dist/bedrock-oss-pricing.js +58 -0
- package/dist/bedrock-oss-pricing.js.map +1 -0
- package/dist/bedrock-pricing.d.ts +15 -0
- package/dist/bedrock-pricing.d.ts.map +1 -0
- package/dist/bedrock-pricing.js +117 -0
- package/dist/bedrock-pricing.js.map +1 -0
- package/dist/blackduck-findings.d.ts.map +1 -1
- package/dist/blackduck-findings.js +35 -20
- package/dist/blackduck-findings.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +4 -4
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/checkmarx-evidence.d.ts +19 -0
- package/dist/checkmarx-evidence.d.ts.map +1 -0
- package/dist/checkmarx-evidence.js +36 -0
- package/dist/checkmarx-evidence.js.map +1 -0
- package/dist/checkmarx-findings.d.ts +4 -0
- package/dist/checkmarx-findings.d.ts.map +1 -0
- package/dist/checkmarx-findings.js +27 -0
- package/dist/checkmarx-findings.js.map +1 -0
- package/dist/checkmarx-one.d.ts +4 -0
- package/dist/checkmarx-one.d.ts.map +1 -0
- package/dist/checkmarx-one.js +53 -0
- package/dist/checkmarx-one.js.map +1 -0
- package/dist/checkmarx-repository.d.ts +12 -0
- package/dist/checkmarx-repository.d.ts.map +1 -0
- package/dist/checkmarx-repository.js +181 -0
- package/dist/checkmarx-repository.js.map +1 -0
- package/dist/checkmarx-xml.d.ts +12 -0
- package/dist/checkmarx-xml.d.ts.map +1 -0
- package/dist/checkmarx-xml.js +196 -0
- package/dist/checkmarx-xml.js.map +1 -0
- package/dist/classify-severity-records.d.ts +1 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +3 -13
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +2 -4
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +11 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1734 -1238
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +16 -3
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +27 -2
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +100 -66
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts.map +1 -1
- package/dist/continuum-findings.js +80 -12
- package/dist/continuum-findings.js.map +1 -1
- package/dist/contract-values.d.ts +2 -0
- package/dist/contract-values.d.ts.map +1 -1
- package/dist/contract-values.js +12 -9
- package/dist/contract-values.js.map +1 -1
- package/dist/cost-model.d.ts +13 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +66 -112
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +42 -3
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +483 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/deduplication/local.d.ts +2 -2
- package/dist/deduplication/local.d.ts.map +1 -1
- package/dist/deduplication/local.js +2 -2
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/refusal.d.ts.map +1 -1
- package/dist/deduplication/refusal.js +25 -5
- package/dist/deduplication/refusal.js.map +1 -1
- package/dist/deduplication/scan.d.ts +3 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +1 -1
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +0 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +22 -33
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-scan-defaults.d.ts +2 -0
- package/dist/deep-scan-defaults.d.ts.map +1 -1
- package/dist/deep-scan-defaults.js +28 -1
- package/dist/deep-scan-defaults.js.map +1 -1
- package/dist/deep-scan.d.ts +2 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +28 -4
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -1
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +1 -1
- package/dist/default-severity-rubric.js.map +1 -1
- package/dist/endor-findings.d.ts +3 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +103 -45
- package/dist/endor-findings.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -1
- package/dist/errors.js.map +1 -1
- package/dist/external-findings-import.d.ts +5 -3
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +7 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +7 -5
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +337 -89
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +8 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +1318 -258
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +20 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +148 -66
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +15 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +42 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +5 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +23 -9
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +5 -4
- package/dist/feedback.js.map +1 -1
- package/dist/finding-prompt.d.ts +5 -0
- package/dist/finding-prompt.d.ts.map +1 -0
- package/dist/finding-prompt.js +32 -0
- package/dist/finding-prompt.js.map +1 -0
- package/dist/findings-client.d.ts +1 -0
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +27 -3
- package/dist/findings-client.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +0 -2
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +15 -4
- package/dist/github-dependabot-findings.js.map +1 -1
- package/dist/github-findings.d.ts +4 -1
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +55 -30
- package/dist/github-findings.js.map +1 -1
- package/dist/hosted-git-remotes.d.ts +5 -0
- package/dist/hosted-git-remotes.d.ts.map +1 -0
- package/dist/hosted-git-remotes.js +285 -0
- package/dist/hosted-git-remotes.js.map +1 -0
- package/dist/hosted-git-repository.d.ts +28 -0
- package/dist/hosted-git-repository.d.ts.map +1 -0
- package/dist/hosted-git-repository.js +222 -0
- package/dist/hosted-git-repository.js.map +1 -0
- package/dist/hosted-scan-protocol.js +2 -2
- package/dist/hosted-scan-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +16 -11
- package/dist/hosted-scan.js.map +1 -1
- package/dist/hosted-scanner-http.d.ts +21 -0
- package/dist/hosted-scanner-http.d.ts.map +1 -0
- package/dist/hosted-scanner-http.js +204 -0
- package/dist/hosted-scanner-http.js.map +1 -0
- package/dist/hosted-scanner-v1.d.ts +6 -0
- package/dist/hosted-scanner-v1.d.ts.map +1 -0
- package/dist/hosted-scanner-v1.js +60 -0
- package/dist/hosted-scanner-v1.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +3 -0
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +47 -65
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +68 -5
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +1 -1
- package/dist/local-git-metadata.d.ts.map +1 -1
- package/dist/local-git-metadata.js +1 -2
- package/dist/local-git-metadata.js.map +1 -1
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +138 -65
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +2 -1
- package/dist/native-json-findings.d.ts.map +1 -1
- package/dist/native-json-findings.js +12 -2
- package/dist/native-json-findings.js.map +1 -1
- package/dist/opengrep-findings.d.ts +1 -0
- package/dist/opengrep-findings.d.ts.map +1 -1
- package/dist/opengrep-findings.js +17 -13
- package/dist/opengrep-findings.js.map +1 -1
- package/dist/operation-telemetry.d.ts +104 -0
- package/dist/operation-telemetry.d.ts.map +1 -0
- package/dist/operation-telemetry.js +293 -0
- package/dist/operation-telemetry.js.map +1 -0
- package/dist/plugin-python-probe.d.ts +4 -0
- package/dist/plugin-python-probe.d.ts.map +1 -0
- package/dist/plugin-python-probe.js +10 -0
- package/dist/plugin-python-probe.js.map +1 -0
- package/dist/private-finding-import.d.ts +97 -2
- package/dist/private-finding-import.d.ts.map +1 -1
- package/dist/private-finding-import.js +58 -34
- package/dist/private-finding-import.js.map +1 -1
- package/dist/provider-profile.d.ts +1 -1
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +8 -1
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/reader-selection.d.ts +2 -0
- package/dist/reader-selection.d.ts.map +1 -1
- package/dist/reader-selection.js +8 -0
- package/dist/reader-selection.js.map +1 -1
- package/dist/remediation.d.ts +1 -4
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -7
- package/dist/remediation.js.map +1 -1
- package/dist/request-metadata.d.ts +3 -0
- package/dist/request-metadata.d.ts.map +1 -1
- package/dist/request-metadata.js +9 -0
- package/dist/request-metadata.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-windows-rename.d.ts +8 -0
- package/dist/retry-windows-rename.d.ts.map +1 -0
- package/dist/retry-windows-rename.js +24 -0
- package/dist/retry-windows-rename.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +313 -110
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +1 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -1
- package/dist/saved-scan-bootstrap.js +18 -15
- package/dist/saved-scan-bootstrap.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +141 -56
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +10 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +60 -15
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +6 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +75 -42
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +10 -1
- package/dist/scan-executor.d.ts.map +1 -1
- package/dist/scan-executor.js +22 -2
- package/dist/scan-executor.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +9 -19
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +106 -77
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-measurement.d.ts +26 -0
- package/dist/scan-measurement.d.ts.map +1 -0
- package/dist/scan-measurement.js +77 -0
- package/dist/scan-measurement.js.map +1 -0
- package/dist/scan-progress.d.ts +1 -0
- package/dist/scan-progress.d.ts.map +1 -1
- package/dist/scan-progress.js +3 -0
- package/dist/scan-progress.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +4 -1
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +1 -1
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +1 -24
- package/dist/scan-settings.js.map +1 -1
- package/dist/scanner-import.d.ts +20 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +200 -8
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +4 -1
- package/dist/scanner-repository-url.d.ts.map +1 -1
- package/dist/scanner-repository-url.js +10 -6
- package/dist/scanner-repository-url.js.map +1 -1
- package/dist/security-policy.d.ts +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +6 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +107 -43
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/semgrep-guardian-findings.d.ts +38 -0
- package/dist/semgrep-guardian-findings.d.ts.map +1 -0
- package/dist/semgrep-guardian-findings.js +165 -0
- package/dist/semgrep-guardian-findings.js.map +1 -0
- package/dist/semgrep-platform-collector.d.ts +26 -0
- package/dist/semgrep-platform-collector.d.ts.map +1 -0
- package/dist/semgrep-platform-collector.js +108 -0
- package/dist/semgrep-platform-collector.js.map +1 -0
- package/dist/semgrep-platform-findings.d.ts +207 -6
- package/dist/semgrep-platform-findings.d.ts.map +1 -1
- package/dist/semgrep-platform-findings.js +983 -103
- package/dist/semgrep-platform-findings.js.map +1 -1
- package/dist/semgrep-platform-v1.d.ts +6 -0
- package/dist/semgrep-platform-v1.d.ts.map +1 -0
- package/dist/semgrep-platform-v1.js +83 -0
- package/dist/semgrep-platform-v1.js.map +1 -0
- package/dist/server/api.d.ts +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embedding-tokenizer.cdx.json +33 -0
- package/dist/server/embedding-tokenizer.d.ts +2 -0
- package/dist/server/embedding-tokenizer.d.ts.map +1 -0
- package/dist/server/embedding-tokenizer.js +322 -0
- package/dist/server/embedding-tokenizer.js.map +6 -0
- package/dist/server/embeddings.d.ts +16 -2
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +35 -5
- package/dist/server/embeddings.js.map +1 -1
- package/dist/session-lines.d.ts +5 -0
- package/dist/session-lines.d.ts.map +1 -0
- package/dist/session-lines.js +60 -0
- package/dist/session-lines.js.map +1 -0
- package/dist/severity-review.d.ts +3 -1
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +3 -2
- package/dist/severity-review.js.map +1 -1
- package/dist/skill-authentication.d.ts +1 -0
- package/dist/skill-authentication.d.ts.map +1 -1
- package/dist/skill-authentication.js +1 -0
- package/dist/skill-authentication.js.map +1 -1
- package/dist/snyk-findings.d.ts +7 -2
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +93 -70
- package/dist/snyk-findings.js.map +1 -1
- package/dist/snyk-rest-findings.d.ts +76 -0
- package/dist/snyk-rest-findings.d.ts.map +1 -0
- package/dist/snyk-rest-findings.js +1051 -0
- package/dist/snyk-rest-findings.js.map +1 -0
- package/dist/snyk-rest-v1.d.ts +28 -0
- package/dist/snyk-rest-v1.d.ts.map +1 -0
- package/dist/snyk-rest-v1.js +132 -0
- package/dist/snyk-rest-v1.js.map +1 -0
- package/dist/snyk-token-origin.d.ts +4 -0
- package/dist/snyk-token-origin.d.ts.map +1 -0
- package/dist/snyk-token-origin.js +82 -0
- package/dist/snyk-token-origin.js.map +1 -0
- package/dist/sonar-collector.d.ts.map +1 -1
- package/dist/sonar-collector.js +0 -3
- package/dist/sonar-collector.js.map +1 -1
- package/dist/sonar-import.d.ts.map +1 -1
- package/dist/sonar-import.js +2 -4
- package/dist/sonar-import.js.map +1 -1
- package/dist/target-drift.d.ts +9 -0
- package/dist/target-drift.d.ts.map +1 -0
- package/dist/target-drift.js +27 -0
- package/dist/target-drift.js.map +1 -0
- package/dist/targets.d.ts +2 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +56 -20
- package/dist/targets.js.map +1 -1
- package/dist/tenable-findings.d.ts +9 -0
- package/dist/tenable-findings.d.ts.map +1 -0
- package/dist/tenable-findings.js +122 -0
- package/dist/tenable-findings.js.map +1 -0
- package/dist/terminal-stream.d.ts +13 -0
- package/dist/terminal-stream.d.ts.map +1 -0
- package/dist/terminal-stream.js +35 -0
- package/dist/terminal-stream.js.map +1 -0
- package/dist/trivy-findings.d.ts +19 -0
- package/dist/trivy-findings.d.ts.map +1 -0
- package/dist/trivy-findings.js +435 -0
- package/dist/trivy-findings.js.map +1 -0
- package/dist/trivy-import.d.ts +19 -0
- package/dist/trivy-import.d.ts.map +1 -0
- package/dist/trivy-import.js +151 -0
- package/dist/trivy-import.js.map +1 -0
- package/dist/validation-records.js +1 -1
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +2 -0
- package/dist/veracode-findings.d.ts.map +1 -1
- package/dist/veracode-findings.js +49 -11
- package/dist/veracode-findings.js.map +1 -1
- package/dist/vertex-pricing.d.ts +8 -0
- package/dist/vertex-pricing.d.ts.map +1 -0
- package/dist/vertex-pricing.js +20 -0
- package/dist/vertex-pricing.js.map +1 -0
- package/dist/windows-path.d.ts +1 -0
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +26 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-findings.d.ts +4 -0
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +57 -3
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +27 -12
- package/docs/cli.md +497 -550
- package/docs/dedupe-records.md +44 -24
- package/docs/findings-service.md +66 -39
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +50 -42
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +18 -15
- package/schemas/external-findings.schema.json +3 -1
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
- package/dist/external-imports-feature.d.ts +0 -6
- package/dist/external-imports-feature.d.ts.map +0 -1
- package/dist/external-imports-feature.js +0 -51
- package/dist/external-imports-feature.js.map +0 -1
- package/dist/finding-normalization.d.ts +0 -5
- package/dist/finding-normalization.d.ts.map +0 -1
- package/dist/finding-normalization.js +0 -155
- package/dist/finding-normalization.js.map +0 -1
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { forwardExternalImportSetting } from "./external-imports-feature.js";
|
|
2
1
|
import { executablePathForSpawn } from "./executable-path.js";
|
|
2
|
+
import { retryWindowsRename } from "./retry-windows-rename.js";
|
|
3
3
|
export { executablePathForSpawn } from "./executable-path.js";
|
|
4
|
+
import { PLUGIN_PYTHON_PROBE, PLUGIN_PYTHON_PROBE_TIMEOUT_MS, PLUGIN_PYTHON_READY, } from "./plugin-python-probe.js";
|
|
4
5
|
import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
|
|
5
6
|
import { gitProtectionRoots } from "./targets.js";
|
|
6
7
|
import { isNonEmptyString, notify } from "./value.js";
|
|
@@ -21,7 +22,7 @@ import { parse } from "smol-toml";
|
|
|
21
22
|
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
22
23
|
import { isRecord } from "./record.js";
|
|
23
24
|
import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
24
|
-
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
25
|
+
import { isWindowsUnsafePathComponent, sqliteFilename, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
25
26
|
const execFile = promisify(execFileCallback);
|
|
26
27
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
27
28
|
export const PLUGIN_NAME = "codex-security";
|
|
@@ -56,6 +57,7 @@ const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
|
|
|
56
57
|
"OPENROUTER_API_KEY",
|
|
57
58
|
"FIREWORKS_API_KEY",
|
|
58
59
|
"CHEAPER_INFERENCE_API_KEY",
|
|
60
|
+
"HF_TOKEN",
|
|
59
61
|
]);
|
|
60
62
|
const PREPARE_SCAN_ARTIFACT_RESTORER_PROGRAM = `
|
|
61
63
|
from pathlib import Path
|
|
@@ -281,6 +283,7 @@ const WINDOWS_PRINCIPAL_ALIASES = {
|
|
|
281
283
|
HA: "S-1-5-32-578",
|
|
282
284
|
AA: "S-1-5-32-579",
|
|
283
285
|
};
|
|
286
|
+
const WINDOWS_ACCOUNT_SID = /^S-1-5-21-(?:\d+-){3}\d+$/u;
|
|
284
287
|
const WINDOWS_SID = /^S-1-(?:\d+-)*\d+$/u;
|
|
285
288
|
const WINDOWS_GUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
|
|
286
289
|
const WINDOWS_SDDL_SID = "(?:S-1-(?:\\d+-)*\\d+|[A-Z]{2})";
|
|
@@ -367,7 +370,10 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
|
|
|
367
370
|
if (type === "A" || type === "OA" || type === "XA" || type === "ZA") {
|
|
368
371
|
if (!trustedPrincipal(principal)) {
|
|
369
372
|
if (options.scope !== "ancestor" ||
|
|
370
|
-
|
|
373
|
+
// OWNER RIGHTS applies to the owner already verified above. Every
|
|
374
|
+
// descendant is inspected with its own security descriptor.
|
|
375
|
+
(principal !== WINDOWS_OWNER_RIGHTS_SID &&
|
|
376
|
+
windowsAceAllowsAncestorReplacement(rights, inheritanceFlags))) {
|
|
371
377
|
untrustedPrincipals.add(principal);
|
|
372
378
|
}
|
|
373
379
|
}
|
|
@@ -387,7 +393,9 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
|
|
|
387
393
|
}
|
|
388
394
|
}
|
|
389
395
|
}
|
|
390
|
-
else
|
|
396
|
+
else if (principal === currentUserSid ||
|
|
397
|
+
!WINDOWS_ACCOUNT_SID.test(principal) ||
|
|
398
|
+
(options.currentGroupSids?.has(principal) ?? true)) {
|
|
391
399
|
deniedPrincipals.add(principal);
|
|
392
400
|
}
|
|
393
401
|
remaining = rest;
|
|
@@ -584,6 +592,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
584
592
|
const ancestorPath = ancestors[index];
|
|
585
593
|
try {
|
|
586
594
|
const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
595
|
+
currentGroupSids: options.currentGroupSids,
|
|
587
596
|
resolvedAliases: options.resolvedAliases,
|
|
588
597
|
scope: "ancestor",
|
|
589
598
|
});
|
|
@@ -605,6 +614,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
605
614
|
if (index === ancestors.length) {
|
|
606
615
|
try {
|
|
607
616
|
home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
617
|
+
currentGroupSids: options.currentGroupSids,
|
|
608
618
|
resolvedAliases: options.resolvedAliases,
|
|
609
619
|
});
|
|
610
620
|
}
|
|
@@ -617,6 +627,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
617
627
|
return;
|
|
618
628
|
}
|
|
619
629
|
const descendant = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
630
|
+
currentGroupSids: options.currentGroupSids,
|
|
620
631
|
resolvedAliases: options.resolvedAliases,
|
|
621
632
|
scope: "file",
|
|
622
633
|
});
|
|
@@ -644,17 +655,45 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
644
655
|
}
|
|
645
656
|
throw new Error("Windows credential descendants could not be verified");
|
|
646
657
|
}
|
|
658
|
+
/** A file server may add its own groups to the client's token. */
|
|
659
|
+
export async function isLocalWindowsCredentialVolume(path, readDriveType) {
|
|
660
|
+
const drive = /^\\\\[?.]\\([A-Z]:)\\/iu.exec(win32.toNamespacedPath(path))?.[1];
|
|
661
|
+
if (!drive)
|
|
662
|
+
return false;
|
|
663
|
+
// Win32_LogicalDisk reports removable, local disk, and RAM disk as 2, 3, 6.
|
|
664
|
+
return ["2", "3", "6"].includes((await readDriveType(drive)).trim());
|
|
665
|
+
}
|
|
666
|
+
/** Keep every token group, including groups used only for deny ACEs. */
|
|
667
|
+
export function parseWindowsTokenGroupSids(output) {
|
|
668
|
+
const groups = new Set();
|
|
669
|
+
for (const row of output.trim().split(/\r?\n/u)) {
|
|
670
|
+
const sid = /^"(?:[^"]|"")*","(?:[^"]|"")*","(S-1-(?:\d+-)*\d+)","(?:[^"]|"")*"$/u.exec(row)?.[1];
|
|
671
|
+
if (!sid)
|
|
672
|
+
throw new Error("Unable to identify Windows token group SIDs");
|
|
673
|
+
groups.add(sid);
|
|
674
|
+
}
|
|
675
|
+
return groups;
|
|
676
|
+
}
|
|
647
677
|
async function secureWindowsCredentialHome(path) {
|
|
648
678
|
const ancestorAclScript = windowsCredentialAncestorAclScript(path);
|
|
679
|
+
const treePath = win32.toNamespacedPath(path);
|
|
649
680
|
const systemRoot = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
650
681
|
const systemDirectory = join(systemRoot, "System32");
|
|
651
|
-
const
|
|
682
|
+
const powershellDirectory = join(systemDirectory, "WindowsPowerShell", "v1.0");
|
|
683
|
+
const powershell = join(powershellDirectory, "powershell.exe");
|
|
684
|
+
const powershellArgs = [
|
|
685
|
+
"-NoLogo",
|
|
686
|
+
"-NoProfile",
|
|
687
|
+
"-NonInteractive",
|
|
688
|
+
"-Command",
|
|
689
|
+
];
|
|
652
690
|
const inheritedEnvironment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "PSMODULEPATH"));
|
|
653
691
|
const processOptions = {
|
|
654
692
|
env: {
|
|
655
693
|
...inheritedEnvironment,
|
|
656
694
|
CODEX_SECURITY_CREDENTIAL_ACL_PATH: path,
|
|
657
|
-
|
|
695
|
+
CODEX_SECURITY_CREDENTIAL_TREE_PATH: treePath,
|
|
696
|
+
PSModulePath: join(powershellDirectory, "Modules"),
|
|
658
697
|
},
|
|
659
698
|
encoding: "utf8",
|
|
660
699
|
windowsHide: true,
|
|
@@ -672,30 +711,47 @@ async function secureWindowsCredentialHome(path) {
|
|
|
672
711
|
const script = [
|
|
673
712
|
"$ErrorActionPreference = 'Stop'",
|
|
674
713
|
"$script:descriptorCount = 0",
|
|
675
|
-
"function Write-CredentialAcl($path) {
|
|
714
|
+
"function Write-CredentialAcl($path) {",
|
|
715
|
+
" $descriptors = @(Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $path | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl)",
|
|
716
|
+
" if ($descriptors.Count -ne @($path).Count) { throw 'Windows credential ACL could not be verified' }",
|
|
717
|
+
" foreach ($descriptor in $descriptors) { if (-not $descriptor) { throw 'Windows credential ACL could not be verified' }; $script:descriptorCount += 1; $descriptor }",
|
|
718
|
+
"}",
|
|
676
719
|
"function Read-CredentialDescendants($path) {",
|
|
677
720
|
" try { $entries = @(Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $path -Force) } catch {",
|
|
678
721
|
// A child can disappear while an existing directory is being enumerated.
|
|
679
722
|
// Retry that incomplete listing before accepting a vanished descendant.
|
|
680
723
|
` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetChildItemCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
|
|
681
|
-
" if ($path -ne $env:
|
|
724
|
+
" if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
|
|
682
725
|
" throw",
|
|
683
726
|
" }",
|
|
684
|
-
" foreach ($entry in $entries) {",
|
|
727
|
+
" $children = @(foreach ($entry in $entries) {",
|
|
685
728
|
" if (($entry.Attributes -band 1024) -and ($entry.LinkType -in @('SymbolicLink', 'Junction'))) { throw 'Windows credential home contains a symbolic link or junction' }",
|
|
686
729
|
" if ($entry.PSObject.TypeNames -notcontains 'System.IO.DirectoryInfo' -and $entry.PSObject.TypeNames -notcontains 'System.IO.FileInfo') { throw 'Windows credential home contains an unsafe entry' }",
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
"
|
|
691
|
-
"
|
|
730
|
+
// Keep the extended-length path when Windows PowerShell returns child names.
|
|
731
|
+
' "$path\\$($entry.Name)"',
|
|
732
|
+
" })",
|
|
733
|
+
" if ($children.Count -eq 0) { return }",
|
|
734
|
+
" try { Write-CredentialAcl $children } catch {",
|
|
735
|
+
// A vanished path is the only reason to retry the batch one child at a time.
|
|
736
|
+
" if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
|
|
737
|
+
" for ($i = 0; $i -lt $children.Count; $i++) {",
|
|
738
|
+
" try { Write-CredentialAcl $children[$i] } catch {",
|
|
739
|
+
" if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
|
|
740
|
+
" $children[$i] = $null",
|
|
741
|
+
" }",
|
|
692
742
|
" }",
|
|
693
|
-
"
|
|
743
|
+
" }",
|
|
744
|
+
" for ($i = 0; $i -lt $children.Count; $i++) {",
|
|
745
|
+
" if ($children[$i] -and $entries[$i].PSIsContainer) { Read-CredentialDescendants $children[$i] }",
|
|
694
746
|
" }",
|
|
695
747
|
"}",
|
|
696
748
|
ancestorAclScript,
|
|
697
749
|
"Write-CredentialAcl $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
698
|
-
"Read-CredentialDescendants $env:
|
|
750
|
+
"try { Read-CredentialDescendants $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH } catch {",
|
|
751
|
+
// Either a batch or a single-child Get-Acl may report an incomplete listing.
|
|
752
|
+
` if ($_.FullyQualifiedErrorId -in @('System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand', 'GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand')) { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
|
|
753
|
+
" throw",
|
|
754
|
+
"}",
|
|
699
755
|
`"${WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX}$script:descriptorCount"`,
|
|
700
756
|
].join("\n");
|
|
701
757
|
const resolvePrincipalScript = [
|
|
@@ -704,31 +760,40 @@ async function secureWindowsCredentialHome(path) {
|
|
|
704
760
|
"Microsoft.PowerShell.Utility\\ConvertFrom-SddlString -Sddl $descriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty RawDescriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Owner | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Value",
|
|
705
761
|
].join("; ");
|
|
706
762
|
const resolvedAliases = {};
|
|
763
|
+
function requireNumericSid(value) {
|
|
764
|
+
if (!WINDOWS_SID.test(value))
|
|
765
|
+
throw new Error("Windows credential ACL contains an unresolvable identity");
|
|
766
|
+
return value;
|
|
767
|
+
}
|
|
707
768
|
const resolvePrincipal = async (principal) => {
|
|
708
769
|
if (!/^[A-Z]{2}$/u.test(principal) ||
|
|
709
770
|
WINDOWS_PRINCIPAL_ALIASES[principal] !== undefined ||
|
|
710
771
|
resolvedAliases[principal] !== undefined) {
|
|
711
772
|
return;
|
|
712
773
|
}
|
|
713
|
-
const resolved = await execFile(powershell, [
|
|
714
|
-
"-NoLogo",
|
|
715
|
-
"-NoProfile",
|
|
716
|
-
"-NonInteractive",
|
|
717
|
-
"-Command",
|
|
718
|
-
resolvePrincipalScript,
|
|
719
|
-
], {
|
|
774
|
+
const resolved = await execFile(powershell, [...powershellArgs, resolvePrincipalScript], {
|
|
720
775
|
...processOptions,
|
|
721
776
|
env: {
|
|
722
777
|
...processOptions.env,
|
|
723
778
|
CODEX_SECURITY_CREDENTIAL_PRINCIPAL: principal,
|
|
724
779
|
},
|
|
725
780
|
});
|
|
726
|
-
|
|
727
|
-
if (!WINDOWS_SID.test(numeric)) {
|
|
728
|
-
throw new Error("Windows credential ACL contains an unresolvable identity");
|
|
729
|
-
}
|
|
730
|
-
resolvedAliases[principal] = numeric;
|
|
781
|
+
resolvedAliases[principal] = requireNumericSid(resolved.stdout.trim());
|
|
731
782
|
};
|
|
783
|
+
const loadLocalGroupSids = async () => {
|
|
784
|
+
const local = await isLocalWindowsCredentialVolume(treePath, async (drive) => {
|
|
785
|
+
const volume = await execFile(powershell, [
|
|
786
|
+
...powershellArgs,
|
|
787
|
+
`$ErrorActionPreference = 'Stop'; (CimCmdlets\\Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = '${drive}'").DriveType`,
|
|
788
|
+
], processOptions);
|
|
789
|
+
return volume.stdout;
|
|
790
|
+
});
|
|
791
|
+
if (!local)
|
|
792
|
+
return null;
|
|
793
|
+
const groups = await execFile(join(systemDirectory, "whoami.exe"), ["/groups", "/fo", "csv", "/nh"], processOptions);
|
|
794
|
+
return parseWindowsTokenGroupSids(groups.stdout);
|
|
795
|
+
};
|
|
796
|
+
let currentGroupSids;
|
|
732
797
|
const resolveDescriptorAliases = async (descriptor) => {
|
|
733
798
|
const header = WINDOWS_SECURITY_DESCRIPTOR.exec(descriptor.trim());
|
|
734
799
|
if (header === null)
|
|
@@ -737,9 +802,18 @@ async function secureWindowsCredentialHome(path) {
|
|
|
737
802
|
let remaining = header[3];
|
|
738
803
|
while (remaining.startsWith("(")) {
|
|
739
804
|
const { rule, rest } = windowsSecurityDescriptorRule(remaining);
|
|
740
|
-
const
|
|
741
|
-
|
|
805
|
+
const fields = rule.split(";");
|
|
806
|
+
const principal = fields[5];
|
|
807
|
+
if (principal !== undefined) {
|
|
742
808
|
await resolvePrincipal(principal);
|
|
809
|
+
const trustee = resolvedAliases[principal] ?? principal;
|
|
810
|
+
if (currentGroupSids === undefined &&
|
|
811
|
+
["D", "OD", "XD"].includes(fields[0]) &&
|
|
812
|
+
trustee !== sid &&
|
|
813
|
+
WINDOWS_ACCOUNT_SID.test(trustee)) {
|
|
814
|
+
currentGroupSids = await loadLocalGroupSids();
|
|
815
|
+
}
|
|
816
|
+
}
|
|
743
817
|
remaining = rest;
|
|
744
818
|
}
|
|
745
819
|
};
|
|
@@ -747,25 +821,19 @@ async function secureWindowsCredentialHome(path) {
|
|
|
747
821
|
const readAcl = async () => {
|
|
748
822
|
const snapshot = await inspectWindowsCredentialAclSnapshot(path, sid, {
|
|
749
823
|
command: powershell,
|
|
750
|
-
args: [
|
|
824
|
+
args: [...powershellArgs, script],
|
|
751
825
|
environment: processOptions.env,
|
|
826
|
+
get currentGroupSids() {
|
|
827
|
+
return currentGroupSids ?? undefined;
|
|
828
|
+
},
|
|
752
829
|
resolvedAliases,
|
|
753
830
|
resolveDescriptorAliases,
|
|
754
831
|
});
|
|
755
832
|
descendantsArePrivate = snapshot.descendantsArePrivate;
|
|
756
833
|
return snapshot.home;
|
|
757
834
|
};
|
|
758
|
-
const icacls = join(systemDirectory, "icacls.exe");
|
|
759
|
-
const installTrustedAcl =
|
|
760
|
-
await execFile(icacls, [
|
|
761
|
-
target,
|
|
762
|
-
"/inheritance:r",
|
|
763
|
-
"/grant:r",
|
|
764
|
-
`*${sid}:(OI)(CI)F`,
|
|
765
|
-
`*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`,
|
|
766
|
-
`*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`,
|
|
767
|
-
], processOptions);
|
|
768
|
-
};
|
|
835
|
+
const icacls = (target, ...args) => execFile(join(systemDirectory, "icacls.exe"), [target, ...args], processOptions);
|
|
836
|
+
const installTrustedAcl = () => icacls(path, "/inheritance:r", "/grant:r", `*${sid}:(OI)(CI)F`, `*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`, `*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`);
|
|
769
837
|
let existing;
|
|
770
838
|
for (let attempt = 0; existing === undefined && attempt < 3; attempt += 1) {
|
|
771
839
|
try {
|
|
@@ -773,7 +841,7 @@ async function secureWindowsCredentialHome(path) {
|
|
|
773
841
|
}
|
|
774
842
|
catch (error) {
|
|
775
843
|
if (error instanceof RepairableWindowsCredentialOwnerError) {
|
|
776
|
-
await
|
|
844
|
+
await icacls(path, "/setowner", `*${sid}`);
|
|
777
845
|
}
|
|
778
846
|
else if (error instanceof RepairableWindowsCredentialAclError) {
|
|
779
847
|
await installTrustedAcl();
|
|
@@ -789,7 +857,7 @@ async function secureWindowsCredentialHome(path) {
|
|
|
789
857
|
if (existing.grantsCurrentUserAccess &&
|
|
790
858
|
existing.untrustedPrincipals.length === 0 &&
|
|
791
859
|
!existing.protected) {
|
|
792
|
-
await
|
|
860
|
+
await icacls(path, "/inheritance:d");
|
|
793
861
|
existing = await readAcl();
|
|
794
862
|
}
|
|
795
863
|
let verified = existing;
|
|
@@ -798,17 +866,12 @@ async function secureWindowsCredentialHome(path) {
|
|
|
798
866
|
verified.untrustedPrincipals.length !== 0) {
|
|
799
867
|
await installTrustedAcl();
|
|
800
868
|
verified = await readAcl();
|
|
801
|
-
for (const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
for (const principal of verified.deniedPrincipals) {
|
|
808
|
-
if (!WINDOWS_SID.test(principal)) {
|
|
809
|
-
throw new Error("Windows credential ACL contains an unresolvable identity");
|
|
810
|
-
}
|
|
811
|
-
await execFile(icacls, [path, "/remove:d", `*${principal}`], processOptions);
|
|
869
|
+
for (const [remove, principals] of [
|
|
870
|
+
["/remove:g", verified.untrustedPrincipals],
|
|
871
|
+
["/remove:d", verified.deniedPrincipals],
|
|
872
|
+
]) {
|
|
873
|
+
for (const principal of principals)
|
|
874
|
+
await icacls(path, remove, `*${requireNumericSid(principal)}`);
|
|
812
875
|
}
|
|
813
876
|
if (verified.untrustedPrincipals.length !== 0 ||
|
|
814
877
|
verified.deniedPrincipals.length !== 0) {
|
|
@@ -825,13 +888,32 @@ async function secureWindowsCredentialHome(path) {
|
|
|
825
888
|
throw new Error("Windows credential ACL grants access to another identity");
|
|
826
889
|
}
|
|
827
890
|
if (!descendantsArePrivate) {
|
|
828
|
-
await
|
|
891
|
+
await icacls(join(treePath, "*"), "/reset", "/t", "/q");
|
|
829
892
|
await readAcl();
|
|
830
893
|
if (!descendantsArePrivate) {
|
|
831
894
|
throw new Error("Windows credential descendants remain accessible");
|
|
832
895
|
}
|
|
833
896
|
}
|
|
834
897
|
}
|
|
898
|
+
export function sqliteDatabaseOpener(access = "read-write") {
|
|
899
|
+
const require = createRequire(import.meta.url);
|
|
900
|
+
const bun = process.versions["bun"] !== undefined;
|
|
901
|
+
const Database = (bun ? require("bun:sqlite").Database : require("node:sqlite").DatabaseSync);
|
|
902
|
+
return (path) => {
|
|
903
|
+
const filename = sqliteFilename(path);
|
|
904
|
+
if (access === "read-write")
|
|
905
|
+
return new Database(filename);
|
|
906
|
+
// Apple's SQLite requires write access to initialize missing WAL sidecars.
|
|
907
|
+
// The history reader sets PRAGMA query_only on this existing-file connection.
|
|
908
|
+
return new Database(filename, bun
|
|
909
|
+
? {
|
|
910
|
+
readonly: process.platform !== "darwin",
|
|
911
|
+
readwrite: process.platform === "darwin",
|
|
912
|
+
create: false,
|
|
913
|
+
}
|
|
914
|
+
: { readOnly: true });
|
|
915
|
+
};
|
|
916
|
+
}
|
|
835
917
|
export async function withCredentialHomeLock(codexHome, operation, signal) {
|
|
836
918
|
const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
|
|
837
919
|
try {
|
|
@@ -854,17 +936,11 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
854
936
|
if (existingDatabaseMetadata !== null) {
|
|
855
937
|
requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
|
|
856
938
|
}
|
|
857
|
-
const
|
|
858
|
-
// Both supported runtimes bundle SQLite. Keep the transaction in the process
|
|
859
|
-
// doing the protected work, so pausing it cannot expire its lock.
|
|
860
|
-
const Database = process.versions["bun"]
|
|
861
|
-
? require("bun:sqlite")
|
|
862
|
-
.Database
|
|
863
|
-
: require("node:sqlite").DatabaseSync;
|
|
939
|
+
const openDatabase = sqliteDatabaseOpener();
|
|
864
940
|
// Let SQLite create a missing guard so no separate descriptor can close after
|
|
865
941
|
// another connection acquires its process-owned POSIX lock. Keep the guard
|
|
866
942
|
// across releases so every contender locks the same inode.
|
|
867
|
-
const database =
|
|
943
|
+
const database = openDatabase(databasePath);
|
|
868
944
|
let databaseLocked = false;
|
|
869
945
|
try {
|
|
870
946
|
// SQLite creates new databases with the process umask. Tighten or repair
|
|
@@ -1035,6 +1111,51 @@ async function recoverStaleCredentialHomeLock(lock) {
|
|
|
1035
1111
|
await rm(quarantine, { recursive: true, force: true });
|
|
1036
1112
|
return true;
|
|
1037
1113
|
}
|
|
1114
|
+
function sameInode(left, right) {
|
|
1115
|
+
return left.dev === right.dev && left.ino === right.ino;
|
|
1116
|
+
}
|
|
1117
|
+
/** Distinguish two hard links from two paths to the same directory entry. */
|
|
1118
|
+
async function hasSeparateAmbientLink(localPath, ambientHome) {
|
|
1119
|
+
try {
|
|
1120
|
+
const local = await lstat(localPath, { bigint: true });
|
|
1121
|
+
if (!local.isFile() || local.nlink < 2n || local.ino === 0n)
|
|
1122
|
+
return false;
|
|
1123
|
+
const ambient = await lstat(join(ambientHome, "auth.json"), {
|
|
1124
|
+
bigint: true,
|
|
1125
|
+
});
|
|
1126
|
+
if (!ambient.isFile() || !sameInode(local, ambient))
|
|
1127
|
+
return false;
|
|
1128
|
+
const [localDir, ambientDir] = await Promise.all([
|
|
1129
|
+
stat(dirname(localPath), { bigint: true }),
|
|
1130
|
+
stat(ambientHome, { bigint: true }),
|
|
1131
|
+
]);
|
|
1132
|
+
return (localDir.ino !== 0n &&
|
|
1133
|
+
ambientDir.ino !== 0n &&
|
|
1134
|
+
!sameInode(localDir, ambientDir));
|
|
1135
|
+
}
|
|
1136
|
+
catch {
|
|
1137
|
+
// Without a verified second link, leave logout to the configured native store.
|
|
1138
|
+
return false;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
/** Run under the credential-home lock so status cannot reimport the sign-in during logout. */
|
|
1142
|
+
export async function logoutCredentialHome(home, ambientHome, nativeLogout, onLoggedOut) {
|
|
1143
|
+
const localPath = join(home, "auth.json");
|
|
1144
|
+
const shared = await hasSeparateAmbientLink(localPath, ambientHome);
|
|
1145
|
+
const recordLogout = async () => {
|
|
1146
|
+
await setCodexSecurityCredentialLogout(home, true);
|
|
1147
|
+
if (shared)
|
|
1148
|
+
await rm(localPath);
|
|
1149
|
+
onLoggedOut?.();
|
|
1150
|
+
};
|
|
1151
|
+
// Detach before native logout can revoke a shared token, even if native cleanup fails.
|
|
1152
|
+
if (shared)
|
|
1153
|
+
await recordLogout();
|
|
1154
|
+
const status = await nativeLogout();
|
|
1155
|
+
if (!shared && (status === undefined || status === 0))
|
|
1156
|
+
await recordLogout();
|
|
1157
|
+
return status;
|
|
1158
|
+
}
|
|
1038
1159
|
export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
|
|
1039
1160
|
await requireSecureCredentialHome(codexHome);
|
|
1040
1161
|
const marker = join(codexHome, CREDENTIAL_LOGOUT_MARKER);
|
|
@@ -1142,7 +1263,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
|
|
|
1142
1263
|
}
|
|
1143
1264
|
export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
|
|
1144
1265
|
if (isWithin(repository, outputDirectory) ||
|
|
1145
|
-
(pathKind === "output"
|
|
1266
|
+
((pathKind === "output" || pathKind === "state") &&
|
|
1267
|
+
isWithin(outputDirectory, repository))) {
|
|
1146
1268
|
throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
|
|
1147
1269
|
}
|
|
1148
1270
|
}
|
|
@@ -1248,7 +1370,17 @@ export async function runWorkbench(options, args, input) {
|
|
|
1248
1370
|
? ARCHIVE_REGISTRATION_PROGRAM
|
|
1249
1371
|
: WORKBENCH_SCRIPT_PROGRAM),
|
|
1250
1372
|
script,
|
|
1251
|
-
], pluginHelperEnvironment(
|
|
1373
|
+
], pluginHelperEnvironment({
|
|
1374
|
+
...(node?.environment ?? options.environment),
|
|
1375
|
+
// Python's compressed-rollout reader needs the selected Node even when
|
|
1376
|
+
// this SDK was launched by absolute path without Node on PATH.
|
|
1377
|
+
...(!native &&
|
|
1378
|
+
!process.versions["bun"] &&
|
|
1379
|
+
environmentValue(options.environment, "CODEX_MCP_NODE_PATH") ===
|
|
1380
|
+
undefined
|
|
1381
|
+
? { CODEX_MCP_NODE_PATH: process.execPath }
|
|
1382
|
+
: {}),
|
|
1383
|
+
}),
|
|
1252
1384
|
// The SDK owns configuration normalization; the helper receives its resolved location.
|
|
1253
1385
|
nativeLocalDedupe
|
|
1254
1386
|
? `{"stateDirectory":${JSON.stringify(stateDirectory)},"payload":${input ?? "null"}}`
|
|
@@ -1329,8 +1461,9 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1329
1461
|
throw new OutputDirectoryNotEmptyError(path);
|
|
1330
1462
|
}
|
|
1331
1463
|
requireOutputDirectoryOwnership(metadata, path);
|
|
1332
|
-
|
|
1333
|
-
|
|
1464
|
+
const writableLeaf = !archiveExisting ||
|
|
1465
|
+
(process.platform === "win32" && (await readdir(path)).length === 0);
|
|
1466
|
+
const canonical = await checkedOutputPath(path, writableLeaf);
|
|
1334
1467
|
requireModelSafeOutputDir(canonical);
|
|
1335
1468
|
return canonical;
|
|
1336
1469
|
}
|
|
@@ -1486,13 +1619,12 @@ export async function prepareScanRegistrationOutput(outputDirectory, repositoryN
|
|
|
1486
1619
|
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
|
|
1487
1620
|
}
|
|
1488
1621
|
async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
|
|
1489
|
-
if (outputDirectory === undefined) {
|
|
1490
|
-
requireModelSafeOutputDir(temporaryRoot);
|
|
1491
|
-
requireModelSafeOutputDir(await realpath(temporaryRoot));
|
|
1492
|
-
}
|
|
1493
1622
|
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1494
|
-
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1495
1623
|
if (path === null) {
|
|
1624
|
+
requireModelSafeOutputDir(temporaryRoot);
|
|
1625
|
+
const canonicalRoot = await realpath(temporaryRoot);
|
|
1626
|
+
requireModelSafeOutputDir(canonicalRoot);
|
|
1627
|
+
validateLocation?.(canonicalRoot);
|
|
1496
1628
|
const prefix = `codex-security-${safePrefix(repositoryName)}`;
|
|
1497
1629
|
let created;
|
|
1498
1630
|
if (process.platform === "win32") {
|
|
@@ -1500,11 +1632,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1500
1632
|
// Reserve room within NTFS's 255-unit component limit for later archival.
|
|
1501
1633
|
// The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
|
|
1502
1634
|
const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
|
|
1503
|
-
created = join(
|
|
1635
|
+
created = join(canonicalRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
|
|
1504
1636
|
await createWindowsOutputDirectory(created, false);
|
|
1505
1637
|
}
|
|
1506
1638
|
else {
|
|
1507
|
-
created = await mkdtemp(join(
|
|
1639
|
+
created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
|
|
1508
1640
|
}
|
|
1509
1641
|
try {
|
|
1510
1642
|
if ((process.umask() & 0o700) !== 0)
|
|
@@ -1516,6 +1648,7 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1516
1648
|
throw error;
|
|
1517
1649
|
}
|
|
1518
1650
|
}
|
|
1651
|
+
validateLocation?.(path);
|
|
1519
1652
|
let createdRoot;
|
|
1520
1653
|
try {
|
|
1521
1654
|
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
@@ -1535,7 +1668,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1535
1668
|
if ((process.umask() & 0o700) !== 0)
|
|
1536
1669
|
await chmod(path, 0o700);
|
|
1537
1670
|
}
|
|
1538
|
-
|
|
1671
|
+
// Registration retains a populated scan for archival. An empty Windows
|
|
1672
|
+
// directory must still satisfy the checks for a writable scan output.
|
|
1673
|
+
const preserveContents = existingOutput === "preserve" &&
|
|
1674
|
+
(process.platform !== "win32" || (await readdir(path)).length !== 0);
|
|
1675
|
+
return await validatePreparedOutputDir(path, validateLocation, preserveContents);
|
|
1539
1676
|
}
|
|
1540
1677
|
catch (error) {
|
|
1541
1678
|
if (createdRoot !== undefined) {
|
|
@@ -1548,10 +1685,19 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1548
1685
|
});
|
|
1549
1686
|
}
|
|
1550
1687
|
}
|
|
1688
|
+
async function windowsOutputBinding() {
|
|
1689
|
+
return createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
|
|
1690
|
+
}
|
|
1691
|
+
export async function requireWindowsOutputPath(path, writableLeaf, retainedDirectory) {
|
|
1692
|
+
const native = await windowsOutputBinding();
|
|
1693
|
+
const error = native.validateWindowsOutputPath(Buffer.from(win32.toNamespacedPath(path), "utf16le"), writableLeaf, retainedDirectory);
|
|
1694
|
+
if (error !== 0)
|
|
1695
|
+
throw new OutputDirectoryError(`Scan output directory or its parent could not be trusted (Windows error ${error}): ${path}`);
|
|
1696
|
+
}
|
|
1551
1697
|
export async function createWindowsOutputDirectory(path, recursive) {
|
|
1552
|
-
const native =
|
|
1698
|
+
const native = await windowsOutputBinding();
|
|
1553
1699
|
const create = async (target) => {
|
|
1554
|
-
const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
|
|
1700
|
+
const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"), true);
|
|
1555
1701
|
let error = createOne();
|
|
1556
1702
|
let firstCreated;
|
|
1557
1703
|
if (recursive &&
|
|
@@ -1562,8 +1708,10 @@ export async function createWindowsOutputDirectory(path, recursive) {
|
|
|
1562
1708
|
}
|
|
1563
1709
|
if (error === 0)
|
|
1564
1710
|
return firstCreated ?? target;
|
|
1565
|
-
if (recursive && error === 183 && (await stat(target)).isDirectory())
|
|
1711
|
+
if (recursive && error === 183 && (await stat(target)).isDirectory()) {
|
|
1712
|
+
await requireWindowsOutputPath(target, target === path);
|
|
1566
1713
|
return firstCreated;
|
|
1714
|
+
}
|
|
1567
1715
|
throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
|
|
1568
1716
|
};
|
|
1569
1717
|
return create(path);
|
|
@@ -1573,14 +1721,42 @@ export async function validatePreparedOutputDir(path, validateLocation, allowNon
|
|
|
1573
1721
|
if (!metadata.isDirectory()) {
|
|
1574
1722
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1575
1723
|
}
|
|
1576
|
-
const canonical = await
|
|
1724
|
+
const canonical = await checkedOutputPath(path, !allowNonempty);
|
|
1577
1725
|
requireModelSafeOutputDir(canonical);
|
|
1578
1726
|
validateLocation?.(canonical);
|
|
1579
1727
|
if (!allowNonempty && (await readdir(canonical)).length !== 0) {
|
|
1580
1728
|
throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
|
|
1581
1729
|
}
|
|
1582
1730
|
requireOutputDirectoryOwnership(metadata, path);
|
|
1583
|
-
|
|
1731
|
+
return canonical;
|
|
1732
|
+
}
|
|
1733
|
+
async function checkedOutputPath(path, writableLeaf) {
|
|
1734
|
+
if (process.platform === "win32") {
|
|
1735
|
+
// Keep the selected leaf for the no-follow check, including across an
|
|
1736
|
+
// in-place directory change between lstat and canonicalization.
|
|
1737
|
+
const directory = dirname(path);
|
|
1738
|
+
const parent = await realpath(directory);
|
|
1739
|
+
const selected = join(parent, relative(directory, path));
|
|
1740
|
+
await requireWindowsOutputPath(selected, writableLeaf);
|
|
1741
|
+
const canonical = await realpath(selected);
|
|
1742
|
+
if (canonical === selected)
|
|
1743
|
+
return selected;
|
|
1744
|
+
// Accept a canonical leaf spelling (case or short name) within the checked parent.
|
|
1745
|
+
if (dirname(canonical) === parent) {
|
|
1746
|
+
const [leaf, resolved] = await Promise.all([
|
|
1747
|
+
lstat(selected, { bigint: true }),
|
|
1748
|
+
lstat(canonical, { bigint: true }),
|
|
1749
|
+
]);
|
|
1750
|
+
if (leaf.isDirectory() && leaf.ino !== 0n && sameInode(leaf, resolved)) {
|
|
1751
|
+
return canonical;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
throw new OutputDirectoryError(`Scan output directory changed during preparation: ${path}`);
|
|
1755
|
+
}
|
|
1756
|
+
await requireSecureOutputAncestry(path);
|
|
1757
|
+
const canonical = await realpath(path);
|
|
1758
|
+
if (canonical !== path)
|
|
1759
|
+
await requireSecureOutputAncestry(canonical);
|
|
1584
1760
|
return canonical;
|
|
1585
1761
|
}
|
|
1586
1762
|
export function requirePrivateOutputDirectory(metadata, path, effectiveUid = process.geteuid?.()) {
|
|
@@ -1601,7 +1777,7 @@ export function requireOutputDirectoryOwnership(metadata, path, effectiveUid = p
|
|
|
1601
1777
|
/** Reject shared parents whose owner can rename or replace scan output. */
|
|
1602
1778
|
export async function requireSecureOutputAncestry(path, effectiveUid = process.geteuid?.()) {
|
|
1603
1779
|
if (process.platform === "win32")
|
|
1604
|
-
return;
|
|
1780
|
+
return requireWindowsOutputPath(path);
|
|
1605
1781
|
let current = dirname(resolve(path));
|
|
1606
1782
|
while (true) {
|
|
1607
1783
|
try {
|
|
@@ -1736,6 +1912,7 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1736
1912
|
const archivePath = resolve(expandHome(archive));
|
|
1737
1913
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
1738
1914
|
const staging = await realpath(await mkdtemp(join(dirname(destination), ".codex-security-plugin-")));
|
|
1915
|
+
let publishingOnWindows = false;
|
|
1739
1916
|
try {
|
|
1740
1917
|
throwIfSignalAborted(signal);
|
|
1741
1918
|
let expandedSize = 0;
|
|
@@ -1798,12 +1975,29 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1798
1975
|
const pluginRoot = await discoverPluginRoot(staging);
|
|
1799
1976
|
throwIfSignalAborted(signal);
|
|
1800
1977
|
const relativeRoot = relative(staging, pluginRoot);
|
|
1801
|
-
|
|
1978
|
+
if (process.platform === "win32") {
|
|
1979
|
+
publishingOnWindows = true;
|
|
1980
|
+
await retryWindowsRename(async () => {
|
|
1981
|
+
throwIfSignalAborted(signal);
|
|
1982
|
+
if (await lstat(destination).catch(nullIfMissingFileError))
|
|
1983
|
+
throw new Error(`Destination already exists: ${destination}`);
|
|
1984
|
+
await rename(staging, destination);
|
|
1985
|
+
}, undefined, signal);
|
|
1986
|
+
publishingOnWindows = false;
|
|
1987
|
+
}
|
|
1988
|
+
else {
|
|
1989
|
+
await rename(staging, destination);
|
|
1990
|
+
}
|
|
1802
1991
|
return await validatePluginRoot(join(destination, relativeRoot));
|
|
1803
1992
|
}
|
|
1804
1993
|
catch (error) {
|
|
1805
|
-
|
|
1994
|
+
let cleanupDiagnostic = "";
|
|
1995
|
+
await rm(staging, { recursive: true, force: true }).catch((cleanupError) => {
|
|
1996
|
+
cleanupDiagnostic = `\nCould not remove staging directory ${staging}: ${errorMessage(cleanupError)}`;
|
|
1997
|
+
});
|
|
1806
1998
|
throwIfSignalAborted(signal);
|
|
1999
|
+
if (publishingOnWindows)
|
|
2000
|
+
throw new PluginBootstrapError(`Could not publish extracted plugin ZIP: ${errorMessage(error)}${cleanupDiagnostic}`, { cause: error });
|
|
1807
2001
|
if (error instanceof PluginBootstrapError)
|
|
1808
2002
|
throw error;
|
|
1809
2003
|
throw new PluginBootstrapError(`Invalid plugin ZIP: ${archivePath}`, {
|
|
@@ -2103,9 +2297,18 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
2103
2297
|
const previous = await readFile(installRecord, "utf8")
|
|
2104
2298
|
.then((value) => JSON.parse(value))
|
|
2105
2299
|
.catch((error) => {
|
|
2106
|
-
|
|
2300
|
+
const code = nodeErrorCode(error);
|
|
2301
|
+
if (code === "ENOENT" || error instanceof SyntaxError) {
|
|
2107
2302
|
return null;
|
|
2108
2303
|
}
|
|
2304
|
+
if (process.platform === "win32" &&
|
|
2305
|
+
error instanceof Error &&
|
|
2306
|
+
(code === "EACCES" || code === "EPERM")) {
|
|
2307
|
+
// Keep the original system error, including its path, code and syscall.
|
|
2308
|
+
error.message +=
|
|
2309
|
+
" If the SDK created this plugin installation receipt but cannot reopen it, " +
|
|
2310
|
+
"check its read permissions and the permissions new files inherit from the sdk-marketplace directory.";
|
|
2311
|
+
}
|
|
2109
2312
|
throw error;
|
|
2110
2313
|
});
|
|
2111
2314
|
const plugins = configuration["plugins"];
|
|
@@ -2261,11 +2464,9 @@ export async function resolvePluginPython(options = {}) {
|
|
|
2261
2464
|
if (inherited) {
|
|
2262
2465
|
return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
|
|
2263
2466
|
}
|
|
2264
|
-
const home = options.homeDirectory ?? homedir();
|
|
2265
|
-
const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2266
|
-
join(home, ".cache");
|
|
2267
2467
|
const managedRoots = options.managedRuntimeRoots ?? [
|
|
2268
|
-
join(
|
|
2468
|
+
join(environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2469
|
+
join(options.homeDirectory ?? homedir(), ".cache"), "codex-runtimes", "codex-primary-runtime"),
|
|
2269
2470
|
];
|
|
2270
2471
|
const relativeCandidates = process.platform === "win32"
|
|
2271
2472
|
? [
|
|
@@ -2296,14 +2497,12 @@ export async function resolvePluginPython(options = {}) {
|
|
|
2296
2497
|
"Set pythonPath, --python, or PYTHON, install the Codex managed runtime, or add python3/python (py on Windows) to PATH.");
|
|
2297
2498
|
}
|
|
2298
2499
|
export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
2299
|
-
|
|
2500
|
+
return {
|
|
2300
2501
|
...pythonUtf8Environment(environment),
|
|
2301
2502
|
PYTHON: python,
|
|
2302
2503
|
CODEX_SECURITY_PYTHON_COMMAND: python,
|
|
2303
2504
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
2304
2505
|
};
|
|
2305
|
-
forwardExternalImportSetting(environment, child);
|
|
2306
|
-
return child;
|
|
2307
2506
|
}
|
|
2308
2507
|
export function environmentWithGit(environment, git) {
|
|
2309
2508
|
if (git === undefined)
|
|
@@ -2334,6 +2533,16 @@ function pluginHelperEnvironment(environment) {
|
|
|
2334
2533
|
export async function cleanupSdkDirectory(path) {
|
|
2335
2534
|
await rm(path, { recursive: true, force: true });
|
|
2336
2535
|
}
|
|
2536
|
+
// A child can finish or reject a request before the parent finishes writing it.
|
|
2537
|
+
export function isDisconnectedChildStdin(error) {
|
|
2538
|
+
return [
|
|
2539
|
+
"EPIPE",
|
|
2540
|
+
"ECONNRESET",
|
|
2541
|
+
"ENOTCONN",
|
|
2542
|
+
"EOF",
|
|
2543
|
+
"ERR_STREAM_DESTROYED",
|
|
2544
|
+
].includes(error.code ?? "");
|
|
2545
|
+
}
|
|
2337
2546
|
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2338
2547
|
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2339
2548
|
const abort = () => cancellation?.abort(signal?.reason);
|
|
@@ -2372,7 +2581,7 @@ export async function runCodexCommand(command, args, environment, input, signal,
|
|
|
2372
2581
|
processError = error;
|
|
2373
2582
|
});
|
|
2374
2583
|
child.stdin.on("error", (error) => {
|
|
2375
|
-
if (!
|
|
2584
|
+
if (!isDisconnectedChildStdin(error))
|
|
2376
2585
|
processError = error;
|
|
2377
2586
|
});
|
|
2378
2587
|
child.once("close", (exitCode) => processError === undefined
|
|
@@ -2437,6 +2646,8 @@ export async function probeCodexSandbox(command, environment, signal) {
|
|
|
2437
2646
|
}
|
|
2438
2647
|
catch (error) {
|
|
2439
2648
|
signal?.throwIfAborted();
|
|
2649
|
+
if (timeout.aborted)
|
|
2650
|
+
throw new SandboxUnavailableError(`Codex sandbox probe timed out after ${SANDBOX_PROBE_TIMEOUT_MILLISECONDS / 1000} seconds.`, { cause: error });
|
|
2440
2651
|
detail = processErrorDetail(error);
|
|
2441
2652
|
}
|
|
2442
2653
|
const guidance = process.platform === "linux"
|
|
@@ -2476,7 +2687,7 @@ async function validatePluginRoot(root) {
|
|
|
2476
2687
|
await pluginMetadata(root);
|
|
2477
2688
|
return await realpath(root);
|
|
2478
2689
|
}
|
|
2479
|
-
async function copyPluginTree(source, destination, signal) {
|
|
2690
|
+
export async function copyPluginTree(source, destination, signal) {
|
|
2480
2691
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
2481
2692
|
try {
|
|
2482
2693
|
await cp(source, destination, {
|
|
@@ -2543,21 +2754,14 @@ async function usablePython(candidate, environment = process.env, protectedRoot
|
|
|
2543
2754
|
if (command === null)
|
|
2544
2755
|
return null;
|
|
2545
2756
|
try {
|
|
2546
|
-
const { stdout } = await execFile(command.executable, [
|
|
2547
|
-
"-I",
|
|
2548
|
-
"-c",
|
|
2549
|
-
"import importlib.util,sys\nif sys.version_info < (3, 10): raise SystemExit(1)\nif sys.version_info < (3, 11) and importlib.util.find_spec('tomli') is None: raise SystemExit(1)\nprint('codex-security-python-ok')",
|
|
2550
|
-
], {
|
|
2757
|
+
const { stdout } = await execFile(command.executable, ["-I", "-c", PLUGIN_PYTHON_PROBE], {
|
|
2551
2758
|
env: command.environment,
|
|
2552
2759
|
encoding: "utf8",
|
|
2553
|
-
|
|
2554
|
-
timeout: 30_000,
|
|
2760
|
+
timeout: PLUGIN_PYTHON_PROBE_TIMEOUT_MS,
|
|
2555
2761
|
windowsHide: true,
|
|
2556
2762
|
signal,
|
|
2557
2763
|
});
|
|
2558
|
-
return stdout.trim() ===
|
|
2559
|
-
? command.executable
|
|
2560
|
-
: null;
|
|
2764
|
+
return stdout.trim() === PLUGIN_PYTHON_READY ? command.executable : null;
|
|
2561
2765
|
}
|
|
2562
2766
|
catch (error) {
|
|
2563
2767
|
if (signal?.aborted)
|
|
@@ -2577,8 +2781,7 @@ export function sameFile(left, right) {
|
|
|
2577
2781
|
return Promise.all([
|
|
2578
2782
|
stat(left, { bigint: true }),
|
|
2579
2783
|
stat(right, { bigint: true }),
|
|
2580
|
-
]).then(([leftMetadata, rightMetadata]) => leftMetadata
|
|
2581
|
-
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2784
|
+
]).then(([leftMetadata, rightMetadata]) => sameInode(leftMetadata, rightMetadata), () => false);
|
|
2582
2785
|
}
|
|
2583
2786
|
function expandExecutableHome(value, environment) {
|
|
2584
2787
|
const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
|
|
@@ -2588,17 +2791,17 @@ function expandExecutableHome(value, environment) {
|
|
|
2588
2791
|
: expandHome(path, environment);
|
|
2589
2792
|
}
|
|
2590
2793
|
export function expandHome(value, environment = process.env) {
|
|
2591
|
-
const home = (process.platform === "win32"
|
|
2794
|
+
const home = () => (process.platform === "win32"
|
|
2592
2795
|
? (environmentValue(environment, "USERPROFILE") ??
|
|
2593
2796
|
environmentValue(environment, "HOME"))
|
|
2594
2797
|
: (environmentValue(environment, "HOME") ??
|
|
2595
2798
|
environmentValue(environment, "USERPROFILE"))) ?? homedir();
|
|
2596
2799
|
if (value === "~")
|
|
2597
|
-
return home;
|
|
2800
|
+
return home();
|
|
2598
2801
|
if (value.startsWith("~/"))
|
|
2599
|
-
return join(home, value.slice(2));
|
|
2802
|
+
return join(home(), value.slice(2));
|
|
2600
2803
|
if (value.startsWith("~\\")) {
|
|
2601
|
-
return join(home, ...value.slice(2).split("\\"));
|
|
2804
|
+
return join(home(), ...value.slice(2).split("\\"));
|
|
2602
2805
|
}
|
|
2603
2806
|
return value;
|
|
2604
2807
|
}
|