@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { JsonObject } from "./config.js";
|
|
2
|
+
export type ArtifactOutput = Pick<NodeJS.WriteStream, "write">;
|
|
3
|
+
export declare const ARTIFACT_EXPORT_FILENAMES: {
|
|
4
|
+
readonly csv: "findings.csv";
|
|
5
|
+
readonly json: "findings.json";
|
|
6
|
+
readonly sarif: "results.sarif";
|
|
7
|
+
readonly md: "threatmodel.md";
|
|
8
|
+
};
|
|
9
|
+
export type ExportFormat = keyof typeof ARTIFACT_EXPORT_FILENAMES;
|
|
10
|
+
export type ExportArtifactKind = "findings" | "threat-model";
|
|
11
|
+
export interface ArtifactExportArguments {
|
|
12
|
+
scanDir: string;
|
|
13
|
+
artifact?: ExportArtifactKind;
|
|
14
|
+
format: ExportFormat;
|
|
15
|
+
output: string;
|
|
16
|
+
sourceRoot?: string;
|
|
17
|
+
pythonPath?: string;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
includeMetadata?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type ExportArtifactOptions = {
|
|
22
|
+
source: {
|
|
23
|
+
directory: string;
|
|
24
|
+
scanId?: never;
|
|
25
|
+
} | {
|
|
26
|
+
scanId: string;
|
|
27
|
+
directory?: never;
|
|
28
|
+
};
|
|
29
|
+
output: string;
|
|
30
|
+
pythonPath?: string;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
} & ({
|
|
33
|
+
artifact: "threat-model";
|
|
34
|
+
format?: "md";
|
|
35
|
+
sourceRoot?: never;
|
|
36
|
+
} | {
|
|
37
|
+
artifact?: "findings";
|
|
38
|
+
format?: "csv" | "json" | "sarif";
|
|
39
|
+
sourceRoot?: string;
|
|
40
|
+
});
|
|
41
|
+
export interface ArtifactExportResult {
|
|
42
|
+
path: string | null;
|
|
43
|
+
provenance: JsonObject | null;
|
|
44
|
+
}
|
|
45
|
+
interface HelperOptions {
|
|
46
|
+
pythonPath?: string;
|
|
47
|
+
protectedRoot?: string;
|
|
48
|
+
pluginRoot?: string;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
output?: ArtifactOutput;
|
|
51
|
+
failureMessage?: string;
|
|
52
|
+
}
|
|
53
|
+
export declare function resolveArtifactFormat(artifact: ExportArtifactKind, format?: ExportFormat): ExportFormat;
|
|
54
|
+
export declare function runArtifactHelper(args: readonly string[], options?: HelperOptions): Promise<{
|
|
55
|
+
stdout: string;
|
|
56
|
+
stderr: string;
|
|
57
|
+
}>;
|
|
58
|
+
export declare function writeThreatModel(directory: string, options?: HelperOptions): Promise<string>;
|
|
59
|
+
/** Read the current document path without making an optional projection required. */
|
|
60
|
+
export declare function readThreatModelPath(directory: string, options?: HelperOptions): Promise<string | null>;
|
|
61
|
+
export declare function runArtifactExport(arguments_: ArtifactExportArguments, output?: ArtifactOutput): Promise<string | undefined>;
|
|
62
|
+
export declare function resolveArtifactExportOutput(arguments_: ArtifactExportArguments, currentDirectory: string): Promise<ArtifactExportArguments>;
|
|
63
|
+
/** Resolve saved artifacts after the workbench validates their recorded identity. */
|
|
64
|
+
export declare function resolveSavedArtifactDirectory(scanId: string, artifact: ExportArtifactKind, format: ExportFormat, workbench: (args: readonly string[]) => Promise<JsonObject>): Promise<string>;
|
|
65
|
+
/** Export saved artifacts without authenticating or starting Codex. */
|
|
66
|
+
export declare function exportArtifact(options: ExportArtifactOptions): Promise<ArtifactExportResult>;
|
|
67
|
+
export declare function writeArtifactOutput(output: ArtifactOutput, value: string | Uint8Array | AsyncIterable<Uint8Array>): Promise<void>;
|
|
68
|
+
export declare function exportEnvironment(environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=artifact-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-export.d.ts","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAY9C,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAE/D,eAAO,MAAM,yBAAyB;aACpC,GAAG,EAAE,cAAc;aACnB,IAAI,EAAE,eAAe;aACrB,KAAK,EAAE,eAAe;aACtB,EAAE,EAAE,gBAAgB;CACZ,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,yBAAyB,CAAC;AAClE,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE7D,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EACF;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,CAAA;KAAE,GACrC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB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AE,cAAc,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgC7B;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,uBAAuB,EACnC,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,uBAAuB,CAAC,CA8ElC;AAED,qFAAqF;AACrF,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,GAC1D,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,uEAAuE;AACvE,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CA8D/B;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,GACrD,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,GAAE,MAAM,CAAC,UAAwB,GAC3C,MAAM,CAAC,UAAU,CAuBnB"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { workbenchArgs } from "./workbench-arguments.js";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { Writable as NodeWritable } from "node:stream";
|
|
6
|
+
import { pipeline } from "node:stream/promises";
|
|
7
|
+
import { CodexSecurityError } from "./errors.js";
|
|
8
|
+
import { relativePathIsOutside as isOutsidePath } from "./targets.js";
|
|
9
|
+
import { bundledPluginRoot, codexSecurityStateDirectory, expandHome, pythonUtf8Environment, resolvePluginPython, runWorkbench, } from "./runtime.js";
|
|
10
|
+
export const ARTIFACT_EXPORT_FILENAMES = {
|
|
11
|
+
csv: "findings.csv",
|
|
12
|
+
json: "findings.json",
|
|
13
|
+
sarif: "results.sarif",
|
|
14
|
+
md: "threatmodel.md",
|
|
15
|
+
};
|
|
16
|
+
export function resolveArtifactFormat(artifact, format) {
|
|
17
|
+
const selected = format ?? (artifact === "threat-model" ? "md" : "sarif");
|
|
18
|
+
if ((artifact === "threat-model") !== (selected === "md")) {
|
|
19
|
+
throw new CodexSecurityError(artifact === "threat-model"
|
|
20
|
+
? "Threat-model exports only support --export-format md."
|
|
21
|
+
: "Findings exports support --export-format csv, json, or sarif.");
|
|
22
|
+
}
|
|
23
|
+
return selected;
|
|
24
|
+
}
|
|
25
|
+
export async function runArtifactHelper(args, options = {}) {
|
|
26
|
+
const environment = exportEnvironment();
|
|
27
|
+
const python = await resolvePluginPython({
|
|
28
|
+
configuredPath: options.pythonPath,
|
|
29
|
+
environment,
|
|
30
|
+
protectedRoot: options.protectedRoot,
|
|
31
|
+
signal: options.signal,
|
|
32
|
+
});
|
|
33
|
+
const plugin = options.pluginRoot ?? (await bundledPluginRoot());
|
|
34
|
+
const invocation = spawn(python, [
|
|
35
|
+
"-I",
|
|
36
|
+
"-X",
|
|
37
|
+
"utf8",
|
|
38
|
+
"-B",
|
|
39
|
+
join(plugin, "scripts", "finalize_scan_contract.py"),
|
|
40
|
+
...args,
|
|
41
|
+
], {
|
|
42
|
+
env: environment,
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
44
|
+
windowsHide: true,
|
|
45
|
+
signal: options.signal,
|
|
46
|
+
});
|
|
47
|
+
let stderr = "";
|
|
48
|
+
let stdout = "";
|
|
49
|
+
invocation.stderr.setEncoding("utf8");
|
|
50
|
+
invocation.stderr.on("data", (chunk) => {
|
|
51
|
+
stderr = `${stderr}${chunk}`.slice(-64 * 1024);
|
|
52
|
+
});
|
|
53
|
+
const forwarded = options.output === undefined
|
|
54
|
+
? (async () => {
|
|
55
|
+
invocation.stdout.setEncoding("utf8");
|
|
56
|
+
for await (const chunk of invocation.stdout)
|
|
57
|
+
stdout += chunk;
|
|
58
|
+
})()
|
|
59
|
+
: writeArtifactOutput(options.output, invocation.stdout);
|
|
60
|
+
let status;
|
|
61
|
+
try {
|
|
62
|
+
[status] = await Promise.all([
|
|
63
|
+
new Promise((resolve, reject) => {
|
|
64
|
+
invocation.once("error", reject);
|
|
65
|
+
invocation.once("close", (code, signal) => resolve(signal === null ? (code ?? 1) : 1));
|
|
66
|
+
}),
|
|
67
|
+
forwarded,
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
invocation.stdout.destroy();
|
|
72
|
+
invocation.kill();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
if (status !== 0) {
|
|
76
|
+
const detail = stderr.trim().split("\n").at(-1);
|
|
77
|
+
throw new CodexSecurityError(detail?.replace(/^finalize_scan_contract\.py: error: /, "") ||
|
|
78
|
+
options.failureMessage ||
|
|
79
|
+
"Could not export Codex Security artifacts.");
|
|
80
|
+
}
|
|
81
|
+
return { stdout, stderr };
|
|
82
|
+
}
|
|
83
|
+
export async function writeThreatModel(directory, options = {}) {
|
|
84
|
+
const result = await runArtifactHelper(["--scan-dir", directory, "--write-threat-model"], options);
|
|
85
|
+
return result.stderr.trim().replace(/^codex-security: warning: /u, "");
|
|
86
|
+
}
|
|
87
|
+
/** Read the current document path without making an optional projection required. */
|
|
88
|
+
export async function readThreatModelPath(directory, options = {}) {
|
|
89
|
+
try {
|
|
90
|
+
options.signal?.throwIfAborted();
|
|
91
|
+
const result = await runArtifactHelper(["--scan-dir", directory, "--describe-threat-model"], options);
|
|
92
|
+
return JSON.parse(result.stdout).path;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
options.signal?.throwIfAborted();
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export async function runArtifactExport(arguments_, output) {
|
|
100
|
+
const artifact = arguments_.artifact ?? "findings";
|
|
101
|
+
resolveArtifactFormat(artifact, arguments_.format);
|
|
102
|
+
const result = await runArtifactHelper([
|
|
103
|
+
"--scan-dir",
|
|
104
|
+
arguments_.scanDir,
|
|
105
|
+
...(artifact === "findings" ? [] : ["--export-artifact", artifact]),
|
|
106
|
+
"--export-format",
|
|
107
|
+
arguments_.format,
|
|
108
|
+
...(arguments_.output === "-"
|
|
109
|
+
? []
|
|
110
|
+
: ["--export-output", arguments_.output]),
|
|
111
|
+
...(arguments_.sourceRoot === undefined
|
|
112
|
+
? []
|
|
113
|
+
: ["--source-root", arguments_.sourceRoot]),
|
|
114
|
+
...(arguments_.includeMetadata ? ["--export-metadata"] : []),
|
|
115
|
+
], {
|
|
116
|
+
pythonPath: arguments_.pythonPath,
|
|
117
|
+
signal: arguments_.signal,
|
|
118
|
+
failureMessage: artifact === "findings"
|
|
119
|
+
? `Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`
|
|
120
|
+
: "Could not export the saved threat model as Markdown.",
|
|
121
|
+
...(arguments_.output === "-" && output !== undefined ? { output } : {}),
|
|
122
|
+
});
|
|
123
|
+
return (arguments_.output === "-" && output === undefined) ||
|
|
124
|
+
arguments_.includeMetadata
|
|
125
|
+
? result.stdout
|
|
126
|
+
: undefined;
|
|
127
|
+
}
|
|
128
|
+
export async function resolveArtifactExportOutput(arguments_, currentDirectory) {
|
|
129
|
+
const canonicalScan = await realpath(arguments_.scanDir).catch(() => arguments_.scanDir);
|
|
130
|
+
const scanRelativeOutput = relative(arguments_.scanDir, arguments_.output);
|
|
131
|
+
const scanLocalOutput = join("exports", ARTIFACT_EXPORT_FILENAMES[arguments_.format]);
|
|
132
|
+
if (arguments_.output !== "-" &&
|
|
133
|
+
!isOutsidePath(scanRelativeOutput) &&
|
|
134
|
+
scanRelativeOutput !== scanLocalOutput) {
|
|
135
|
+
throw new CodexSecurityError("The export output path cannot overwrite a scan artifact.");
|
|
136
|
+
}
|
|
137
|
+
const outputPath = arguments_.output === "-"
|
|
138
|
+
? "-"
|
|
139
|
+
: !isOutsidePath(scanRelativeOutput)
|
|
140
|
+
? join(canonicalScan, scanRelativeOutput)
|
|
141
|
+
: join(await realpath(dirname(arguments_.output)).catch((error) => {
|
|
142
|
+
if (error.code === "ENOENT")
|
|
143
|
+
throw new CodexSecurityError(`Export output directory does not exist: ${dirname(arguments_.output)}. Create the directory and retry.`);
|
|
144
|
+
throw error;
|
|
145
|
+
}), basename(arguments_.output));
|
|
146
|
+
if (arguments_.output !== "-") {
|
|
147
|
+
const outputFromCurrent = relative(currentDirectory, arguments_.output);
|
|
148
|
+
if (outputFromCurrent !== "" && !isOutsidePath(outputFromCurrent)) {
|
|
149
|
+
let existingParent;
|
|
150
|
+
for (let directory = dirname(arguments_.output); relative(currentDirectory, directory) !== ""; directory = dirname(directory)) {
|
|
151
|
+
const metadata = await lstat(directory).catch((error) => {
|
|
152
|
+
if (error.code === "ENOENT")
|
|
153
|
+
return undefined;
|
|
154
|
+
throw error;
|
|
155
|
+
});
|
|
156
|
+
if (metadata?.isSymbolicLink()) {
|
|
157
|
+
throw new CodexSecurityError("The export output path cannot traverse a repository symlink.");
|
|
158
|
+
}
|
|
159
|
+
if (metadata !== undefined)
|
|
160
|
+
existingParent ??= directory;
|
|
161
|
+
}
|
|
162
|
+
const canonicalCurrent = await realpath(currentDirectory).catch(() => currentDirectory);
|
|
163
|
+
const expectedOutput = existingParent === undefined
|
|
164
|
+
? resolve(canonicalCurrent, outputFromCurrent)
|
|
165
|
+
: resolve(await realpath(existingParent), relative(existingParent, arguments_.output));
|
|
166
|
+
if (isOutsidePath(relative(canonicalCurrent, outputPath)) ||
|
|
167
|
+
relative(expectedOutput, outputPath) !== "") {
|
|
168
|
+
throw new CodexSecurityError("The export output path cannot traverse a repository symlink.");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { ...arguments_, scanDir: canonicalScan, output: outputPath };
|
|
173
|
+
}
|
|
174
|
+
/** Resolve saved artifacts after the workbench validates their recorded identity. */
|
|
175
|
+
export async function resolveSavedArtifactDirectory(scanId, artifact, format, workbench) {
|
|
176
|
+
// Reuse the workbench's recorded digest and scan binding checks without
|
|
177
|
+
// requiring a writable saved-scan directory for stdout or external exports.
|
|
178
|
+
const context = await workbench(workbenchArgs("export-findings", {
|
|
179
|
+
scanId,
|
|
180
|
+
artifact,
|
|
181
|
+
format,
|
|
182
|
+
validateOnly: true,
|
|
183
|
+
}));
|
|
184
|
+
const scan = context["scan"];
|
|
185
|
+
if (typeof scan?.["scanDir"] !== "string")
|
|
186
|
+
throw new CodexSecurityError(`Artifacts for scan ${scanId} are unavailable.`);
|
|
187
|
+
return resolve(expandHome(scan["scanDir"]));
|
|
188
|
+
}
|
|
189
|
+
/** Export saved artifacts without authenticating or starting Codex. */
|
|
190
|
+
export async function exportArtifact(options) {
|
|
191
|
+
const artifact = options.artifact ?? "findings";
|
|
192
|
+
const format = resolveArtifactFormat(artifact, options.format);
|
|
193
|
+
const environment = {
|
|
194
|
+
...exportEnvironment(),
|
|
195
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
|
|
196
|
+
};
|
|
197
|
+
let directory;
|
|
198
|
+
if (options.source.directory !== undefined) {
|
|
199
|
+
directory = resolve(expandHome(options.source.directory));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const python = await resolvePluginPython({
|
|
203
|
+
configuredPath: options.pythonPath,
|
|
204
|
+
environment,
|
|
205
|
+
signal: options.signal,
|
|
206
|
+
});
|
|
207
|
+
const pluginRoot = await bundledPluginRoot();
|
|
208
|
+
directory = await resolveSavedArtifactDirectory(options.source.scanId, artifact, format, (args) => runWorkbench({
|
|
209
|
+
python,
|
|
210
|
+
pluginRoot,
|
|
211
|
+
environment,
|
|
212
|
+
signal: options.signal,
|
|
213
|
+
failureMessage: "Could not export Codex Security scan artifacts",
|
|
214
|
+
}, args));
|
|
215
|
+
}
|
|
216
|
+
const arguments_ = await resolveArtifactExportOutput({
|
|
217
|
+
scanDir: directory,
|
|
218
|
+
artifact,
|
|
219
|
+
format,
|
|
220
|
+
output: options.output === "-" ? "-" : resolve(expandHome(options.output)),
|
|
221
|
+
pythonPath: options.pythonPath,
|
|
222
|
+
signal: options.signal,
|
|
223
|
+
includeMetadata: artifact === "threat-model" && options.output !== "-",
|
|
224
|
+
...(options.sourceRoot === undefined
|
|
225
|
+
? {}
|
|
226
|
+
: { sourceRoot: resolve(expandHome(options.sourceRoot)) }),
|
|
227
|
+
}, process.cwd());
|
|
228
|
+
const metadata = await runArtifactExport(arguments_, options.output === "-" ? process.stdout : undefined);
|
|
229
|
+
const description = metadata === undefined
|
|
230
|
+
? null
|
|
231
|
+
: JSON.parse(metadata);
|
|
232
|
+
return {
|
|
233
|
+
path: arguments_.output === "-" ? null : arguments_.output,
|
|
234
|
+
provenance: description?.provenance ?? null,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
export async function writeArtifactOutput(output, value) {
|
|
238
|
+
const destination = new NodeWritable({
|
|
239
|
+
write(chunk, _encoding, callback) {
|
|
240
|
+
try {
|
|
241
|
+
if (output instanceof NodeWritable) {
|
|
242
|
+
output.write(chunk, callback);
|
|
243
|
+
}
|
|
244
|
+
else if (output.write(chunk)) {
|
|
245
|
+
callback();
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
callback(new CodexSecurityError("The export stdout stream cannot report backpressure safely."));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
const forwardError = (error) => {
|
|
257
|
+
destination.destroy(error);
|
|
258
|
+
};
|
|
259
|
+
if (output instanceof NodeWritable)
|
|
260
|
+
output.once("error", forwardError);
|
|
261
|
+
try {
|
|
262
|
+
await pipeline(typeof value === "string" || value instanceof Uint8Array
|
|
263
|
+
? [value]
|
|
264
|
+
: value, destination);
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
if (output instanceof NodeWritable) {
|
|
268
|
+
output.removeListener("error", forwardError);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export function exportEnvironment(environment = process.env) {
|
|
273
|
+
return pythonUtf8Environment(Object.fromEntries([
|
|
274
|
+
"PATH",
|
|
275
|
+
"Path",
|
|
276
|
+
"PATHEXT",
|
|
277
|
+
"SystemRoot",
|
|
278
|
+
"SYSTEMROOT",
|
|
279
|
+
"WINDIR",
|
|
280
|
+
"TMP",
|
|
281
|
+
"TEMP",
|
|
282
|
+
"TMPDIR",
|
|
283
|
+
"PYTHON",
|
|
284
|
+
"XDG_CACHE_HOME",
|
|
285
|
+
"LANG",
|
|
286
|
+
"LC_ALL",
|
|
287
|
+
"LC_CTYPE",
|
|
288
|
+
]
|
|
289
|
+
.filter((key) => environment[key] !== undefined)
|
|
290
|
+
.map((key) => [key, environment[key]])));
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=artifact-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-export.js","sourceRoot":"","sources":["../src/artifact-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,IAAI,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,E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arguments.js\";\nimport { spawn } from \"node:child_process\";\nimport { lstat, realpath } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { Writable as NodeWritable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { relativePathIsOutside as isOutsidePath } from \"./targets.js\";\nimport {\n bundledPluginRoot,\n codexSecurityStateDirectory,\n expandHome,\n pythonUtf8Environment,\n resolvePluginPython,\n runWorkbench,\n} from \"./runtime.js\";\n\nexport type ArtifactOutput = Pick<NodeJS.WriteStream, \"write\">;\n\nexport const ARTIFACT_EXPORT_FILENAMES = {\n csv: \"findings.csv\",\n json: \"findings.json\",\n sarif: \"results.sarif\",\n md: \"threatmodel.md\",\n} as const;\nexport type ExportFormat = keyof typeof ARTIFACT_EXPORT_FILENAMES;\nexport type ExportArtifactKind = \"findings\" | \"threat-model\";\n\nexport interface ArtifactExportArguments {\n scanDir: string;\n artifact?: ExportArtifactKind;\n format: ExportFormat;\n output: string;\n sourceRoot?: string;\n pythonPath?: string;\n signal?: AbortSignal;\n includeMetadata?: boolean;\n}\n\nexport type ExportArtifactOptions = {\n source:\n | { directory: string; scanId?: never }\n | { scanId: string; directory?: never };\n output: string;\n pythonPath?: string;\n signal?: AbortSignal;\n} & (\n | { artifact: \"threat-model\"; format?: \"md\"; sourceRoot?: never }\n | {\n artifact?: \"findings\";\n format?: \"csv\" | \"json\" | \"sarif\";\n sourceRoot?: string;\n }\n);\n\nexport interface ArtifactExportResult {\n path: string | null;\n provenance: JsonObject | null;\n}\n\ninterface HelperOptions {\n pythonPath?: string;\n protectedRoot?: string;\n pluginRoot?: string;\n signal?: AbortSignal;\n output?: ArtifactOutput;\n failureMessage?: string;\n}\n\nexport function resolveArtifactFormat(\n artifact: ExportArtifactKind,\n format?: ExportFormat,\n): ExportFormat {\n const selected = format ?? (artifact === \"threat-model\" ? \"md\" : \"sarif\");\n if ((artifact === \"threat-model\") !== (selected === \"md\")) {\n throw new CodexSecurityError(\n artifact === \"threat-model\"\n ? \"Threat-model exports only support --export-format md.\"\n : \"Findings exports support --export-format csv, json, or sarif.\",\n );\n }\n return selected;\n}\n\nexport async function runArtifactHelper(\n args: readonly string[],\n options: HelperOptions = {},\n): Promise<{ stdout: string; stderr: string }> {\n const environment = exportEnvironment();\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n protectedRoot: options.protectedRoot,\n signal: options.signal,\n });\n const plugin = options.pluginRoot ?? (await bundledPluginRoot());\n const invocation = spawn(\n python,\n [\n \"-I\",\n \"-X\",\n \"utf8\",\n \"-B\",\n join(plugin, \"scripts\", \"finalize_scan_contract.py\"),\n ...args,\n ],\n {\n env: environment,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n let stderr = \"\";\n let stdout = \"\";\n invocation.stderr.setEncoding(\"utf8\");\n invocation.stderr.on(\"data\", (chunk: string) => {\n stderr = `${stderr}${chunk}`.slice(-64 * 1024);\n });\n const forwarded =\n options.output === undefined\n ? (async () => {\n invocation.stdout.setEncoding(\"utf8\");\n for await (const chunk of invocation.stdout) stdout += chunk;\n })()\n : writeArtifactOutput(options.output, invocation.stdout);\n let status: number;\n try {\n [status] = await Promise.all([\n new Promise<number>((resolve, reject) => {\n invocation.once(\"error\", reject);\n invocation.once(\"close\", (code, signal) =>\n resolve(signal === null ? (code ?? 1) : 1),\n );\n }),\n forwarded,\n ]);\n } catch (error) {\n invocation.stdout.destroy();\n invocation.kill();\n throw error;\n }\n if (status !== 0) {\n const detail = stderr.trim().split(\"\\n\").at(-1);\n throw new CodexSecurityError(\n detail?.replace(/^finalize_scan_contract\\.py: error: /, \"\") ||\n options.failureMessage ||\n \"Could not export Codex Security artifacts.\",\n );\n }\n return { stdout, stderr };\n}\n\nexport async function writeThreatModel(\n directory: string,\n options: HelperOptions = {},\n): Promise<string> {\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--write-threat-model\"],\n options,\n );\n return result.stderr.trim().replace(/^codex-security: warning: /u, \"\");\n}\n\n/** Read the current document path without making an optional projection required. */\nexport async function readThreatModelPath(\n directory: string,\n options: HelperOptions = {},\n): Promise<string | null> {\n try {\n options.signal?.throwIfAborted();\n const result = await runArtifactHelper(\n [\"--scan-dir\", directory, \"--describe-threat-model\"],\n options,\n );\n return (JSON.parse(result.stdout) as ArtifactExportResult).path;\n } catch {\n options.signal?.throwIfAborted();\n return null;\n }\n}\n\nexport async function runArtifactExport(\n arguments_: ArtifactExportArguments,\n output?: ArtifactOutput,\n): Promise<string | undefined> {\n const artifact = arguments_.artifact ?? \"findings\";\n resolveArtifactFormat(artifact, arguments_.format);\n const result = await runArtifactHelper(\n [\n \"--scan-dir\",\n arguments_.scanDir,\n ...(artifact === \"findings\" ? [] : [\"--export-artifact\", artifact]),\n \"--export-format\",\n arguments_.format,\n ...(arguments_.output === \"-\"\n ? []\n : [\"--export-output\", arguments_.output]),\n ...(arguments_.sourceRoot === undefined\n ? []\n : [\"--source-root\", arguments_.sourceRoot]),\n ...(arguments_.includeMetadata ? [\"--export-metadata\"] : []),\n ],\n {\n pythonPath: arguments_.pythonPath,\n signal: arguments_.signal,\n failureMessage:\n artifact === \"findings\"\n ? `Could not export Codex Security findings as ${arguments_.format.toUpperCase()}.`\n : \"Could not export the saved threat model as Markdown.\",\n ...(arguments_.output === \"-\" && output !== undefined ? { output } : {}),\n },\n );\n return (arguments_.output === \"-\" && output === undefined) ||\n arguments_.includeMetadata\n ? result.stdout\n : undefined;\n}\n\nexport async function resolveArtifactExportOutput(\n arguments_: ArtifactExportArguments,\n currentDirectory: string,\n): Promise<ArtifactExportArguments> {\n const canonicalScan = await realpath(arguments_.scanDir).catch(\n () => arguments_.scanDir,\n );\n const scanRelativeOutput = relative(arguments_.scanDir, arguments_.output);\n const scanLocalOutput = join(\n \"exports\",\n ARTIFACT_EXPORT_FILENAMES[arguments_.format],\n );\n if (\n arguments_.output !== \"-\" &&\n !isOutsidePath(scanRelativeOutput) &&\n scanRelativeOutput !== scanLocalOutput\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot overwrite a scan artifact.\",\n );\n }\n const outputPath =\n arguments_.output === \"-\"\n ? \"-\"\n : !isOutsidePath(scanRelativeOutput)\n ? join(canonicalScan, scanRelativeOutput)\n : join(\n await realpath(dirname(arguments_.output)).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\")\n throw new CodexSecurityError(\n `Export output directory does not exist: ${dirname(arguments_.output)}. Create the directory and retry.`,\n );\n throw error;\n },\n ),\n basename(arguments_.output),\n );\n if (arguments_.output !== \"-\") {\n const outputFromCurrent = relative(currentDirectory, arguments_.output);\n if (outputFromCurrent !== \"\" && !isOutsidePath(outputFromCurrent)) {\n let existingParent: string | undefined;\n for (\n let directory = dirname(arguments_.output);\n relative(currentDirectory, directory) !== \"\";\n directory = dirname(directory)\n ) {\n const metadata = await lstat(directory).catch(\n (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n },\n );\n if (metadata?.isSymbolicLink()) {\n throw new CodexSecurityError(\n \"The export output path cannot traverse a repository symlink.\",\n );\n }\n if (metadata !== undefined) existingParent ??= directory;\n }\n const canonicalCurrent = await realpath(currentDirectory).catch(\n () => currentDirectory,\n );\n const expectedOutput =\n existingParent === undefined\n ? resolve(canonicalCurrent, outputFromCurrent)\n : resolve(\n await realpath(existingParent),\n relative(existingParent, arguments_.output),\n );\n if (\n isOutsidePath(relative(canonicalCurrent, outputPath)) ||\n relative(expectedOutput, outputPath) !== \"\"\n ) {\n throw new CodexSecurityError(\n \"The export output path cannot traverse a repository symlink.\",\n );\n }\n }\n }\n return { ...arguments_, scanDir: canonicalScan, output: outputPath };\n}\n\n/** Resolve saved artifacts after the workbench validates their recorded identity. */\nexport async function resolveSavedArtifactDirectory(\n scanId: string,\n artifact: ExportArtifactKind,\n format: ExportFormat,\n workbench: (args: readonly string[]) => Promise<JsonObject>,\n): Promise<string> {\n // Reuse the workbench's recorded digest and scan binding checks without\n // requiring a writable saved-scan directory for stdout or external exports.\n const context = await workbench(\n workbenchArgs(\"export-findings\", {\n scanId,\n artifact,\n format,\n validateOnly: true,\n }),\n );\n const scan = context[\"scan\"] as JsonObject | undefined;\n if (typeof scan?.[\"scanDir\"] !== \"string\")\n throw new CodexSecurityError(\n `Artifacts for scan ${scanId} are unavailable.`,\n );\n return resolve(expandHome(scan[\"scanDir\"]));\n}\n\n/** Export saved artifacts without authenticating or starting Codex. */\nexport async function exportArtifact(\n options: ExportArtifactOptions,\n): Promise<ArtifactExportResult> {\n const artifact = options.artifact ?? \"findings\";\n const format = resolveArtifactFormat(artifact, options.format);\n const environment = {\n ...exportEnvironment(),\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),\n };\n let directory: string;\n if (options.source.directory !== undefined) {\n directory = resolve(expandHome(options.source.directory));\n } else {\n const python = await resolvePluginPython({\n configuredPath: options.pythonPath,\n environment,\n signal: options.signal,\n });\n const pluginRoot = await bundledPluginRoot();\n directory = await resolveSavedArtifactDirectory(\n options.source.scanId,\n artifact,\n format,\n (args) =>\n runWorkbench(\n {\n python,\n pluginRoot,\n environment,\n signal: options.signal,\n failureMessage: \"Could not export Codex Security scan artifacts\",\n },\n args,\n ),\n );\n }\n const arguments_ = await resolveArtifactExportOutput(\n {\n scanDir: directory,\n artifact,\n format,\n output:\n options.output === \"-\" ? \"-\" : resolve(expandHome(options.output)),\n pythonPath: options.pythonPath,\n signal: options.signal,\n includeMetadata: artifact === \"threat-model\" && options.output !== \"-\",\n ...(options.sourceRoot === undefined\n ? {}\n : { sourceRoot: resolve(expandHome(options.sourceRoot)) }),\n },\n process.cwd(),\n );\n const metadata = await runArtifactExport(\n arguments_,\n options.output === \"-\" ? process.stdout : undefined,\n );\n const description =\n metadata === undefined\n ? null\n : (JSON.parse(metadata) as ArtifactExportResult);\n return {\n path: arguments_.output === \"-\" ? null : arguments_.output,\n provenance: description?.provenance ?? null,\n };\n}\n\nexport async function writeArtifactOutput(\n output: ArtifactOutput,\n value: string | Uint8Array | AsyncIterable<Uint8Array>,\n): Promise<void> {\n const destination = new NodeWritable({\n write(chunk, _encoding, callback) {\n try {\n if (output instanceof NodeWritable) {\n output.write(chunk, callback);\n } else if (output.write(chunk)) {\n callback();\n } else {\n callback(\n new CodexSecurityError(\n \"The export stdout stream cannot report backpressure safely.\",\n ),\n );\n }\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n },\n });\n const forwardError = (error: Error): void => {\n destination.destroy(error);\n };\n if (output instanceof NodeWritable) output.once(\"error\", forwardError);\n try {\n await pipeline(\n typeof value === \"string\" || value instanceof Uint8Array\n ? [value]\n : value,\n destination,\n );\n } finally {\n if (output instanceof NodeWritable) {\n output.removeListener(\"error\", forwardError);\n }\n }\n}\n\nexport function exportEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n): NodeJS.ProcessEnv {\n return pythonUtf8Environment(\n Object.fromEntries(\n [\n \"PATH\",\n \"Path\",\n \"PATHEXT\",\n \"SystemRoot\",\n \"SYSTEMROOT\",\n \"WINDIR\",\n \"TMP\",\n \"TEMP\",\n \"TMPDIR\",\n \"PYTHON\",\n \"XDG_CACHE_HOME\",\n \"LANG\",\n \"LC_ALL\",\n \"LC_CTYPE\",\n ]\n .filter((key) => environment[key] !== undefined)\n .map((key) => [key, environment[key]]),\n ),\n );\n}\n"]}
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { type CodexCommand, type ProcessEnvironment } from "./runtime.js";
|
|
2
|
-
export interface LoginResult {
|
|
3
|
-
success: boolean;
|
|
4
|
-
exitCode: number | null;
|
|
5
|
-
stdout: string;
|
|
6
|
-
stderr: string;
|
|
1
|
+
import { runCodexCommand, type CodexCommand, type ProcessEnvironment } from "./runtime.js";
|
|
2
|
+
export interface LoginResult extends Awaited<ReturnType<typeof runCodexCommand>> {
|
|
7
3
|
}
|
|
8
4
|
export interface AccountStatus {
|
|
9
5
|
authenticated: boolean;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAYA,OAAO,EAGL,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AA8DtB,MAAM,WAAW,WAAY,SAAQ,OAAO,CAC1C,UAAU,CAAC,OAAO,eAAe,CAAC,CACnC;CAAG;AAEJ,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,gBAAgB;;IAkB3B,YACE,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,WAAW,EAAE,kBAAkB,EAC/B,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAqDtC;IAED,IAAW,OAAO,IAAI,IAAI,CAEzB;IAED,IAAW,OAAO,IAAI,MAAM,GAAG,IAAI,CAElC;IAED,IAAW,eAAe,IAAI,MAAM,GAAG,IAAI,CAE1C;IAED,IAAW,QAAQ,IAAI,MAAM,GAAG,IAAI,CAEnC;IAEY,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAExC;IAEY,mBAAmB,CAC9B,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAO,GACrC,OAAO,CAAC,IAAI,CAAC,CAGf;IAEM,MAAM,IAAI,IAAI,CAoBpB;CA2CF;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,kBAAkB,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC,CAWtB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,kBAAkB,EAC/B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAgBxB;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,kBAAkB,EAC/B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAaf"}
|
package/dist/auth.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { parse } from "smol-toml";
|
|
7
|
-
import { CodexSecurityError, PluginBootstrapError } from "./errors.js";
|
|
7
|
+
import { CodexSecurityError, PluginBootstrapError, errorMessage, } from "./errors.js";
|
|
8
8
|
import { executablePathForSpawn, expandHome, runCodexCommand, } from "./runtime.js";
|
|
9
9
|
const LOGIN_CHILD_TERMINATION_GRACE_MS = 1_000;
|
|
10
10
|
/** @internal */
|
|
@@ -16,9 +16,13 @@ export function environmentEntry(environment, requested) {
|
|
|
16
16
|
return Object.entries(environment).find(([name]) => name.toUpperCase() === upper)?.[1];
|
|
17
17
|
}
|
|
18
18
|
/** @internal */
|
|
19
|
+
export function withoutOpenAiApiKeys(environment) {
|
|
20
|
+
return Object.fromEntries(Object.entries(environment).filter(([name]) => !["OPENAI_API_KEY", "CODEX_API_KEY"].includes(name.toUpperCase())));
|
|
21
|
+
}
|
|
22
|
+
/** @internal */
|
|
19
23
|
export function configuredCodexHome(environment) {
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
const configured = environmentEntry(environment, "CODEX_HOME");
|
|
25
|
+
return resolve(expandHome(configured?.trim() ? configured : join(homedir(), ".codex"), environment));
|
|
22
26
|
}
|
|
23
27
|
/** @internal */
|
|
24
28
|
export async function readCodexHomeConfig(environment, signal) {
|
|
@@ -32,7 +36,7 @@ export async function readCodexHomeConfig(environment, signal) {
|
|
|
32
36
|
signal?.throwIfAborted();
|
|
33
37
|
if (error.code === "ENOENT")
|
|
34
38
|
return {};
|
|
35
|
-
throw new CodexSecurityError(
|
|
39
|
+
throw new CodexSecurityError(`Could not read the configured Codex provider: ${errorMessage(error)}`, { cause: error });
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
export class CodexLoginHandle {
|
|
@@ -55,7 +59,7 @@ export class CodexLoginHandle {
|
|
|
55
59
|
constructor(command, args, environment, onSuccess) {
|
|
56
60
|
void this.#urlReady.promise.catch(() => undefined);
|
|
57
61
|
void this.#deviceReady.promise.catch(() => undefined);
|
|
58
|
-
this.#child = spawn(executablePathForSpawn(command.command), [...args], {
|
|
62
|
+
this.#child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
|
|
59
63
|
env: environment,
|
|
60
64
|
stdio: ["pipe", "pipe", "pipe"],
|
|
61
65
|
windowsHide: true,
|
|
@@ -82,7 +86,9 @@ export class CodexLoginHandle {
|
|
|
82
86
|
};
|
|
83
87
|
this.#settleInstructionWaiters(result);
|
|
84
88
|
if (result.success) {
|
|
85
|
-
Promise.resolve(
|
|
89
|
+
Promise.resolve()
|
|
90
|
+
.then(onSuccess)
|
|
91
|
+
.then(() => resolve(result), reject);
|
|
86
92
|
}
|
|
87
93
|
else {
|
|
88
94
|
resolve(result);
|
|
@@ -121,8 +127,14 @@ export class CodexLoginHandle {
|
|
|
121
127
|
}
|
|
122
128
|
cancel() {
|
|
123
129
|
this.#canceled = true;
|
|
124
|
-
if (this.#child.exitCode !== null || this.#child.signalCode !== null)
|
|
130
|
+
if (this.#child.exitCode !== null || this.#child.signalCode !== null) {
|
|
131
|
+
// Descendants can retain inherited pipes after the login process exits.
|
|
132
|
+
// Cancellation must release those pipes so the close event can settle.
|
|
133
|
+
this.#child.stdin.destroy();
|
|
134
|
+
this.#child.stdout.destroy();
|
|
135
|
+
this.#child.stderr.destroy();
|
|
125
136
|
return;
|
|
137
|
+
}
|
|
126
138
|
this.#child.kill("SIGTERM");
|
|
127
139
|
if (this.#forcedTermination !== undefined)
|
|
128
140
|
return;
|
|
@@ -201,15 +213,18 @@ export const CODEX_AUTH_CONFIG_KEYS = [
|
|
|
201
213
|
"forced_chatgpt_workspace_id",
|
|
202
214
|
];
|
|
203
215
|
/** @internal Shared login recovery guidance for model commands. */
|
|
204
|
-
export const NO_CREDENTIALS_MESSAGE = "No credentials were found. Run 'codex-security login'
|
|
205
|
-
"'codex-security login --device-auth'
|
|
206
|
-
"
|
|
216
|
+
export const NO_CREDENTIALS_MESSAGE = "No credentials were found. Run 'codex-security login'. On a remote or headless " +
|
|
217
|
+
"machine, use 'codex-security login --device-auth' if your workspace allows it. " +
|
|
218
|
+
"If device auth is disabled, see 'codex-security login --help' for browser login over SSH. " +
|
|
219
|
+
"For CI, set OPENAI_API_KEY or CODEX_API_KEY.";
|
|
207
220
|
function preferredAuthUrl(value) {
|
|
208
221
|
for (const match of plainTerminalText(value).matchAll(/https?:\/\/[^\s<>"']+/g)) {
|
|
209
222
|
const url = match[0].replace(/[.,;:!?)\]}]+$/, "");
|
|
210
223
|
try {
|
|
211
|
-
const
|
|
212
|
-
|
|
224
|
+
const parsed = new URL(url);
|
|
225
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.$/, "");
|
|
226
|
+
if (parsed.protocol === "https:" &&
|
|
227
|
+
hostname !== "localhost" &&
|
|
213
228
|
!hostname.endsWith(".localhost") &&
|
|
214
229
|
!(isIP(hostname) === 4 && hostname.startsWith("127.")) &&
|
|
215
230
|
hostname !== "0.0.0.0" &&
|