@openai/codex-security 0.8.2 → 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 +201 -178
- package/_bundled_plugin/.app.json +4 -0
- package/_bundled_plugin/.mcp.json +6 -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 +51 -14
- package/_bundled_plugin/mcp/server.mjs +2 -11
- package/_bundled_plugin/mcp/server.mjs.br +0 -0
- package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
- package/_bundled_plugin/references/artifact-storage.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -5
- package/_bundled_plugin/references/default-severity-rubric.md +33 -0
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/finding-detail-fields.md +19 -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/references/threat-model.md +1 -0
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
- package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
- package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +188 -454
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +317 -377
- package/_bundled_plugin/scripts/finding_preview.py +25 -29
- 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 +198 -0
- package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
- package/_bundled_plugin/scripts/report_projection.py +167 -178
- 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 +9 -7
- package/_bundled_plugin/scripts/windows_scan_local_files.py +600 -72
- 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 +38 -75
- 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 +152 -248
- 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 +121 -14
- package/_bundled_plugin/scripts/workbench_constants.py +19 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
- package/_bundled_plugin/scripts/workbench_db.py +550 -492
- 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 +90 -4
- package/_bundled_plugin/scripts/workbench_native_indexes.py +29 -33
- 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 +508 -11
- package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
- package/_bundled_plugin/scripts/workbench_scan_history.py +139 -80
- package/_bundled_plugin/scripts/workbench_scan_start.py +84 -25
- package/_bundled_plugin/scripts/workbench_scan_usage.py +666 -117
- package/_bundled_plugin/scripts/workbench_schema.py +44 -55
- package/_bundled_plugin/scripts/workbench_setup.py +251 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
- package/_bundled_plugin/scripts/workbench_source_scopes.py +33 -23
- package/_bundled_plugin/scripts/workbench_target.py +330 -66
- package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
- package/_bundled_plugin/scripts/workbench_validation.py +44 -12
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -16
- package/_bundled_plugin/shared/workbench-migrations.json +53 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
- package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
- package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +6 -4
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
- package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -2
- package/_bundled_plugin/skills/publish-findings/SKILL.md +81 -45
- package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +5 -24
- package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +36 -9
- package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +12 -6
- package/dist/api.d.ts +45 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1144 -411
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +10 -7
- 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 +8 -0
- package/dist/blackduck-findings.d.ts.map +1 -0
- package/dist/blackduck-findings.js +320 -0
- package/dist/blackduck-findings.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +51 -36
- 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 +6 -9
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +9 -21
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +4 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +30 -13
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli.d.ts +14 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2112 -1266
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +2 -2
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts +2 -0
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +6 -0
- package/dist/codex-prompt.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 +32 -6
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +221 -65
- package/dist/config.js.map +1 -1
- package/dist/continuum-findings.d.ts +7 -0
- package/dist/continuum-findings.d.ts.map +1 -0
- package/dist/continuum-findings.js +225 -0
- package/dist/continuum-findings.js.map +1 -0
- package/dist/contract-values.d.ts +30 -0
- package/dist/contract-values.d.ts.map +1 -0
- package/dist/contract-values.js +78 -0
- package/dist/contract-values.js.map +1 -0
- package/dist/contract.d.ts +2 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +58 -669
- package/dist/contract.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 -115
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +61 -4
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +2560 -100
- package/dist/cost.js.map +1 -1
- package/dist/custom-publish.d.ts +4 -0
- package/dist/custom-publish.d.ts.map +1 -1
- package/dist/custom-publish.js +40 -3
- package/dist/custom-publish.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +5 -0
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +2 -0
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +4 -0
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +4 -4
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +11 -4
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/finding-schema.d.ts +19 -1
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +25 -0
- package/dist/deduplication/finding-schema.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 +5 -10
- package/dist/deduplication/local.js.map +1 -1
- package/dist/deduplication/records.d.ts +8 -2
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +36 -8
- package/dist/deduplication/records.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 +13 -0
- package/dist/deep-scan.d.ts.map +1 -1
- package/dist/deep-scan.js +262 -7
- package/dist/deep-scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +1 -2
- package/dist/default-severity-rubric.d.ts.map +1 -1
- package/dist/default-severity-rubric.js +2 -66
- 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 +108 -80
- 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 +9 -2
- 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 +11 -16
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +15 -4
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +619 -225
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +20 -6
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +2356 -308
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +28 -2
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +174 -81
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +17 -3
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +153 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +33 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +335 -51
- 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/finding-retrieval.d.ts +3 -3
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +6 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +2 -2
- package/dist/finding-workflow.js.map +1 -1
- 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/git-remote.d.ts +4 -0
- package/dist/git-remote.d.ts.map +1 -1
- package/dist/git-remote.js +20 -0
- package/dist/git-remote.js.map +1 -1
- package/dist/github-advisories.d.ts +3 -12
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +9 -31
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts.map +1 -1
- package/dist/github-dependabot-findings.js +22 -20
- 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 +392 -79
- package/dist/github-findings.js.map +1 -1
- package/dist/github.d.ts +17 -7
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +43 -30
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +2 -2
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js.map +1 -1
- package/dist/host-records-protocol.d.ts +10 -11
- package/dist/host-records-protocol.d.ts.map +1 -1
- package/dist/host-records-protocol.js +69 -9
- package/dist/host-records-protocol.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 +15 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +71 -44
- 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 +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts.map +1 -1
- package/dist/inspector-findings.js +58 -81
- package/dist/inspector-findings.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +86 -10
- package/dist/knowledge-base.js.map +1 -1
- package/dist/local-git-metadata.d.ts +5 -0
- package/dist/local-git-metadata.d.ts.map +1 -0
- package/dist/local-git-metadata.js +130 -0
- package/dist/local-git-metadata.js.map +1 -0
- package/dist/multiscan.d.ts +6 -4
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +160 -77
- 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 +49 -31
- 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/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +90 -35
- package/dist/patch-tui.js.map +1 -1
- 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 +341 -0
- package/dist/private-finding-import.d.ts.map +1 -0
- package/dist/private-finding-import.js +411 -0
- package/dist/private-finding-import.js.map +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -2
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +11 -3
- package/dist/provider-profile.d.ts.map +1 -1
- package/dist/provider-profile.js +80 -11
- package/dist/provider-profile.js.map +1 -1
- package/dist/publication-telemetry.d.ts +45 -0
- package/dist/publication-telemetry.d.ts.map +1 -0
- package/dist/publication-telemetry.js +50 -0
- package/dist/publication-telemetry.js.map +1 -0
- package/dist/publication.js +7 -1
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +4 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +42 -2
- package/dist/publish.js.map +1 -1
- package/dist/reader-selection.d.ts +15 -0
- package/dist/reader-selection.d.ts.map +1 -0
- package/dist/reader-selection.js +89 -0
- package/dist/reader-selection.js.map +1 -0
- package/dist/record.d.ts +6 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +53 -2
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +3 -1
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +28 -2
- 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 +6 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -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 +22 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +408 -162
- 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 +172 -64
- 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 +68 -25
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +7 -6
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +91 -79
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +12 -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 +31 -28
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +12 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +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 +64 -6
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +406 -48
- package/dist/scanner-import.js.map +1 -1
- package/dist/scanner-repository-url.d.ts +17 -0
- package/dist/scanner-repository-url.d.ts.map +1 -0
- package/dist/scanner-repository-url.js +71 -0
- package/dist/scanner-repository-url.js.map +1 -0
- 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 +124 -88
- 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 +213 -0
- package/dist/semgrep-platform-findings.d.ts.map +1 -0
- package/dist/semgrep-platform-findings.js +1078 -0
- package/dist/semgrep-platform-findings.js.map +1 -0
- 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/severity-rubric.d.ts +20 -0
- package/dist/severity-rubric.d.ts.map +1 -0
- package/dist/severity-rubric.js +73 -0
- package/dist/severity-rubric.js.map +1 -0
- package/dist/severity-store.js +15 -5
- package/dist/severity-store.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 +108 -84
- 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 +16 -0
- package/dist/sonar-collector.d.ts.map +1 -0
- package/dist/sonar-collector.js +380 -0
- package/dist/sonar-collector.js.map +1 -0
- package/dist/sonar-findings.d.ts +49 -0
- package/dist/sonar-findings.d.ts.map +1 -0
- package/dist/sonar-findings.js +288 -0
- package/dist/sonar-findings.js.map +1 -0
- package/dist/sonar-import.d.ts +111 -0
- package/dist/sonar-import.d.ts.map +1 -0
- package/dist/sonar-import.js +277 -0
- package/dist/sonar-import.js.map +1 -0
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +2 -1
- package/dist/suggest-owners.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 +5 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +73 -31
- 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-columns.d.ts +4 -0
- package/dist/terminal-columns.d.ts.map +1 -0
- package/dist/terminal-columns.js +19 -0
- package/dist/terminal-columns.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.d.ts +0 -3
- package/dist/validation-records.d.ts.map +1 -1
- package/dist/validation-records.js +1 -17
- package/dist/validation-records.js.map +1 -1
- package/dist/veracode-findings.d.ts +9 -0
- package/dist/veracode-findings.d.ts.map +1 -0
- package/dist/veracode-findings.js +409 -0
- package/dist/veracode-findings.js.map +1 -0
- 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 +27 -1
- package/dist/windows-path.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -2
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +1 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +14 -2
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +143 -50
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +28 -13
- package/docs/cli.md +623 -843
- package/docs/dedupe-records.md +54 -24
- package/docs/findings-service.md +87 -47
- package/docs/hosted-remediation.md +14 -7
- package/docs/hosted-scans.md +64 -41
- package/docs/telemetry.md +236 -0
- package/docs/validate-records.md +78 -44
- package/package.json +19 -17
- package/schemas/external-findings.schema.json +14 -1
- package/schemas/hosted-scan-v2.fixture.json +16 -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/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
- package/dist/deduplication/records-protocol.d.ts +0 -4
- package/dist/deduplication/records-protocol.d.ts.map +0 -1
- package/dist/deduplication/records-protocol.js +0 -49
- package/dist/deduplication/records-protocol.js.map +0 -1
- 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 -120
- 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
|
|
@@ -139,7 +141,11 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
|
|
|
139
141
|
catch (error) {
|
|
140
142
|
if (error instanceof OutputDirectoryError)
|
|
141
143
|
throw error;
|
|
142
|
-
|
|
144
|
+
const code = nodeErrorCode(error);
|
|
145
|
+
const recovery = code === "EACCES" || code === "EPERM" || code === "EROFS"
|
|
146
|
+
? "\nCheck permissions or set CODEX_SECURITY_STATE_DIR to a private, writable directory outside the repository."
|
|
147
|
+
: "";
|
|
148
|
+
throw new OutputDirectoryError(`Unable to prepare the Codex Security credential home: ${path}\n${errorMessage(error)}${recovery}`, { cause: error });
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
151
|
/**
|
|
@@ -203,7 +209,7 @@ export async function preparePolicyOutputDirectory(path, options = {}) {
|
|
|
203
209
|
}
|
|
204
210
|
await requirePrivateDirectory(metadata, path, "policy output directory", options);
|
|
205
211
|
}
|
|
206
|
-
async function requirePrivateDirectory(metadata, path, description, options) {
|
|
212
|
+
export async function requirePrivateDirectory(metadata, path, description, options = {}) {
|
|
207
213
|
if ((options.platform ?? process.platform) !== "win32") {
|
|
208
214
|
requirePrivateOutputDirectory(metadata, path);
|
|
209
215
|
return;
|
|
@@ -277,6 +283,7 @@ const WINDOWS_PRINCIPAL_ALIASES = {
|
|
|
277
283
|
HA: "S-1-5-32-578",
|
|
278
284
|
AA: "S-1-5-32-579",
|
|
279
285
|
};
|
|
286
|
+
const WINDOWS_ACCOUNT_SID = /^S-1-5-21-(?:\d+-){3}\d+$/u;
|
|
280
287
|
const WINDOWS_SID = /^S-1-(?:\d+-)*\d+$/u;
|
|
281
288
|
const WINDOWS_GUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
|
|
282
289
|
const WINDOWS_SDDL_SID = "(?:S-1-(?:\\d+-)*\\d+|[A-Z]{2})";
|
|
@@ -363,7 +370,10 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
|
|
|
363
370
|
if (type === "A" || type === "OA" || type === "XA" || type === "ZA") {
|
|
364
371
|
if (!trustedPrincipal(principal)) {
|
|
365
372
|
if (options.scope !== "ancestor" ||
|
|
366
|
-
|
|
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))) {
|
|
367
377
|
untrustedPrincipals.add(principal);
|
|
368
378
|
}
|
|
369
379
|
}
|
|
@@ -383,7 +393,9 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
|
|
|
383
393
|
}
|
|
384
394
|
}
|
|
385
395
|
}
|
|
386
|
-
else
|
|
396
|
+
else if (principal === currentUserSid ||
|
|
397
|
+
!WINDOWS_ACCOUNT_SID.test(principal) ||
|
|
398
|
+
(options.currentGroupSids?.has(principal) ?? true)) {
|
|
387
399
|
deniedPrincipals.add(principal);
|
|
388
400
|
}
|
|
389
401
|
remaining = rest;
|
|
@@ -525,13 +537,36 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
525
537
|
throw new WindowsCredentialDescendantsChangedError("Windows credential descendants changed during ACL inspection");
|
|
526
538
|
}
|
|
527
539
|
}
|
|
540
|
+
// win32.parse stops at the UNC marker for extended-length share paths.
|
|
541
|
+
const WINDOWS_CREDENTIAL_UNC_ROOT = /^[\\/]{2}[?.][\\/]UNC[\\/][^\\/]+[\\/][^\\/]+[\\/]?/iu;
|
|
542
|
+
function windowsCredentialRootLength(path) {
|
|
543
|
+
const root = WINDOWS_CREDENTIAL_UNC_ROOT.exec(path)?.[0] ?? win32.parse(path).root;
|
|
544
|
+
if (win32.isAbsolute(path) && win32.relative(root, path) === "") {
|
|
545
|
+
throw new Error("A private Windows directory must be below a volume or share root");
|
|
546
|
+
}
|
|
547
|
+
return root.length;
|
|
548
|
+
}
|
|
549
|
+
export function windowsCredentialAncestorAclScript(path) {
|
|
550
|
+
const rootLength = windowsCredentialRootLength(path);
|
|
551
|
+
return [
|
|
552
|
+
"$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
553
|
+
// Stop at the drive or UNC share root, then inspect the outermost ancestor first.
|
|
554
|
+
`$ancestors = @(while ($path.Length -gt ${rootLength}) { $parent = Microsoft.PowerShell.Management\\Split-Path -Path $path -Parent; if (-not $parent -or $parent -eq $path) { break }; $parent; $path = $parent })`,
|
|
555
|
+
"for ($i = $ancestors.Count - 1; $i -ge 0; $i--) { Write-CredentialAcl $ancestors[$i] }",
|
|
556
|
+
].join("\n");
|
|
557
|
+
}
|
|
528
558
|
export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
|
|
559
|
+
const rootLength = windowsCredentialRootLength(path);
|
|
529
560
|
const ancestors = [];
|
|
530
|
-
|
|
561
|
+
let ancestor = win32.dirname(path);
|
|
562
|
+
while (true) {
|
|
531
563
|
ancestors.push(ancestor);
|
|
532
|
-
|
|
564
|
+
const parent = win32.dirname(ancestor);
|
|
565
|
+
if (ancestor.length <= rootLength || ancestor === parent)
|
|
533
566
|
break;
|
|
567
|
+
ancestor = parent;
|
|
534
568
|
}
|
|
569
|
+
ancestors.reverse();
|
|
535
570
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
536
571
|
let home;
|
|
537
572
|
let descendantsArePrivate = true;
|
|
@@ -557,6 +592,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
557
592
|
const ancestorPath = ancestors[index];
|
|
558
593
|
try {
|
|
559
594
|
const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
595
|
+
currentGroupSids: options.currentGroupSids,
|
|
560
596
|
resolvedAliases: options.resolvedAliases,
|
|
561
597
|
scope: "ancestor",
|
|
562
598
|
});
|
|
@@ -565,9 +601,12 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
565
601
|
}
|
|
566
602
|
}
|
|
567
603
|
catch (error) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
604
|
+
let guidance = "Choose a location outside this ancestor with trusted ownership and permissions.";
|
|
605
|
+
if (index === 0) {
|
|
606
|
+
guidance = WINDOWS_CREDENTIAL_UNC_ROOT.test(win32.toNamespacedPath(ancestorPath))
|
|
607
|
+
? "This share root is unsupported. Choose a location outside this share with trusted ownership and permissions."
|
|
608
|
+
: "This volume root is unsupported. Choose a location on a volume with trusted ancestry; another directory on the same volume will not resolve this.";
|
|
609
|
+
}
|
|
571
610
|
throw new Error(`Windows private-directory ancestor could not be trusted: ${ancestorPath}. ${errorMessage(error)}. ${guidance}`, { cause: error });
|
|
572
611
|
}
|
|
573
612
|
return;
|
|
@@ -575,6 +614,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
575
614
|
if (index === ancestors.length) {
|
|
576
615
|
try {
|
|
577
616
|
home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
617
|
+
currentGroupSids: options.currentGroupSids,
|
|
578
618
|
resolvedAliases: options.resolvedAliases,
|
|
579
619
|
});
|
|
580
620
|
}
|
|
@@ -587,6 +627,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
587
627
|
return;
|
|
588
628
|
}
|
|
589
629
|
const descendant = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
630
|
+
currentGroupSids: options.currentGroupSids,
|
|
590
631
|
resolvedAliases: options.resolvedAliases,
|
|
591
632
|
scope: "file",
|
|
592
633
|
});
|
|
@@ -614,16 +655,45 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
614
655
|
}
|
|
615
656
|
throw new Error("Windows credential descendants could not be verified");
|
|
616
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
|
+
}
|
|
617
677
|
async function secureWindowsCredentialHome(path) {
|
|
678
|
+
const ancestorAclScript = windowsCredentialAncestorAclScript(path);
|
|
679
|
+
const treePath = win32.toNamespacedPath(path);
|
|
618
680
|
const systemRoot = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
619
681
|
const systemDirectory = join(systemRoot, "System32");
|
|
620
|
-
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
|
+
];
|
|
621
690
|
const inheritedEnvironment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "PSMODULEPATH"));
|
|
622
691
|
const processOptions = {
|
|
623
692
|
env: {
|
|
624
693
|
...inheritedEnvironment,
|
|
625
694
|
CODEX_SECURITY_CREDENTIAL_ACL_PATH: path,
|
|
626
|
-
|
|
695
|
+
CODEX_SECURITY_CREDENTIAL_TREE_PATH: treePath,
|
|
696
|
+
PSModulePath: join(powershellDirectory, "Modules"),
|
|
627
697
|
},
|
|
628
698
|
encoding: "utf8",
|
|
629
699
|
windowsHide: true,
|
|
@@ -641,31 +711,47 @@ async function secureWindowsCredentialHome(path) {
|
|
|
641
711
|
const script = [
|
|
642
712
|
"$ErrorActionPreference = 'Stop'",
|
|
643
713
|
"$script:descriptorCount = 0",
|
|
644
|
-
"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
|
+
"}",
|
|
645
719
|
"function Read-CredentialDescendants($path) {",
|
|
646
720
|
" try { $entries = @(Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $path -Force) } catch {",
|
|
647
721
|
// A child can disappear while an existing directory is being enumerated.
|
|
648
722
|
// Retry that incomplete listing before accepting a vanished descendant.
|
|
649
723
|
` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetChildItemCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
|
|
650
|
-
" if ($path -ne $env:
|
|
724
|
+
" if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
|
|
651
725
|
" throw",
|
|
652
726
|
" }",
|
|
653
|
-
" foreach ($entry in $entries) {",
|
|
727
|
+
" $children = @(foreach ($entry in $entries) {",
|
|
654
728
|
" if (($entry.Attributes -band 1024) -and ($entry.LinkType -in @('SymbolicLink', 'Junction'))) { throw 'Windows credential home contains a symbolic link or junction' }",
|
|
655
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' }",
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
"
|
|
660
|
-
"
|
|
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
|
+
" }",
|
|
661
742
|
" }",
|
|
662
|
-
"
|
|
743
|
+
" }",
|
|
744
|
+
" for ($i = 0; $i -lt $children.Count; $i++) {",
|
|
745
|
+
" if ($children[$i] -and $entries[$i].PSIsContainer) { Read-CredentialDescendants $children[$i] }",
|
|
663
746
|
" }",
|
|
664
747
|
"}",
|
|
665
|
-
|
|
666
|
-
"while ($true) { $parent = Microsoft.PowerShell.Management\\Split-Path -Path $path -Parent; if (-not $parent -or $parent -eq $path) { break }; Write-CredentialAcl $parent; $path = $parent }",
|
|
748
|
+
ancestorAclScript,
|
|
667
749
|
"Write-CredentialAcl $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
668
|
-
"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
|
+
"}",
|
|
669
755
|
`"${WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX}$script:descriptorCount"`,
|
|
670
756
|
].join("\n");
|
|
671
757
|
const resolvePrincipalScript = [
|
|
@@ -674,31 +760,40 @@ async function secureWindowsCredentialHome(path) {
|
|
|
674
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",
|
|
675
761
|
].join("; ");
|
|
676
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
|
+
}
|
|
677
768
|
const resolvePrincipal = async (principal) => {
|
|
678
769
|
if (!/^[A-Z]{2}$/u.test(principal) ||
|
|
679
770
|
WINDOWS_PRINCIPAL_ALIASES[principal] !== undefined ||
|
|
680
771
|
resolvedAliases[principal] !== undefined) {
|
|
681
772
|
return;
|
|
682
773
|
}
|
|
683
|
-
const resolved = await execFile(powershell, [
|
|
684
|
-
"-NoLogo",
|
|
685
|
-
"-NoProfile",
|
|
686
|
-
"-NonInteractive",
|
|
687
|
-
"-Command",
|
|
688
|
-
resolvePrincipalScript,
|
|
689
|
-
], {
|
|
774
|
+
const resolved = await execFile(powershell, [...powershellArgs, resolvePrincipalScript], {
|
|
690
775
|
...processOptions,
|
|
691
776
|
env: {
|
|
692
777
|
...processOptions.env,
|
|
693
778
|
CODEX_SECURITY_CREDENTIAL_PRINCIPAL: principal,
|
|
694
779
|
},
|
|
695
780
|
});
|
|
696
|
-
|
|
697
|
-
if (!WINDOWS_SID.test(numeric)) {
|
|
698
|
-
throw new Error("Windows credential ACL contains an unresolvable identity");
|
|
699
|
-
}
|
|
700
|
-
resolvedAliases[principal] = numeric;
|
|
781
|
+
resolvedAliases[principal] = requireNumericSid(resolved.stdout.trim());
|
|
701
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;
|
|
702
797
|
const resolveDescriptorAliases = async (descriptor) => {
|
|
703
798
|
const header = WINDOWS_SECURITY_DESCRIPTOR.exec(descriptor.trim());
|
|
704
799
|
if (header === null)
|
|
@@ -707,9 +802,18 @@ async function secureWindowsCredentialHome(path) {
|
|
|
707
802
|
let remaining = header[3];
|
|
708
803
|
while (remaining.startsWith("(")) {
|
|
709
804
|
const { rule, rest } = windowsSecurityDescriptorRule(remaining);
|
|
710
|
-
const
|
|
711
|
-
|
|
805
|
+
const fields = rule.split(";");
|
|
806
|
+
const principal = fields[5];
|
|
807
|
+
if (principal !== undefined) {
|
|
712
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
|
+
}
|
|
713
817
|
remaining = rest;
|
|
714
818
|
}
|
|
715
819
|
};
|
|
@@ -717,25 +821,19 @@ async function secureWindowsCredentialHome(path) {
|
|
|
717
821
|
const readAcl = async () => {
|
|
718
822
|
const snapshot = await inspectWindowsCredentialAclSnapshot(path, sid, {
|
|
719
823
|
command: powershell,
|
|
720
|
-
args: [
|
|
824
|
+
args: [...powershellArgs, script],
|
|
721
825
|
environment: processOptions.env,
|
|
826
|
+
get currentGroupSids() {
|
|
827
|
+
return currentGroupSids ?? undefined;
|
|
828
|
+
},
|
|
722
829
|
resolvedAliases,
|
|
723
830
|
resolveDescriptorAliases,
|
|
724
831
|
});
|
|
725
832
|
descendantsArePrivate = snapshot.descendantsArePrivate;
|
|
726
833
|
return snapshot.home;
|
|
727
834
|
};
|
|
728
|
-
const icacls = join(systemDirectory, "icacls.exe");
|
|
729
|
-
const installTrustedAcl =
|
|
730
|
-
await execFile(icacls, [
|
|
731
|
-
target,
|
|
732
|
-
"/inheritance:r",
|
|
733
|
-
"/grant:r",
|
|
734
|
-
`*${sid}:(OI)(CI)F`,
|
|
735
|
-
`*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`,
|
|
736
|
-
`*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`,
|
|
737
|
-
], processOptions);
|
|
738
|
-
};
|
|
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`);
|
|
739
837
|
let existing;
|
|
740
838
|
for (let attempt = 0; existing === undefined && attempt < 3; attempt += 1) {
|
|
741
839
|
try {
|
|
@@ -743,7 +841,7 @@ async function secureWindowsCredentialHome(path) {
|
|
|
743
841
|
}
|
|
744
842
|
catch (error) {
|
|
745
843
|
if (error instanceof RepairableWindowsCredentialOwnerError) {
|
|
746
|
-
await
|
|
844
|
+
await icacls(path, "/setowner", `*${sid}`);
|
|
747
845
|
}
|
|
748
846
|
else if (error instanceof RepairableWindowsCredentialAclError) {
|
|
749
847
|
await installTrustedAcl();
|
|
@@ -759,7 +857,7 @@ async function secureWindowsCredentialHome(path) {
|
|
|
759
857
|
if (existing.grantsCurrentUserAccess &&
|
|
760
858
|
existing.untrustedPrincipals.length === 0 &&
|
|
761
859
|
!existing.protected) {
|
|
762
|
-
await
|
|
860
|
+
await icacls(path, "/inheritance:d");
|
|
763
861
|
existing = await readAcl();
|
|
764
862
|
}
|
|
765
863
|
let verified = existing;
|
|
@@ -768,17 +866,12 @@ async function secureWindowsCredentialHome(path) {
|
|
|
768
866
|
verified.untrustedPrincipals.length !== 0) {
|
|
769
867
|
await installTrustedAcl();
|
|
770
868
|
verified = await readAcl();
|
|
771
|
-
for (const
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
for (const principal of verified.deniedPrincipals) {
|
|
778
|
-
if (!WINDOWS_SID.test(principal)) {
|
|
779
|
-
throw new Error("Windows credential ACL contains an unresolvable identity");
|
|
780
|
-
}
|
|
781
|
-
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)}`);
|
|
782
875
|
}
|
|
783
876
|
if (verified.untrustedPrincipals.length !== 0 ||
|
|
784
877
|
verified.deniedPrincipals.length !== 0) {
|
|
@@ -795,13 +888,32 @@ async function secureWindowsCredentialHome(path) {
|
|
|
795
888
|
throw new Error("Windows credential ACL grants access to another identity");
|
|
796
889
|
}
|
|
797
890
|
if (!descendantsArePrivate) {
|
|
798
|
-
await
|
|
891
|
+
await icacls(join(treePath, "*"), "/reset", "/t", "/q");
|
|
799
892
|
await readAcl();
|
|
800
893
|
if (!descendantsArePrivate) {
|
|
801
894
|
throw new Error("Windows credential descendants remain accessible");
|
|
802
895
|
}
|
|
803
896
|
}
|
|
804
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
|
+
}
|
|
805
917
|
export async function withCredentialHomeLock(codexHome, operation, signal) {
|
|
806
918
|
const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
|
|
807
919
|
try {
|
|
@@ -824,17 +936,11 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
824
936
|
if (existingDatabaseMetadata !== null) {
|
|
825
937
|
requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
|
|
826
938
|
}
|
|
827
|
-
const
|
|
828
|
-
// Both supported runtimes bundle SQLite. Keep the transaction in the process
|
|
829
|
-
// doing the protected work, so pausing it cannot expire its lock.
|
|
830
|
-
const Database = process.versions["bun"]
|
|
831
|
-
? require("bun:sqlite")
|
|
832
|
-
.Database
|
|
833
|
-
: require("node:sqlite").DatabaseSync;
|
|
939
|
+
const openDatabase = sqliteDatabaseOpener();
|
|
834
940
|
// Let SQLite create a missing guard so no separate descriptor can close after
|
|
835
941
|
// another connection acquires its process-owned POSIX lock. Keep the guard
|
|
836
942
|
// across releases so every contender locks the same inode.
|
|
837
|
-
const database =
|
|
943
|
+
const database = openDatabase(databasePath);
|
|
838
944
|
let databaseLocked = false;
|
|
839
945
|
try {
|
|
840
946
|
// SQLite creates new databases with the process umask. Tighten or repair
|
|
@@ -1005,6 +1111,51 @@ async function recoverStaleCredentialHomeLock(lock) {
|
|
|
1005
1111
|
await rm(quarantine, { recursive: true, force: true });
|
|
1006
1112
|
return true;
|
|
1007
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
|
+
}
|
|
1008
1159
|
export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
|
|
1009
1160
|
await requireSecureCredentialHome(codexHome);
|
|
1010
1161
|
const marker = join(codexHome, CREDENTIAL_LOGOUT_MARKER);
|
|
@@ -1112,7 +1263,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
|
|
|
1112
1263
|
}
|
|
1113
1264
|
export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
|
|
1114
1265
|
if (isWithin(repository, outputDirectory) ||
|
|
1115
|
-
(pathKind === "output"
|
|
1266
|
+
((pathKind === "output" || pathKind === "state") &&
|
|
1267
|
+
isWithin(outputDirectory, repository))) {
|
|
1116
1268
|
throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
|
|
1117
1269
|
}
|
|
1118
1270
|
}
|
|
@@ -1160,20 +1312,24 @@ workbench["main"](before_archive=before_archive)
|
|
|
1160
1312
|
export async function runWorkbench(options, args, input) {
|
|
1161
1313
|
const script = join(options.pluginRoot, "scripts", "workbench_db.py");
|
|
1162
1314
|
const signal = options.signal;
|
|
1315
|
+
// Explicitly selected external plugins retain their own workbench protocol.
|
|
1316
|
+
const nativeLocalDedupe = args[0] === "local-dedupe" &&
|
|
1317
|
+
(await sameFile(options.pluginRoot, await bundledPluginRoot()));
|
|
1163
1318
|
const run = async (arguments_, input, archiveHandshake = false) => {
|
|
1164
|
-
const native =
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1319
|
+
const native = nativeLocalDedupe ||
|
|
1320
|
+
[
|
|
1321
|
+
"database-info",
|
|
1322
|
+
"store-findings",
|
|
1323
|
+
"list-stored-findings",
|
|
1324
|
+
"store-external-findings",
|
|
1325
|
+
"list-external-findings",
|
|
1326
|
+
"find-potential-duplicates",
|
|
1327
|
+
"store-dedupe-groups",
|
|
1328
|
+
"list-dedupe-groups",
|
|
1329
|
+
"dashboard",
|
|
1330
|
+
"severity-classification",
|
|
1331
|
+
"read-severity-classification",
|
|
1332
|
+
].includes(arguments_[0] ?? "");
|
|
1177
1333
|
const node = native && process.versions["bun"]
|
|
1178
1334
|
? await resolveTrustedExecutable("node", options.environment, [
|
|
1179
1335
|
process.cwd(),
|
|
@@ -1198,12 +1354,9 @@ export async function runWorkbench(options, args, input) {
|
|
|
1198
1354
|
? (options.stateDirectory ??
|
|
1199
1355
|
codexSecurityStateDirectory(options.environment))
|
|
1200
1356
|
: undefined;
|
|
1201
|
-
//
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
if (framedArguments)
|
|
1205
|
-
program =
|
|
1206
|
-
WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
|
|
1357
|
+
// Validate one JSON document before framing its unchanged source as payload.
|
|
1358
|
+
if (nativeLocalDedupe && input !== undefined)
|
|
1359
|
+
JSON.parse(input);
|
|
1207
1360
|
const result = await runCodexCommand({ command }, native
|
|
1208
1361
|
? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
|
|
1209
1362
|
: [
|
|
@@ -1211,23 +1364,38 @@ export async function runWorkbench(options, args, input) {
|
|
|
1211
1364
|
"-X",
|
|
1212
1365
|
"utf8",
|
|
1213
1366
|
"-B",
|
|
1214
|
-
|
|
1367
|
+
"-c",
|
|
1368
|
+
WORKBENCH_ARGUMENTS_PROGRAM +
|
|
1369
|
+
(archiveHandshake
|
|
1370
|
+
? ARCHIVE_REGISTRATION_PROGRAM
|
|
1371
|
+
: WORKBENCH_SCRIPT_PROGRAM),
|
|
1215
1372
|
script,
|
|
1216
|
-
|
|
1217
|
-
|
|
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
|
+
}),
|
|
1218
1384
|
// The SDK owns configuration normalization; the helper receives its resolved location.
|
|
1385
|
+
nativeLocalDedupe
|
|
1386
|
+
? `{"stateDirectory":${JSON.stringify(stateDirectory)},"payload":${input ?? "null"}}`
|
|
1387
|
+
: native
|
|
1388
|
+
? JSON.stringify(arguments_[0] === "database-info"
|
|
1389
|
+
? stateDirectory
|
|
1390
|
+
: {
|
|
1391
|
+
stateDirectory,
|
|
1392
|
+
payload: input === undefined ? undefined : JSON.parse(input),
|
|
1393
|
+
})
|
|
1394
|
+
: input, signal, archiveHandshake,
|
|
1395
|
+
// Frame Python arguments on stdin to preserve NUL and long diagnostics.
|
|
1219
1396
|
native
|
|
1220
|
-
?
|
|
1221
|
-
|
|
1222
|
-
: {
|
|
1223
|
-
stateDirectory,
|
|
1224
|
-
payload: input === undefined ? undefined : JSON.parse(input),
|
|
1225
|
-
})
|
|
1226
|
-
: input, signal, archiveHandshake,
|
|
1227
|
-
// Match native argv's UTF-8 encoding for the private argument frame.
|
|
1228
|
-
framedArguments
|
|
1229
|
-
? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
|
|
1230
|
-
: undefined);
|
|
1397
|
+
? undefined
|
|
1398
|
+
: `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`);
|
|
1231
1399
|
if (!result.success) {
|
|
1232
1400
|
throw new Error(result.stderr.trim() ||
|
|
1233
1401
|
result.stdout.trim() ||
|
|
@@ -1293,8 +1461,9 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1293
1461
|
throw new OutputDirectoryNotEmptyError(path);
|
|
1294
1462
|
}
|
|
1295
1463
|
requireOutputDirectoryOwnership(metadata, path);
|
|
1296
|
-
|
|
1297
|
-
|
|
1464
|
+
const writableLeaf = !archiveExisting ||
|
|
1465
|
+
(process.platform === "win32" && (await readdir(path)).length === 0);
|
|
1466
|
+
const canonical = await checkedOutputPath(path, writableLeaf);
|
|
1298
1467
|
requireModelSafeOutputDir(canonical);
|
|
1299
1468
|
return canonical;
|
|
1300
1469
|
}
|
|
@@ -1450,13 +1619,12 @@ export async function prepareScanRegistrationOutput(outputDirectory, repositoryN
|
|
|
1450
1619
|
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
|
|
1451
1620
|
}
|
|
1452
1621
|
async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
|
|
1453
|
-
if (outputDirectory === undefined) {
|
|
1454
|
-
requireModelSafeOutputDir(temporaryRoot);
|
|
1455
|
-
requireModelSafeOutputDir(await realpath(temporaryRoot));
|
|
1456
|
-
}
|
|
1457
1622
|
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1458
|
-
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1459
1623
|
if (path === null) {
|
|
1624
|
+
requireModelSafeOutputDir(temporaryRoot);
|
|
1625
|
+
const canonicalRoot = await realpath(temporaryRoot);
|
|
1626
|
+
requireModelSafeOutputDir(canonicalRoot);
|
|
1627
|
+
validateLocation?.(canonicalRoot);
|
|
1460
1628
|
const prefix = `codex-security-${safePrefix(repositoryName)}`;
|
|
1461
1629
|
let created;
|
|
1462
1630
|
if (process.platform === "win32") {
|
|
@@ -1464,11 +1632,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1464
1632
|
// Reserve room within NTFS's 255-unit component limit for later archival.
|
|
1465
1633
|
// The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
|
|
1466
1634
|
const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
|
|
1467
|
-
created = join(
|
|
1635
|
+
created = join(canonicalRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
|
|
1468
1636
|
await createWindowsOutputDirectory(created, false);
|
|
1469
1637
|
}
|
|
1470
1638
|
else {
|
|
1471
|
-
created = await mkdtemp(join(
|
|
1639
|
+
created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
|
|
1472
1640
|
}
|
|
1473
1641
|
try {
|
|
1474
1642
|
if ((process.umask() & 0o700) !== 0)
|
|
@@ -1480,6 +1648,7 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1480
1648
|
throw error;
|
|
1481
1649
|
}
|
|
1482
1650
|
}
|
|
1651
|
+
validateLocation?.(path);
|
|
1483
1652
|
let createdRoot;
|
|
1484
1653
|
try {
|
|
1485
1654
|
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
@@ -1499,7 +1668,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1499
1668
|
if ((process.umask() & 0o700) !== 0)
|
|
1500
1669
|
await chmod(path, 0o700);
|
|
1501
1670
|
}
|
|
1502
|
-
|
|
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);
|
|
1503
1676
|
}
|
|
1504
1677
|
catch (error) {
|
|
1505
1678
|
if (createdRoot !== undefined) {
|
|
@@ -1512,10 +1685,19 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1512
1685
|
});
|
|
1513
1686
|
}
|
|
1514
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
|
+
}
|
|
1515
1697
|
export async function createWindowsOutputDirectory(path, recursive) {
|
|
1516
|
-
const native =
|
|
1698
|
+
const native = await windowsOutputBinding();
|
|
1517
1699
|
const create = async (target) => {
|
|
1518
|
-
const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
|
|
1700
|
+
const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"), true);
|
|
1519
1701
|
let error = createOne();
|
|
1520
1702
|
let firstCreated;
|
|
1521
1703
|
if (recursive &&
|
|
@@ -1526,8 +1708,10 @@ export async function createWindowsOutputDirectory(path, recursive) {
|
|
|
1526
1708
|
}
|
|
1527
1709
|
if (error === 0)
|
|
1528
1710
|
return firstCreated ?? target;
|
|
1529
|
-
if (recursive && error === 183 && (await stat(target)).isDirectory())
|
|
1711
|
+
if (recursive && error === 183 && (await stat(target)).isDirectory()) {
|
|
1712
|
+
await requireWindowsOutputPath(target, target === path);
|
|
1530
1713
|
return firstCreated;
|
|
1714
|
+
}
|
|
1531
1715
|
throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
|
|
1532
1716
|
};
|
|
1533
1717
|
return create(path);
|
|
@@ -1537,15 +1721,42 @@ export async function validatePreparedOutputDir(path, validateLocation, allowNon
|
|
|
1537
1721
|
if (!metadata.isDirectory()) {
|
|
1538
1722
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1539
1723
|
}
|
|
1540
|
-
const canonical = await
|
|
1724
|
+
const canonical = await checkedOutputPath(path, !allowNonempty);
|
|
1541
1725
|
requireModelSafeOutputDir(canonical);
|
|
1542
1726
|
validateLocation?.(canonical);
|
|
1543
|
-
|
|
1544
|
-
if (!allowNonempty && entries.length !== 0) {
|
|
1727
|
+
if (!allowNonempty && (await readdir(canonical)).length !== 0) {
|
|
1545
1728
|
throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
|
|
1546
1729
|
}
|
|
1547
1730
|
requireOutputDirectoryOwnership(metadata, path);
|
|
1548
|
-
|
|
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);
|
|
1549
1760
|
return canonical;
|
|
1550
1761
|
}
|
|
1551
1762
|
export function requirePrivateOutputDirectory(metadata, path, effectiveUid = process.geteuid?.()) {
|
|
@@ -1566,7 +1777,7 @@ export function requireOutputDirectoryOwnership(metadata, path, effectiveUid = p
|
|
|
1566
1777
|
/** Reject shared parents whose owner can rename or replace scan output. */
|
|
1567
1778
|
export async function requireSecureOutputAncestry(path, effectiveUid = process.geteuid?.()) {
|
|
1568
1779
|
if (process.platform === "win32")
|
|
1569
|
-
return;
|
|
1780
|
+
return requireWindowsOutputPath(path);
|
|
1570
1781
|
let current = dirname(resolve(path));
|
|
1571
1782
|
while (true) {
|
|
1572
1783
|
try {
|
|
@@ -1701,6 +1912,7 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1701
1912
|
const archivePath = resolve(expandHome(archive));
|
|
1702
1913
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
1703
1914
|
const staging = await realpath(await mkdtemp(join(dirname(destination), ".codex-security-plugin-")));
|
|
1915
|
+
let publishingOnWindows = false;
|
|
1704
1916
|
try {
|
|
1705
1917
|
throwIfSignalAborted(signal);
|
|
1706
1918
|
let expandedSize = 0;
|
|
@@ -1763,12 +1975,29 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1763
1975
|
const pluginRoot = await discoverPluginRoot(staging);
|
|
1764
1976
|
throwIfSignalAborted(signal);
|
|
1765
1977
|
const relativeRoot = relative(staging, pluginRoot);
|
|
1766
|
-
|
|
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
|
+
}
|
|
1767
1991
|
return await validatePluginRoot(join(destination, relativeRoot));
|
|
1768
1992
|
}
|
|
1769
1993
|
catch (error) {
|
|
1770
|
-
|
|
1994
|
+
let cleanupDiagnostic = "";
|
|
1995
|
+
await rm(staging, { recursive: true, force: true }).catch((cleanupError) => {
|
|
1996
|
+
cleanupDiagnostic = `\nCould not remove staging directory ${staging}: ${errorMessage(cleanupError)}`;
|
|
1997
|
+
});
|
|
1771
1998
|
throwIfSignalAborted(signal);
|
|
1999
|
+
if (publishingOnWindows)
|
|
2000
|
+
throw new PluginBootstrapError(`Could not publish extracted plugin ZIP: ${errorMessage(error)}${cleanupDiagnostic}`, { cause: error });
|
|
1772
2001
|
if (error instanceof PluginBootstrapError)
|
|
1773
2002
|
throw error;
|
|
1774
2003
|
throw new PluginBootstrapError(`Invalid plugin ZIP: ${archivePath}`, {
|
|
@@ -2068,9 +2297,18 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
2068
2297
|
const previous = await readFile(installRecord, "utf8")
|
|
2069
2298
|
.then((value) => JSON.parse(value))
|
|
2070
2299
|
.catch((error) => {
|
|
2071
|
-
|
|
2300
|
+
const code = nodeErrorCode(error);
|
|
2301
|
+
if (code === "ENOENT" || error instanceof SyntaxError) {
|
|
2072
2302
|
return null;
|
|
2073
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
|
+
}
|
|
2074
2312
|
throw error;
|
|
2075
2313
|
});
|
|
2076
2314
|
const plugins = configuration["plugins"];
|
|
@@ -2226,11 +2464,9 @@ export async function resolvePluginPython(options = {}) {
|
|
|
2226
2464
|
if (inherited) {
|
|
2227
2465
|
return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
|
|
2228
2466
|
}
|
|
2229
|
-
const home = options.homeDirectory ?? homedir();
|
|
2230
|
-
const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2231
|
-
join(home, ".cache");
|
|
2232
2467
|
const managedRoots = options.managedRuntimeRoots ?? [
|
|
2233
|
-
join(
|
|
2468
|
+
join(environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2469
|
+
join(options.homeDirectory ?? homedir(), ".cache"), "codex-runtimes", "codex-primary-runtime"),
|
|
2234
2470
|
];
|
|
2235
2471
|
const relativeCandidates = process.platform === "win32"
|
|
2236
2472
|
? [
|
|
@@ -2261,14 +2497,12 @@ export async function resolvePluginPython(options = {}) {
|
|
|
2261
2497
|
"Set pythonPath, --python, or PYTHON, install the Codex managed runtime, or add python3/python (py on Windows) to PATH.");
|
|
2262
2498
|
}
|
|
2263
2499
|
export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
2264
|
-
|
|
2500
|
+
return {
|
|
2265
2501
|
...pythonUtf8Environment(environment),
|
|
2266
2502
|
PYTHON: python,
|
|
2267
2503
|
CODEX_SECURITY_PYTHON_COMMAND: python,
|
|
2268
2504
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
2269
2505
|
};
|
|
2270
|
-
forwardExternalImportSetting(environment, child);
|
|
2271
|
-
return child;
|
|
2272
2506
|
}
|
|
2273
2507
|
export function environmentWithGit(environment, git) {
|
|
2274
2508
|
if (git === undefined)
|
|
@@ -2299,6 +2533,16 @@ function pluginHelperEnvironment(environment) {
|
|
|
2299
2533
|
export async function cleanupSdkDirectory(path) {
|
|
2300
2534
|
await rm(path, { recursive: true, force: true });
|
|
2301
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
|
+
}
|
|
2302
2546
|
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2303
2547
|
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2304
2548
|
const abort = () => cancellation?.abort(signal?.reason);
|
|
@@ -2337,26 +2581,30 @@ export async function runCodexCommand(command, args, environment, input, signal,
|
|
|
2337
2581
|
processError = error;
|
|
2338
2582
|
});
|
|
2339
2583
|
child.stdin.on("error", (error) => {
|
|
2340
|
-
if (!
|
|
2584
|
+
if (!isDisconnectedChildStdin(error))
|
|
2341
2585
|
processError = error;
|
|
2342
2586
|
});
|
|
2343
2587
|
child.once("close", (exitCode) => processError === undefined
|
|
2344
2588
|
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
2345
2589
|
: reject(processError));
|
|
2346
2590
|
});
|
|
2347
|
-
|
|
2591
|
+
let forceTermination;
|
|
2592
|
+
const settleCanceledChild = () => {
|
|
2348
2593
|
if (!commandSignal?.aborted)
|
|
2349
2594
|
return;
|
|
2350
|
-
if (child.exitCode === null && child.signalCode === null)
|
|
2595
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
2596
|
+
// spawn already sent SIGTERM. Give the command time to exit cleanly.
|
|
2597
|
+
forceTermination ??= setTimeout(() => child.kill("SIGKILL"), 1_000);
|
|
2351
2598
|
return;
|
|
2599
|
+
}
|
|
2352
2600
|
child.stdin.destroy();
|
|
2353
2601
|
child.stdout.destroy();
|
|
2354
2602
|
child.stderr.destroy();
|
|
2355
2603
|
};
|
|
2356
|
-
commandSignal?.addEventListener("abort",
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2604
|
+
commandSignal?.addEventListener("abort", settleCanceledChild, { once: true });
|
|
2605
|
+
child.once("exit", settleCanceledChild);
|
|
2606
|
+
if (commandSignal?.aborted)
|
|
2607
|
+
settleCanceledChild();
|
|
2360
2608
|
if (archiveHandshake) {
|
|
2361
2609
|
signal?.addEventListener("abort", abort, { once: true });
|
|
2362
2610
|
if (signal?.aborted)
|
|
@@ -2374,8 +2622,9 @@ export async function runCodexCommand(command, args, environment, input, signal,
|
|
|
2374
2622
|
finally {
|
|
2375
2623
|
if (archiveHandshake)
|
|
2376
2624
|
signal?.removeEventListener("abort", abort);
|
|
2377
|
-
|
|
2378
|
-
|
|
2625
|
+
clearTimeout(forceTermination);
|
|
2626
|
+
commandSignal?.removeEventListener("abort", settleCanceledChild);
|
|
2627
|
+
child.removeListener("exit", settleCanceledChild);
|
|
2379
2628
|
}
|
|
2380
2629
|
}
|
|
2381
2630
|
export async function probeCodexSandbox(command, environment, signal) {
|
|
@@ -2397,9 +2646,14 @@ export async function probeCodexSandbox(command, environment, signal) {
|
|
|
2397
2646
|
}
|
|
2398
2647
|
catch (error) {
|
|
2399
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 });
|
|
2400
2651
|
detail = processErrorDetail(error);
|
|
2401
2652
|
}
|
|
2402
|
-
|
|
2653
|
+
const guidance = process.platform === "linux"
|
|
2654
|
+
? "\nOn Linux this usually means unprivileged user namespaces are restricted (kernel.apparmor_restrict_unprivileged_userns=1 on Ubuntu 24.04 and later), which Bubblewrap needs; inside the container image, use the AppArmor profile and Compose override from the SDK README."
|
|
2655
|
+
: "";
|
|
2656
|
+
throw new SandboxUnavailableError(`Codex could not run a command in its sandbox: ${detail}\nTo reproduce, run '${command.command} ${args.join(" ")}'.${guidance}`);
|
|
2403
2657
|
}
|
|
2404
2658
|
async function runPluginCommand(command, args, environment, signal) {
|
|
2405
2659
|
try {
|
|
@@ -2433,7 +2687,7 @@ async function validatePluginRoot(root) {
|
|
|
2433
2687
|
await pluginMetadata(root);
|
|
2434
2688
|
return await realpath(root);
|
|
2435
2689
|
}
|
|
2436
|
-
async function copyPluginTree(source, destination, signal) {
|
|
2690
|
+
export async function copyPluginTree(source, destination, signal) {
|
|
2437
2691
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
2438
2692
|
try {
|
|
2439
2693
|
await cp(source, destination, {
|
|
@@ -2500,21 +2754,14 @@ async function usablePython(candidate, environment = process.env, protectedRoot
|
|
|
2500
2754
|
if (command === null)
|
|
2501
2755
|
return null;
|
|
2502
2756
|
try {
|
|
2503
|
-
const { stdout } = await execFile(command.executable, [
|
|
2504
|
-
"-I",
|
|
2505
|
-
"-c",
|
|
2506
|
-
"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')",
|
|
2507
|
-
], {
|
|
2757
|
+
const { stdout } = await execFile(command.executable, ["-I", "-c", PLUGIN_PYTHON_PROBE], {
|
|
2508
2758
|
env: command.environment,
|
|
2509
2759
|
encoding: "utf8",
|
|
2510
|
-
|
|
2511
|
-
timeout: 30_000,
|
|
2760
|
+
timeout: PLUGIN_PYTHON_PROBE_TIMEOUT_MS,
|
|
2512
2761
|
windowsHide: true,
|
|
2513
2762
|
signal,
|
|
2514
2763
|
});
|
|
2515
|
-
return stdout.trim() ===
|
|
2516
|
-
? command.executable
|
|
2517
|
-
: null;
|
|
2764
|
+
return stdout.trim() === PLUGIN_PYTHON_READY ? command.executable : null;
|
|
2518
2765
|
}
|
|
2519
2766
|
catch (error) {
|
|
2520
2767
|
if (signal?.aborted)
|
|
@@ -2534,8 +2781,7 @@ export function sameFile(left, right) {
|
|
|
2534
2781
|
return Promise.all([
|
|
2535
2782
|
stat(left, { bigint: true }),
|
|
2536
2783
|
stat(right, { bigint: true }),
|
|
2537
|
-
]).then(([leftMetadata, rightMetadata]) => leftMetadata
|
|
2538
|
-
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2784
|
+
]).then(([leftMetadata, rightMetadata]) => sameInode(leftMetadata, rightMetadata), () => false);
|
|
2539
2785
|
}
|
|
2540
2786
|
function expandExecutableHome(value, environment) {
|
|
2541
2787
|
const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
|
|
@@ -2545,17 +2791,17 @@ function expandExecutableHome(value, environment) {
|
|
|
2545
2791
|
: expandHome(path, environment);
|
|
2546
2792
|
}
|
|
2547
2793
|
export function expandHome(value, environment = process.env) {
|
|
2548
|
-
const home = (process.platform === "win32"
|
|
2794
|
+
const home = () => (process.platform === "win32"
|
|
2549
2795
|
? (environmentValue(environment, "USERPROFILE") ??
|
|
2550
2796
|
environmentValue(environment, "HOME"))
|
|
2551
2797
|
: (environmentValue(environment, "HOME") ??
|
|
2552
2798
|
environmentValue(environment, "USERPROFILE"))) ?? homedir();
|
|
2553
2799
|
if (value === "~")
|
|
2554
|
-
return home;
|
|
2800
|
+
return home();
|
|
2555
2801
|
if (value.startsWith("~/"))
|
|
2556
|
-
return join(home, value.slice(2));
|
|
2802
|
+
return join(home(), value.slice(2));
|
|
2557
2803
|
if (value.startsWith("~\\")) {
|
|
2558
|
-
return join(home, ...value.slice(2).split("\\"));
|
|
2804
|
+
return join(home(), ...value.slice(2).split("\\"));
|
|
2559
2805
|
}
|
|
2560
2806
|
return value;
|
|
2561
2807
|
}
|