@openai/codex-security 0.1.15 → 0.1.17
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 +204 -4
- package/_bundled_plugin/.app.json +1 -1
- package/_bundled_plugin/.mcp.json +9 -3
- 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/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/sarif-adapter.md +5 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +34 -6
- package/_bundled_plugin/scripts/finalize_scan_contract.py +121 -32
- package/_bundled_plugin/scripts/generate_in_scope_files.py +20 -0
- package/_bundled_plugin/scripts/generate_rank_input.py +23 -7
- package/_bundled_plugin/scripts/launch_codex_security_mcp +32 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +27 -0
- package/_bundled_plugin/scripts/workbench_cli.py +22 -15
- package/_bundled_plugin/scripts/workbench_db.py +35 -35
- package/_bundled_plugin/scripts/workbench_progress.py +6 -3
- package/_bundled_plugin/scripts/workbench_scan_history.py +17 -2
- package/_bundled_plugin/scripts/workbench_target.py +36 -5
- package/_bundled_plugin/scripts/workbench_validation.py +9 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +17 -1
- package/_bundled_plugin/skills/verify-fix/SKILL.md +44 -0
- package/_bundled_plugin/skills/verify-fix/agents/openai.yaml +4 -0
- package/dist/api.d.ts +16 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +180 -11
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +12 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +781 -62
- package/dist/cli.js.map +1 -1
- package/dist/component-plan.d.ts +15 -0
- package/dist/component-plan.d.ts.map +1 -0
- package/dist/component-plan.js +145 -0
- package/dist/component-plan.js.map +1 -0
- package/dist/component-scan.d.ts +83 -0
- package/dist/component-scan.d.ts.map +1 -0
- package/dist/component-scan.js +279 -0
- package/dist/component-scan.js.map +1 -0
- package/dist/contract.d.ts +8 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +27 -8
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +20 -0
- package/dist/cost-model.d.ts.map +1 -0
- package/dist/cost-model.js +86 -0
- package/dist/cost-model.js.map +1 -0
- package/dist/cost.d.ts +2 -11
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -95
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts +4 -0
- package/dist/custom-validation-prompt.d.ts.map +1 -0
- package/dist/custom-validation-prompt.js +94 -0
- package/dist/custom-validation-prompt.js.map +1 -0
- package/dist/custom-validation.d.ts +45 -0
- package/dist/custom-validation.d.ts.map +1 -0
- package/dist/custom-validation.js +292 -0
- package/dist/custom-validation.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +53 -5
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.js +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +3 -4
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +109 -38
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +12 -5
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +72 -28
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +9 -2
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +205 -7
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +5 -21
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts +4 -0
- package/dist/scan-sessions.d.ts.map +1 -0
- package/dist/scan-sessions.js +35 -0
- package/dist/scan-sessions.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +16 -1
- package/dist/targets.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -20
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts +3 -0
- package/dist/windows-path.d.ts.map +1 -0
- package/dist/windows-path.js +16 -0
- package/dist/windows-path.js.map +1 -0
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +12 -0
- package/dist/worker-progress.js.map +1 -1
- package/package.json +8 -2
package/dist/publication.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication.js","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAuB,MAAM,eAAe,CAAC;AAQlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AA+BjD,MAAM,iBAAiB,GAAG;IACxB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,aAAa,EAAE,SAAS;CAC2C,CAAC;AAEtE,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,aAAqB,EACrB,OAAsC;IAEtC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,aAAa,EAAE;QACjD,UAAU,EAAE,MAAM,iBAAiB,EAAE;KACtC,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAA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O,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,KAAK,CACJ,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,MAAM,GAAG,CAAC;QAClB,OAAO,KAAK,GAAG;QACf,OAAO,KAAK,IAAI;QAChB,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAClC,CAAC;AACN,CAAC","sourcesContent":["import { resolve } from \"node:path\";\nimport { loadContract, type LoadedContract } from \"./contract.js\";\nimport type {\n Finding,\n FindingCodeEvidence,\n FindingLocation,\n ScanTargetRecord,\n SeverityLevel,\n} from \"./models.js\";\nimport { bundledPluginRoot } from \"./runtime.js\";\n\nexport interface LinearPublicationDestination {\n type: \"linear\";\n teamId: string;\n projectId?: string;\n}\n\nexport interface PrepareScanPublicationOptions {\n destination: \"linear\";\n teamId: string;\n projectId?: string;\n uploadedAt?: string;\n}\n\nexport interface PreparedPublicationIssue {\n findingId: string;\n occurrenceId: string;\n title: string;\n description: string;\n priority?: 1 | 2 | 3 | 4;\n}\n\nexport interface PreparedScanPublication {\n scanId: string;\n uploadId: string;\n scanDirectory: string;\n destination: LinearPublicationDestination;\n issues: PreparedPublicationIssue[];\n}\n\nconst LINEAR_PRIORITIES = {\n critical: 1,\n high: 2,\n medium: 3,\n low: 4,\n informational: undefined,\n} as const satisfies Record<SeverityLevel, 1 | 2 | 3 | 4 | undefined>;\n\nexport async function prepareScanPublication(\n scanDirectory: string,\n options: PrepareScanPublicationOptions,\n): Promise<PreparedScanPublication> {\n const contract = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n });\n const uploadedAt = options.uploadedAt ?? new Date().toISOString();\n const scanId = contract.manifest.scan.id;\n\n return {\n scanId,\n uploadId: scanId,\n scanDirectory: resolve(scanDirectory),\n destination: {\n type: options.destination,\n teamId: options.teamId,\n ...(options.projectId === undefined\n ? {}\n : { projectId: options.projectId }),\n },\n issues: contract.findings.findings.map((finding) => {\n const priority = LINEAR_PRIORITIES[finding.severity.level];\n return {\n findingId: finding.findingId,\n occurrenceId: finding.occurrenceId,\n title: `[Codex Security][${finding.severity.level.toUpperCase()}] ${finding.title}`,\n description: renderFindingDescription(contract, finding, uploadedAt),\n ...(priority === undefined ? {} : { priority }),\n };\n }),\n };\n}\n\nfunction renderFindingDescription(\n contract: LoadedContract,\n finding: Finding,\n uploadedAt: string,\n): string {\n const { coverage } = contract;\n const { scan } = contract.manifest;\n const lines = [\n \"## Codex Security finding\",\n \"\",\n `**Scan ID:** ${scan.id}`,\n `**Finding ID:** ${finding.findingId}`,\n `**Occurrence ID:** ${finding.occurrenceId}`,\n `**Fingerprint:** ${finding.fingerprints.primary}`,\n `**Severity:** ${finding.severity.level.toUpperCase()}`,\n `**Confidence:** ${finding.confidence.level.toUpperCase()}`,\n ...(finding.taxonomy.cwe.length === 0\n ? []\n : [`**CWE:** ${finding.taxonomy.cwe.join(\", \")}`]),\n \"\",\n \"## Scanned code\",\n \"\",\n `**Repository:** ${scan.target.displayName}`,\n ...(scan.target.remote === undefined\n ? []\n : [`**Remote:** ${scan.target.remote}`]),\n ...renderTargetIdentity(scan.target),\n `**Scanned scope:** ${scan.scope.includePaths.join(\", \") || \"entire repository\"}`,\n ...(scan.scope.excludePaths.length === 0\n ? []\n : [`**Excluded scope:** ${scan.scope.excludePaths.join(\", \")}`]),\n `**Coverage:** ${coverage.completeness}`,\n `**Coverage mode:** ${coverage.mode}`,\n `**Scan mode:** ${scanMode(coverage.mode)}`,\n `**Started:** ${scan.startedAt}`,\n `**Completed:** ${scan.completedAt}`,\n `**Uploaded:** ${uploadedAt}`,\n \"\",\n \"### Affected locations\",\n \"\",\n ...finding.locations.map((location) =>\n renderLocation(scan.target, location),\n ),\n \"\",\n \"## Summary\",\n \"\",\n finding.summary,\n ];\n\n const rootCause = finding.rootCause;\n if (typeof rootCause === \"string\") {\n lines.push(\"\", \"## Root cause\", \"\", rootCause);\n } else if (rootCause !== undefined) {\n lines.push(\"\", \"## Root cause\", \"\", rootCause.summary);\n if (rootCause.code !== undefined) {\n lines.push(\"\", fencedCode(rootCause.code, rootCause.language));\n }\n }\n\n if (finding.codeEvidence !== undefined && finding.codeEvidence.length > 0) {\n lines.push(\"\", \"## Source-code evidence\");\n for (const evidence of finding.codeEvidence) {\n lines.push(\"\", ...renderCodeEvidence(scan.target, evidence));\n }\n }\n\n lines.push(\"\", \"## Remediation\", \"\", finding.remediation);\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nfunction renderTargetIdentity(target: ScanTargetRecord): string[] {\n const lines: string[] = [];\n if (target.revision !== undefined) {\n const label = target.kind === \"git_revision\" ? \"Revision\" : \"Base revision\";\n lines.push(`**${label}:** ${target.revision}`);\n }\n if (target.baseRevision !== undefined) {\n lines.push(`**Diff base revision:** ${target.baseRevision}`);\n }\n if (target.headRevision !== undefined) {\n lines.push(`**Diff head revision:** ${target.headRevision}`);\n }\n if (target.snapshotDigest !== undefined) {\n lines.push(`**Snapshot digest:** ${target.snapshotDigest}`);\n }\n return lines;\n}\n\nfunction scanMode(mode: LoadedContract[\"coverage\"][\"mode\"]): string {\n if (mode === \"deep_repository\") return \"deep\";\n if (mode === \"repository\") return \"standard\";\n return mode;\n}\n\nfunction renderLocation(\n target: ScanTargetRecord,\n location: FindingLocation,\n): string {\n const role =\n location.role === undefined ? \"Location\" : humanizeRole(location.role);\n const label = `${location.path}:${location.startLine}${\n location.endLine === undefined || location.endLine === location.startLine\n ? \"\"\n : `-${location.endLine}`\n }`;\n const sourceUrl = immutableSourceUrl(target, location);\n return `- **${role}:** ${sourceUrl === undefined ? `\\`${label}\\`` : `[\\`${label}\\`](${sourceUrl})`}`;\n}\n\nfunction renderCodeEvidence(\n target: ScanTargetRecord,\n evidence: FindingCodeEvidence,\n): string[] {\n const location: FindingLocation = {\n path: evidence.path,\n startLine: evidence.startLine,\n ...(evidence.endLine === undefined ? {} : { endLine: evidence.endLine }),\n ...(evidence.role === undefined ? {} : { role: evidence.role }),\n };\n return [\n `### ${evidence.label}`,\n \"\",\n renderLocation(target, location),\n \"\",\n fencedCode(evidence.code, evidence.language),\n \"\",\n evidence.explanation,\n ];\n}\n\nfunction humanizeRole(role: string): string {\n const words = role.replaceAll(\"_\", \" \");\n return `${words.slice(0, 1).toUpperCase()}${words.slice(1)}`;\n}\n\nfunction fencedCode(code: string, language?: string): string {\n let fenceLength = 3;\n for (const match of code.matchAll(/`+/g)) {\n fenceLength = Math.max(fenceLength, match[0].length + 1);\n }\n const fence = \"`\".repeat(fenceLength);\n const tag =\n language !== undefined && /^[A-Za-z0-9_+.-]+$/.test(language)\n ? language\n : \"\";\n return `${fence}${tag}\\n${code}\\n${fence}`;\n}\n\nfunction immutableSourceUrl(\n target: ScanTargetRecord,\n location: FindingLocation,\n): string | undefined {\n if (\n target.kind !== \"git_revision\" ||\n target.remote === undefined ||\n target.revision === undefined ||\n !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(target.revision) ||\n !isSafeRepositoryPath(location.path)\n ) {\n return undefined;\n }\n\n let remote: URL;\n try {\n remote = new URL(target.remote);\n } catch {\n return undefined;\n }\n if (\n remote.protocol !== \"https:\" ||\n (remote.hostname !== \"github.com\" && !remote.hostname.endsWith(\".ghe.com\"))\n ) {\n return undefined;\n }\n\n const repository = remote.pathname\n .replace(/\\.git\\/?$/, \"\")\n .replace(/\\/$/, \"\");\n const path = location.path.split(\"/\").map(encodeURIComponent).join(\"/\");\n remote.pathname = `${repository}/blob/${target.revision}/${path}`;\n remote.hash = `L${location.startLine}${\n location.endLine === undefined || location.endLine === location.startLine\n ? \"\"\n : `-L${location.endLine}`\n }`;\n return remote.toString();\n}\n\nfunction isSafeRepositoryPath(path: string): boolean {\n if (\n path.includes(\"\\\\\") ||\n /^[A-Za-z]:/.test(path) ||\n /[\\u0000-\\u001f\\u007f]/.test(path)\n ) {\n return false;\n }\n\n return path\n .split(\"/\")\n .every(\n (segment) =>\n segment.length > 0 &&\n segment !== \".\" &&\n segment !== \"..\" &&\n !/%(?:2e|2f|5c)/i.test(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C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxE,MAAM,CAAC,QAAQ,GAAG,GAAG,UAAU,SAAS,MAAM,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;IAClE,MAAM,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,SAAS,GAClC,QAAQ,CAAC,OAAO,KAAK,SAAS,IAAI,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,SAAS;QACvE,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,KAAK,QAAQ,CAAC,OAAO,EAC3B,EAAE,CAAC;IACH,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACxC,IACE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QACnB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QACvB,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,KAAK,CACJ,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,MAAM,GAAG,CAAC;QAClB,OAAO,KAAK,GAAG;QACf,OAAO,KAAK,IAAI;QAChB,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAClC,CAAC;AACN,CAAC","sourcesContent":["import {\n loadContractWithScanDirectory,\n type LoadedContract,\n} from \"./contract.js\";\nimport type {\n Finding,\n FindingCodeEvidence,\n FindingLocation,\n ScanTargetRecord,\n SeverityLevel,\n} from \"./models.js\";\nimport { bundledPluginRoot } from \"./runtime.js\";\n\nexport interface LinearPublicationDestination {\n type: \"linear\";\n teamId: string;\n projectId?: string;\n}\n\nexport interface PrepareScanPublicationOptions {\n destination: \"linear\";\n teamId: string;\n projectId?: string;\n uploadedAt?: string;\n}\n\nexport interface PreparedPublicationIssue {\n findingId: string;\n occurrenceId: string;\n title: string;\n description: string;\n priority?: 1 | 2 | 3 | 4;\n}\n\nexport interface PreparedScanPublication {\n scanId: string;\n uploadId: string;\n scanDirectory: string;\n destination: LinearPublicationDestination;\n issues: PreparedPublicationIssue[];\n}\n\nconst LINEAR_PRIORITIES = {\n critical: 1,\n high: 2,\n medium: 3,\n low: 4,\n informational: undefined,\n} as const satisfies Record<SeverityLevel, 1 | 2 | 3 | 4 | undefined>;\n\nexport async function prepareScanPublication(\n scanDirectory: string,\n options: PrepareScanPublicationOptions,\n): Promise<PreparedScanPublication> {\n const { contract, scanDirectory: canonicalScanDirectory } =\n await loadContractWithScanDirectory(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n });\n const uploadedAt = options.uploadedAt ?? new Date().toISOString();\n const scanId = contract.manifest.scan.id;\n\n return {\n scanId,\n uploadId: scanId,\n scanDirectory: canonicalScanDirectory,\n destination: {\n type: options.destination,\n teamId: options.teamId,\n ...(options.projectId === undefined\n ? {}\n : { projectId: options.projectId }),\n },\n issues: contract.findings.findings.map((finding) => {\n const priority = LINEAR_PRIORITIES[finding.severity.level];\n return {\n findingId: finding.findingId,\n occurrenceId: finding.occurrenceId,\n title: `[Codex Security][${finding.severity.level.toUpperCase()}] ${finding.title}`,\n description: renderFindingDescription(contract, finding, uploadedAt),\n ...(priority === undefined ? {} : { priority }),\n };\n }),\n };\n}\n\nfunction renderFindingDescription(\n contract: LoadedContract,\n finding: Finding,\n uploadedAt: string,\n): string {\n const { coverage } = contract;\n const { scan } = contract.manifest;\n const lines = [\n \"## Codex Security finding\",\n \"\",\n `**Scan ID:** ${scan.id}`,\n `**Finding ID:** ${finding.findingId}`,\n `**Occurrence ID:** ${finding.occurrenceId}`,\n `**Fingerprint:** ${finding.fingerprints.primary}`,\n `**Severity:** ${finding.severity.level.toUpperCase()}`,\n `**Confidence:** ${finding.confidence.level.toUpperCase()}`,\n ...(finding.taxonomy.cwe.length === 0\n ? []\n : [`**CWE:** ${finding.taxonomy.cwe.join(\", \")}`]),\n \"\",\n \"## Scanned code\",\n \"\",\n `**Repository:** ${scan.target.displayName}`,\n ...(scan.target.remote === undefined\n ? []\n : [`**Remote:** ${scan.target.remote}`]),\n ...renderTargetIdentity(scan.target),\n `**Scanned scope:** ${scan.scope.includePaths.join(\", \") || \"entire repository\"}`,\n ...(scan.scope.excludePaths.length === 0\n ? []\n : [`**Excluded scope:** ${scan.scope.excludePaths.join(\", \")}`]),\n `**Coverage:** ${coverage.completeness}`,\n `**Coverage mode:** ${coverage.mode}`,\n `**Scan mode:** ${scanMode(coverage.mode)}`,\n `**Started:** ${scan.startedAt}`,\n `**Completed:** ${scan.completedAt}`,\n `**Uploaded:** ${uploadedAt}`,\n \"\",\n \"### Affected locations\",\n \"\",\n ...finding.locations.map((location) =>\n renderLocation(scan.target, location),\n ),\n \"\",\n \"## Summary\",\n \"\",\n finding.summary,\n ];\n\n const rootCause = finding.rootCause;\n if (typeof rootCause === \"string\") {\n lines.push(\"\", \"## Root cause\", \"\", rootCause);\n } else if (rootCause !== undefined) {\n lines.push(\"\", \"## Root cause\", \"\", rootCause.summary);\n if (rootCause.code !== undefined) {\n lines.push(\"\", fencedCode(rootCause.code, rootCause.language));\n }\n }\n\n if (finding.codeEvidence !== undefined && finding.codeEvidence.length > 0) {\n lines.push(\"\", \"## Source-code evidence\");\n for (const evidence of finding.codeEvidence) {\n lines.push(\"\", ...renderCodeEvidence(scan.target, evidence));\n }\n }\n\n lines.push(\"\", \"## Remediation\", \"\", finding.remediation);\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nfunction renderTargetIdentity(target: ScanTargetRecord): string[] {\n const lines: string[] = [];\n if (target.revision !== undefined) {\n const label = target.kind === \"git_revision\" ? \"Revision\" : \"Base revision\";\n lines.push(`**${label}:** ${target.revision}`);\n }\n if (target.baseRevision !== undefined) {\n lines.push(`**Diff base revision:** ${target.baseRevision}`);\n }\n if (target.headRevision !== undefined) {\n lines.push(`**Diff head revision:** ${target.headRevision}`);\n }\n if (target.snapshotDigest !== undefined) {\n lines.push(`**Snapshot digest:** ${target.snapshotDigest}`);\n }\n return lines;\n}\n\nfunction scanMode(mode: LoadedContract[\"coverage\"][\"mode\"]): string {\n if (mode === \"deep_repository\") return \"deep\";\n if (mode === \"repository\") return \"standard\";\n return mode;\n}\n\nfunction renderLocation(\n target: ScanTargetRecord,\n location: FindingLocation,\n): string {\n const role =\n location.role === undefined ? \"Location\" : humanizeRole(location.role);\n const label = `${location.path}:${location.startLine}${\n location.endLine === undefined || location.endLine === location.startLine\n ? \"\"\n : `-${location.endLine}`\n }`;\n const sourceUrl = immutableSourceUrl(target, location);\n return `- **${role}:** ${sourceUrl === undefined ? `\\`${label}\\`` : `[\\`${label}\\`](${sourceUrl})`}`;\n}\n\nfunction renderCodeEvidence(\n target: ScanTargetRecord,\n evidence: FindingCodeEvidence,\n): string[] {\n const location: FindingLocation = {\n path: evidence.path,\n startLine: evidence.startLine,\n ...(evidence.endLine === undefined ? {} : { endLine: evidence.endLine }),\n ...(evidence.role === undefined ? {} : { role: evidence.role }),\n };\n return [\n `### ${evidence.label}`,\n \"\",\n renderLocation(target, location),\n \"\",\n fencedCode(evidence.code, evidence.language),\n \"\",\n evidence.explanation,\n ];\n}\n\nfunction humanizeRole(role: string): string {\n const words = role.replaceAll(\"_\", \" \");\n return `${words.slice(0, 1).toUpperCase()}${words.slice(1)}`;\n}\n\nfunction fencedCode(code: string, language?: string): string {\n let fenceLength = 3;\n for (const match of code.matchAll(/`+/g)) {\n fenceLength = Math.max(fenceLength, match[0].length + 1);\n }\n const fence = \"`\".repeat(fenceLength);\n const tag =\n language !== undefined && /^[A-Za-z0-9_+.-]+$/.test(language)\n ? language\n : \"\";\n return `${fence}${tag}\\n${code}\\n${fence}`;\n}\n\nfunction immutableSourceUrl(\n target: ScanTargetRecord,\n location: FindingLocation,\n): string | undefined {\n if (\n target.kind !== \"git_revision\" ||\n target.remote === undefined ||\n target.revision === undefined ||\n !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(target.revision) ||\n !isSafeRepositoryPath(location.path)\n ) {\n return undefined;\n }\n\n let remote: URL;\n try {\n remote = new URL(target.remote);\n } catch {\n return undefined;\n }\n if (\n remote.protocol !== \"https:\" ||\n (remote.hostname !== \"github.com\" && !remote.hostname.endsWith(\".ghe.com\"))\n ) {\n return undefined;\n }\n\n const repository = remote.pathname\n .replace(/\\.git\\/?$/, \"\")\n .replace(/\\/$/, \"\");\n const path = location.path.split(\"/\").map(encodeURIComponent).join(\"/\");\n remote.pathname = `${repository}/blob/${target.revision}/${path}`;\n remote.hash = `L${location.startLine}${\n location.endLine === undefined || location.endLine === location.startLine\n ? \"\"\n : `-L${location.endLine}`\n }`;\n return remote.toString();\n}\n\nfunction isSafeRepositoryPath(path: string): boolean {\n if (\n path.includes(\"\\\\\") ||\n /^[A-Za-z]:/.test(path) ||\n /[\\u0000-\\u001f\\u007f]/.test(path)\n ) {\n return false;\n }\n\n return path\n .split(\"/\")\n .every(\n (segment) =>\n segment.length > 0 &&\n segment !== \".\" &&\n segment !== \"..\" &&\n !/%(?:2e|2f|5c)/i.test(segment),\n );\n}\n"]}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -98,13 +98,14 @@ export declare function requirePrivateCredentialFile(metadata: Pick<Stats, "mode
|
|
|
98
98
|
export declare function preserveCodexSecurityPluginRegistration(codexHome: string, config: JsonObject): Promise<JsonObject>;
|
|
99
99
|
export declare function requireOutputOutsideRepository(repository: string, outputDirectory: string, pathKind?: ProtectedScanPathKind): void;
|
|
100
100
|
export declare function requireOutputOutsideRepositories(repositories: readonly string[], outputDirectory: string, pathKind?: ProtectedScanPathKind): void;
|
|
101
|
-
export declare function preparePersistentOutputRoot(stateDirectory: string, category: "scans" | "policies", repositoryName: string): Promise<string>;
|
|
102
|
-
export declare function runWorkbench(options: WorkbenchCommandOptions, args: readonly string[]): Promise<JsonObject>;
|
|
101
|
+
export declare function preparePersistentOutputRoot(stateDirectory: string, category: "scans" | "policies" | "validations", repositoryName: string): Promise<string>;
|
|
102
|
+
export declare function runWorkbench(options: WorkbenchCommandOptions, args: readonly string[], input?: string): Promise<JsonObject>;
|
|
103
103
|
export declare function bundledPluginCandidates(moduleDirectory: string): string[];
|
|
104
104
|
export declare function bundledPluginRoot(): Promise<string>;
|
|
105
105
|
export declare function validateOutputDir(outputDirectory?: string, archiveExisting?: boolean): Promise<string | null>;
|
|
106
106
|
export declare function planOutputArchive(outputDirectory: string | null): Promise<string | null>;
|
|
107
107
|
export declare function requireModelSafeOutputDir(path: string): void;
|
|
108
|
+
export declare function canonicalizeModelSafePath(input: string): Promise<string>;
|
|
108
109
|
export declare function prepareOutputDir(outputDirectory: string | undefined, repositoryName: string, temporaryRoot?: string, validateLocation?: (path: string) => void, archiveExisting?: boolean, onOutputArchived?: (archiveDir: string) => void): Promise<string>;
|
|
109
110
|
export declare function validatePreparedOutputDir(path: string, validateLocation?: (path: string) => void): Promise<string>;
|
|
110
111
|
export declare function requirePrivateOutputDirectory(metadata: Pick<Stats, "mode" | "uid">, path: string, effectiveUid?: number | undefined): void;
|
|
@@ -129,6 +130,7 @@ export declare function pluginMetadata(root: string): Promise<{
|
|
|
129
130
|
}>;
|
|
130
131
|
export declare function resolvePluginPython(options?: PluginPythonOptions): Promise<string>;
|
|
131
132
|
export declare function pluginExecutionEnvironment(python: string, environment?: ProcessEnvironment): ProcessEnvironment;
|
|
133
|
+
export declare function pythonUtf8Environment(environment: ProcessEnvironment): ProcessEnvironment;
|
|
132
134
|
export declare function cleanupSdkDirectory(path: string): Promise<void>;
|
|
133
135
|
export declare function runCodexCommand(command: CodexCommand, args: readonly string[], environment: ProcessEnvironment, input?: string, signal?: AbortSignal): Promise<CodexCommandResult>;
|
|
134
136
|
export declare function isPythonPathCandidate(candidate: string): boolean;
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAA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runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { constants, existsSync, readdirSync, } from "node:fs";
|
|
4
|
-
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile, } from "node:fs/promises";
|
|
4
|
+
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
@@ -14,6 +14,7 @@ import extractZip from "extract-zip";
|
|
|
14
14
|
import { parse } from "smol-toml";
|
|
15
15
|
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, errorMessage, } from "./errors.js";
|
|
16
16
|
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
17
|
+
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
17
18
|
const execFile = promisify(execFileCallback);
|
|
18
19
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
19
20
|
export const PLUGIN_NAME = "codex-security";
|
|
@@ -24,8 +25,10 @@ const MAX_ZIP_EXPANDED_SIZE = 512 * 1024 * 1024;
|
|
|
24
25
|
const MODEL_UNSAFE_PATH = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u;
|
|
25
26
|
const CREDENTIAL_LOCK_NAME = ".codex-security-scan.lock";
|
|
26
27
|
const CREDENTIAL_LOGOUT_MARKER = ".codex-security-logged-out";
|
|
28
|
+
const CREDENTIAL_LOCK_HEARTBEAT_MILLISECONDS = 5_000;
|
|
27
29
|
const CREDENTIAL_LOCK_POLL_MILLISECONDS = 25;
|
|
28
30
|
const INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS = 30_000;
|
|
31
|
+
const MAX_PROCESS_ID = 2_147_483_647;
|
|
29
32
|
const MAX_WINDOWS_CREDENTIAL_ACL_STDERR = 64 * 1024;
|
|
30
33
|
function environmentValue(environment, requested) {
|
|
31
34
|
const exact = environment[requested]?.trim();
|
|
@@ -37,11 +40,12 @@ function environmentValue(environment, requested) {
|
|
|
37
40
|
}
|
|
38
41
|
export function codexSecurityStateDirectory(environment = process.env) {
|
|
39
42
|
const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const path = configured !== undefined
|
|
44
|
+
? resolve(expandHome(configured, environment))
|
|
45
|
+
: resolve(expandHome(environmentValue(environment, "CODEX_HOME") ??
|
|
46
|
+
join(homedir(), ".codex"), environment), "state", "plugins", "codex-security");
|
|
47
|
+
requireModelSafeOutputDir(path);
|
|
48
|
+
return path;
|
|
45
49
|
}
|
|
46
50
|
export function codexSecurityCredentialHome(environment = process.env) {
|
|
47
51
|
return join(codexSecurityStateDirectory(environment), "codex-home");
|
|
@@ -569,7 +573,9 @@ async function secureWindowsCredentialHome(path) {
|
|
|
569
573
|
"$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
570
574
|
"while ($true) { $parent = Microsoft.PowerShell.Management\\Split-Path -Path $path -Parent; if (-not $parent -or $parent -eq $path) { break }; Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $parent | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl; $path = $parent }",
|
|
571
575
|
"Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl",
|
|
572
|
-
|
|
576
|
+
// A temporary descendant can disappear after enumeration. Its missing
|
|
577
|
+
// descriptor reduces the count and retries the stable snapshot.
|
|
578
|
+
"Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH -Recurse -Force | Microsoft.PowerShell.Core\\ForEach-Object { try { Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $_.FullName | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl } catch { if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw } } }",
|
|
573
579
|
].join("; ");
|
|
574
580
|
const resolvePrincipalScript = [
|
|
575
581
|
"$ErrorActionPreference = 'Stop'",
|
|
@@ -726,7 +732,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
726
732
|
throw error;
|
|
727
733
|
});
|
|
728
734
|
if (existingLock !== null) {
|
|
729
|
-
if (await recoverStaleCredentialHomeLock(lock))
|
|
735
|
+
if (await recoverStaleCredentialHomeLock(lock, signal))
|
|
730
736
|
continue;
|
|
731
737
|
await delay(CREDENTIAL_LOCK_POLL_MILLISECONDS, undefined, { signal });
|
|
732
738
|
continue;
|
|
@@ -742,7 +748,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
742
748
|
catch (error) {
|
|
743
749
|
if (nodeErrorCode(error) !== "EEXIST")
|
|
744
750
|
throw error;
|
|
745
|
-
if (await recoverStaleCredentialHomeLock(lock))
|
|
751
|
+
if (await recoverStaleCredentialHomeLock(lock, signal))
|
|
746
752
|
continue;
|
|
747
753
|
await delay(CREDENTIAL_LOCK_POLL_MILLISECONDS, undefined, { signal });
|
|
748
754
|
continue;
|
|
@@ -754,10 +760,19 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
754
760
|
await rm(lock, { recursive: true, force: true }).catch(() => undefined);
|
|
755
761
|
throw error;
|
|
756
762
|
}
|
|
763
|
+
const heartbeat = setInterval(async () => {
|
|
764
|
+
try {
|
|
765
|
+
const now = new Date();
|
|
766
|
+
await utimes(lock, now, now);
|
|
767
|
+
}
|
|
768
|
+
catch { }
|
|
769
|
+
}, CREDENTIAL_LOCK_HEARTBEAT_MILLISECONDS);
|
|
770
|
+
heartbeat.unref();
|
|
757
771
|
let released = false;
|
|
758
772
|
return async () => {
|
|
759
773
|
if (released)
|
|
760
774
|
return;
|
|
775
|
+
clearInterval(heartbeat);
|
|
761
776
|
await requireSecureCredentialHome(codexHome, {
|
|
762
777
|
...securityOptions,
|
|
763
778
|
expectedDevice,
|
|
@@ -772,7 +787,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
772
787
|
};
|
|
773
788
|
}
|
|
774
789
|
}
|
|
775
|
-
async function recoverStaleCredentialHomeLock(lock) {
|
|
790
|
+
async function recoverStaleCredentialHomeLock(lock, signal) {
|
|
776
791
|
const metadata = await lstat(lock).catch((error) => {
|
|
777
792
|
if (nodeErrorCode(error) === "ENOENT")
|
|
778
793
|
return null;
|
|
@@ -791,28 +806,49 @@ async function recoverStaleCredentialHomeLock(lock) {
|
|
|
791
806
|
if (nodeErrorCode(error) !== "ENOENT" && !(error instanceof SyntaxError)) {
|
|
792
807
|
throw error;
|
|
793
808
|
}
|
|
794
|
-
if (Date.now() - metadata.mtimeMs <
|
|
795
|
-
INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS) {
|
|
796
|
-
return false;
|
|
797
|
-
}
|
|
798
809
|
}
|
|
799
|
-
|
|
810
|
+
// Only positive signed-32-bit PIDs identify an owner. Other values can name
|
|
811
|
+
// process groups or fail argument validation, so use the stale-age check.
|
|
812
|
+
const ownerPid = isRecord(owner) ? owner["pid"] : undefined;
|
|
813
|
+
let ownerExited = false;
|
|
814
|
+
let ownerIsAlive = false;
|
|
815
|
+
if (typeof ownerPid === "number" &&
|
|
816
|
+
Number.isInteger(ownerPid) &&
|
|
817
|
+
ownerPid > 0 &&
|
|
818
|
+
ownerPid <= MAX_PROCESS_ID) {
|
|
800
819
|
try {
|
|
801
|
-
process.kill(
|
|
802
|
-
|
|
820
|
+
process.kill(ownerPid, 0);
|
|
821
|
+
ownerIsAlive = true;
|
|
803
822
|
}
|
|
804
823
|
catch (error) {
|
|
805
|
-
if (nodeErrorCode(error)
|
|
806
|
-
|
|
807
|
-
|
|
824
|
+
if (nodeErrorCode(error) === "ESRCH")
|
|
825
|
+
ownerExited = true;
|
|
826
|
+
else if (nodeErrorCode(error) === "EPERM")
|
|
827
|
+
ownerIsAlive = true;
|
|
828
|
+
else
|
|
808
829
|
throw error;
|
|
809
|
-
}
|
|
810
830
|
}
|
|
811
831
|
}
|
|
812
|
-
|
|
813
|
-
INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS) {
|
|
832
|
+
if (!ownerExited &&
|
|
833
|
+
Date.now() - metadata.mtimeMs < INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS) {
|
|
814
834
|
return false;
|
|
815
835
|
}
|
|
836
|
+
if (ownerIsAlive) {
|
|
837
|
+
await delay(CREDENTIAL_LOCK_HEARTBEAT_MILLISECONDS, undefined, { signal });
|
|
838
|
+
const refreshedMetadata = await lstat(lock).catch((error) => {
|
|
839
|
+
if (nodeErrorCode(error) === "ENOENT")
|
|
840
|
+
return null;
|
|
841
|
+
throw error;
|
|
842
|
+
});
|
|
843
|
+
if (refreshedMetadata === null)
|
|
844
|
+
return true;
|
|
845
|
+
if (!refreshedMetadata.isDirectory() ||
|
|
846
|
+
refreshedMetadata.isSymbolicLink()) {
|
|
847
|
+
throw new OutputDirectoryError(`Codex Security credential-home lock is not a directory: ${lock}`);
|
|
848
|
+
}
|
|
849
|
+
if (refreshedMetadata.mtimeMs > metadata.mtimeMs)
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
816
852
|
const quarantine = `${lock}.stale-${randomUUID()}`;
|
|
817
853
|
try {
|
|
818
854
|
await rename(lock, quarantine);
|
|
@@ -950,35 +986,39 @@ export function requireOutputOutsideRepositories(repositories, outputDirectory,
|
|
|
950
986
|
requireOutputOutsideRepository(repository, outputDirectory, pathKind);
|
|
951
987
|
}
|
|
952
988
|
export async function preparePersistentOutputRoot(stateDirectory, category, repositoryName) {
|
|
989
|
+
requireModelSafeOutputDir(stateDirectory);
|
|
953
990
|
await mkdir(stateDirectory, { recursive: true, mode: 0o700 });
|
|
954
991
|
let root = await realpath(stateDirectory);
|
|
955
992
|
for (const directory of [category, safePrefix(repositoryName)]) {
|
|
956
993
|
root = join(root, directory);
|
|
957
994
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
958
995
|
if (!(await lstat(root)).isDirectory()) {
|
|
959
|
-
throw new OutputDirectoryError(`Persistent ${category === "scans" ? "scan" : "policy"} output must use real directories: ${root}`);
|
|
996
|
+
throw new OutputDirectoryError(`Persistent ${category === "scans" ? "scan" : category === "policies" ? "policy" : "validation"} output must use real directories: ${root}`);
|
|
960
997
|
}
|
|
961
998
|
}
|
|
962
999
|
return root;
|
|
963
1000
|
}
|
|
964
|
-
export async function runWorkbench(options, args) {
|
|
1001
|
+
export async function runWorkbench(options, args, input) {
|
|
965
1002
|
let stdout;
|
|
966
1003
|
try {
|
|
967
|
-
|
|
1004
|
+
const environment = Object.fromEntries(Object.entries(options.environment).filter(([name]) => name.toUpperCase() !== "OPENAI_API_KEY" &&
|
|
1005
|
+
name.toUpperCase() !== "CODEX_API_KEY" &&
|
|
1006
|
+
name.toUpperCase() !== "OPENROUTER_API_KEY" &&
|
|
1007
|
+
name.toUpperCase() !== "FIREWORKS_API_KEY"));
|
|
1008
|
+
const result = await runCodexCommand({ command: options.python }, [
|
|
968
1009
|
"-I",
|
|
1010
|
+
"-X",
|
|
1011
|
+
"utf8",
|
|
969
1012
|
"-B",
|
|
970
1013
|
join(options.pluginRoot, "scripts", "workbench_db.py"),
|
|
971
1014
|
...args,
|
|
972
|
-
],
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
windowsHide: true,
|
|
980
|
-
signal: options.signal,
|
|
981
|
-
}));
|
|
1015
|
+
], pythonUtf8Environment(environment), input, options.signal);
|
|
1016
|
+
if (!result.success) {
|
|
1017
|
+
throw new Error(result.stderr.trim() ||
|
|
1018
|
+
result.stdout.trim() ||
|
|
1019
|
+
`Workbench exited with status ${result.exitCode}.`);
|
|
1020
|
+
}
|
|
1021
|
+
stdout = result.stdout;
|
|
982
1022
|
}
|
|
983
1023
|
catch (error) {
|
|
984
1024
|
if (options.signal?.aborted)
|
|
@@ -1096,6 +1136,28 @@ export function requireModelSafeOutputDir(path) {
|
|
|
1096
1136
|
if (MODEL_UNSAFE_PATH.test(path)) {
|
|
1097
1137
|
throw new OutputDirectoryError("Scan output directory must not contain control or line-separator characters.");
|
|
1098
1138
|
}
|
|
1139
|
+
const ambiguous = process.platform === "win32" ? windowsUnsafePathComponent(path) : undefined;
|
|
1140
|
+
if (ambiguous !== undefined) {
|
|
1141
|
+
throw new OutputDirectoryError(`Codex Security paths must not contain Windows-ambiguous components: ${ambiguous}`);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
export async function canonicalizeModelSafePath(input) {
|
|
1145
|
+
const path = resolve(expandHome(input));
|
|
1146
|
+
requireModelSafeOutputDir(path);
|
|
1147
|
+
for (let ancestor = path;; ancestor = dirname(ancestor)) {
|
|
1148
|
+
try {
|
|
1149
|
+
const canonicalAncestor = resolve(ancestor, await realpath(ancestor));
|
|
1150
|
+
const canonical = resolve(canonicalAncestor, relative(ancestor, path));
|
|
1151
|
+
requireModelSafeOutputDir(canonical);
|
|
1152
|
+
return canonical;
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
if (nodeErrorCode(error) !== "ENOENT")
|
|
1156
|
+
throw error;
|
|
1157
|
+
if (dirname(ancestor) === ancestor)
|
|
1158
|
+
throw error;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1099
1161
|
}
|
|
1100
1162
|
export async function prepareOutputDir(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false, onOutputArchived) {
|
|
1101
1163
|
if (outputDirectory === undefined) {
|
|
@@ -1644,11 +1706,20 @@ export async function resolvePluginPython(options = {}) {
|
|
|
1644
1706
|
}
|
|
1645
1707
|
export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
1646
1708
|
return {
|
|
1647
|
-
...environment,
|
|
1709
|
+
...pythonUtf8Environment(environment),
|
|
1648
1710
|
PYTHON: python,
|
|
1649
1711
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1650
1712
|
};
|
|
1651
1713
|
}
|
|
1714
|
+
export function pythonUtf8Environment(environment) {
|
|
1715
|
+
const normalized = { ...environment };
|
|
1716
|
+
for (const name of Object.keys(normalized)) {
|
|
1717
|
+
if (name.toUpperCase() === "PYTHONUTF8")
|
|
1718
|
+
delete normalized[name];
|
|
1719
|
+
}
|
|
1720
|
+
normalized["PYTHONUTF8"] = "1";
|
|
1721
|
+
return normalized;
|
|
1722
|
+
}
|
|
1652
1723
|
export async function cleanupSdkDirectory(path) {
|
|
1653
1724
|
await rm(path, { recursive: true, force: true });
|
|
1654
1725
|
}
|
|
@@ -1764,7 +1835,7 @@ function safeArchivePath(value) {
|
|
|
1764
1835
|
parts.includes("..") ||
|
|
1765
1836
|
value.includes("\\") ||
|
|
1766
1837
|
value.includes("\0") ||
|
|
1767
|
-
parts.some(
|
|
1838
|
+
parts.some(isWindowsUnsafePathComponent) ||
|
|
1768
1839
|
normalized.length === 0) {
|
|
1769
1840
|
throw new PluginBootstrapError(`Plugin ZIP contains an unsafe path: ${value}`);
|
|
1770
1841
|
}
|