@openai/codex-security 0.1.31 → 0.3.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 +442 -2434
- package/_bundled_plugin/.app.json +5 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
- package/_bundled_plugin/.mcp.json +3 -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 +7 -214
- 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 +563 -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 +5 -5
- package/_bundled_plugin/references/config-preflight.md +1 -5
- package/_bundled_plugin/references/core-scan.md +34 -10
- package/_bundled_plugin/references/final-report.md +13 -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 +3 -4
- package/_bundled_plugin/references/scan-contract.md +11 -6
- 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 +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +23 -47
- 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 +71 -192
- package/_bundled_plugin/schemas/scan-manifest.schema.json +83 -95
- 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 +245 -356
- 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 +29 -69
- package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
- package/_bundled_plugin/scripts/deep_scan_workbench.py +208 -363
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +733 -375
- package/_bundled_plugin/scripts/finding_preview.py +81 -91
- package/_bundled_plugin/scripts/generate_in_scope_files.py +48 -102
- package/_bundled_plugin/scripts/generate_rank_input.py +117 -888
- package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -6
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
- package/_bundled_plugin/scripts/rank_preview.py +43 -902
- package/_bundled_plugin/scripts/report_projection.py +143 -219
- package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
- package/_bundled_plugin/scripts/threat_model_projection.py +161 -0
- 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 +59 -9
- 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 +21 -6
- package/_bundled_plugin/scripts/workbench_cli.py +99 -190
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +524 -672
- package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
- package/_bundled_plugin/scripts/workbench_finding_index.py +20 -7
- 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 +28 -18
- package/_bundled_plugin/scripts/workbench_progress.py +26 -92
- package/_bundled_plugin/scripts/workbench_publication.py +77 -116
- package/_bundled_plugin/scripts/workbench_remediation.py +14 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1402 -263
- package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
- package/_bundled_plugin/scripts/workbench_scan_start.py +109 -52
- package/_bundled_plugin/scripts/workbench_scan_usage.py +30 -49
- package/_bundled_plugin/scripts/workbench_schema.py +71 -1370
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +16 -7
- package/_bundled_plugin/scripts/workbench_target.py +526 -150
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +19 -44
- package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
- package/_bundled_plugin/shared/workbench-migrations.json +397 -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 +6 -6
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
- 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-diff-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
- 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 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +970 -553
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +292 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts +2 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -12
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +9 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +28 -17
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +16 -35
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +285 -0
- package/dist/cli-help.js.map +1 -0
- 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 +22 -24
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1660 -1556
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +11 -17
- 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-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +3 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +68 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts +2 -5
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +38 -34
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +7 -5
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +54 -44
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +93 -104
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +15 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +124 -348
- 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 +75 -34
- 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 +116 -134
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +7 -6
- 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 +23 -16
- 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 +33 -20
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +9 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +129 -20
- 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 +26 -4
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +59 -47
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +59 -113
- 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.map +1 -1
- package/dist/deduplication/records-protocol.js +12 -28
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +188 -12
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +34 -24
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.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 +159 -44
- 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 +7 -23
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +2 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +32 -47
- 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 +5 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- package/dist/errors.js.map +1 -1
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +53 -21
- package/dist/feedback.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +26 -30
- 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 +18 -13
- 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 +16 -44
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +9 -4
- package/dist/github.js.map +1 -1
- package/dist/import-scan.d.ts.map +1 -1
- package/dist/import-scan.js +49 -39
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +11 -5
- 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 +115 -47
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +4 -10
- 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 +24 -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 +225 -153
- 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 +69 -14
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +5 -6
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +5 -3
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.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 +40 -79
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +48 -76
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +1 -2
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +7 -16
- 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 +138 -199
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- 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/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +25 -17
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +619 -255
- 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 +16 -32
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +19 -30
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +31 -18
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +307 -347
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +3 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +351 -92
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +55 -15
- 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 +14 -12
- 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 +18 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.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 +15 -33
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +17 -9
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +131 -98
- 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 +11 -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 +55 -55
- 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 +20 -32
- 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 +6 -5
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +15 -10
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +12 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +124 -62
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.d.ts +6 -1
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +28 -9
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +27 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.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 +2 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +40 -46
- package/dist/worker-progress.js.map +1 -1
- package/docs/cli.md +1778 -0
- package/docs/dedupe-records.md +24 -0
- package/docs/findings-service.md +402 -0
- package/package.json +23 -23
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- 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 -119
- 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/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.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 -6
- package/dist/server/routes.d.ts.map +0 -1
- package/dist/server/routes.js +0 -86
- 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 -17
- 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,13 @@
|
|
|
1
|
+
import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
|
|
2
|
+
import { gitProtectionRoots } from "./targets.js";
|
|
3
|
+
import { isNonEmptyString, notify } from "./value.js";
|
|
1
4
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
5
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { chmodSync, constants, createWriteStream,
|
|
6
|
+
import { chmodSync, constants, createWriteStream, } from "node:fs";
|
|
4
7
|
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
5
8
|
import { homedir, tmpdir } from "node:os";
|
|
6
9
|
import { createRequire } from "node:module";
|
|
7
10
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, win32, } from "node:path";
|
|
8
|
-
import { createInterface } from "node:readline";
|
|
9
11
|
import { fileURLToPath } from "node:url";
|
|
10
12
|
import { promisify } from "node:util";
|
|
11
13
|
import { pipeline } from "node:stream/promises";
|
|
@@ -13,12 +15,25 @@ import { crc32 } from "node:zlib";
|
|
|
13
15
|
import { setTimeout as delay } from "node:timers/promises";
|
|
14
16
|
import { openPromise as openZip } from "yauzl";
|
|
15
17
|
import { parse } from "smol-toml";
|
|
16
|
-
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, errorMessage, } from "./errors.js";
|
|
17
|
-
import {
|
|
18
|
+
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
19
|
+
import { isRecord } from "./record.js";
|
|
20
|
+
import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
18
21
|
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
19
22
|
const execFile = promisify(execFileCallback);
|
|
20
23
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
21
24
|
export const PLUGIN_NAME = "codex-security";
|
|
25
|
+
const MARKETPLACE_MANIFEST = `${JSON.stringify({
|
|
26
|
+
name: MARKETPLACE_NAME,
|
|
27
|
+
interface: { displayName: "Codex Security SDK" },
|
|
28
|
+
plugins: [
|
|
29
|
+
{
|
|
30
|
+
name: PLUGIN_NAME,
|
|
31
|
+
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
32
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
33
|
+
category: "Security",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}, null, 2)}\n`;
|
|
22
37
|
const MAX_ZIP_ENTRIES = 4_096;
|
|
23
38
|
const MAX_ZIP_CENTRAL_DIRECTORY = 16 * 1024 * 1024;
|
|
24
39
|
const MAX_ZIP_ENTRY_SIZE = 128 * 1024 * 1024;
|
|
@@ -32,6 +47,7 @@ const CREDENTIAL_LOCK_POLL_MILLISECONDS = 25;
|
|
|
32
47
|
const INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS = 30_000;
|
|
33
48
|
const MAX_PROCESS_ID = 2_147_483_647;
|
|
34
49
|
const MAX_WINDOWS_CREDENTIAL_ACL_STDERR = 64 * 1024;
|
|
50
|
+
const SANDBOX_PROBE_TIMEOUT_MILLISECONDS = 10_000;
|
|
35
51
|
const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
|
|
36
52
|
"OPENAI_API_KEY",
|
|
37
53
|
"CODEX_API_KEY",
|
|
@@ -70,19 +86,18 @@ except (module["ContractError"], OSError) as error:
|
|
|
70
86
|
`.trim();
|
|
71
87
|
const WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX = "CODEX_SECURITY_ACL_COMPLETE:";
|
|
72
88
|
const WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE = 2;
|
|
73
|
-
function environmentValue(environment, requested) {
|
|
74
|
-
const exact = environment[requested]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
?.trim();
|
|
89
|
+
function environmentValue(environment, requested, preserveWhitespace = false) {
|
|
90
|
+
const exact = environment[requested];
|
|
91
|
+
const value = exact?.trim()
|
|
92
|
+
? exact
|
|
93
|
+
: Object.entries(environment).find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1];
|
|
94
|
+
return preserveWhitespace ? value : value?.trim();
|
|
80
95
|
}
|
|
81
96
|
export function codexSecurityStateDirectory(environment = process.env) {
|
|
82
97
|
const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
|
|
83
98
|
const path = configured !== undefined
|
|
84
99
|
? resolve(expandHome(configured, environment))
|
|
85
|
-
: resolve(expandHome(environmentValue(environment, "CODEX_HOME") ??
|
|
100
|
+
: resolve(expandHome(environmentValue(environment, "CODEX_HOME", true) ??
|
|
86
101
|
join(homedir(), ".codex"), environment), "state", "plugins", "codex-security");
|
|
87
102
|
requireModelSafeOutputDir(path);
|
|
88
103
|
return path;
|
|
@@ -98,9 +113,7 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
|
|
|
98
113
|
}
|
|
99
114
|
catch (error) {
|
|
100
115
|
if (nodeErrorCode(error) === "EEXIST") {
|
|
101
|
-
|
|
102
|
-
if (existing !== null &&
|
|
103
|
-
(!existing.isDirectory() || existing.isSymbolicLink())) {
|
|
116
|
+
if ((await lstat(path).catch(() => null))?.isDirectory() === false) {
|
|
104
117
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`, { cause: error });
|
|
105
118
|
}
|
|
106
119
|
}
|
|
@@ -109,7 +122,7 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
|
|
|
109
122
|
if ((process.umask() & 0o700) !== 0)
|
|
110
123
|
await chmod(path, 0o700);
|
|
111
124
|
const metadata = await lstat(path, { bigint: true });
|
|
112
|
-
if (!metadata.isDirectory()
|
|
125
|
+
if (!metadata.isDirectory()) {
|
|
113
126
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`);
|
|
114
127
|
}
|
|
115
128
|
const canonical = await realpath(path);
|
|
@@ -156,7 +169,7 @@ export async function requireSecureCredentialHome(path, options = {}) {
|
|
|
156
169
|
throw new OutputDirectoryError(`Codex Security credential home was replaced: ${canonical}`);
|
|
157
170
|
}
|
|
158
171
|
metadata = canonicalMetadata;
|
|
159
|
-
if (!metadata.isDirectory()
|
|
172
|
+
if (!metadata.isDirectory()) {
|
|
160
173
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`);
|
|
161
174
|
}
|
|
162
175
|
if (options.expectedDevice !== undefined &&
|
|
@@ -201,9 +214,7 @@ function windowsCredentialAclFailure(error) {
|
|
|
201
214
|
: undefined;
|
|
202
215
|
const detail = typeof stderr === "string" && stderr.trim() !== ""
|
|
203
216
|
? stderr
|
|
204
|
-
: error
|
|
205
|
-
? error.message
|
|
206
|
-
: String(error);
|
|
217
|
+
: errorMessage(error);
|
|
207
218
|
const normalized = errorMessage(detail)
|
|
208
219
|
.replace(/\s+/gu, " ")
|
|
209
220
|
.trim()
|
|
@@ -441,10 +452,10 @@ function windowsAceAllowsAncestorReplacement(rights, inheritanceFlags) {
|
|
|
441
452
|
if (/^0x[\da-f]+$/iu.test(rights)) {
|
|
442
453
|
return (BigInt(rights) & 0x100d0040n) !== 0n;
|
|
443
454
|
}
|
|
444
|
-
|
|
445
|
-
|
|
455
|
+
// Rights tokens stay aligned to pairs of UTF-16 code units.
|
|
456
|
+
for (const [right] of rights.matchAll(/[\s\S]{2}/g)) {
|
|
457
|
+
if (["FA", "GA", "FW", "GW", "SD", "WD", "WO", "DC", "DT"].includes(right))
|
|
446
458
|
return true;
|
|
447
|
-
}
|
|
448
459
|
}
|
|
449
460
|
return false;
|
|
450
461
|
}
|
|
@@ -478,20 +489,25 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
478
489
|
reject(Object.assign(new Error(`Windows credential ACL inspection failed with ${reason}`), { code, signal, stderr }));
|
|
479
490
|
});
|
|
480
491
|
});
|
|
481
|
-
let descriptors = 0;
|
|
482
492
|
try {
|
|
483
493
|
await Promise.all([
|
|
484
494
|
completion,
|
|
485
495
|
(async () => {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
for await (const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
496
|
+
// Consume chunks directly: readline can resume its queued-line
|
|
497
|
+
// iterator after EOF and throw instead of draining the last lines.
|
|
498
|
+
child.stdout.setEncoding("utf8");
|
|
499
|
+
let pending = "";
|
|
500
|
+
for await (const chunk of child.stdout) {
|
|
501
|
+
const lines = (pending + chunk).split(/[\r\n]/u);
|
|
502
|
+
pending = lines.pop();
|
|
503
|
+
for (const descriptor of lines) {
|
|
504
|
+
if (descriptor === "")
|
|
505
|
+
continue;
|
|
506
|
+
await inspectDescriptor(descriptor);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (pending !== "") {
|
|
510
|
+
await inspectDescriptor(pending);
|
|
495
511
|
}
|
|
496
512
|
})(),
|
|
497
513
|
]);
|
|
@@ -505,7 +521,6 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
505
521
|
// Finish descriptor callbacks before allowing another snapshot attempt.
|
|
506
522
|
throw new WindowsCredentialDescendantsChangedError("Windows credential descendants changed during ACL inspection");
|
|
507
523
|
}
|
|
508
|
-
return descriptors;
|
|
509
524
|
}
|
|
510
525
|
export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
|
|
511
526
|
let ancestors = 0;
|
|
@@ -775,6 +790,15 @@ async function secureWindowsCredentialHome(path) {
|
|
|
775
790
|
}
|
|
776
791
|
}
|
|
777
792
|
}
|
|
793
|
+
export async function withCredentialHomeLock(codexHome, operation, signal) {
|
|
794
|
+
const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
|
|
795
|
+
try {
|
|
796
|
+
return await operation();
|
|
797
|
+
}
|
|
798
|
+
finally {
|
|
799
|
+
await release();
|
|
800
|
+
}
|
|
801
|
+
}
|
|
778
802
|
export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal, securityOptions = {}) {
|
|
779
803
|
throwIfSignalAborted(signal);
|
|
780
804
|
const homeMetadata = await requireSecureCredentialHome(codexHome, securityOptions);
|
|
@@ -784,11 +808,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
784
808
|
const ownerPath = join(lock, "owner.json");
|
|
785
809
|
const token = randomUUID();
|
|
786
810
|
const databasePath = join(codexHome, CREDENTIAL_LOCK_DATABASE);
|
|
787
|
-
const existingDatabaseMetadata = await lstat(databasePath).catch(
|
|
788
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
789
|
-
return null;
|
|
790
|
-
throw error;
|
|
791
|
-
});
|
|
811
|
+
const existingDatabaseMetadata = await lstat(databasePath).catch(nullIfMissingFileError);
|
|
792
812
|
if (existingDatabaseMetadata !== null) {
|
|
793
813
|
requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
|
|
794
814
|
}
|
|
@@ -847,12 +867,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
847
867
|
}
|
|
848
868
|
databaseLocked = true;
|
|
849
869
|
}
|
|
850
|
-
|
|
851
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
852
|
-
return null;
|
|
853
|
-
throw error;
|
|
854
|
-
});
|
|
855
|
-
if (existingLock !== null) {
|
|
870
|
+
if ((await lstat(lock).catch(nullIfMissingFileError)) !== null) {
|
|
856
871
|
if (await recoverStaleCredentialHomeLock(lock))
|
|
857
872
|
continue;
|
|
858
873
|
await delay(CREDENTIAL_LOCK_POLL_MILLISECONDS, undefined, { signal });
|
|
@@ -925,14 +940,10 @@ function requireCredentialLockDatabaseFile(metadata, path) {
|
|
|
925
940
|
}
|
|
926
941
|
}
|
|
927
942
|
async function recoverStaleCredentialHomeLock(lock) {
|
|
928
|
-
const metadata = await lstat(lock).catch(
|
|
929
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
930
|
-
return null;
|
|
931
|
-
throw error;
|
|
932
|
-
});
|
|
943
|
+
const metadata = await lstat(lock).catch(nullIfMissingFileError);
|
|
933
944
|
if (metadata === null)
|
|
934
945
|
return true;
|
|
935
|
-
if (!metadata.isDirectory()
|
|
946
|
+
if (!metadata.isDirectory()) {
|
|
936
947
|
throw new OutputDirectoryError(`Codex Security credential-home lock is not a directory: ${lock}`);
|
|
937
948
|
}
|
|
938
949
|
let owner;
|
|
@@ -1009,8 +1020,7 @@ export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
|
|
|
1009
1020
|
export async function codexSecurityCredentialAllowsAmbientImport(codexHome) {
|
|
1010
1021
|
await requireSecureCredentialHome(codexHome);
|
|
1011
1022
|
try {
|
|
1012
|
-
|
|
1013
|
-
if (!marker.isFile() || marker.isSymbolicLink()) {
|
|
1023
|
+
if (!(await lstat(join(codexHome, CREDENTIAL_LOGOUT_MARKER))).isFile()) {
|
|
1014
1024
|
throw new OutputDirectoryError(`Codex Security logout marker is not a regular file: ${codexHome}`);
|
|
1015
1025
|
}
|
|
1016
1026
|
return false;
|
|
@@ -1033,7 +1043,7 @@ export async function codexSecurityHasStoredFileCredentials(codexHome) {
|
|
|
1033
1043
|
return false;
|
|
1034
1044
|
throw error;
|
|
1035
1045
|
}
|
|
1036
|
-
if (!metadata.isFile()
|
|
1046
|
+
if (!metadata.isFile()) {
|
|
1037
1047
|
throw new OutputDirectoryError(`Codex Security stored authentication is not a regular file: ${path}`);
|
|
1038
1048
|
}
|
|
1039
1049
|
requirePrivateCredentialFile(metadata, path);
|
|
@@ -1089,16 +1099,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
|
|
|
1089
1099
|
};
|
|
1090
1100
|
}
|
|
1091
1101
|
export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
if (outputRelative === "" ||
|
|
1095
|
-
(outputRelative !== ".." &&
|
|
1096
|
-
!outputRelative.startsWith(`..${sep}`) &&
|
|
1097
|
-
!isAbsolute(outputRelative)) ||
|
|
1098
|
-
(pathKind === "output" &&
|
|
1099
|
-
repositoryRelative !== ".." &&
|
|
1100
|
-
!repositoryRelative.startsWith(`..${sep}`) &&
|
|
1101
|
-
!isAbsolute(repositoryRelative))) {
|
|
1102
|
+
if (isWithin(repository, outputDirectory) ||
|
|
1103
|
+
(pathKind === "output" && isWithin(outputDirectory, repository))) {
|
|
1102
1104
|
throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
|
|
1103
1105
|
}
|
|
1104
1106
|
}
|
|
@@ -1119,11 +1121,125 @@ export async function preparePersistentOutputRoot(stateDirectory, category, repo
|
|
|
1119
1121
|
}
|
|
1120
1122
|
return root;
|
|
1121
1123
|
}
|
|
1122
|
-
const
|
|
1124
|
+
const WORKBENCH_ARGUMENTS_PROGRAM = String.raw `
|
|
1125
|
+
import json, sys
|
|
1126
|
+
sys.argv[2:] = json.loads(sys.stdin.buffer.readline())
|
|
1127
|
+
`;
|
|
1128
|
+
const WORKBENCH_SCRIPT_PROGRAM = String.raw `
|
|
1129
|
+
import runpy, sys
|
|
1130
|
+
sys.argv = sys.argv[1:]
|
|
1131
|
+
runpy.run_path(sys.argv[0], run_name="__main__")
|
|
1132
|
+
`;
|
|
1133
|
+
const ARCHIVE_READY = "codex-security-archive-ready\n";
|
|
1134
|
+
const ARCHIVE_REGISTRATION_PROGRAM = String.raw `
|
|
1135
|
+
import io, json, runpy, sys
|
|
1136
|
+
control = sys.stdin
|
|
1137
|
+
payload = json.loads(control.readline())
|
|
1138
|
+
sys.stdin = io.TextIOWrapper(io.BytesIO(payload.encode("utf-8")), encoding="utf-8")
|
|
1139
|
+
sys.argv = sys.argv[1:]
|
|
1140
|
+
workbench = runpy.run_path(sys.argv[0])
|
|
1141
|
+
def before_archive():
|
|
1142
|
+
sys.stdout.buffer.write(b"codex-security-archive-ready\n")
|
|
1143
|
+
sys.stdout.buffer.flush()
|
|
1144
|
+
if control.readline() != "\n":
|
|
1145
|
+
raise SystemExit("Scan registration canceled before archival.")
|
|
1146
|
+
workbench["main"](before_archive=before_archive)
|
|
1147
|
+
`;
|
|
1148
|
+
// Internal publication callers use only the SDK's bundled workbench.
|
|
1149
|
+
const PUBLICATION_PROGRAM = String.raw `
|
|
1150
|
+
import json, runpy, sys
|
|
1151
|
+
from contextlib import closing
|
|
1152
|
+
workbench = runpy.run_path(sys.argv[1])
|
|
1153
|
+
context = workbench["_WORKBENCH_PUBLICATION_CONTEXT"]
|
|
1154
|
+
payload = json.load(sys.stdin, parse_constant=workbench["reject_non_finite_json"])
|
|
1155
|
+
handler = getattr(workbench["publication"], sys.argv[2].replace("-", "_"))
|
|
1156
|
+
if sys.argv[2] == "inspect-linear-publication":
|
|
1157
|
+
result = handler(context, payload)
|
|
1158
|
+
else:
|
|
1159
|
+
with closing(workbench["connect"]()) as connection:
|
|
1160
|
+
result = handler(context, connection, payload)
|
|
1161
|
+
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
1162
|
+
`;
|
|
1123
1163
|
export async function runWorkbench(options, args, input) {
|
|
1124
1164
|
const script = join(options.pluginRoot, "scripts", "workbench_db.py");
|
|
1125
|
-
const
|
|
1126
|
-
|
|
1165
|
+
const signal = options.signal;
|
|
1166
|
+
const run = async (arguments_, input, archiveHandshake = false) => {
|
|
1167
|
+
const native = [
|
|
1168
|
+
"database-info",
|
|
1169
|
+
"store-findings",
|
|
1170
|
+
"list-stored-findings",
|
|
1171
|
+
"find-potential-duplicates",
|
|
1172
|
+
"store-dedupe-groups",
|
|
1173
|
+
"list-dedupe-groups",
|
|
1174
|
+
"dashboard",
|
|
1175
|
+
"severity-classification",
|
|
1176
|
+
"read-severity-classification",
|
|
1177
|
+
].includes(arguments_[0] ?? "");
|
|
1178
|
+
const node = native && process.versions["bun"]
|
|
1179
|
+
? await resolveTrustedExecutable("node", options.environment, [
|
|
1180
|
+
process.cwd(),
|
|
1181
|
+
options.currentDirectory ?? process.cwd(),
|
|
1182
|
+
...(typeof options.protectedRoot === "string"
|
|
1183
|
+
? [options.protectedRoot]
|
|
1184
|
+
: (options.protectedRoot ?? [])),
|
|
1185
|
+
])
|
|
1186
|
+
: undefined;
|
|
1187
|
+
if (node === null) {
|
|
1188
|
+
throw new Error("Node.js is not available on a trusted PATH.");
|
|
1189
|
+
}
|
|
1190
|
+
const command = native
|
|
1191
|
+
? (node?.executable ?? process.execPath)
|
|
1192
|
+
: (options.python ??= await resolvePluginPython({
|
|
1193
|
+
environment: options.environment,
|
|
1194
|
+
protectedRoot: options.protectedRoot,
|
|
1195
|
+
currentDirectory: options.currentDirectory,
|
|
1196
|
+
signal: options.signal,
|
|
1197
|
+
}));
|
|
1198
|
+
const stateDirectory = native
|
|
1199
|
+
? (options.stateDirectory ??
|
|
1200
|
+
codexSecurityStateDirectory(options.environment))
|
|
1201
|
+
: undefined;
|
|
1202
|
+
const publicationInput = input !== undefined &&
|
|
1203
|
+
arguments_.length === 1 &&
|
|
1204
|
+
[
|
|
1205
|
+
"inspect-linear-publication",
|
|
1206
|
+
"prepare-linear-publication",
|
|
1207
|
+
"record-linear-publications",
|
|
1208
|
+
].includes(arguments_[0]);
|
|
1209
|
+
// OS argv cannot carry NUL, but workbench text fields can.
|
|
1210
|
+
const framedArguments = !native && arguments_.some((argument) => argument.includes("\0"));
|
|
1211
|
+
let program = archiveHandshake
|
|
1212
|
+
? ARCHIVE_REGISTRATION_PROGRAM
|
|
1213
|
+
: publicationInput
|
|
1214
|
+
? PUBLICATION_PROGRAM
|
|
1215
|
+
: undefined;
|
|
1216
|
+
if (framedArguments)
|
|
1217
|
+
program =
|
|
1218
|
+
WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
|
|
1219
|
+
const result = await runCodexCommand({ command }, native
|
|
1220
|
+
? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
|
|
1221
|
+
: [
|
|
1222
|
+
"-I",
|
|
1223
|
+
"-X",
|
|
1224
|
+
"utf8",
|
|
1225
|
+
"-B",
|
|
1226
|
+
...(program === undefined ? [] : ["-c", program]),
|
|
1227
|
+
script,
|
|
1228
|
+
...(framedArguments ? [] : arguments_),
|
|
1229
|
+
], pluginHelperEnvironment(node?.environment ?? options.environment),
|
|
1230
|
+
// The SDK owns configuration normalization; the helper receives its resolved location.
|
|
1231
|
+
native
|
|
1232
|
+
? JSON.stringify(arguments_[0] === "database-info"
|
|
1233
|
+
? stateDirectory
|
|
1234
|
+
: {
|
|
1235
|
+
stateDirectory,
|
|
1236
|
+
payload: input === undefined ? undefined : JSON.parse(input),
|
|
1237
|
+
})
|
|
1238
|
+
: input, signal, archiveHandshake,
|
|
1239
|
+
// Match native argv's UTF-8 encoding for the private argument frame.
|
|
1240
|
+
framedArguments
|
|
1241
|
+
? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
|
|
1242
|
+
: undefined);
|
|
1127
1243
|
if (!result.success) {
|
|
1128
1244
|
throw new Error(result.stderr.trim() ||
|
|
1129
1245
|
result.stdout.trim() ||
|
|
@@ -1133,45 +1249,18 @@ export async function runWorkbench(options, args, input) {
|
|
|
1133
1249
|
};
|
|
1134
1250
|
let stdout;
|
|
1135
1251
|
try {
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const key = JSON.stringify([options.python, script]);
|
|
1142
|
-
let support = workbenchComparisonSupport.get(key);
|
|
1143
|
-
if (support === undefined) {
|
|
1144
|
-
const help = await run(["save-scan-comparison", "--help"]);
|
|
1145
|
-
options.signal?.throwIfAborted();
|
|
1146
|
-
support = {
|
|
1147
|
-
stdin: help.includes("--matches-json-stdin"),
|
|
1148
|
-
related: help
|
|
1149
|
-
.replace(/\s+/gu, " ")
|
|
1150
|
-
.includes("Comparison payload supports related findings."),
|
|
1151
|
-
};
|
|
1152
|
-
workbenchComparisonSupport.set(key, support);
|
|
1153
|
-
}
|
|
1154
|
-
const comparison = JSON.parse(input);
|
|
1155
|
-
if (isRecord(comparison) && "related" in comparison && !support.related) {
|
|
1156
|
-
delete comparison["related"];
|
|
1157
|
-
input = JSON.stringify(comparison);
|
|
1158
|
-
}
|
|
1159
|
-
if (!support.stdin) {
|
|
1160
|
-
arguments_.splice(matchesStdinIndex, 1, "--matches-json", input);
|
|
1161
|
-
input = undefined;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
stdout = await run(arguments_, input);
|
|
1252
|
+
const archiveHandshake = signal !== undefined &&
|
|
1253
|
+
args[0] === "register-cli-scan" &&
|
|
1254
|
+
args.includes("--archive-existing") &&
|
|
1255
|
+
!args.includes("--archived-scan-dir");
|
|
1256
|
+
stdout = await run(args, input, archiveHandshake);
|
|
1165
1257
|
}
|
|
1166
1258
|
catch (error) {
|
|
1167
1259
|
if (options.signal?.aborted)
|
|
1168
1260
|
throw error;
|
|
1169
1261
|
const detail = processErrorDetail(error);
|
|
1170
|
-
const databaseFailure = /\b(?:unable to open database file|attempt to write a readonly database|readonly database|disk i\/o error)\b/iu.test(detail);
|
|
1171
1262
|
const failure = options.failureMessage ?? "Could not run the Codex Security workbench";
|
|
1172
|
-
throw new CodexSecurityError(
|
|
1173
|
-
? `${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.`
|
|
1174
|
-
: `${failure}: ${detail}`, { cause: error });
|
|
1263
|
+
throw new CodexSecurityError(`${failure}: ${detail}`, { cause: error });
|
|
1175
1264
|
}
|
|
1176
1265
|
let result;
|
|
1177
1266
|
try {
|
|
@@ -1204,16 +1293,12 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1204
1293
|
if (outputDirectory === undefined) {
|
|
1205
1294
|
return null;
|
|
1206
1295
|
}
|
|
1207
|
-
requireModelSafeOutputDir(outputDirectory);
|
|
1208
1296
|
const path = resolve(expandHome(outputDirectory));
|
|
1297
|
+
requireModelSafeOutputDir(path);
|
|
1209
1298
|
try {
|
|
1210
|
-
const metadata = await lstat(path).catch(
|
|
1211
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1212
|
-
return null;
|
|
1213
|
-
throw error;
|
|
1214
|
-
});
|
|
1299
|
+
const metadata = await lstat(path).catch(nullIfMissingFileError);
|
|
1215
1300
|
if (metadata !== null) {
|
|
1216
|
-
if (!metadata.isDirectory()
|
|
1301
|
+
if (!metadata.isDirectory()) {
|
|
1217
1302
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1218
1303
|
}
|
|
1219
1304
|
if (!archiveExisting && (await readdir(path)).length !== 0) {
|
|
@@ -1278,8 +1363,7 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1278
1363
|
}
|
|
1279
1364
|
const prepared = JSON.parse(result.stdout);
|
|
1280
1365
|
if (!isRecord(prepared) ||
|
|
1281
|
-
|
|
1282
|
-
prepared["canonicalPath"].length === 0 ||
|
|
1366
|
+
!isNonEmptyString(prepared["canonicalPath"]) ||
|
|
1283
1367
|
typeof prepared["dev"] !== "string" ||
|
|
1284
1368
|
!/^(?:0|[1-9]\d*)$/u.test(prepared["dev"]) ||
|
|
1285
1369
|
typeof prepared["ino"] !== "string" ||
|
|
@@ -1310,7 +1394,7 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1310
1394
|
relativePath,
|
|
1311
1395
|
dev,
|
|
1312
1396
|
ino,
|
|
1313
|
-
], pluginHelperEnvironment(options.environment), contents
|
|
1397
|
+
], pluginHelperEnvironment(options.environment), contents);
|
|
1314
1398
|
if (!result.success) {
|
|
1315
1399
|
throw new Error(result.stderr.trim() ||
|
|
1316
1400
|
result.stdout.trim() ||
|
|
@@ -1318,8 +1402,6 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1318
1402
|
}
|
|
1319
1403
|
}
|
|
1320
1404
|
catch (error) {
|
|
1321
|
-
if (options.signal?.aborted)
|
|
1322
|
-
throw error;
|
|
1323
1405
|
throw new OutputDirectoryError("Could not safely restore a completed scan artifact.", { cause: error });
|
|
1324
1406
|
}
|
|
1325
1407
|
},
|
|
@@ -1328,18 +1410,13 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1328
1410
|
export async function planOutputArchive(outputDirectory) {
|
|
1329
1411
|
if (outputDirectory === null)
|
|
1330
1412
|
return null;
|
|
1331
|
-
const entries = await readdir(outputDirectory).catch(
|
|
1332
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1333
|
-
return null;
|
|
1334
|
-
throw error;
|
|
1335
|
-
});
|
|
1413
|
+
const entries = await readdir(outputDirectory).catch(nullIfMissingFileError);
|
|
1336
1414
|
if (entries === null || entries.length === 0)
|
|
1337
1415
|
return null;
|
|
1338
|
-
|
|
1416
|
+
return `${outputDirectory}.previous-${new Date()
|
|
1339
1417
|
.toISOString()
|
|
1340
1418
|
.replaceAll(/[-:]/g, "")
|
|
1341
|
-
.replace(/\.\d{3}Z$/, "")
|
|
1342
|
-
return `${outputDirectory}.previous-${timestamp}-${randomUUID().slice(0, 8)}`;
|
|
1419
|
+
.replace(/\.\d{3}Z$/, "")}-${randomUUID().slice(0, 8)}`;
|
|
1343
1420
|
}
|
|
1344
1421
|
export function requireModelSafeOutputDir(path) {
|
|
1345
1422
|
if (MODEL_UNSAFE_PATH.test(path)) {
|
|
@@ -1353,27 +1430,40 @@ export function requireModelSafeOutputDir(path) {
|
|
|
1353
1430
|
export async function canonicalizeModelSafePath(input) {
|
|
1354
1431
|
const path = resolve(expandHome(input));
|
|
1355
1432
|
requireModelSafeOutputDir(path);
|
|
1356
|
-
|
|
1433
|
+
const canonical = await canonicalConfigPath(path);
|
|
1434
|
+
requireModelSafeOutputDir(canonical);
|
|
1435
|
+
return canonical;
|
|
1436
|
+
}
|
|
1437
|
+
export async function canonicalConfigPath(path) {
|
|
1438
|
+
let existing = resolve(path);
|
|
1439
|
+
const missing = [];
|
|
1440
|
+
while (true) {
|
|
1357
1441
|
try {
|
|
1358
|
-
|
|
1359
|
-
const canonical = resolve(canonicalAncestor, relative(ancestor, path));
|
|
1360
|
-
requireModelSafeOutputDir(canonical);
|
|
1361
|
-
return canonical;
|
|
1442
|
+
return join(await realpath(existing), ...missing);
|
|
1362
1443
|
}
|
|
1363
1444
|
catch (error) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1445
|
+
const parent = dirname(existing);
|
|
1446
|
+
if (error.code !== "ENOENT" ||
|
|
1447
|
+
parent === existing)
|
|
1367
1448
|
throw error;
|
|
1449
|
+
missing.unshift(basename(existing));
|
|
1450
|
+
existing = parent;
|
|
1368
1451
|
}
|
|
1369
1452
|
}
|
|
1370
1453
|
}
|
|
1371
1454
|
export async function prepareOutputDir(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false, onOutputArchived) {
|
|
1455
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "archive" : "reject", onOutputArchived);
|
|
1456
|
+
}
|
|
1457
|
+
/** Leave archival to the scan registration transaction. */
|
|
1458
|
+
export async function prepareScanRegistrationOutput(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false) {
|
|
1459
|
+
return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
|
|
1460
|
+
}
|
|
1461
|
+
async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
|
|
1372
1462
|
if (outputDirectory === undefined) {
|
|
1373
1463
|
requireModelSafeOutputDir(temporaryRoot);
|
|
1374
1464
|
requireModelSafeOutputDir(await realpath(temporaryRoot));
|
|
1375
1465
|
}
|
|
1376
|
-
const path = await validateOutputDir(outputDirectory,
|
|
1466
|
+
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1377
1467
|
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1378
1468
|
if (path === null) {
|
|
1379
1469
|
const created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
|
|
@@ -1389,16 +1479,12 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1389
1479
|
}
|
|
1390
1480
|
let createdRoot;
|
|
1391
1481
|
try {
|
|
1392
|
-
let existing = await lstat(path).catch(
|
|
1393
|
-
|
|
1394
|
-
return null;
|
|
1395
|
-
throw error;
|
|
1396
|
-
});
|
|
1397
|
-
if (existing !== null && archiveExisting) {
|
|
1482
|
+
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
1483
|
+
if (existing !== null && existingOutput === "archive") {
|
|
1398
1484
|
const archiveDir = await planOutputArchive(path);
|
|
1399
1485
|
if (archiveDir !== null) {
|
|
1400
1486
|
await rename(path, archiveDir);
|
|
1401
|
-
onOutputArchived?.(archiveDir);
|
|
1487
|
+
notify(() => onOutputArchived?.(archiveDir));
|
|
1402
1488
|
existing = null;
|
|
1403
1489
|
}
|
|
1404
1490
|
}
|
|
@@ -1407,7 +1493,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1407
1493
|
if ((process.umask() & 0o700) !== 0)
|
|
1408
1494
|
await chmod(path, 0o700);
|
|
1409
1495
|
}
|
|
1410
|
-
return await validatePreparedOutputDir(path, validateLocation);
|
|
1496
|
+
return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
|
|
1411
1497
|
}
|
|
1412
1498
|
catch (error) {
|
|
1413
1499
|
if (createdRoot !== undefined) {
|
|
@@ -1420,16 +1506,16 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1420
1506
|
});
|
|
1421
1507
|
}
|
|
1422
1508
|
}
|
|
1423
|
-
export async function validatePreparedOutputDir(path, validateLocation) {
|
|
1509
|
+
export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
|
|
1424
1510
|
const metadata = await lstat(path);
|
|
1425
|
-
if (!metadata.isDirectory()
|
|
1511
|
+
if (!metadata.isDirectory()) {
|
|
1426
1512
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1427
1513
|
}
|
|
1428
1514
|
const canonical = await realpath(path);
|
|
1429
1515
|
requireModelSafeOutputDir(canonical);
|
|
1430
1516
|
validateLocation?.(canonical);
|
|
1431
1517
|
const entries = await readdir(canonical);
|
|
1432
|
-
if (entries.length !== 0) {
|
|
1518
|
+
if (!allowNonempty && entries.length !== 0) {
|
|
1433
1519
|
throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
|
|
1434
1520
|
}
|
|
1435
1521
|
requirePrivateOutputDirectory(metadata, path);
|
|
@@ -1475,7 +1561,7 @@ export async function requireSecureOutputAncestry(path, effectiveUid = process.g
|
|
|
1475
1561
|
catch (error) {
|
|
1476
1562
|
throw new OutputDirectoryError(`Unable to inspect scan output parent directory: ${current}`, { cause: error });
|
|
1477
1563
|
}
|
|
1478
|
-
if (!metadata.isDirectory()
|
|
1564
|
+
if (!metadata.isDirectory()) {
|
|
1479
1565
|
throw new OutputDirectoryError(`Scan output parent must be a non-symlink directory: ${current}`);
|
|
1480
1566
|
}
|
|
1481
1567
|
requireTrustedOutputAncestor(metadata, current, effectiveUid);
|
|
@@ -1724,75 +1810,168 @@ async function rejectBackslashZipNames(path, signal) {
|
|
|
1724
1810
|
}
|
|
1725
1811
|
}
|
|
1726
1812
|
export async function resolvePluginPath(pluginPath, workspace, signal) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1813
|
+
try {
|
|
1814
|
+
if (pluginPath === undefined) {
|
|
1815
|
+
return await bundledPluginRoot();
|
|
1816
|
+
}
|
|
1817
|
+
const path = resolve(expandHome(pluginPath));
|
|
1818
|
+
const metadata = await lstat(path).catch(() => null);
|
|
1819
|
+
if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
|
|
1820
|
+
return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
|
|
1821
|
+
}
|
|
1822
|
+
if (metadata?.isDirectory()) {
|
|
1823
|
+
throwIfSignalAborted(signal);
|
|
1824
|
+
return await validatePluginRoot(path);
|
|
1825
|
+
}
|
|
1826
|
+
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1729
1827
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1828
|
+
catch (error) {
|
|
1829
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1830
|
+
throw error;
|
|
1831
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1734
1832
|
}
|
|
1735
|
-
|
|
1833
|
+
}
|
|
1834
|
+
export async function createMarketplace(codexHome, pluginRoot, signal) {
|
|
1835
|
+
try {
|
|
1736
1836
|
throwIfSignalAborted(signal);
|
|
1737
|
-
|
|
1837
|
+
const root = await realpath(pluginRoot);
|
|
1838
|
+
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1839
|
+
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1840
|
+
await copyPluginTree(root, pluginDestination, signal);
|
|
1841
|
+
const projection = await pluginRuntimeProjection(pluginDestination, signal);
|
|
1842
|
+
for (const [path, file] of projection?.files ?? []) {
|
|
1843
|
+
const destination = join(pluginDestination, path);
|
|
1844
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
1845
|
+
await writeFile(destination, file.contents, { mode: file.mode, signal });
|
|
1846
|
+
if (file.mode !== undefined)
|
|
1847
|
+
await chmod(destination, file.mode);
|
|
1848
|
+
}
|
|
1849
|
+
await writeMarketplaceManifest(marketplace, signal);
|
|
1850
|
+
return marketplace;
|
|
1851
|
+
}
|
|
1852
|
+
catch (error) {
|
|
1853
|
+
if (signal?.aborted || error instanceof LocalPluginBootstrapError)
|
|
1854
|
+
throw error;
|
|
1855
|
+
throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
|
|
1738
1856
|
}
|
|
1739
|
-
throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
|
|
1740
1857
|
}
|
|
1741
|
-
|
|
1858
|
+
async function writeMarketplaceManifest(marketplace, signal) {
|
|
1742
1859
|
throwIfSignalAborted(signal);
|
|
1743
|
-
const root = await realpath(pluginRoot);
|
|
1744
|
-
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1745
|
-
const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1746
|
-
await copyPluginTree(root, pluginDestination, signal);
|
|
1747
|
-
throwIfSignalAborted(signal);
|
|
1748
|
-
const manifest = {
|
|
1749
|
-
name: MARKETPLACE_NAME,
|
|
1750
|
-
interface: { displayName: "Codex Security SDK" },
|
|
1751
|
-
plugins: [
|
|
1752
|
-
{
|
|
1753
|
-
name: PLUGIN_NAME,
|
|
1754
|
-
source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
|
|
1755
|
-
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
1756
|
-
category: "Security",
|
|
1757
|
-
},
|
|
1758
|
-
],
|
|
1759
|
-
};
|
|
1760
1860
|
const manifestPath = join(marketplace, ".agents", "plugins", "marketplace.json");
|
|
1761
1861
|
await mkdir(dirname(manifestPath), { recursive: true, mode: 0o700 });
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1862
|
+
const temporary = `${manifestPath}.${randomUUID()}.tmp`;
|
|
1863
|
+
try {
|
|
1864
|
+
await writeFile(temporary, MARKETPLACE_MANIFEST, {
|
|
1865
|
+
encoding: "utf8",
|
|
1866
|
+
flag: "wx",
|
|
1867
|
+
mode: 0o600,
|
|
1868
|
+
signal,
|
|
1869
|
+
});
|
|
1870
|
+
throwIfSignalAborted(signal);
|
|
1871
|
+
try {
|
|
1872
|
+
await rename(temporary, manifestPath);
|
|
1873
|
+
}
|
|
1874
|
+
catch (error) {
|
|
1875
|
+
// Concurrent replacement can fail on Windows after another repair wins.
|
|
1876
|
+
const published = await readFile(manifestPath, "utf8").catch(() => null);
|
|
1877
|
+
if (published !== MARKETPLACE_MANIFEST)
|
|
1878
|
+
throw error;
|
|
1879
|
+
}
|
|
1880
|
+
throwIfSignalAborted(signal);
|
|
1881
|
+
}
|
|
1882
|
+
finally {
|
|
1883
|
+
await rm(temporary, { force: true });
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
async function pluginRuntimeProjection(root, signal) {
|
|
1887
|
+
const path = join(root, ".mcp.json");
|
|
1888
|
+
// Keep the source link checks ahead of any configuration read.
|
|
1889
|
+
if (!(await lstat(path).catch(nullIfMissingFileError))?.isFile())
|
|
1890
|
+
return;
|
|
1891
|
+
const configuration = JSON.parse(await readFile(path, { encoding: "utf8", signal }));
|
|
1892
|
+
const servers = isRecord(configuration)
|
|
1893
|
+
? configuration["mcpServers"]
|
|
1894
|
+
: undefined;
|
|
1895
|
+
const server = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;
|
|
1896
|
+
if (!isRecord(server) ||
|
|
1897
|
+
(server["command"] !== "./scripts/launch_codex_security_mcp" &&
|
|
1898
|
+
server["command"] !== "./scripts/launch_codex_security_mcp.cmd")) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
const environment = server["env_vars"];
|
|
1902
|
+
if (environment !== undefined && !Array.isArray(environment))
|
|
1903
|
+
return;
|
|
1904
|
+
if (!Array.isArray(environment) ||
|
|
1905
|
+
!environment.includes("CODEX_SECURITY_PLUGIN_ROOT")) {
|
|
1906
|
+
server["env_vars"] = [
|
|
1907
|
+
...(Array.isArray(environment) ? environment : []),
|
|
1908
|
+
"CODEX_SECURITY_PLUGIN_ROOT",
|
|
1909
|
+
];
|
|
1910
|
+
}
|
|
1911
|
+
const files = new Map();
|
|
1912
|
+
server["command"] =
|
|
1913
|
+
server["command"] === "./scripts/launch_codex_security_mcp.cmd"
|
|
1914
|
+
? "./scripts/launch_codex_security_mcp_sdk.cmd"
|
|
1915
|
+
: "./scripts/launch_codex_security_mcp_sdk";
|
|
1916
|
+
files.set("scripts/launch_codex_security_mcp_sdk", {
|
|
1917
|
+
contents: Buffer.from("#!/bin/sh\n" +
|
|
1918
|
+
'if [ -n "${CODEX_SECURITY_PLUGIN_ROOT:-}" ]; then\n' +
|
|
1919
|
+
' exec "$CODEX_SECURITY_PLUGIN_ROOT/scripts/launch_codex_security_mcp" "$@"\n' +
|
|
1920
|
+
"fi\n" +
|
|
1921
|
+
'exec "$(dirname "$0")/launch_codex_security_mcp" "$@"\n'),
|
|
1922
|
+
mode: 0o755,
|
|
1767
1923
|
});
|
|
1768
|
-
|
|
1769
|
-
|
|
1924
|
+
files.set("scripts/launch_codex_security_mcp_sdk.cmd", {
|
|
1925
|
+
contents: Buffer.from("@echo off\r\nsetlocal DisableDelayedExpansion\r\n" +
|
|
1926
|
+
"if not defined CODEX_SECURITY_PLUGIN_ROOT goto codex_security_sdk_original\r\n" +
|
|
1927
|
+
'"%CODEX_SECURITY_PLUGIN_ROOT%\\scripts\\launch_codex_security_mcp.cmd" %*\r\n' +
|
|
1928
|
+
"exit /b\r\n:codex_security_sdk_original\r\n" +
|
|
1929
|
+
'"%~dp0launch_codex_security_mcp.cmd" %*\r\n'),
|
|
1930
|
+
mode: 0o755,
|
|
1931
|
+
});
|
|
1932
|
+
files.set(".mcp.json", {
|
|
1933
|
+
contents: Buffer.from(`${JSON.stringify(configuration, null, 2)}\n`),
|
|
1934
|
+
});
|
|
1935
|
+
return { root, files };
|
|
1770
1936
|
}
|
|
1771
1937
|
export function resolveCodexCommand(environment = process.env) {
|
|
1772
1938
|
const configured = environmentValue(environment, "CODEX_CLI_PATH");
|
|
1773
|
-
const expanded = configured === undefined
|
|
1939
|
+
const expanded = configured === undefined
|
|
1940
|
+
? undefined
|
|
1941
|
+
: expandExecutableHome(configured, environment);
|
|
1774
1942
|
if (expanded &&
|
|
1775
1943
|
(process.platform !== "win32" || /\.(?:exe|com)$/iu.test(expanded))) {
|
|
1776
|
-
return {
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1944
|
+
return {
|
|
1945
|
+
command: process.platform === "win32"
|
|
1946
|
+
? resolve(expanded)
|
|
1947
|
+
: isAbsolute(expanded)
|
|
1948
|
+
? expanded
|
|
1949
|
+
: `${process.cwd()}${sep}${expanded}`,
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
return { command: resolveBundledCodexExecutable() };
|
|
1953
|
+
}
|
|
1954
|
+
export async function codexExecutableReadPaths(command) {
|
|
1955
|
+
const executable = await realpath(command);
|
|
1956
|
+
const packageJson = resolve(dirname(executable), "..", "package.json");
|
|
1781
1957
|
try {
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1958
|
+
const metadata = JSON.parse(await readFile(packageJson, "utf8"));
|
|
1959
|
+
if (metadata?.name !== "@openai/codex" ||
|
|
1960
|
+
typeof metadata.bin?.codex !== "string")
|
|
1961
|
+
return [executable];
|
|
1962
|
+
const launcher = await realpath(resolve(dirname(packageJson), metadata.bin.codex));
|
|
1963
|
+
if (launcher !== executable)
|
|
1964
|
+
return [executable];
|
|
1788
1965
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
if (target === undefined || !existsSync(command)) {
|
|
1793
|
-
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.`);
|
|
1966
|
+
catch {
|
|
1967
|
+
// A custom executable need not belong to a readable, valid npm package.
|
|
1968
|
+
return [executable];
|
|
1794
1969
|
}
|
|
1795
|
-
|
|
1970
|
+
// npm's entrypoint launches a native binary, which Linux re-executes in the sandbox.
|
|
1971
|
+
return [
|
|
1972
|
+
executable,
|
|
1973
|
+
await realpath(resolveBundledCodexExecutable(packageJson)),
|
|
1974
|
+
];
|
|
1796
1975
|
}
|
|
1797
1976
|
export function executablePathForSpawn(command) {
|
|
1798
1977
|
if (process.platform !== "win32" || !win32.isAbsolute(command))
|
|
@@ -1806,6 +1985,13 @@ export function executablePathForSpawn(command) {
|
|
|
1806
1985
|
export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
1807
1986
|
const root = await realpath(pluginRoot);
|
|
1808
1987
|
const { name, version } = await pluginMetadata(root);
|
|
1988
|
+
const projection = await pluginRuntimeProjection(root, options.signal).catch((error) => {
|
|
1989
|
+
if (options.signal?.aborted)
|
|
1990
|
+
throw error;
|
|
1991
|
+
throw new LocalPluginBootstrapError(errorMessage(error), {
|
|
1992
|
+
cause: error,
|
|
1993
|
+
});
|
|
1994
|
+
});
|
|
1809
1995
|
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1810
1996
|
throwIfSignalAborted(options.signal);
|
|
1811
1997
|
const command = options.codexCommand ?? resolveCodexCommand(options.environment);
|
|
@@ -1814,38 +2000,74 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1814
2000
|
CODEX_HOME: codexHome,
|
|
1815
2001
|
};
|
|
1816
2002
|
const run = options.runCodex ?? runPluginCommand;
|
|
1817
|
-
const existing = await lstat(marketplace).catch(
|
|
1818
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1819
|
-
return null;
|
|
1820
|
-
throw error;
|
|
1821
|
-
});
|
|
2003
|
+
const existing = await lstat(marketplace).catch(nullIfMissingFileError);
|
|
1822
2004
|
if (existing !== null && !existing.isDirectory()) {
|
|
1823
|
-
throw new
|
|
2005
|
+
throw new LocalPluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
|
|
1824
2006
|
}
|
|
1825
2007
|
const staged = existing === null
|
|
1826
2008
|
? null
|
|
1827
2009
|
: await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
|
|
1828
|
-
|
|
2010
|
+
const stagedRoot = join(marketplace, "plugins", PLUGIN_NAME);
|
|
2011
|
+
const stagedMatches = staged?.version === version &&
|
|
2012
|
+
(await pluginContentsMatch(root, stagedRoot, options.signal, false, projection));
|
|
2013
|
+
if (!stagedMatches) {
|
|
1829
2014
|
if (existing !== null) {
|
|
1830
2015
|
await rm(marketplace, { recursive: true, force: true });
|
|
1831
2016
|
}
|
|
1832
2017
|
await createMarketplace(codexHome, root, options.signal);
|
|
1833
2018
|
}
|
|
2019
|
+
else if ((await readFile(join(marketplace, ".agents", "plugins", "marketplace.json"), "utf8").catch(nullIfMissingFileError)) !== MARKETPLACE_MANIFEST) {
|
|
2020
|
+
await writeMarketplaceManifest(marketplace, options.signal);
|
|
2021
|
+
}
|
|
1834
2022
|
const config = await readFile(join(codexHome, "config.toml"), "utf8").catch((error) => {
|
|
1835
2023
|
if (nodeErrorCode(error) === "ENOENT")
|
|
1836
2024
|
return "";
|
|
1837
2025
|
throw error;
|
|
1838
2026
|
});
|
|
1839
|
-
const
|
|
2027
|
+
const configuration = parse(config);
|
|
2028
|
+
const marketplaces = configuration["marketplaces"];
|
|
1840
2029
|
const registration = isRecord(marketplaces)
|
|
1841
2030
|
? marketplaces[MARKETPLACE_NAME]
|
|
1842
2031
|
: undefined;
|
|
1843
|
-
|
|
1844
|
-
registration["source_type"]
|
|
1845
|
-
typeof registration["source"]
|
|
1846
|
-
|
|
2032
|
+
const registered = isRecord(registration) &&
|
|
2033
|
+
registration["source_type"] === "local" &&
|
|
2034
|
+
typeof registration["source"] === "string" &&
|
|
2035
|
+
(await sameFile(registration["source"], marketplace));
|
|
2036
|
+
if (!registered) {
|
|
1847
2037
|
await run(command, ["plugin", "marketplace", "add", marketplace], environment, options.signal);
|
|
1848
2038
|
}
|
|
2039
|
+
const installRecord = join(marketplace, "installed-plugin.json");
|
|
2040
|
+
const previous = await readFile(installRecord, "utf8")
|
|
2041
|
+
.then((value) => JSON.parse(value))
|
|
2042
|
+
.catch((error) => {
|
|
2043
|
+
if (nodeErrorCode(error) === "ENOENT" || error instanceof SyntaxError) {
|
|
2044
|
+
return null;
|
|
2045
|
+
}
|
|
2046
|
+
throw error;
|
|
2047
|
+
});
|
|
2048
|
+
const plugins = configuration["plugins"];
|
|
2049
|
+
const plugin = isRecord(plugins)
|
|
2050
|
+
? plugins[`${PLUGIN_NAME}@${MARKETPLACE_NAME}`]
|
|
2051
|
+
: undefined;
|
|
2052
|
+
// Codex replaces the shared install even at the same version. Reuse it so
|
|
2053
|
+
// workers from an earlier scan can keep using their plugin files.
|
|
2054
|
+
if (stagedMatches &&
|
|
2055
|
+
registered &&
|
|
2056
|
+
isRecord(plugin) &&
|
|
2057
|
+
plugin["enabled"] === true &&
|
|
2058
|
+
isRecord(previous) &&
|
|
2059
|
+
typeof previous["installedPath"] === "string" &&
|
|
2060
|
+
previous["version"] === version &&
|
|
2061
|
+
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true, projection))) {
|
|
2062
|
+
return {
|
|
2063
|
+
pluginRoot: root,
|
|
2064
|
+
marketplaceRoot: marketplace,
|
|
2065
|
+
installedRoot: previous["installedPath"],
|
|
2066
|
+
marketplaceName: MARKETPLACE_NAME,
|
|
2067
|
+
name,
|
|
2068
|
+
version,
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
1849
2071
|
const output = await run(command, ["plugin", "add", "--json", `${PLUGIN_NAME}@${MARKETPLACE_NAME}`], environment, options.signal);
|
|
1850
2072
|
let installed;
|
|
1851
2073
|
try {
|
|
@@ -1859,6 +2081,10 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1859
2081
|
installed["version"] !== version) {
|
|
1860
2082
|
throw new PluginBootstrapError("Codex plugin install did not return the selected plugin path and version.");
|
|
1861
2083
|
}
|
|
2084
|
+
await writeFile(installRecord, JSON.stringify({
|
|
2085
|
+
installedPath: installed["installedPath"],
|
|
2086
|
+
version,
|
|
2087
|
+
}), { mode: 0o600, signal: options.signal });
|
|
1862
2088
|
return {
|
|
1863
2089
|
pluginRoot: root,
|
|
1864
2090
|
marketplaceRoot: marketplace,
|
|
@@ -1868,43 +2094,115 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1868
2094
|
version,
|
|
1869
2095
|
};
|
|
1870
2096
|
}
|
|
2097
|
+
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false, projection) {
|
|
2098
|
+
throwIfSignalAborted(signal);
|
|
2099
|
+
const sourceMetadata = await lstat(source);
|
|
2100
|
+
const destinationMetadata = await lstat(destination).catch((error) => {
|
|
2101
|
+
if (["ENOENT", "ENOTDIR"].includes(nodeErrorCode(error) ?? "")) {
|
|
2102
|
+
return null;
|
|
2103
|
+
}
|
|
2104
|
+
throw error;
|
|
2105
|
+
});
|
|
2106
|
+
if (destinationMetadata === null)
|
|
2107
|
+
return false;
|
|
2108
|
+
if (sourceMetadata.isFile() && destinationMetadata.isFile()) {
|
|
2109
|
+
const projected = projection?.files.get(relative(projection.root, source).split(sep).join("/"));
|
|
2110
|
+
if ((projected === undefined &&
|
|
2111
|
+
sourceMetadata.size !== destinationMetadata.size) ||
|
|
2112
|
+
((projected?.mode === undefined || process.platform !== "win32") &&
|
|
2113
|
+
((projected?.mode ?? sourceMetadata.mode) & 0o111) !==
|
|
2114
|
+
(destinationMetadata.mode & 0o111))) {
|
|
2115
|
+
return false;
|
|
2116
|
+
}
|
|
2117
|
+
const [sourceBytes, destinationBytes] = await Promise.all([
|
|
2118
|
+
readFile(source, { signal }),
|
|
2119
|
+
readFile(destination, { signal }),
|
|
2120
|
+
]);
|
|
2121
|
+
return (projected?.contents ?? sourceBytes).equals(destinationBytes);
|
|
2122
|
+
}
|
|
2123
|
+
if (!sourceMetadata.isDirectory() || !destinationMetadata.isDirectory()) {
|
|
2124
|
+
return false;
|
|
2125
|
+
}
|
|
2126
|
+
const entries = await readdir(source);
|
|
2127
|
+
const projectedDirectory = projection === undefined
|
|
2128
|
+
? undefined
|
|
2129
|
+
: relative(projection.root, source).split(sep).join("/") || ".";
|
|
2130
|
+
const generated = [...(projection?.files ?? [])].filter(([path]) => dirname(path) === projectedDirectory && !entries.includes(basename(path)));
|
|
2131
|
+
if (!allowExtraFiles &&
|
|
2132
|
+
entries.length + generated.length !== (await readdir(destination)).length) {
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
for (const [path, file] of generated) {
|
|
2136
|
+
const generatedPath = join(destination, basename(path));
|
|
2137
|
+
const metadata = await lstat(generatedPath).catch(nullIfMissingFileError);
|
|
2138
|
+
if (!metadata?.isFile() ||
|
|
2139
|
+
(process.platform !== "win32" &&
|
|
2140
|
+
(metadata.mode & 0o111) !== ((file.mode ?? 0o644) & 0o111)) ||
|
|
2141
|
+
!file.contents.equals(await readFile(generatedPath, { signal }))) {
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
for (const entry of entries) {
|
|
2146
|
+
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles, projection))) {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return true;
|
|
2151
|
+
}
|
|
1871
2152
|
export async function pluginMetadata(root) {
|
|
1872
2153
|
const manifestPath = join(root, ".codex-plugin", "plugin.json");
|
|
1873
2154
|
let manifest;
|
|
1874
2155
|
try {
|
|
1875
|
-
|
|
1876
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
2156
|
+
if (!(await lstat(manifestPath)).isFile()) {
|
|
1877
2157
|
throw new Error("plugin manifest is not a regular file");
|
|
1878
2158
|
}
|
|
1879
2159
|
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1880
2160
|
}
|
|
1881
2161
|
catch (error) {
|
|
1882
|
-
throw new
|
|
2162
|
+
throw new LocalPluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
|
|
1883
2163
|
cause: error,
|
|
1884
2164
|
});
|
|
1885
2165
|
}
|
|
1886
2166
|
if (!isRecord(manifest) || manifest["name"] !== PLUGIN_NAME) {
|
|
1887
|
-
throw new
|
|
2167
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have name 'codex-security'.");
|
|
1888
2168
|
}
|
|
1889
2169
|
const version = manifest["version"];
|
|
1890
2170
|
if (typeof version !== "string" || version.trim().length === 0) {
|
|
1891
|
-
throw new
|
|
2171
|
+
throw new LocalPluginBootstrapError("Plugin manifest must have a non-empty version.");
|
|
1892
2172
|
}
|
|
1893
2173
|
return { name: PLUGIN_NAME, version };
|
|
1894
2174
|
}
|
|
1895
2175
|
export async function resolvePluginPython(options = {}) {
|
|
1896
2176
|
const environment = options.environment ?? process.env;
|
|
1897
|
-
const
|
|
2177
|
+
const requestedRoots = options.protectedRoot ?? process.cwd();
|
|
2178
|
+
const protectedRoot = typeof requestedRoots === "string" ? [requestedRoots] : [...requestedRoots];
|
|
2179
|
+
const callerDirectories = [
|
|
2180
|
+
process.cwd(),
|
|
2181
|
+
options.currentDirectory ?? process.cwd(),
|
|
2182
|
+
];
|
|
2183
|
+
// Preserve target and enclosing-checkout protection for every interpreter.
|
|
2184
|
+
for (const directory of new Set([...callerDirectories, ...protectedRoot])) {
|
|
2185
|
+
for (const checkout of await gitProtectionRoots(directory, options.signal))
|
|
2186
|
+
if (!protectedRoot.includes(checkout))
|
|
2187
|
+
protectedRoot.push(checkout);
|
|
2188
|
+
}
|
|
2189
|
+
// Named interpreters are ambient PATH discovery, even when PYTHON names one.
|
|
2190
|
+
// Explicit trusted paths and managed runtimes retain their existing precedence.
|
|
2191
|
+
const discoveryRoots = [...protectedRoot, ...callerDirectories];
|
|
1898
2192
|
if (options.configuredPath !== undefined) {
|
|
1899
|
-
return await requirePython(options.configuredPath, "configured plugin Python", environment,
|
|
2193
|
+
return await requirePython(options.configuredPath, "configured plugin Python", environment, isPythonPathCandidate(options.configuredPath)
|
|
2194
|
+
? protectedRoot
|
|
2195
|
+
: discoveryRoots, options.signal);
|
|
1900
2196
|
}
|
|
1901
2197
|
const inherited = environmentValue(environment, "PYTHON");
|
|
1902
2198
|
if (inherited) {
|
|
1903
|
-
return await requirePython(inherited, "PYTHON", environment, protectedRoot, options.signal);
|
|
2199
|
+
return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
|
|
1904
2200
|
}
|
|
1905
2201
|
const home = options.homeDirectory ?? homedir();
|
|
2202
|
+
const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
|
|
2203
|
+
join(home, ".cache");
|
|
1906
2204
|
const managedRoots = options.managedRuntimeRoots ?? [
|
|
1907
|
-
join(
|
|
2205
|
+
join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
|
|
1908
2206
|
];
|
|
1909
2207
|
const relativeCandidates = process.platform === "win32"
|
|
1910
2208
|
? [
|
|
@@ -1927,7 +2225,7 @@ export async function resolvePluginPython(options = {}) {
|
|
|
1927
2225
|
for (const candidate of process.platform === "win32"
|
|
1928
2226
|
? ["python", "python3", "py"]
|
|
1929
2227
|
: ["python3", "python"]) {
|
|
1930
|
-
const resolved = await usablePython(candidate, environment,
|
|
2228
|
+
const resolved = await usablePython(candidate, environment, discoveryRoots, options.signal);
|
|
1931
2229
|
if (resolved !== null)
|
|
1932
2230
|
return resolved;
|
|
1933
2231
|
}
|
|
@@ -1938,9 +2236,24 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
|
1938
2236
|
return {
|
|
1939
2237
|
...pythonUtf8Environment(environment),
|
|
1940
2238
|
PYTHON: python,
|
|
2239
|
+
CODEX_SECURITY_PYTHON_COMMAND: python,
|
|
1941
2240
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1942
2241
|
};
|
|
1943
2242
|
}
|
|
2243
|
+
export function environmentWithGit(environment, git) {
|
|
2244
|
+
if (git === undefined)
|
|
2245
|
+
return environment;
|
|
2246
|
+
const result = { ...environment };
|
|
2247
|
+
for (const name of Object.keys(result)) {
|
|
2248
|
+
const normalized = name.toUpperCase();
|
|
2249
|
+
if (normalized === "CODEX_SECURITY_GIT" || normalized === "PATH") {
|
|
2250
|
+
delete result[name];
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
result["CODEX_SECURITY_GIT"] = git.executable ?? "";
|
|
2254
|
+
result["PATH"] = git.environment["PATH"] ?? "";
|
|
2255
|
+
return result;
|
|
2256
|
+
}
|
|
1944
2257
|
export function pythonUtf8Environment(environment) {
|
|
1945
2258
|
const normalized = { ...environment };
|
|
1946
2259
|
for (const name of Object.keys(normalized)) {
|
|
@@ -1956,12 +2269,15 @@ function pluginHelperEnvironment(environment) {
|
|
|
1956
2269
|
export async function cleanupSdkDirectory(path) {
|
|
1957
2270
|
await rm(path, { recursive: true, force: true });
|
|
1958
2271
|
}
|
|
1959
|
-
export async function runCodexCommand(command, args, environment, input, signal) {
|
|
1960
|
-
const
|
|
2272
|
+
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2273
|
+
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2274
|
+
const abort = () => cancellation?.abort(signal?.reason);
|
|
2275
|
+
let awaitingArchive = archiveHandshake;
|
|
2276
|
+
const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
|
|
1961
2277
|
env: environment,
|
|
1962
2278
|
stdio: ["pipe", "pipe", "pipe"],
|
|
1963
2279
|
windowsHide: true,
|
|
1964
|
-
signal,
|
|
2280
|
+
signal: cancellation?.signal ?? signal,
|
|
1965
2281
|
});
|
|
1966
2282
|
let stdout = "";
|
|
1967
2283
|
let stderr = "";
|
|
@@ -1970,6 +2286,17 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
1970
2286
|
child.stderr.setEncoding("utf8");
|
|
1971
2287
|
child.stdout.on("data", (chunk) => {
|
|
1972
2288
|
stdout += chunk;
|
|
2289
|
+
if (awaitingArchive && stdout.startsWith(ARCHIVE_READY)) {
|
|
2290
|
+
awaitingArchive = false;
|
|
2291
|
+
stdout = stdout.slice(ARCHIVE_READY.length);
|
|
2292
|
+
signal?.removeEventListener("abort", abort);
|
|
2293
|
+
// The helper cannot rename until this acknowledgement. Detach and check
|
|
2294
|
+
// cancellation before allowing the filesystem/database transaction.
|
|
2295
|
+
if (signal?.aborted)
|
|
2296
|
+
abort();
|
|
2297
|
+
else
|
|
2298
|
+
child.stdin.end("\n");
|
|
2299
|
+
}
|
|
1973
2300
|
});
|
|
1974
2301
|
child.stderr.on("data", (chunk) => {
|
|
1975
2302
|
stderr += chunk;
|
|
@@ -1986,8 +2313,47 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
1986
2313
|
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
1987
2314
|
: reject(processError));
|
|
1988
2315
|
});
|
|
1989
|
-
|
|
1990
|
-
|
|
2316
|
+
if (archiveHandshake) {
|
|
2317
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2318
|
+
if (signal?.aborted)
|
|
2319
|
+
abort();
|
|
2320
|
+
}
|
|
2321
|
+
try {
|
|
2322
|
+
if (stdinPrefix !== undefined)
|
|
2323
|
+
child.stdin.write(stdinPrefix);
|
|
2324
|
+
if (archiveHandshake)
|
|
2325
|
+
child.stdin.write(`${JSON.stringify(input ?? "")}\n`);
|
|
2326
|
+
else
|
|
2327
|
+
child.stdin.end(input);
|
|
2328
|
+
return await completion;
|
|
2329
|
+
}
|
|
2330
|
+
finally {
|
|
2331
|
+
if (archiveHandshake)
|
|
2332
|
+
signal?.removeEventListener("abort", abort);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
export async function probeCodexSandbox(command, environment, signal) {
|
|
2336
|
+
// This preflight covers the Unix sandbox backends.
|
|
2337
|
+
if (process.platform === "win32")
|
|
2338
|
+
return;
|
|
2339
|
+
// Reuse the resolved Codex executable instead of looking up a probe on PATH.
|
|
2340
|
+
const args = ["sandbox", "--", command.command, "--version"];
|
|
2341
|
+
const timeout = AbortSignal.timeout(SANDBOX_PROBE_TIMEOUT_MILLISECONDS);
|
|
2342
|
+
let detail;
|
|
2343
|
+
try {
|
|
2344
|
+
const result = await runCodexCommand(command, args, environment, undefined, signal === undefined ? timeout : AbortSignal.any([signal, timeout]));
|
|
2345
|
+
if (result.success)
|
|
2346
|
+
return;
|
|
2347
|
+
detail =
|
|
2348
|
+
result.stderr.trim() ||
|
|
2349
|
+
result.stdout.trim() ||
|
|
2350
|
+
`Codex exited with status ${result.exitCode}.`;
|
|
2351
|
+
}
|
|
2352
|
+
catch (error) {
|
|
2353
|
+
signal?.throwIfAborted();
|
|
2354
|
+
detail = processErrorDetail(error);
|
|
2355
|
+
}
|
|
2356
|
+
throw new SandboxUnavailableError(`Codex could not run a command in its sandbox; reproduce with '${command.command} ${args.join(" ")}'. On 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. Codex reported: ${detail}`);
|
|
1991
2357
|
}
|
|
1992
2358
|
async function runPluginCommand(command, args, environment, signal) {
|
|
1993
2359
|
try {
|
|
@@ -2083,7 +2449,7 @@ async function requirePython(candidate, source, environment, protectedRoot, sign
|
|
|
2083
2449
|
}
|
|
2084
2450
|
async function usablePython(candidate, environment = process.env, protectedRoot = process.cwd(), signal) {
|
|
2085
2451
|
const command = await resolveTrustedExecutable(isPythonPathCandidate(candidate)
|
|
2086
|
-
?
|
|
2452
|
+
? expandExecutableHome(candidate, environment)
|
|
2087
2453
|
: candidate, environment, protectedRoot);
|
|
2088
2454
|
if (command === null)
|
|
2089
2455
|
return null;
|
|
@@ -2110,35 +2476,26 @@ async function usablePython(candidate, environment = process.env, protectedRoot
|
|
|
2110
2476
|
}
|
|
2111
2477
|
}
|
|
2112
2478
|
export function isPythonPathCandidate(candidate) {
|
|
2113
|
-
return
|
|
2114
|
-
candidate.includes("\\") ||
|
|
2115
|
-
candidate.startsWith("."));
|
|
2479
|
+
return candidate.includes("/") || candidate.includes("\\");
|
|
2116
2480
|
}
|
|
2117
2481
|
async function hasPluginManifest(root) {
|
|
2118
|
-
return await
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
]);
|
|
2136
|
-
return (leftMetadata.dev === rightMetadata.dev &&
|
|
2137
|
-
leftMetadata.ino === rightMetadata.ino);
|
|
2138
|
-
}
|
|
2139
|
-
catch {
|
|
2140
|
-
return false;
|
|
2141
|
-
}
|
|
2482
|
+
return await lstat(join(root, ".codex-plugin", "plugin.json")).then((metadata) => metadata.isFile(), () => false);
|
|
2483
|
+
}
|
|
2484
|
+
/** @internal Compare filesystem identity without depending on path spelling. */
|
|
2485
|
+
export function sameFile(left, right) {
|
|
2486
|
+
// NTFS file IDs can exceed JavaScript's safe integer range.
|
|
2487
|
+
return Promise.all([
|
|
2488
|
+
stat(left, { bigint: true }),
|
|
2489
|
+
stat(right, { bigint: true }),
|
|
2490
|
+
]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
|
|
2491
|
+
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2492
|
+
}
|
|
2493
|
+
function expandExecutableHome(value, environment) {
|
|
2494
|
+
const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
|
|
2495
|
+
// Expand only the home prefix; joining the suffix would collapse symlink/.. paths.
|
|
2496
|
+
return path.startsWith("~/")
|
|
2497
|
+
? `${expandHome("~", environment)}${sep}${path.slice(2)}`
|
|
2498
|
+
: expandHome(path, environment);
|
|
2142
2499
|
}
|
|
2143
2500
|
export function expandHome(value, environment = process.env) {
|
|
2144
2501
|
const home = (process.platform === "win32"
|
|
@@ -2173,20 +2530,27 @@ function processErrorDetail(error) {
|
|
|
2173
2530
|
}
|
|
2174
2531
|
return String(error) || "unknown error";
|
|
2175
2532
|
}
|
|
2176
|
-
function isRecord(value) {
|
|
2177
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2178
|
-
}
|
|
2179
2533
|
function nodeErrorCode(error) {
|
|
2180
2534
|
return isRecord(error) && typeof error["code"] === "string"
|
|
2181
2535
|
? error["code"]
|
|
2182
2536
|
: undefined;
|
|
2183
2537
|
}
|
|
2184
|
-
function abortReason(signal) {
|
|
2185
|
-
return (signal.reason ??
|
|
2186
|
-
new DOMException("The operation was aborted.", "AbortError"));
|
|
2187
|
-
}
|
|
2188
2538
|
function throwIfSignalAborted(signal) {
|
|
2189
2539
|
if (signal?.aborted)
|
|
2190
2540
|
throw abortReason(signal);
|
|
2191
2541
|
}
|
|
2542
|
+
function nullIfMissingFileError(error) {
|
|
2543
|
+
if (nodeErrorCode(error) === "ENOENT")
|
|
2544
|
+
return null;
|
|
2545
|
+
throw error;
|
|
2546
|
+
}
|
|
2547
|
+
/** @internal */
|
|
2548
|
+
export function workbenchEnvironment(environment) {
|
|
2549
|
+
return {
|
|
2550
|
+
...environment,
|
|
2551
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(environment),
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
/** @internal */
|
|
2555
|
+
export const resolveWorkbenchRuntime = (options) => Promise.all([resolvePluginPython(options), bundledPluginRoot()]);
|
|
2192
2556
|
//# sourceMappingURL=runtime.js.map
|