@openai/codex-security 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +437 -2692
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +4 -0
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
- package/_bundled_plugin/examples/completed-scan/report.md +28 -26
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
- package/_bundled_plugin/mcp/helpers.mjs +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
- 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/permission-profile-preflight.mjs +556 -0
- package/_bundled_plugin/mcp/server.mjs +1 -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/preflight/capability-profiles.toml +0 -13
- package/_bundled_plugin/references/artifact-storage.md +2 -2
- package/_bundled_plugin/references/config-preflight.md +0 -4
- package/_bundled_plugin/references/core-scan.md +21 -9
- package/_bundled_plugin/references/final-report.md +11 -13
- package/_bundled_plugin/references/finding-detail-fields.md +90 -80
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-artifacts.md +1 -2
- package/_bundled_plugin/references/scan-contract.md +9 -4
- package/_bundled_plugin/references/scan-prologue.md +12 -0
- package/_bundled_plugin/references/security-guidance.md +2 -2
- package/_bundled_plugin/references/standalone-validation.md +11 -0
- package/_bundled_plugin/references/threat-model.md +1 -1
- package/_bundled_plugin/schemas/coverage.schema.json +43 -170
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
- package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
- package/_bundled_plugin/schemas/findings.schema.json +159 -567
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
- package/_bundled_plugin/schemas/scan-manifest.schema.json +78 -220
- package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
- package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
- package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
- package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
- package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
- package/_bundled_plugin/scripts/codex_session.mjs +53 -0
- package/_bundled_plugin/scripts/config_preflight.py +26 -62
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
- package/_bundled_plugin/scripts/finalize_scan_contract.py +321 -237
- package/_bundled_plugin/scripts/finding_preview.py +39 -9
- package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
- package/_bundled_plugin/scripts/generate_rank_input.py +115 -926
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +42 -918
- package/_bundled_plugin/scripts/report_projection.py +150 -183
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
- package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
- package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
- package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
- package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
- package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
- package/_bundled_plugin/scripts/workbench/storage.py +10 -6
- package/_bundled_plugin/scripts/workbench_cli.py +102 -184
- package/_bundled_plugin/scripts/workbench_db.py +463 -464
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
- package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
- package/_bundled_plugin/scripts/workbench_progress.py +14 -58
- package/_bundled_plugin/scripts/workbench_publication.py +234 -289
- package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
- package/_bundled_plugin/scripts/workbench_scan_usage.py +194 -42
- package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
- package/_bundled_plugin/scripts/workbench_target.py +430 -142
- package/_bundled_plugin/scripts/workbench_validation.py +31 -28
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +414 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
- package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
- package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +15 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +48 -176
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
- package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
- package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
- package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
- package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
- package/bin/codex-security.mjs +9 -2
- package/dist/api.d.ts +63 -10
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1015 -383
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +1 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +28 -13
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +19 -9
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +1 -0
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-severity.d.ts +26 -9
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +13 -30
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +17 -13
- package/dist/cli-help.js.map +1 -1
- package/dist/cli-signals.d.ts +8 -0
- package/dist/cli-signals.d.ts.map +1 -0
- package/dist/cli-signals.js +28 -0
- package/dist/cli-signals.js.map +1 -0
- package/dist/cli.d.ts +4 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1102 -905
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +10 -9
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codeowners.d.ts +19 -0
- package/dist/codeowners.d.ts.map +1 -0
- package/dist/codeowners.js +138 -0
- package/dist/codeowners.js.map +1 -0
- package/dist/codex-sdk-environment.d.ts +1 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -1
- package/dist/codex-sdk-environment.js +40 -2
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +39 -31
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +6 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +25 -36
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -74
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +16 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +91 -255
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +13 -6
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +14 -4
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts +10 -2
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +102 -104
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +6 -5
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts +1 -2
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +9 -3
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +4 -2
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +23 -9
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +8 -6
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +128 -19
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +5 -2
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +18 -4
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +27 -5
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +58 -48
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +19 -51
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/diagnostics.d.ts +17 -0
- package/dist/deduplication/diagnostics.d.ts.map +1 -0
- package/dist/deduplication/diagnostics.js +5 -0
- package/dist/deduplication/diagnostics.js.map +1 -0
- package/dist/deduplication/finding-schema.d.ts.map +1 -1
- package/dist/deduplication/finding-schema.js +7 -1
- package/dist/deduplication/finding-schema.js.map +1 -1
- package/dist/deduplication/local.d.ts +31 -0
- package/dist/deduplication/local.d.ts.map +1 -0
- package/dist/deduplication/local.js +166 -0
- package/dist/deduplication/local.js.map +1 -0
- package/dist/deduplication/records-protocol.d.ts +3 -8
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -184
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +186 -11
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +10 -18
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts +9 -3
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +158 -39
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +2 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +4 -4
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +17 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +19 -17
- package/dist/deep-progress.js.map +1 -1
- package/dist/deep-scan.d.ts +20 -0
- package/dist/deep-scan.d.ts.map +1 -0
- package/dist/deep-scan.js +113 -0
- package/dist/deep-scan.js.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/executable-path.d.ts +2 -0
- package/dist/executable-path.d.ts.map +1 -0
- package/dist/executable-path.js +12 -0
- package/dist/executable-path.js.map +1 -0
- package/dist/feedback.d.ts +1 -4
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +54 -22
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +4 -8
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-normalization.d.ts +5 -0
- package/dist/finding-normalization.d.ts.map +1 -0
- package/dist/finding-normalization.js +120 -0
- package/dist/finding-normalization.js.map +1 -0
- package/dist/finding-retrieval.d.ts +9 -0
- package/dist/finding-retrieval.d.ts.map +1 -1
- package/dist/finding-retrieval.js.map +1 -1
- package/dist/finding-workflow.d.ts +13 -8
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +14 -6
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-client.d.ts +2 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +36 -9
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-errors.d.ts +16 -0
- package/dist/findings-errors.d.ts.map +1 -0
- package/dist/findings-errors.js +24 -0
- package/dist/findings-errors.js.map +1 -0
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +12 -30
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +7 -1
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +19 -0
- package/dist/host-protocol.d.ts.map +1 -0
- package/dist/host-protocol.js +270 -0
- package/dist/host-protocol.js.map +1 -0
- package/dist/hosted-scan-protocol.d.ts +4 -0
- package/dist/hosted-scan-protocol.d.ts.map +1 -0
- package/dist/hosted-scan-protocol.js +25 -0
- package/dist/hosted-scan-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +117 -0
- package/dist/hosted-scan.d.ts.map +1 -0
- package/dist/hosted-scan.js +260 -0
- package/dist/hosted-scan.js.map +1 -0
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +48 -38
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +7 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +114 -46
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -7
- package/dist/linear.js.map +1 -1
- package/dist/mock-scan.d.ts.map +1 -1
- package/dist/mock-scan.js +0 -1
- package/dist/mock-scan.js.map +1 -1
- package/dist/models.d.ts +0 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts +9 -3
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +240 -135
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +10 -2
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +67 -8
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +3 -2
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config.js +3 -3
- package/dist/project-config.js.map +1 -1
- package/dist/provider-profile.d.ts +21 -0
- package/dist/provider-profile.d.ts.map +1 -0
- package/dist/provider-profile.js +133 -0
- package/dist/provider-profile.js.map +1 -0
- package/dist/publication-events.d.ts +6 -8
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +25 -50
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +95 -109
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -4
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +2 -13
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +1 -5
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +109 -160
- package/dist/publish.js.map +1 -1
- package/dist/request-metadata.d.ts +9 -0
- package/dist/request-metadata.d.ts.map +1 -0
- package/dist/request-metadata.js +13 -0
- package/dist/request-metadata.js.map +1 -0
- package/dist/runtime.d.ts +20 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +407 -148
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan-bootstrap.d.ts +14 -0
- package/dist/saved-scan-bootstrap.d.ts.map +1 -0
- package/dist/saved-scan-bootstrap.js +261 -0
- package/dist/saved-scan-bootstrap.js.map +1 -0
- package/dist/saved-scan.d.ts +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +6 -12
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.js +11 -8
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +28 -15
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +276 -281
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -0
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +345 -77
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-executor.d.ts +104 -0
- package/dist/scan-executor.d.ts.map +1 -0
- package/dist/scan-executor.js +62 -0
- package/dist/scan-executor.js.map +1 -0
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +54 -13
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-inputs.d.ts +6 -0
- package/dist/scan-inputs.d.ts.map +1 -0
- package/dist/scan-inputs.js +71 -0
- package/dist/scan-inputs.js.map +1 -0
- package/dist/scan-logs.d.ts +2 -3
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +12 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +17 -0
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-skill-paths.d.ts +8 -0
- package/dist/scan-skill-paths.d.ts.map +1 -0
- package/dist/scan-skill-paths.js +47 -0
- package/dist/scan-skill-paths.js.map +1 -0
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +7 -27
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +9 -5
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +33 -14
- package/dist/security-policy.js.map +1 -1
- package/dist/server/api.d.ts +0 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js +0 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/embeddings.d.ts +3 -1
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +10 -3
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/errors.d.ts +5 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +7 -0
- package/dist/server/errors.js.map +1 -1
- package/dist/server/sqlite-store.d.ts +0 -2
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +54 -44
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/server/storage.d.ts +0 -2
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js.map +1 -1
- package/dist/severity-store.js +19 -24
- package/dist/severity-store.js.map +1 -1
- package/dist/standalone-validation-prompt.d.ts +2 -0
- package/dist/standalone-validation-prompt.d.ts.map +1 -0
- package/dist/standalone-validation-prompt.js +10 -0
- package/dist/standalone-validation-prompt.js.map +1 -0
- package/dist/suggest-owners.d.ts +4 -2
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +11 -5
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +11 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +123 -72
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +2 -2
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +8 -6
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.js +7 -0
- package/dist/value.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/workbench-arguments.d.ts +3 -0
- package/dist/workbench-arguments.d.ts.map +1 -0
- package/dist/workbench-arguments.js +15 -0
- package/dist/workbench-arguments.js.map +1 -0
- package/dist/worker-progress.d.ts +44 -11
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +48 -49
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1788 -0
- package/docs/findings-service.md +402 -0
- package/docs/hosted-scans.md +242 -0
- package/package.json +23 -22
- package/schemas/hosted-scan-v2.fixture.json +145 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
- package/_bundled_plugin/scripts/workbench_findings.py +0 -221
- package/_bundled_plugin/scripts/workbench_severity.py +0 -122
- package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
- package/dist/server/dashboard/app.css +0 -2
- package/dist/server/dashboard/app.js +0 -66
- package/dist/server/dashboard/index.html +0 -18
- package/dist/server/dashboard-types.d.ts +0 -48
- package/dist/server/dashboard-types.d.ts.map +0 -1
- package/dist/server/dashboard-types.js +0 -2
- package/dist/server/dashboard-types.js.map +0 -1
- package/dist/server/dashboard.d.ts +0 -6
- package/dist/server/dashboard.d.ts.map +0 -1
- package/dist/server/dashboard.js +0 -59
- package/dist/server/dashboard.js.map +0 -1
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -6
- package/dist/server/index.js.map +0 -1
- package/dist/server/routes.d.ts +0 -7
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -98
- package/dist/server/routes.js.map +0 -1
- package/dist/server/serve.d.ts +0 -2
- package/dist/server/serve.d.ts.map +0 -1
- package/dist/server/serve.js +0 -28
- package/dist/server/serve.js.map +0 -1
- package/dist/server/server.d.ts +0 -10
- package/dist/server/server.d.ts.map +0 -1
- package/dist/server/server.js +0 -16
- package/dist/server/server.js.map +0 -1
- package/dist/server/validation.d.ts +0 -17
- package/dist/server/validation.d.ts.map +0 -1
- package/dist/server/validation.js +0 -53
- package/dist/server/validation.js.map +0 -1
package/dist/runtime.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { executablePathForSpawn } from "./executable-path.js";
|
|
2
|
+
export { executablePathForSpawn } from "./executable-path.js";
|
|
3
|
+
import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
|
|
4
|
+
import { gitProtectionRoots } from "./targets.js";
|
|
5
|
+
import { isNonEmptyString, notify } from "./value.js";
|
|
6
|
+
import { execFile as execFileCallback, spawn, } from "node:child_process";
|
|
3
7
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { chmodSync, constants, createWriteStream,
|
|
8
|
+
import { chmodSync, constants, createWriteStream, } from "node:fs";
|
|
5
9
|
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
6
10
|
import { homedir, tmpdir } from "node:os";
|
|
7
11
|
import { createRequire } from "node:module";
|
|
8
|
-
import { basename, dirname, extname, join, relative, resolve,
|
|
12
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
9
13
|
import { fileURLToPath } from "node:url";
|
|
10
14
|
import { promisify } from "node:util";
|
|
11
15
|
import { pipeline } from "node:stream/promises";
|
|
@@ -13,13 +17,25 @@ import { crc32 } from "node:zlib";
|
|
|
13
17
|
import { setTimeout as delay } from "node:timers/promises";
|
|
14
18
|
import { openPromise as openZip } from "yauzl";
|
|
15
19
|
import { parse } from "smol-toml";
|
|
16
|
-
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
20
|
+
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
17
21
|
import { isRecord } from "./record.js";
|
|
18
22
|
import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
19
23
|
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
20
24
|
const execFile = promisify(execFileCallback);
|
|
21
25
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
22
26
|
export const PLUGIN_NAME = "codex-security";
|
|
27
|
+
const MARKETPLACE_MANIFEST = `${JSON.stringify({
|
|
28
|
+
name: MARKETPLACE_NAME,
|
|
29
|
+
interface: { displayName: "Codex Security SDK" },
|
|
30
|
+
plugins: [
|
|
31
|
+
{
|
|
32
|
+
name: PLUGIN_NAME,
|
|
33
|
+
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
34
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
35
|
+
category: "Security",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
}, null, 2)}\n`;
|
|
23
39
|
const MAX_ZIP_ENTRIES = 4_096;
|
|
24
40
|
const MAX_ZIP_CENTRAL_DIRECTORY = 16 * 1024 * 1024;
|
|
25
41
|
const MAX_ZIP_ENTRY_SIZE = 128 * 1024 * 1024;
|
|
@@ -72,19 +88,18 @@ except (module["ContractError"], OSError) as error:
|
|
|
72
88
|
`.trim();
|
|
73
89
|
const WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX = "CODEX_SECURITY_ACL_COMPLETE:";
|
|
74
90
|
const WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE = 2;
|
|
75
|
-
function environmentValue(environment, requested) {
|
|
76
|
-
const exact = environment[requested]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
?.trim();
|
|
91
|
+
function environmentValue(environment, requested, preserveWhitespace = false) {
|
|
92
|
+
const exact = environment[requested];
|
|
93
|
+
const value = exact?.trim()
|
|
94
|
+
? exact
|
|
95
|
+
: Object.entries(environment).find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1];
|
|
96
|
+
return preserveWhitespace ? value : value?.trim();
|
|
82
97
|
}
|
|
83
98
|
export function codexSecurityStateDirectory(environment = process.env) {
|
|
84
99
|
const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
|
|
85
100
|
const path = configured !== undefined
|
|
86
101
|
? resolve(expandHome(configured, environment))
|
|
87
|
-
: resolve(expandHome(environmentValue(environment, "CODEX_HOME") ??
|
|
102
|
+
: resolve(expandHome(environmentValue(environment, "CODEX_HOME", true) ??
|
|
88
103
|
join(homedir(), ".codex"), environment), "state", "plugins", "codex-security");
|
|
89
104
|
requireModelSafeOutputDir(path);
|
|
90
105
|
return path;
|
|
@@ -439,10 +454,10 @@ function windowsAceAllowsAncestorReplacement(rights, inheritanceFlags) {
|
|
|
439
454
|
if (/^0x[\da-f]+$/iu.test(rights)) {
|
|
440
455
|
return (BigInt(rights) & 0x100d0040n) !== 0n;
|
|
441
456
|
}
|
|
442
|
-
|
|
443
|
-
|
|
457
|
+
// Rights tokens stay aligned to pairs of UTF-16 code units.
|
|
458
|
+
for (const [right] of rights.matchAll(/[\s\S]{2}/g)) {
|
|
459
|
+
if (["FA", "GA", "FW", "GW", "SD", "WD", "WO", "DC", "DT"].includes(right))
|
|
444
460
|
return true;
|
|
445
|
-
}
|
|
446
461
|
}
|
|
447
462
|
return false;
|
|
448
463
|
}
|
|
@@ -777,6 +792,15 @@ async function secureWindowsCredentialHome(path) {
|
|
|
777
792
|
}
|
|
778
793
|
}
|
|
779
794
|
}
|
|
795
|
+
export async function withCredentialHomeLock(codexHome, operation, signal) {
|
|
796
|
+
const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
|
|
797
|
+
try {
|
|
798
|
+
return await operation();
|
|
799
|
+
}
|
|
800
|
+
finally {
|
|
801
|
+
await release();
|
|
802
|
+
}
|
|
803
|
+
}
|
|
780
804
|
export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal, securityOptions = {}) {
|
|
781
805
|
throwIfSignalAborted(signal);
|
|
782
806
|
const homeMetadata = await requireSecureCredentialHome(codexHome, securityOptions);
|
|
@@ -1099,11 +1123,99 @@ export async function preparePersistentOutputRoot(stateDirectory, category, repo
|
|
|
1099
1123
|
}
|
|
1100
1124
|
return root;
|
|
1101
1125
|
}
|
|
1102
|
-
const
|
|
1126
|
+
const WORKBENCH_ARGUMENTS_PROGRAM = String.raw `
|
|
1127
|
+
import json, sys
|
|
1128
|
+
sys.argv[2:] = json.loads(sys.stdin.buffer.readline())
|
|
1129
|
+
`;
|
|
1130
|
+
const WORKBENCH_SCRIPT_PROGRAM = String.raw `
|
|
1131
|
+
import runpy, sys
|
|
1132
|
+
sys.argv = sys.argv[1:]
|
|
1133
|
+
runpy.run_path(sys.argv[0], run_name="__main__")
|
|
1134
|
+
`;
|
|
1135
|
+
const ARCHIVE_READY = "codex-security-archive-ready\n";
|
|
1136
|
+
const ARCHIVE_REGISTRATION_PROGRAM = String.raw `
|
|
1137
|
+
import io, json, runpy, sys
|
|
1138
|
+
control = sys.stdin
|
|
1139
|
+
payload = json.loads(control.readline())
|
|
1140
|
+
sys.stdin = io.TextIOWrapper(io.BytesIO(payload.encode("utf-8")), encoding="utf-8")
|
|
1141
|
+
sys.argv = sys.argv[1:]
|
|
1142
|
+
workbench = runpy.run_path(sys.argv[0])
|
|
1143
|
+
def before_archive():
|
|
1144
|
+
sys.stdout.buffer.write(b"codex-security-archive-ready\n")
|
|
1145
|
+
sys.stdout.buffer.flush()
|
|
1146
|
+
if control.readline() != "\n":
|
|
1147
|
+
raise SystemExit("Scan registration canceled before archival.")
|
|
1148
|
+
workbench["main"](before_archive=before_archive)
|
|
1149
|
+
`;
|
|
1103
1150
|
export async function runWorkbench(options, args, input) {
|
|
1104
1151
|
const script = join(options.pluginRoot, "scripts", "workbench_db.py");
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1152
|
+
const signal = options.signal;
|
|
1153
|
+
const run = async (arguments_, input, archiveHandshake = false) => {
|
|
1154
|
+
const native = [
|
|
1155
|
+
"database-info",
|
|
1156
|
+
"store-findings",
|
|
1157
|
+
"list-stored-findings",
|
|
1158
|
+
"find-potential-duplicates",
|
|
1159
|
+
"store-dedupe-groups",
|
|
1160
|
+
"list-dedupe-groups",
|
|
1161
|
+
"dashboard",
|
|
1162
|
+
"severity-classification",
|
|
1163
|
+
"read-severity-classification",
|
|
1164
|
+
].includes(arguments_[0] ?? "");
|
|
1165
|
+
const node = native && process.versions["bun"]
|
|
1166
|
+
? await resolveTrustedExecutable("node", options.environment, [
|
|
1167
|
+
process.cwd(),
|
|
1168
|
+
options.currentDirectory ?? process.cwd(),
|
|
1169
|
+
...(typeof options.protectedRoot === "string"
|
|
1170
|
+
? [options.protectedRoot]
|
|
1171
|
+
: (options.protectedRoot ?? [])),
|
|
1172
|
+
])
|
|
1173
|
+
: undefined;
|
|
1174
|
+
if (node === null) {
|
|
1175
|
+
throw new Error("Node.js is not available on a trusted PATH.");
|
|
1176
|
+
}
|
|
1177
|
+
const command = native
|
|
1178
|
+
? (node?.executable ?? process.execPath)
|
|
1179
|
+
: (options.python ??= await resolvePluginPython({
|
|
1180
|
+
environment: options.environment,
|
|
1181
|
+
protectedRoot: options.protectedRoot,
|
|
1182
|
+
currentDirectory: options.currentDirectory,
|
|
1183
|
+
signal: options.signal,
|
|
1184
|
+
}));
|
|
1185
|
+
const stateDirectory = native
|
|
1186
|
+
? (options.stateDirectory ??
|
|
1187
|
+
codexSecurityStateDirectory(options.environment))
|
|
1188
|
+
: undefined;
|
|
1189
|
+
// OS argv cannot carry NUL, but workbench text fields can.
|
|
1190
|
+
const framedArguments = !native && arguments_.some((argument) => argument.includes("\0"));
|
|
1191
|
+
let program = archiveHandshake ? ARCHIVE_REGISTRATION_PROGRAM : undefined;
|
|
1192
|
+
if (framedArguments)
|
|
1193
|
+
program =
|
|
1194
|
+
WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
|
|
1195
|
+
const result = await runCodexCommand({ command }, native
|
|
1196
|
+
? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
|
|
1197
|
+
: [
|
|
1198
|
+
"-I",
|
|
1199
|
+
"-X",
|
|
1200
|
+
"utf8",
|
|
1201
|
+
"-B",
|
|
1202
|
+
...(program === undefined ? [] : ["-c", program]),
|
|
1203
|
+
script,
|
|
1204
|
+
...(framedArguments ? [] : arguments_),
|
|
1205
|
+
], pluginHelperEnvironment(node?.environment ?? options.environment),
|
|
1206
|
+
// The SDK owns configuration normalization; the helper receives its resolved location.
|
|
1207
|
+
native
|
|
1208
|
+
? JSON.stringify(arguments_[0] === "database-info"
|
|
1209
|
+
? stateDirectory
|
|
1210
|
+
: {
|
|
1211
|
+
stateDirectory,
|
|
1212
|
+
payload: input === undefined ? undefined : JSON.parse(input),
|
|
1213
|
+
})
|
|
1214
|
+
: input, signal, archiveHandshake,
|
|
1215
|
+
// Match native argv's UTF-8 encoding for the private argument frame.
|
|
1216
|
+
framedArguments
|
|
1217
|
+
? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
|
|
1218
|
+
: undefined);
|
|
1107
1219
|
if (!result.success) {
|
|
1108
1220
|
throw new Error(result.stderr.trim() ||
|
|
1109
1221
|
result.stdout.trim() ||
|
|
@@ -1113,45 +1225,18 @@ export async function runWorkbench(options, args, input) {
|
|
|
1113
1225
|
};
|
|
1114
1226
|
let stdout;
|
|
1115
1227
|
try {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const key = JSON.stringify([options.python, script]);
|
|
1122
|
-
let support = workbenchComparisonSupport.get(key);
|
|
1123
|
-
if (support === undefined) {
|
|
1124
|
-
const help = await run(["save-scan-comparison", "--help"]);
|
|
1125
|
-
options.signal?.throwIfAborted();
|
|
1126
|
-
support = {
|
|
1127
|
-
stdin: help.includes("--matches-json-stdin"),
|
|
1128
|
-
related: help
|
|
1129
|
-
.replace(/\s+/gu, " ")
|
|
1130
|
-
.includes("Comparison payload supports related findings."),
|
|
1131
|
-
};
|
|
1132
|
-
workbenchComparisonSupport.set(key, support);
|
|
1133
|
-
}
|
|
1134
|
-
const comparison = JSON.parse(input);
|
|
1135
|
-
if (isRecord(comparison) && "related" in comparison && !support.related) {
|
|
1136
|
-
delete comparison["related"];
|
|
1137
|
-
input = JSON.stringify(comparison);
|
|
1138
|
-
}
|
|
1139
|
-
if (!support.stdin) {
|
|
1140
|
-
arguments_.splice(matchesStdinIndex, 1, "--matches-json", input);
|
|
1141
|
-
input = undefined;
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
stdout = await run(arguments_, input);
|
|
1228
|
+
const archiveHandshake = signal !== undefined &&
|
|
1229
|
+
args[0] === "register-cli-scan" &&
|
|
1230
|
+
args.includes("--archive-existing") &&
|
|
1231
|
+
!args.includes("--archived-scan-dir");
|
|
1232
|
+
stdout = await run(args, input, archiveHandshake);
|
|
1145
1233
|
}
|
|
1146
1234
|
catch (error) {
|
|
1147
1235
|
if (options.signal?.aborted)
|
|
1148
1236
|
throw error;
|
|
1149
1237
|
const detail = processErrorDetail(error);
|
|
1150
|
-
const databaseFailure = /\b(?:unable to open database file|attempt to write a readonly database|readonly database|disk i\/o error)\b/iu.test(detail);
|
|
1151
1238
|
const failure = options.failureMessage ?? "Could not run the Codex Security workbench";
|
|
1152
|
-
throw new CodexSecurityError(
|
|
1153
|
-
? `${failure}: cannot open the workbench database at ${join(codexSecurityStateDirectory(options.environment), "workbench.sqlite3")}. Ensure the state directory and SQLite journal files are writable, or set CODEX_SECURITY_STATE_DIR to a writable directory outside the scanned repository.`
|
|
1154
|
-
: `${failure}: ${detail}`, { cause: error });
|
|
1239
|
+
throw new CodexSecurityError(`${failure}: ${detail}`, { cause: error });
|
|
1155
1240
|
}
|
|
1156
1241
|
let result;
|
|
1157
1242
|
try {
|
|
@@ -1184,8 +1269,8 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1184
1269
|
if (outputDirectory === undefined) {
|
|
1185
1270
|
return null;
|
|
1186
1271
|
}
|
|
1187
|
-
requireModelSafeOutputDir(outputDirectory);
|
|
1188
1272
|
const path = resolve(expandHome(outputDirectory));
|
|
1273
|
+
requireModelSafeOutputDir(path);
|
|
1189
1274
|
try {
|
|
1190
1275
|
const metadata = await lstat(path).catch(nullIfMissingFileError);
|
|
1191
1276
|
if (metadata !== null) {
|
|
@@ -1343,11 +1428,18 @@ export async function canonicalConfigPath(path) {
|
|
|
1343
1428
|
}
|
|
1344
1429
|
}
|
|
1345
1430
|
export async function prepareOutputDir(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false, onOutputArchived) {
|
|
1431
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "archive" : "reject", onOutputArchived);
|
|
1432
|
+
}
|
|
1433
|
+
/** Leave archival to the scan registration transaction. */
|
|
1434
|
+
export async function prepareScanRegistrationOutput(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false) {
|
|
1435
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
|
|
1436
|
+
}
|
|
1437
|
+
async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
|
|
1346
1438
|
if (outputDirectory === undefined) {
|
|
1347
1439
|
requireModelSafeOutputDir(temporaryRoot);
|
|
1348
1440
|
requireModelSafeOutputDir(await realpath(temporaryRoot));
|
|
1349
1441
|
}
|
|
1350
|
-
const path = await validateOutputDir(outputDirectory,
|
|
1442
|
+
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1351
1443
|
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1352
1444
|
if (path === null) {
|
|
1353
1445
|
const created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
|
|
@@ -1364,11 +1456,11 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1364
1456
|
let createdRoot;
|
|
1365
1457
|
try {
|
|
1366
1458
|
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
1367
|
-
if (existing !== null &&
|
|
1459
|
+
if (existing !== null && existingOutput === "archive") {
|
|
1368
1460
|
const archiveDir = await planOutputArchive(path);
|
|
1369
1461
|
if (archiveDir !== null) {
|
|
1370
1462
|
await rename(path, archiveDir);
|
|
1371
|
-
onOutputArchived?.(archiveDir);
|
|
1463
|
+
notify(() => onOutputArchived?.(archiveDir));
|
|
1372
1464
|
existing = null;
|
|
1373
1465
|
}
|
|
1374
1466
|
}
|
|
@@ -1377,7 +1469,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1377
1469
|
if ((process.umask() & 0o700) !== 0)
|
|
1378
1470
|
await chmod(path, 0o700);
|
|
1379
1471
|
}
|
|
1380
|
-
return await validatePreparedOutputDir(path, validateLocation);
|
|
1472
|
+
return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
|
|
1381
1473
|
}
|
|
1382
1474
|
catch (error) {
|
|
1383
1475
|
if (createdRoot !== undefined) {
|
|
@@ -1390,7 +1482,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1390
1482
|
});
|
|
1391
1483
|
}
|
|
1392
1484
|
}
|
|
1393
|
-
export async function validatePreparedOutputDir(path, validateLocation) {
|
|
1485
|
+
export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
|
|
1394
1486
|
const metadata = await lstat(path);
|
|
1395
1487
|
if (!metadata.isDirectory()) {
|
|
1396
1488
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
@@ -1399,7 +1491,7 @@ export async function validatePreparedOutputDir(path, validateLocation) {
|
|
|
1399
1491
|
requireModelSafeOutputDir(canonical);
|
|
1400
1492
|
validateLocation?.(canonical);
|
|
1401
1493
|
const entries = await readdir(canonical);
|
|
1402
|
-
if (entries.length !== 0) {
|
|
1494
|
+
if (!allowNonempty && entries.length !== 0) {
|
|
1403
1495
|
throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
|
|
1404
1496
|
}
|
|
1405
1497
|
requirePrivateOutputDirectory(metadata, path);
|
|
@@ -1694,88 +1786,179 @@ async function rejectBackslashZipNames(path, signal) {
|
|
|
1694
1786
|
}
|
|
1695
1787
|
}
|
|
1696
1788
|
export async function resolvePluginPath(pluginPath, workspace, signal) {
|
|
1697
|
-
|
|
1698
|
-
|
|
1789
|
+
try {
|
|
1790
|
+
if (pluginPath === undefined) {
|
|
1791
|
+
return await bundledPluginRoot();
|
|
1792
|
+
}
|
|
1793
|
+
const path = resolve(expandHome(pluginPath));
|
|
1794
|
+
const metadata = await lstat(path).catch(() => null);
|
|
1795
|
+
if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
|
|
1796
|
+
return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
|
|
1797
|
+
}
|
|
1798
|
+
if (metadata?.isDirectory()) {
|
|
1799
|
+
throwIfSignalAborted(signal);
|
|
1800
|
+
return await validatePluginRoot(path);
|
|
1801
|
+
}
|
|
1802
|
+
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1699
1803
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1804
|
+
catch (error) {
|
|
1805
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1806
|
+
throw error;
|
|
1807
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1704
1808
|
}
|
|
1705
|
-
|
|
1809
|
+
}
|
|
1810
|
+
export async function createMarketplace(codexHome, pluginRoot, signal) {
|
|
1811
|
+
try {
|
|
1706
1812
|
throwIfSignalAborted(signal);
|
|
1707
|
-
|
|
1813
|
+
const root = await realpath(pluginRoot);
|
|
1814
|
+
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1815
|
+
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1816
|
+
await copyPluginTree(root, pluginDestination, signal);
|
|
1817
|
+
const projection = await pluginRuntimeProjection(pluginDestination, signal);
|
|
1818
|
+
for (const [path, file] of projection?.files ?? []) {
|
|
1819
|
+
const destination = join(pluginDestination, path);
|
|
1820
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
1821
|
+
await writeFile(destination, file.contents, { mode: file.mode, signal });
|
|
1822
|
+
if (file.mode !== undefined)
|
|
1823
|
+
await chmod(destination, file.mode);
|
|
1824
|
+
}
|
|
1825
|
+
await writeMarketplaceManifest(marketplace, signal);
|
|
1826
|
+
return marketplace;
|
|
1827
|
+
}
|
|
1828
|
+
catch (error) {
|
|
1829
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1830
|
+
throw error;
|
|
1831
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1708
1832
|
}
|
|
1709
|
-
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1710
1833
|
}
|
|
1711
|
-
|
|
1834
|
+
async function writeMarketplaceManifest(marketplace, signal) {
|
|
1712
1835
|
throwIfSignalAborted(signal);
|
|
1713
|
-
const root = await realpath(pluginRoot);
|
|
1714
|
-
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1715
|
-
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1716
|
-
await copyPluginTree(root, pluginDestination, signal);
|
|
1717
|
-
throwIfSignalAborted(signal);
|
|
1718
|
-
const manifest = {
|
|
1719
|
-
name: MARKETPLACE_NAME,
|
|
1720
|
-
interface: { displayName: "Codex Security SDK" },
|
|
1721
|
-
plugins: [
|
|
1722
|
-
{
|
|
1723
|
-
name: PLUGIN_NAME,
|
|
1724
|
-
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
1725
|
-
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
1726
|
-
category: "Security",
|
|
1727
|
-
},
|
|
1728
|
-
],
|
|
1729
|
-
};
|
|
1730
1836
|
const manifestPath = join(marketplace, ".agents", "plugins", "marketplace.json");
|
|
1731
1837
|
await mkdir(dirname(manifestPath), { recursive: true, mode: 0o700 });
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1838
|
+
const temporary = `${manifestPath}.${randomUUID()}.tmp`;
|
|
1839
|
+
try {
|
|
1840
|
+
await writeFile(temporary, MARKETPLACE_MANIFEST, {
|
|
1841
|
+
encoding: "utf8",
|
|
1842
|
+
flag: "wx",
|
|
1843
|
+
mode: 0o600,
|
|
1844
|
+
signal,
|
|
1845
|
+
});
|
|
1846
|
+
throwIfSignalAborted(signal);
|
|
1847
|
+
try {
|
|
1848
|
+
await rename(temporary, manifestPath);
|
|
1849
|
+
}
|
|
1850
|
+
catch (error) {
|
|
1851
|
+
// Concurrent replacement can fail on Windows after another repair wins.
|
|
1852
|
+
const published = await readFile(manifestPath, "utf8").catch(() => null);
|
|
1853
|
+
if (published !== MARKETPLACE_MANIFEST)
|
|
1854
|
+
throw error;
|
|
1855
|
+
}
|
|
1856
|
+
throwIfSignalAborted(signal);
|
|
1857
|
+
}
|
|
1858
|
+
finally {
|
|
1859
|
+
await rm(temporary, { force: true });
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
async function pluginRuntimeProjection(root, signal) {
|
|
1863
|
+
const path = join(root, ".mcp.json");
|
|
1864
|
+
// Keep the source link checks ahead of any configuration read.
|
|
1865
|
+
if (!(await lstat(path).catch(nullIfMissingFileError))?.isFile())
|
|
1866
|
+
return;
|
|
1867
|
+
const configuration = JSON.parse(await readFile(path, { encoding: "utf8", signal }));
|
|
1868
|
+
const servers = isRecord(configuration)
|
|
1869
|
+
? configuration["mcpServers"]
|
|
1870
|
+
: undefined;
|
|
1871
|
+
const server = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;
|
|
1872
|
+
if (!isRecord(server) ||
|
|
1873
|
+
(server["command"] !== "./scripts/launch_codex_security_mcp" &&
|
|
1874
|
+
server["command"] !== "./scripts/launch_codex_security_mcp.cmd")) {
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
const environment = server["env_vars"];
|
|
1878
|
+
if (environment !== undefined && !Array.isArray(environment))
|
|
1879
|
+
return;
|
|
1880
|
+
if (!Array.isArray(environment) ||
|
|
1881
|
+
!environment.includes("CODEX_SECURITY_PLUGIN_ROOT")) {
|
|
1882
|
+
server["env_vars"] = [
|
|
1883
|
+
...(Array.isArray(environment) ? environment : []),
|
|
1884
|
+
"CODEX_SECURITY_PLUGIN_ROOT",
|
|
1885
|
+
];
|
|
1886
|
+
}
|
|
1887
|
+
const files = new Map();
|
|
1888
|
+
server["command"] =
|
|
1889
|
+
server["command"] === "./scripts/launch_codex_security_mcp.cmd"
|
|
1890
|
+
? "./scripts/launch_codex_security_mcp_sdk.cmd"
|
|
1891
|
+
: "./scripts/launch_codex_security_mcp_sdk";
|
|
1892
|
+
files.set("scripts/launch_codex_security_mcp_sdk", {
|
|
1893
|
+
contents: Buffer.from("#!/bin/sh\n" +
|
|
1894
|
+
'if [ -n "${CODEX_SECURITY_PLUGIN_ROOT:-}" ]; then\n' +
|
|
1895
|
+
' exec "$CODEX_SECURITY_PLUGIN_ROOT/scripts/launch_codex_security_mcp" "$@"\n' +
|
|
1896
|
+
"fi\n" +
|
|
1897
|
+
'exec "$(dirname "$0")/launch_codex_security_mcp" "$@"\n'),
|
|
1898
|
+
mode: 0o755,
|
|
1737
1899
|
});
|
|
1738
|
-
|
|
1739
|
-
|
|
1900
|
+
files.set("scripts/launch_codex_security_mcp_sdk.cmd", {
|
|
1901
|
+
contents: Buffer.from("@echo off\r\nsetlocal DisableDelayedExpansion\r\n" +
|
|
1902
|
+
"if not defined CODEX_SECURITY_PLUGIN_ROOT goto codex_security_sdk_original\r\n" +
|
|
1903
|
+
'"%CODEX_SECURITY_PLUGIN_ROOT%\\scripts\\launch_codex_security_mcp.cmd" %*\r\n' +
|
|
1904
|
+
"exit /b\r\n:codex_security_sdk_original\r\n" +
|
|
1905
|
+
'"%~dp0launch_codex_security_mcp.cmd" %*\r\n'),
|
|
1906
|
+
mode: 0o755,
|
|
1907
|
+
});
|
|
1908
|
+
files.set(".mcp.json", {
|
|
1909
|
+
contents: Buffer.from(`${JSON.stringify(configuration, null, 2)}\n`),
|
|
1910
|
+
});
|
|
1911
|
+
return { root, files };
|
|
1740
1912
|
}
|
|
1741
1913
|
export function resolveCodexCommand(environment = process.env) {
|
|
1742
1914
|
const configured = environmentValue(environment, "CODEX_CLI_PATH");
|
|
1743
|
-
const expanded = configured === undefined
|
|
1915
|
+
const expanded = configured === undefined
|
|
1916
|
+
? undefined
|
|
1917
|
+
: expandExecutableHome(configured, environment);
|
|
1744
1918
|
if (expanded &&
|
|
1745
1919
|
(process.platform !== "win32" || /\.(?:exe|com)$/iu.test(expanded))) {
|
|
1746
|
-
return {
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
const codexPackageJson = require.resolve("@openai/codex/package.json");
|
|
1754
|
-
packageJson = createRequire(codexPackageJson).resolve(`${packageName}/package.json`);
|
|
1755
|
-
}
|
|
1756
|
-
catch (error) {
|
|
1757
|
-
throw new PluginBootstrapError(`The bundled Codex executable could not be resolved from ${packageName}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`, { cause: error });
|
|
1758
|
-
}
|
|
1759
|
-
const vendor = join(dirname(packageJson), "vendor");
|
|
1760
|
-
const target = readdirSync(vendor, { withFileTypes: true }).find((entry) => entry.isDirectory());
|
|
1761
|
-
const command = join(vendor, target?.name ?? "", "bin", process.platform === "win32" ? "codex.exe" : "codex");
|
|
1762
|
-
if (target === undefined || !existsSync(command)) {
|
|
1763
|
-
throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`);
|
|
1920
|
+
return {
|
|
1921
|
+
command: process.platform === "win32"
|
|
1922
|
+
? resolve(expanded)
|
|
1923
|
+
: isAbsolute(expanded)
|
|
1924
|
+
? expanded
|
|
1925
|
+
: `${process.cwd()}${sep}${expanded}`,
|
|
1926
|
+
};
|
|
1764
1927
|
}
|
|
1765
|
-
return { command };
|
|
1928
|
+
return { command: resolveBundledCodexExecutable() };
|
|
1766
1929
|
}
|
|
1767
|
-
export function
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1930
|
+
export async function codexExecutableReadPaths(command) {
|
|
1931
|
+
const executable = await realpath(command);
|
|
1932
|
+
const packageJson = resolve(dirname(executable), "..", "package.json");
|
|
1933
|
+
try {
|
|
1934
|
+
const metadata = JSON.parse(await readFile(packageJson, "utf8"));
|
|
1935
|
+
if (metadata?.name !== "@openai/codex" ||
|
|
1936
|
+
typeof metadata.bin?.codex !== "string")
|
|
1937
|
+
return [executable];
|
|
1938
|
+
const launcher = await realpath(resolve(dirname(packageJson), metadata.bin.codex));
|
|
1939
|
+
if (launcher !== executable)
|
|
1940
|
+
return [executable];
|
|
1941
|
+
}
|
|
1942
|
+
catch {
|
|
1943
|
+
// A custom executable need not belong to a readable, valid npm package.
|
|
1944
|
+
return [executable];
|
|
1945
|
+
}
|
|
1946
|
+
// npm's entrypoint launches a native binary, which Linux re-executes in the sandbox.
|
|
1947
|
+
return [
|
|
1948
|
+
executable,
|
|
1949
|
+
await realpath(resolveBundledCodexExecutable(packageJson)),
|
|
1950
|
+
];
|
|
1775
1951
|
}
|
|
1776
1952
|
export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
1777
1953
|
const root = await realpath(pluginRoot);
|
|
1778
1954
|
const { name, version } = await pluginMetadata(root);
|
|
1955
|
+
const projection = await pluginRuntimeProjection(root, options.signal).catch((error) => {
|
|
1956
|
+
if (options.signal?.aborted)
|
|
1957
|
+
throw error;
|
|
1958
|
+
throw new LocalPluginBootstrapError(errorMessage(error), {
|
|
1959
|
+
cause: error,
|
|
1960
|
+
});
|
|
1961
|
+
});
|
|
1779
1962
|
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1780
1963
|
throwIfSignalAborted(options.signal);
|
|
1781
1964
|
const command = options.codexCommand ?? resolveCodexCommand(options.environment);
|
|
@@ -1786,20 +1969,23 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1786
1969
|
const run = options.runCodex ?? runPluginCommand;
|
|
1787
1970
|
const existing = await lstat(marketplace).catch(nullIfMissingFileError);
|
|
1788
1971
|
if (existing !== null && !existing.isDirectory()) {
|
|
1789
|
-
throw new
|
|
1972
|
+
throw new LocalPluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
|
|
1790
1973
|
}
|
|
1791
1974
|
const staged = existing === null
|
|
1792
1975
|
? null
|
|
1793
1976
|
: await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
|
|
1794
1977
|
const stagedRoot = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1795
1978
|
const stagedMatches = staged?.version === version &&
|
|
1796
|
-
(await pluginContentsMatch(root, stagedRoot, options.signal));
|
|
1979
|
+
(await pluginContentsMatch(root, stagedRoot, options.signal, false, projection));
|
|
1797
1980
|
if (!stagedMatches) {
|
|
1798
1981
|
if (existing !== null) {
|
|
1799
1982
|
await rm(marketplace, { recursive: true, force: true });
|
|
1800
1983
|
}
|
|
1801
1984
|
await createMarketplace(codexHome, root, options.signal);
|
|
1802
1985
|
}
|
|
1986
|
+
else if ((await readFile(join(marketplace, ".agents", "plugins", "marketplace.json"), "utf8").catch(nullIfMissingFileError)) !== MARKETPLACE_MANIFEST) {
|
|
1987
|
+
await writeMarketplaceManifest(marketplace, options.signal);
|
|
1988
|
+
}
|
|
1803
1989
|
const config = await readFile(join(codexHome, "config.toml"), "utf8").catch((error) => {
|
|
1804
1990
|
if (nodeErrorCode(error) === "ENOENT")
|
|
1805
1991
|
return "";
|
|
@@ -1839,7 +2025,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1839
2025
|
isRecord(previous) &&
|
|
1840
2026
|
typeof previous["installedPath"] === "string" &&
|
|
1841
2027
|
previous["version"] === version &&
|
|
1842
|
-
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true))) {
|
|
2028
|
+
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true, projection))) {
|
|
1843
2029
|
return {
|
|
1844
2030
|
pluginRoot: root,
|
|
1845
2031
|
marketplaceRoot: marketplace,
|
|
@@ -1875,7 +2061,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1875
2061
|
version,
|
|
1876
2062
|
};
|
|
1877
2063
|
}
|
|
1878
|
-
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false) {
|
|
2064
|
+
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false, projection) {
|
|
1879
2065
|
throwIfSignalAborted(signal);
|
|
1880
2066
|
const sourceMetadata = await lstat(source);
|
|
1881
2067
|
const destinationMetadata = await lstat(destination).catch((error) => {
|
|
@@ -1887,26 +2073,44 @@ async function pluginContentsMatch(source, destination, signal, allowExtraFiles
|
|
|
1887
2073
|
if (destinationMetadata === null)
|
|
1888
2074
|
return false;
|
|
1889
2075
|
if (sourceMetadata.isFile() && destinationMetadata.isFile()) {
|
|
1890
|
-
|
|
1891
|
-
|
|
2076
|
+
const projected = projection?.files.get(relative(projection.root, source).split(sep).join("/"));
|
|
2077
|
+
if ((projected === undefined &&
|
|
2078
|
+
sourceMetadata.size !== destinationMetadata.size) ||
|
|
2079
|
+
((projected?.mode === undefined || process.platform !== "win32") &&
|
|
2080
|
+
((projected?.mode ?? sourceMetadata.mode) & 0o111) !==
|
|
2081
|
+
(destinationMetadata.mode & 0o111))) {
|
|
1892
2082
|
return false;
|
|
1893
2083
|
}
|
|
1894
2084
|
const [sourceBytes, destinationBytes] = await Promise.all([
|
|
1895
2085
|
readFile(source, { signal }),
|
|
1896
2086
|
readFile(destination, { signal }),
|
|
1897
2087
|
]);
|
|
1898
|
-
return sourceBytes.equals(destinationBytes);
|
|
2088
|
+
return (projected?.contents ?? sourceBytes).equals(destinationBytes);
|
|
1899
2089
|
}
|
|
1900
2090
|
if (!sourceMetadata.isDirectory() || !destinationMetadata.isDirectory()) {
|
|
1901
2091
|
return false;
|
|
1902
2092
|
}
|
|
1903
2093
|
const entries = await readdir(source);
|
|
2094
|
+
const projectedDirectory = projection === undefined
|
|
2095
|
+
? undefined
|
|
2096
|
+
: relative(projection.root, source).split(sep).join("/") || ".";
|
|
2097
|
+
const generated = [...(projection?.files ?? [])].filter(([path]) => dirname(path) === projectedDirectory && !entries.includes(basename(path)));
|
|
1904
2098
|
if (!allowExtraFiles &&
|
|
1905
|
-
entries.length !== (await readdir(destination)).length) {
|
|
2099
|
+
entries.length + generated.length !== (await readdir(destination)).length) {
|
|
1906
2100
|
return false;
|
|
1907
2101
|
}
|
|
2102
|
+
for (const [path, file] of generated) {
|
|
2103
|
+
const generatedPath = join(destination, basename(path));
|
|
2104
|
+
const metadata = await lstat(generatedPath).catch(nullIfMissingFileError);
|
|
2105
|
+
if (!metadata?.isFile() ||
|
|
2106
|
+
(process.platform !== "win32" &&
|
|
2107
|
+
(metadata.mode & 0o111) !== ((file.mode ?? 0o644) & 0o111)) ||
|
|
2108
|
+
!file.contents.equals(await readFile(generatedPath, { signal }))) {
|
|
2109
|
+
return false;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
1908
2112
|
for (const entry of entries) {
|
|
1909
|
-
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles))) {
|
|
2113
|
+
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles, projection))) {
|
|
1910
2114
|
return false;
|
|
1911
2115
|
}
|
|
1912
2116
|
}
|
|
@@ -1922,32 +2126,50 @@ export async function pluginMetadata(root) {
|
|
|
1922
2126
|
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1923
2127
|
}
|
|
1924
2128
|
catch (error) {
|
|
1925
|
-
throw new
|
|
2129
|
+
throw new LocalPluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
|
|
1926
2130
|
cause: error,
|
|
1927
2131
|
});
|
|
1928
2132
|
}
|
|
1929
2133
|
if (!isRecord(manifest) || manifest["name"] !== PLUGIN_NAME) {
|
|
1930
|
-
throw new
|
|
2134
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have name 'codex-security'.");
|
|
1931
2135
|
}
|
|
1932
2136
|
const version = manifest["version"];
|
|
1933
2137
|
if (typeof version !== "string" || version.trim().length === 0) {
|
|
1934
|
-
throw new
|
|
2138
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have a non-empty version.");
|
|
1935
2139
|
}
|
|
1936
2140
|
return { name: PLUGIN_NAME, version };
|
|
1937
2141
|
}
|
|
1938
2142
|
export async function resolvePluginPython(options = {}) {
|
|
1939
2143
|
const environment = options.environment ?? process.env;
|
|
1940
|
-
const
|
|
2144
|
+
const requestedRoots = options.protectedRoot ?? process.cwd();
|
|
2145
|
+
const protectedRoot = typeof requestedRoots === "string" ? [requestedRoots] : [...requestedRoots];
|
|
2146
|
+
const callerDirectories = [
|
|
2147
|
+
process.cwd(),
|
|
2148
|
+
options.currentDirectory ?? process.cwd(),
|
|
2149
|
+
];
|
|
2150
|
+
// Preserve target and enclosing-checkout protection for every interpreter.
|
|
2151
|
+
for (const directory of new Set([...callerDirectories, ...protectedRoot])) {
|
|
2152
|
+
for (const checkout of await gitProtectionRoots(directory, options.signal))
|
|
2153
|
+
if (!protectedRoot.includes(checkout))
|
|
2154
|
+
protectedRoot.push(checkout);
|
|
2155
|
+
}
|
|
2156
|
+
// Named interpreters are ambient PATH discovery, even when PYTHON names one.
|
|
2157
|
+
// Explicit trusted paths and managed runtimes retain their existing precedence.
|
|
2158
|
+
const discoveryRoots = [...protectedRoot, ...callerDirectories];
|
|
1941
2159
|
if (options.configuredPath !== undefined) {
|
|
1942
|
-
return await requirePython(options.configuredPath, "configured plugin Python", environment,
|
|
2160
|
+
return await requirePython(options.configuredPath, "configured plugin Python", environment, isPythonPathCandidate(options.configuredPath)
|
|
2161
|
+
? protectedRoot
|
|
2162
|
+
: discoveryRoots, options.signal);
|
|
1943
2163
|
}
|
|
1944
2164
|
const inherited = environmentValue(environment, "PYTHON");
|
|
1945
2165
|
if (inherited) {
|
|
1946
|
-
return await requirePython(inherited, "PYTHON", environment, protectedRoot, options.signal);
|
|
2166
|
+
return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
|
|
1947
2167
|
}
|
|
1948
2168
|
const home = options.homeDirectory ?? homedir();
|
|
2169
|
+
const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2170
|
+
join(home, ".cache");
|
|
1949
2171
|
const managedRoots = options.managedRuntimeRoots ?? [
|
|
1950
|
-
join(
|
|
2172
|
+
join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
|
|
1951
2173
|
];
|
|
1952
2174
|
const relativeCandidates = process.platform === "win32"
|
|
1953
2175
|
? [
|
|
@@ -1970,7 +2192,7 @@ export async function resolvePluginPython(options = {}) {
|
|
|
1970
2192
|
for (const candidate of process.platform === "win32"
|
|
1971
2193
|
? ["python", "python3", "py"]
|
|
1972
2194
|
: ["python3", "python"]) {
|
|
1973
|
-
const resolved = await usablePython(candidate, environment,
|
|
2195
|
+
const resolved = await usablePython(candidate, environment, discoveryRoots, options.signal);
|
|
1974
2196
|
if (resolved !== null)
|
|
1975
2197
|
return resolved;
|
|
1976
2198
|
}
|
|
@@ -1981,6 +2203,7 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
|
1981
2203
|
return {
|
|
1982
2204
|
...pythonUtf8Environment(environment),
|
|
1983
2205
|
PYTHON: python,
|
|
2206
|
+
CODEX_SECURITY_PYTHON_COMMAND: python,
|
|
1984
2207
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1985
2208
|
};
|
|
1986
2209
|
}
|
|
@@ -2013,12 +2236,15 @@ function pluginHelperEnvironment(environment) {
|
|
|
2013
2236
|
export async function cleanupSdkDirectory(path) {
|
|
2014
2237
|
await rm(path, { recursive: true, force: true });
|
|
2015
2238
|
}
|
|
2016
|
-
export async function runCodexCommand(command, args, environment, input, signal) {
|
|
2017
|
-
const
|
|
2239
|
+
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2240
|
+
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2241
|
+
const abort = () => cancellation?.abort(signal?.reason);
|
|
2242
|
+
let awaitingArchive = archiveHandshake;
|
|
2243
|
+
const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
|
|
2018
2244
|
env: environment,
|
|
2019
2245
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2020
2246
|
windowsHide: true,
|
|
2021
|
-
signal,
|
|
2247
|
+
signal: cancellation?.signal ?? signal,
|
|
2022
2248
|
});
|
|
2023
2249
|
let stdout = "";
|
|
2024
2250
|
let stderr = "";
|
|
@@ -2027,6 +2253,17 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
2027
2253
|
child.stderr.setEncoding("utf8");
|
|
2028
2254
|
child.stdout.on("data", (chunk) => {
|
|
2029
2255
|
stdout += chunk;
|
|
2256
|
+
if (awaitingArchive && stdout.startsWith(ARCHIVE_READY)) {
|
|
2257
|
+
awaitingArchive = false;
|
|
2258
|
+
stdout = stdout.slice(ARCHIVE_READY.length);
|
|
2259
|
+
signal?.removeEventListener("abort", abort);
|
|
2260
|
+
// The helper cannot rename until this acknowledgement. Detach and check
|
|
2261
|
+
// cancellation before allowing the filesystem/database transaction.
|
|
2262
|
+
if (signal?.aborted)
|
|
2263
|
+
abort();
|
|
2264
|
+
else
|
|
2265
|
+
child.stdin.end("\n");
|
|
2266
|
+
}
|
|
2030
2267
|
});
|
|
2031
2268
|
child.stderr.on("data", (chunk) => {
|
|
2032
2269
|
stderr += chunk;
|
|
@@ -2043,8 +2280,24 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
2043
2280
|
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
2044
2281
|
: reject(processError));
|
|
2045
2282
|
});
|
|
2046
|
-
|
|
2047
|
-
|
|
2283
|
+
if (archiveHandshake) {
|
|
2284
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2285
|
+
if (signal?.aborted)
|
|
2286
|
+
abort();
|
|
2287
|
+
}
|
|
2288
|
+
try {
|
|
2289
|
+
if (stdinPrefix !== undefined)
|
|
2290
|
+
child.stdin.write(stdinPrefix);
|
|
2291
|
+
if (archiveHandshake)
|
|
2292
|
+
child.stdin.write(`${JSON.stringify(input ?? "")}\n`);
|
|
2293
|
+
else
|
|
2294
|
+
child.stdin.end(input);
|
|
2295
|
+
return await completion;
|
|
2296
|
+
}
|
|
2297
|
+
finally {
|
|
2298
|
+
if (archiveHandshake)
|
|
2299
|
+
signal?.removeEventListener("abort", abort);
|
|
2300
|
+
}
|
|
2048
2301
|
}
|
|
2049
2302
|
export async function probeCodexSandbox(command, environment, signal) {
|
|
2050
2303
|
// This preflight covers the Unix sandbox backends.
|
|
@@ -2163,7 +2416,7 @@ async function requirePython(candidate, source, environment, protectedRoot, sign
|
|
|
2163
2416
|
}
|
|
2164
2417
|
async function usablePython(candidate, environment = process.env, protectedRoot = process.cwd(), signal) {
|
|
2165
2418
|
const command = await resolveTrustedExecutable(isPythonPathCandidate(candidate)
|
|
2166
|
-
?
|
|
2419
|
+
? expandExecutableHome(candidate, environment)
|
|
2167
2420
|
: candidate, environment, protectedRoot);
|
|
2168
2421
|
if (command === null)
|
|
2169
2422
|
return null;
|
|
@@ -2190,14 +2443,13 @@ async function usablePython(candidate, environment = process.env, protectedRoot
|
|
|
2190
2443
|
}
|
|
2191
2444
|
}
|
|
2192
2445
|
export function isPythonPathCandidate(candidate) {
|
|
2193
|
-
return
|
|
2194
|
-
candidate.includes("\\") ||
|
|
2195
|
-
candidate.startsWith("."));
|
|
2446
|
+
return candidate.includes("/") || candidate.includes("\\");
|
|
2196
2447
|
}
|
|
2197
2448
|
async function hasPluginManifest(root) {
|
|
2198
2449
|
return await lstat(join(root, ".codex-plugin", "plugin.json")).then((metadata) => metadata.isFile(), () => false);
|
|
2199
2450
|
}
|
|
2200
|
-
|
|
2451
|
+
/** @internal Compare filesystem identity without depending on path spelling. */
|
|
2452
|
+
export function sameFile(left, right) {
|
|
2201
2453
|
// NTFS file IDs can exceed JavaScript's safe integer range.
|
|
2202
2454
|
return Promise.all([
|
|
2203
2455
|
stat(left, { bigint: true }),
|
|
@@ -2205,6 +2457,13 @@ function sameFile(left, right) {
|
|
|
2205
2457
|
]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
|
|
2206
2458
|
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2207
2459
|
}
|
|
2460
|
+
function expandExecutableHome(value, environment) {
|
|
2461
|
+
const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
|
|
2462
|
+
// Expand only the home prefix; joining the suffix would collapse symlink/.. paths.
|
|
2463
|
+
return path.startsWith("~/")
|
|
2464
|
+
? `${expandHome("~", environment)}${sep}${path.slice(2)}`
|
|
2465
|
+
: expandHome(path, environment);
|
|
2466
|
+
}
|
|
2208
2467
|
export function expandHome(value, environment = process.env) {
|
|
2209
2468
|
const home = (process.platform === "win32"
|
|
2210
2469
|
? (environmentValue(environment, "USERPROFILE") ??
|