@openai/codex-security 0.1.7 → 0.1.9
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 +23 -11
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/mcp/server.mjs +1 -1
- 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 +2 -2
- package/_bundled_plugin/references/config-preflight.md +6 -6
- package/_bundled_plugin/references/desktop-config-preflight.md +11 -0
- package/_bundled_plugin/references/final-report.md +10 -14
- package/_bundled_plugin/references/scan-artifacts.md +17 -17
- package/_bundled_plugin/references/shared-hard-rules.md +2 -2
- package/_bundled_plugin/scripts/deep_scan_workbench.py +422 -48
- package/_bundled_plugin/scripts/generate_rank_input.py +118 -1
- package/_bundled_plugin/scripts/workbench_cli.py +1 -50
- package/_bundled_plugin/scripts/workbench_constants.py +0 -3
- package/_bundled_plugin/scripts/workbench_db.py +7 -297
- package/_bundled_plugin/scripts/workbench_progress.py +11 -0
- package/_bundled_plugin/scripts/workbench_scan_history.py +8 -64
- package/_bundled_plugin/scripts/workbench_target.py +2 -6
- package/_bundled_plugin/scripts/workbench_validation.py +0 -211
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +10 -10
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +25 -43
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +2 -4
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +11 -23
- package/_bundled_plugin/skills/security-scan/SKILL.md +89 -26
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +25 -0
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +11 -38
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +5 -6
- package/_bundled_plugin/skills/triage-finding/SKILL.md +6 -14
- package/_bundled_plugin/skills/validation/SKILL.md +9 -9
- package/dist/api.d.ts +3 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +113 -82
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +18 -71
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +57 -136
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +7 -228
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +0 -4
- package/dist/cost.js.map +1 -1
- package/dist/knowledge-base.js +4 -4
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +5 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +232 -26
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts +13 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +136 -242
- package/dist/runtime.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +8 -29
- package/dist/worker-progress.js.map +1 -1
- package/package.json +3 -3
- package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
package/dist/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { constants, existsSync } from "node:fs";
|
|
4
4
|
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -21,10 +21,6 @@ const MAX_ZIP_ENTRIES = 4_096;
|
|
|
21
21
|
const MAX_ZIP_CENTRAL_DIRECTORY = 16 * 1024 * 1024;
|
|
22
22
|
const MAX_ZIP_ENTRY_SIZE = 128 * 1024 * 1024;
|
|
23
23
|
const MAX_ZIP_EXPANDED_SIZE = 512 * 1024 * 1024;
|
|
24
|
-
const MAX_PLUGIN_MANIFEST_SIZE = 1024 * 1024;
|
|
25
|
-
const MAX_PLUGIN_COPY_ENTRIES = 4_096;
|
|
26
|
-
const MAX_PLUGIN_COPY_FILE_SIZE = 128 * 1024 * 1024;
|
|
27
|
-
const MAX_PLUGIN_COPY_SIZE = 512 * 1024 * 1024;
|
|
28
24
|
const MODEL_UNSAFE_PATH = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u;
|
|
29
25
|
const CREDENTIAL_LOCK_NAME = ".codex-security-scan.lock";
|
|
30
26
|
const CREDENTIAL_LOGOUT_MARKER = ".codex-security-logged-out";
|
|
@@ -230,6 +226,11 @@ class RepairableWindowsCredentialAclError extends Error {
|
|
|
230
226
|
super("Windows credential ACL requires repair", { cause });
|
|
231
227
|
}
|
|
232
228
|
}
|
|
229
|
+
class RepairableWindowsCredentialOwnerError extends Error {
|
|
230
|
+
constructor(cause) {
|
|
231
|
+
super(cause.message, { cause });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
233
234
|
/** Inspect a Windows DACL without translating locale-specific account names. */
|
|
234
235
|
export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options = {}) {
|
|
235
236
|
if (!WINDOWS_SID.test(currentUserSid)) {
|
|
@@ -396,28 +397,37 @@ function windowsAceAllowsAncestorReplacement(rights, inheritanceFlags) {
|
|
|
396
397
|
}
|
|
397
398
|
return false;
|
|
398
399
|
}
|
|
399
|
-
export async function verifyStableWindowsCredentialDescendants(path, inspectDescriptors) {
|
|
400
|
+
export async function verifyStableWindowsCredentialDescendants(path, inspectDescriptors, options = {}) {
|
|
400
401
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
401
402
|
let descendants = 0;
|
|
402
403
|
const pending = [path];
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
404
|
+
try {
|
|
405
|
+
while (pending.length !== 0) {
|
|
406
|
+
const current = pending.pop();
|
|
407
|
+
const directory = await opendir(current);
|
|
408
|
+
for await (const entry of directory) {
|
|
409
|
+
const child = join(current, entry.name);
|
|
410
|
+
const metadata = await lstat(child);
|
|
411
|
+
if (metadata.isSymbolicLink()) {
|
|
412
|
+
throw new Error("Windows credential home contains a symbolic link or junction");
|
|
413
|
+
}
|
|
414
|
+
if (!metadata.isDirectory() && !metadata.isFile()) {
|
|
415
|
+
throw new Error("Windows credential home contains an unsafe entry");
|
|
416
|
+
}
|
|
417
|
+
descendants += 1;
|
|
418
|
+
if (metadata.isDirectory())
|
|
419
|
+
pending.push(child);
|
|
414
420
|
}
|
|
415
|
-
descendants += 1;
|
|
416
|
-
if (metadata.isDirectory())
|
|
417
|
-
pending.push(child);
|
|
418
421
|
}
|
|
419
422
|
}
|
|
420
|
-
|
|
423
|
+
catch (error) {
|
|
424
|
+
const failure = error;
|
|
425
|
+
if (failure.code === "ENOENT" && failure.path !== path) {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
if (descendants === 0 && options.inspectEmpty !== true)
|
|
421
431
|
return;
|
|
422
432
|
if ((await inspectDescriptors()) === descendants)
|
|
423
433
|
return;
|
|
@@ -473,6 +483,66 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
473
483
|
}
|
|
474
484
|
return descriptors;
|
|
475
485
|
}
|
|
486
|
+
export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
|
|
487
|
+
let ancestors = 0;
|
|
488
|
+
for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
|
|
489
|
+
ancestors += 1;
|
|
490
|
+
if (ancestor === dirname(ancestor))
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
let home;
|
|
494
|
+
let descendantsArePrivate = true;
|
|
495
|
+
await verifyStableWindowsCredentialDescendants(path, async () => {
|
|
496
|
+
home = undefined;
|
|
497
|
+
descendantsArePrivate = true;
|
|
498
|
+
let inspected = 0;
|
|
499
|
+
const descriptors = await streamWindowsCredentialAclDescriptors(options.command, options.args, async (descriptor) => {
|
|
500
|
+
const index = inspected;
|
|
501
|
+
inspected += 1;
|
|
502
|
+
await options.resolveDescriptorAliases?.(descriptor);
|
|
503
|
+
if (index < ancestors) {
|
|
504
|
+
const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
505
|
+
resolvedAliases: options.resolvedAliases,
|
|
506
|
+
scope: "ancestor",
|
|
507
|
+
});
|
|
508
|
+
if (ancestor.untrustedPrincipals.length !== 0) {
|
|
509
|
+
throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
|
|
510
|
+
}
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (index === ancestors) {
|
|
514
|
+
try {
|
|
515
|
+
home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
516
|
+
resolvedAliases: options.resolvedAliases,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
if (error instanceof UntrustedWindowsCredentialOwnerError) {
|
|
521
|
+
throw new RepairableWindowsCredentialOwnerError(error);
|
|
522
|
+
}
|
|
523
|
+
throw new RepairableWindowsCredentialAclError(error);
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const descendant = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
528
|
+
resolvedAliases: options.resolvedAliases,
|
|
529
|
+
scope: "file",
|
|
530
|
+
});
|
|
531
|
+
if (!descendant.grantsCurrentUserAccess ||
|
|
532
|
+
descendant.untrustedPrincipals.length !== 0) {
|
|
533
|
+
descendantsArePrivate = false;
|
|
534
|
+
}
|
|
535
|
+
}, { environment: options.environment });
|
|
536
|
+
if (descriptors <= ancestors) {
|
|
537
|
+
throw new Error("Windows credential-home ancestry could not be verified");
|
|
538
|
+
}
|
|
539
|
+
return descriptors - ancestors - 1;
|
|
540
|
+
}, { inspectEmpty: true });
|
|
541
|
+
if (home === undefined) {
|
|
542
|
+
throw new Error("Windows credential ACL could not be verified");
|
|
543
|
+
}
|
|
544
|
+
return { home, descendantsArePrivate };
|
|
545
|
+
}
|
|
476
546
|
async function secureWindowsCredentialHome(path) {
|
|
477
547
|
const systemRoot = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
478
548
|
const systemDirectory = join(systemRoot, "System32");
|
|
@@ -497,7 +567,10 @@ async function secureWindowsCredentialHome(path) {
|
|
|
497
567
|
// arbitrary .NET constructors, static methods, and SID translation do not.
|
|
498
568
|
const script = [
|
|
499
569
|
"$ErrorActionPreference = 'Stop'",
|
|
570
|
+
"$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
571
|
+
"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 }",
|
|
500
572
|
"Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl",
|
|
573
|
+
"Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH -Recurse -Force | Microsoft.PowerShell.Security\\Get-Acl | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl",
|
|
501
574
|
].join("; ");
|
|
502
575
|
const resolvePrincipalScript = [
|
|
503
576
|
"$ErrorActionPreference = 'Stop'",
|
|
@@ -544,19 +617,17 @@ async function secureWindowsCredentialHome(path) {
|
|
|
544
617
|
remaining = rest;
|
|
545
618
|
}
|
|
546
619
|
};
|
|
620
|
+
let descendantsArePrivate = true;
|
|
547
621
|
const readAcl = async () => {
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
throw error;
|
|
558
|
-
throw new RepairableWindowsCredentialAclError(error);
|
|
559
|
-
}
|
|
622
|
+
const snapshot = await inspectWindowsCredentialAclSnapshot(path, sid, {
|
|
623
|
+
command: powershell,
|
|
624
|
+
args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script],
|
|
625
|
+
environment: processOptions.env,
|
|
626
|
+
resolvedAliases,
|
|
627
|
+
resolveDescriptorAliases,
|
|
628
|
+
});
|
|
629
|
+
descendantsArePrivate = snapshot.descendantsArePrivate;
|
|
630
|
+
return snapshot.home;
|
|
560
631
|
};
|
|
561
632
|
const icacls = join(systemDirectory, "icacls.exe");
|
|
562
633
|
const installTrustedAcl = async (target = path) => {
|
|
@@ -569,69 +640,13 @@ async function secureWindowsCredentialHome(path) {
|
|
|
569
640
|
`*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`,
|
|
570
641
|
], processOptions);
|
|
571
642
|
};
|
|
572
|
-
const ancestorScript = [
|
|
573
|
-
"$ErrorActionPreference = 'Stop'",
|
|
574
|
-
"$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
|
|
575
|
-
"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 }",
|
|
576
|
-
].join("; ");
|
|
577
|
-
const ancestorPaths = [];
|
|
578
|
-
for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
|
|
579
|
-
ancestorPaths.push(ancestor);
|
|
580
|
-
if (ancestor === dirname(ancestor))
|
|
581
|
-
break;
|
|
582
|
-
}
|
|
583
|
-
const ancestry = await execFile(powershell, ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", ancestorScript], processOptions);
|
|
584
|
-
const ancestorDescriptors = ancestry.stdout
|
|
585
|
-
.split(/\r?\n/u)
|
|
586
|
-
.filter((descriptor) => descriptor !== "");
|
|
587
|
-
if (ancestorDescriptors.length !== ancestorPaths.length) {
|
|
588
|
-
throw new Error("Windows credential-home ancestry could not be verified");
|
|
589
|
-
}
|
|
590
|
-
for (const descriptor of ancestorDescriptors) {
|
|
591
|
-
await resolveDescriptorAliases(descriptor);
|
|
592
|
-
const ancestor = inspectWindowsCredentialAcl(descriptor, sid, {
|
|
593
|
-
resolvedAliases,
|
|
594
|
-
scope: "ancestor",
|
|
595
|
-
});
|
|
596
|
-
if (ancestor.untrustedPrincipals.length === 0)
|
|
597
|
-
continue;
|
|
598
|
-
throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
|
|
599
|
-
}
|
|
600
|
-
const descendantsArePrivate = async () => {
|
|
601
|
-
const descendantScript = [
|
|
602
|
-
"$ErrorActionPreference = 'Stop'",
|
|
603
|
-
"Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH -Recurse -Force | Microsoft.PowerShell.Security\\Get-Acl | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl",
|
|
604
|
-
].join("; ");
|
|
605
|
-
let privateDescendants = true;
|
|
606
|
-
await verifyStableWindowsCredentialDescendants(path, async () => {
|
|
607
|
-
privateDescendants = true;
|
|
608
|
-
return streamWindowsCredentialAclDescriptors(powershell, [
|
|
609
|
-
"-NoLogo",
|
|
610
|
-
"-NoProfile",
|
|
611
|
-
"-NonInteractive",
|
|
612
|
-
"-Command",
|
|
613
|
-
descendantScript,
|
|
614
|
-
], async (descriptor) => {
|
|
615
|
-
await resolveDescriptorAliases(descriptor);
|
|
616
|
-
const descendant = inspectWindowsCredentialAcl(descriptor, sid, {
|
|
617
|
-
resolvedAliases,
|
|
618
|
-
scope: "file",
|
|
619
|
-
});
|
|
620
|
-
if (!descendant.grantsCurrentUserAccess ||
|
|
621
|
-
descendant.untrustedPrincipals.length !== 0) {
|
|
622
|
-
privateDescendants = false;
|
|
623
|
-
}
|
|
624
|
-
}, { environment: processOptions.env });
|
|
625
|
-
});
|
|
626
|
-
return privateDescendants;
|
|
627
|
-
};
|
|
628
643
|
let existing;
|
|
629
644
|
for (let attempt = 0; existing === undefined && attempt < 3; attempt += 1) {
|
|
630
645
|
try {
|
|
631
646
|
existing = await readAcl();
|
|
632
647
|
}
|
|
633
648
|
catch (error) {
|
|
634
|
-
if (error instanceof
|
|
649
|
+
if (error instanceof RepairableWindowsCredentialOwnerError) {
|
|
635
650
|
await execFile(icacls, [path, "/setowner", `*${sid}`], processOptions);
|
|
636
651
|
}
|
|
637
652
|
else if (error instanceof RepairableWindowsCredentialAclError) {
|
|
@@ -683,9 +698,10 @@ async function secureWindowsCredentialHome(path) {
|
|
|
683
698
|
if (verified.untrustedPrincipals.length !== 0) {
|
|
684
699
|
throw new Error("Windows credential ACL grants access to another identity");
|
|
685
700
|
}
|
|
686
|
-
if (!
|
|
701
|
+
if (!descendantsArePrivate) {
|
|
687
702
|
await execFile(icacls, [join(path, "*"), "/reset", "/t", "/q"], processOptions);
|
|
688
|
-
|
|
703
|
+
await readAcl();
|
|
704
|
+
if (!descendantsArePrivate) {
|
|
689
705
|
throw new Error("Windows credential descendants remain accessible");
|
|
690
706
|
}
|
|
691
707
|
}
|
|
@@ -935,7 +951,7 @@ export async function runWorkbench(options, args) {
|
|
|
935
951
|
name.toUpperCase() !== "OPENROUTER_API_KEY" &&
|
|
936
952
|
name.toUpperCase() !== "FIREWORKS_API_KEY")),
|
|
937
953
|
encoding: "utf8",
|
|
938
|
-
maxBuffer:
|
|
954
|
+
maxBuffer: Infinity,
|
|
939
955
|
windowsHide: true,
|
|
940
956
|
signal: options.signal,
|
|
941
957
|
}));
|
|
@@ -1452,101 +1468,6 @@ export async function createMarketplace(codexHome, pluginRoot, signal) {
|
|
|
1452
1468
|
throwIfSignalAborted(signal);
|
|
1453
1469
|
return marketplace;
|
|
1454
1470
|
}
|
|
1455
|
-
async function pluginProjectionFingerprint(root, signal) {
|
|
1456
|
-
throwIfSignalAborted(signal);
|
|
1457
|
-
const canonical = await realpath(root);
|
|
1458
|
-
const contractPath = join(canonical, ".internal", "external-promotion", "external-projection-contract.json");
|
|
1459
|
-
let paths;
|
|
1460
|
-
if (canonical === (await bundledPluginRoot()) &&
|
|
1461
|
-
(await isRegularFile(contractPath))) {
|
|
1462
|
-
let contract;
|
|
1463
|
-
try {
|
|
1464
|
-
contract = JSON.parse(await readFile(contractPath, "utf8"));
|
|
1465
|
-
}
|
|
1466
|
-
catch (error) {
|
|
1467
|
-
throw new PluginBootstrapError(`Invalid plugin projection contract: ${contractPath}`, { cause: error });
|
|
1468
|
-
}
|
|
1469
|
-
const shipped = isRecord(contract) ? contract["shippedExact"] : undefined;
|
|
1470
|
-
if (!Array.isArray(shipped) ||
|
|
1471
|
-
!shipped.every((path) => typeof path === "string")) {
|
|
1472
|
-
throw new PluginBootstrapError("Plugin projection contract must contain shippedExact paths.");
|
|
1473
|
-
}
|
|
1474
|
-
paths = [
|
|
1475
|
-
...new Set([".codex-plugin/plugin.json", ...shipped]
|
|
1476
|
-
.filter((path) => !path.startsWith("sdk/"))
|
|
1477
|
-
.map((path) => safeArchivePath(path))),
|
|
1478
|
-
];
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
paths = [];
|
|
1482
|
-
const pending = [canonical];
|
|
1483
|
-
let entries = 1;
|
|
1484
|
-
while (pending.length > 0) {
|
|
1485
|
-
throwIfSignalAborted(signal);
|
|
1486
|
-
const path = pending.pop();
|
|
1487
|
-
const metadata = await lstat(path);
|
|
1488
|
-
if (metadata.isSymbolicLink()) {
|
|
1489
|
-
throw new PluginBootstrapError(`Plugin contains an unsafe source path: ${path}`);
|
|
1490
|
-
}
|
|
1491
|
-
if (metadata.isDirectory()) {
|
|
1492
|
-
for await (const entry of pluginDirectoryEntries(path, signal)) {
|
|
1493
|
-
const child = join(path, entry);
|
|
1494
|
-
if (++entries > MAX_PLUGIN_COPY_ENTRIES) {
|
|
1495
|
-
throw new PluginBootstrapError(`Plugin source exceeds the copy entry limit: ${child}`);
|
|
1496
|
-
}
|
|
1497
|
-
pending.push(child);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
else if (metadata.isFile()) {
|
|
1501
|
-
paths.push(relative(canonical, path).split(sep).join("/"));
|
|
1502
|
-
}
|
|
1503
|
-
else {
|
|
1504
|
-
throw new PluginBootstrapError(`Plugin contains a non-regular file: ${path}`);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
paths.sort();
|
|
1509
|
-
const fingerprint = createHash("sha256");
|
|
1510
|
-
let totalSize = 0;
|
|
1511
|
-
for (const relativePath of paths) {
|
|
1512
|
-
throwIfSignalAborted(signal);
|
|
1513
|
-
const path = join(canonical, ...relativePath.split("/"));
|
|
1514
|
-
const metadata = await lstat(path);
|
|
1515
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
1516
|
-
throw new PluginBootstrapError(`Plugin projection contains an unsafe source path: ${path}`);
|
|
1517
|
-
}
|
|
1518
|
-
if (metadata.size > MAX_PLUGIN_COPY_FILE_SIZE) {
|
|
1519
|
-
throw new PluginBootstrapError(`Plugin source exceeds the per-file safety limit: ${path}`);
|
|
1520
|
-
}
|
|
1521
|
-
totalSize += metadata.size;
|
|
1522
|
-
if (totalSize > MAX_PLUGIN_COPY_SIZE) {
|
|
1523
|
-
throw new PluginBootstrapError("Plugin source exceeds the copy safety limit.");
|
|
1524
|
-
}
|
|
1525
|
-
const handle = await open(path, constants.O_RDONLY |
|
|
1526
|
-
(process.platform === "win32"
|
|
1527
|
-
? 0
|
|
1528
|
-
: constants.O_NOFOLLOW | constants.O_NONBLOCK));
|
|
1529
|
-
try {
|
|
1530
|
-
if (!samePluginFile(metadata, await handle.stat())) {
|
|
1531
|
-
throw new PluginBootstrapError(`Plugin source changed before its integrity could be verified: ${path}`);
|
|
1532
|
-
}
|
|
1533
|
-
const contents = await readExactly(handle, metadata.size, 0, signal);
|
|
1534
|
-
if (!samePluginFile(metadata, await handle.stat())) {
|
|
1535
|
-
throw new PluginBootstrapError(`Plugin source changed while its integrity was being verified: ${path}`);
|
|
1536
|
-
}
|
|
1537
|
-
fingerprint.update(relativePath);
|
|
1538
|
-
fingerprint.update("\0");
|
|
1539
|
-
fingerprint.update(String(metadata.size));
|
|
1540
|
-
fingerprint.update("\0");
|
|
1541
|
-
fingerprint.update(contents);
|
|
1542
|
-
fingerprint.update("\0");
|
|
1543
|
-
}
|
|
1544
|
-
finally {
|
|
1545
|
-
await handle.close();
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
return fingerprint.digest("hex");
|
|
1549
|
-
}
|
|
1550
1471
|
async function codexSecurityPluginRegistration(codexHome) {
|
|
1551
1472
|
let config;
|
|
1552
1473
|
try {
|
|
@@ -1568,12 +1489,18 @@ async function codexSecurityPluginRegistration(codexHome) {
|
|
|
1568
1489
|
}
|
|
1569
1490
|
export function resolveCodexCommand() {
|
|
1570
1491
|
const { packageName, targetTriple } = codexPlatformPackage();
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1492
|
+
let packageJson;
|
|
1493
|
+
try {
|
|
1494
|
+
const require = createRequire(import.meta.url);
|
|
1495
|
+
const codexPackageJson = require.resolve("@openai/codex/package.json");
|
|
1496
|
+
packageJson = createRequire(codexPackageJson).resolve(`${packageName}/package.json`);
|
|
1497
|
+
}
|
|
1498
|
+
catch (error) {
|
|
1499
|
+
throw new PluginBootstrapError(`The bundled Codex executable could not be resolved from ${packageName}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`, { cause: error });
|
|
1500
|
+
}
|
|
1574
1501
|
const command = join(dirname(packageJson), "vendor", targetTriple, "bin", process.platform === "win32" ? "codex.exe" : "codex");
|
|
1575
1502
|
if (!existsSync(command)) {
|
|
1576
|
-
throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable for ${targetTriple}.`);
|
|
1503
|
+
throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable for ${targetTriple}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`);
|
|
1577
1504
|
}
|
|
1578
1505
|
return { command, prefixArgs: [] };
|
|
1579
1506
|
}
|
|
@@ -1630,20 +1557,14 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1630
1557
|
if (installedRoot !== null) {
|
|
1631
1558
|
const installed = await pluginMetadata(installedRoot);
|
|
1632
1559
|
if (installed.name === name && installed.version === version) {
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
installedRoot,
|
|
1642
|
-
marketplaceName: MARKETPLACE_NAME,
|
|
1643
|
-
name,
|
|
1644
|
-
version,
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1560
|
+
return {
|
|
1561
|
+
pluginRoot: root,
|
|
1562
|
+
marketplaceRoot: existingMarketplace,
|
|
1563
|
+
installedRoot,
|
|
1564
|
+
marketplaceName: MARKETPLACE_NAME,
|
|
1565
|
+
name,
|
|
1566
|
+
version,
|
|
1567
|
+
};
|
|
1647
1568
|
}
|
|
1648
1569
|
upgradeExistingPlugin = true;
|
|
1649
1570
|
}
|
|
@@ -1690,30 +1611,11 @@ export async function pluginMetadata(root) {
|
|
|
1690
1611
|
const manifestPath = join(root, ".codex-plugin", "plugin.json");
|
|
1691
1612
|
let manifest;
|
|
1692
1613
|
try {
|
|
1693
|
-
const
|
|
1694
|
-
if (!
|
|
1695
|
-
|
|
1696
|
-
expected.size > MAX_PLUGIN_MANIFEST_SIZE) {
|
|
1697
|
-
throw new Error("plugin manifest is not a bounded regular file");
|
|
1698
|
-
}
|
|
1699
|
-
const input = await open(manifestPath, constants.O_RDONLY |
|
|
1700
|
-
(process.platform === "win32"
|
|
1701
|
-
? 0
|
|
1702
|
-
: constants.O_NOFOLLOW | constants.O_NONBLOCK));
|
|
1703
|
-
try {
|
|
1704
|
-
const opened = await input.stat();
|
|
1705
|
-
if (!samePluginFile(expected, opened)) {
|
|
1706
|
-
throw new Error("plugin manifest changed before reading");
|
|
1707
|
-
}
|
|
1708
|
-
const bytes = await readExactly(input, expected.size, 0);
|
|
1709
|
-
if (!samePluginFile(expected, await input.stat())) {
|
|
1710
|
-
throw new Error("plugin manifest changed while reading");
|
|
1711
|
-
}
|
|
1712
|
-
manifest = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
1713
|
-
}
|
|
1714
|
-
finally {
|
|
1715
|
-
await input.close();
|
|
1614
|
+
const metadata = await lstat(manifestPath);
|
|
1615
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
1616
|
+
throw new Error("plugin manifest is not a regular file");
|
|
1716
1617
|
}
|
|
1618
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1717
1619
|
}
|
|
1718
1620
|
catch (error) {
|
|
1719
1621
|
throw new PluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
|
|
@@ -1772,7 +1674,11 @@ export async function resolvePluginPython(options = {}) {
|
|
|
1772
1674
|
"Set pythonPath, --python, or PYTHON, install the Codex managed runtime, or add python3/python to PATH.");
|
|
1773
1675
|
}
|
|
1774
1676
|
export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
1775
|
-
return {
|
|
1677
|
+
return {
|
|
1678
|
+
...environment,
|
|
1679
|
+
PYTHON: python,
|
|
1680
|
+
CODEX_CLI_PATH: environment["CODEX_CLI_PATH"]?.trim() || resolveCodexCommand().command,
|
|
1681
|
+
};
|
|
1776
1682
|
}
|
|
1777
1683
|
export async function cleanupSdkDirectory(path) {
|
|
1778
1684
|
await rm(path, { recursive: true, force: true });
|
|
@@ -1858,8 +1764,6 @@ async function copyPluginTree(source, destination, signal) {
|
|
|
1858
1764
|
{ source, destination },
|
|
1859
1765
|
];
|
|
1860
1766
|
const directories = new Map();
|
|
1861
|
-
let entries = 1;
|
|
1862
|
-
let size = 0;
|
|
1863
1767
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
1864
1768
|
try {
|
|
1865
1769
|
while (pending.length > 0) {
|
|
@@ -1873,9 +1777,6 @@ async function copyPluginTree(source, destination, signal) {
|
|
|
1873
1777
|
if (metadata.isDirectory()) {
|
|
1874
1778
|
for await (const entry of pluginDirectoryEntries(current.source, signal)) {
|
|
1875
1779
|
const childSource = join(current.source, entry);
|
|
1876
|
-
if (++entries > MAX_PLUGIN_COPY_ENTRIES) {
|
|
1877
|
-
throw new PluginBootstrapError(`Plugin source exceeds the copy entry limit: ${childSource}`);
|
|
1878
|
-
}
|
|
1879
1780
|
pending.push({
|
|
1880
1781
|
source: childSource,
|
|
1881
1782
|
destination: join(current.destination, entry),
|
|
@@ -1892,13 +1793,6 @@ async function copyPluginTree(source, destination, signal) {
|
|
|
1892
1793
|
if (!metadata.isFile()) {
|
|
1893
1794
|
throw new PluginBootstrapError(`Plugin contains a non-regular file: ${current.source}`);
|
|
1894
1795
|
}
|
|
1895
|
-
if (metadata.size > MAX_PLUGIN_COPY_FILE_SIZE) {
|
|
1896
|
-
throw new PluginBootstrapError(`Plugin source exceeds the per-file safety limit: ${current.source}`);
|
|
1897
|
-
}
|
|
1898
|
-
size += metadata.size;
|
|
1899
|
-
if (size > MAX_PLUGIN_COPY_SIZE) {
|
|
1900
|
-
throw new PluginBootstrapError("Plugin source exceeds the copy safety limit.");
|
|
1901
|
-
}
|
|
1902
1796
|
const input = await open(current.source, constants.O_RDONLY |
|
|
1903
1797
|
(process.platform === "win32"
|
|
1904
1798
|
? 0
|