@openai/codex-security 0.1.10 → 0.1.11
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 +27 -13
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +3 -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/scripts/deep_scan_config.py +21 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +44 -14
- package/_bundled_plugin/scripts/finalize_scan_contract.py +15 -207
- package/_bundled_plugin/scripts/generate_in_scope_files.py +40 -16
- package/_bundled_plugin/scripts/generate_rank_input.py +38 -5
- package/_bundled_plugin/scripts/rank_preview.py +4 -0
- package/_bundled_plugin/scripts/report_projection.py +39 -1
- package/_bundled_plugin/scripts/workbench_cli.py +5 -0
- package/_bundled_plugin/scripts/workbench_db.py +283 -4
- package/_bundled_plugin/scripts/workbench_schema.py +15 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +1 -5
- package/_bundled_plugin/scripts/workbench_target.py +82 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +5 -3
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +217 -92
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +2 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +59 -270
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -4
- package/dist/cli.js.map +1 -1
- package/dist/contract.js +7 -5
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +1 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +23 -1
- package/dist/cost.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +2 -1
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +1 -0
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts +9 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +127 -284
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.js +1 -1
- package/dist/scan-comparison.js.map +1 -1
- package/dist/targets.d.ts +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +22 -0
- package/dist/targets.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/package.json +2 -2
package/dist/runtime.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { constants, existsSync } from "node:fs";
|
|
4
|
-
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile, } from "node:fs/promises";
|
|
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";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
-
import { basename, dirname, extname,
|
|
7
|
+
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
8
8
|
import { createInterface } from "node:readline";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { promisify } from "node:util";
|
|
@@ -27,19 +27,19 @@ const CREDENTIAL_LOGOUT_MARKER = ".codex-security-logged-out";
|
|
|
27
27
|
const CREDENTIAL_LOCK_POLL_MILLISECONDS = 25;
|
|
28
28
|
const INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS = 30_000;
|
|
29
29
|
const MAX_WINDOWS_CREDENTIAL_ACL_STDERR = 64 * 1024;
|
|
30
|
+
function environmentValue(environment, requested) {
|
|
31
|
+
const exact = environment[requested]?.trim();
|
|
32
|
+
if (exact)
|
|
33
|
+
return exact;
|
|
34
|
+
return Object.entries(environment)
|
|
35
|
+
.find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1]
|
|
36
|
+
?.trim();
|
|
37
|
+
}
|
|
30
38
|
export function codexSecurityStateDirectory(environment = process.env) {
|
|
31
|
-
const
|
|
32
|
-
const exact = environment[requested]?.trim();
|
|
33
|
-
if (exact)
|
|
34
|
-
return exact;
|
|
35
|
-
return Object.entries(environment)
|
|
36
|
-
.find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1]
|
|
37
|
-
?.trim();
|
|
38
|
-
};
|
|
39
|
-
const configured = environmentValue("CODEX_SECURITY_STATE_DIR");
|
|
39
|
+
const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
|
|
40
40
|
if (configured !== undefined)
|
|
41
41
|
return resolve(expandHome(configured));
|
|
42
|
-
const codexHome = environmentValue("CODEX_HOME") ?? join(homedir(), ".codex");
|
|
42
|
+
const codexHome = environmentValue(environment, "CODEX_HOME") ?? join(homedir(), ".codex");
|
|
43
43
|
return resolve(expandHome(codexHome), "state", "plugins", "codex-security");
|
|
44
44
|
}
|
|
45
45
|
export function codexSecurityCredentialHome(environment = process.env) {
|
|
@@ -1468,27 +1468,12 @@ export async function createMarketplace(codexHome, pluginRoot, signal) {
|
|
|
1468
1468
|
throwIfSignalAborted(signal);
|
|
1469
1469
|
return marketplace;
|
|
1470
1470
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
if (nodeErrorCode(error) === "ENOENT") {
|
|
1478
|
-
return { marketplace: false, plugin: false };
|
|
1479
|
-
}
|
|
1480
|
-
throw new PluginBootstrapError("Unable to inspect the existing Codex Security plugin registration.", { cause: error });
|
|
1481
|
-
}
|
|
1482
|
-
const marketplaces = isRecord(config) ? config["marketplaces"] : undefined;
|
|
1483
|
-
const plugins = isRecord(config) ? config["plugins"] : undefined;
|
|
1484
|
-
return {
|
|
1485
|
-
marketplace: isRecord(marketplaces) && isRecord(marketplaces[MARKETPLACE_NAME]),
|
|
1486
|
-
plugin: isRecord(plugins) &&
|
|
1487
|
-
isRecord(plugins[`${PLUGIN_NAME}@${MARKETPLACE_NAME}`]),
|
|
1488
|
-
};
|
|
1489
|
-
}
|
|
1490
|
-
export function resolveCodexCommand() {
|
|
1491
|
-
const { packageName, targetTriple } = codexPlatformPackage();
|
|
1471
|
+
export function resolveCodexCommand(environment = process.env) {
|
|
1472
|
+
const configured = environmentValue(environment, "CODEX_CLI_PATH");
|
|
1473
|
+
if (configured)
|
|
1474
|
+
return { command: resolve(configured) };
|
|
1475
|
+
const platform = process.platform === "android" ? "linux" : process.platform;
|
|
1476
|
+
const packageName = `@openai/codex-${platform}-${process.arch}`;
|
|
1492
1477
|
let packageJson;
|
|
1493
1478
|
try {
|
|
1494
1479
|
const require = createRequire(import.meta.url);
|
|
@@ -1498,110 +1483,74 @@ export function resolveCodexCommand() {
|
|
|
1498
1483
|
catch (error) {
|
|
1499
1484
|
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
1485
|
}
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
-
|
|
1486
|
+
const vendor = join(dirname(packageJson), "vendor");
|
|
1487
|
+
const target = readdirSync(vendor, { withFileTypes: true }).find((entry) => entry.isDirectory());
|
|
1488
|
+
const command = join(vendor, target?.name ?? "", "bin", process.platform === "win32" ? "codex.exe" : "codex");
|
|
1489
|
+
if (target === undefined || !existsSync(command)) {
|
|
1490
|
+
throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`);
|
|
1504
1491
|
}
|
|
1505
|
-
return { command
|
|
1506
|
-
}
|
|
1507
|
-
export function codexPlatformPackage(platform = process.platform, architecture = process.arch) {
|
|
1508
|
-
const key = `${platform}:${architecture}`;
|
|
1509
|
-
const target = {
|
|
1510
|
-
"android:arm64": [
|
|
1511
|
-
"@openai/codex-linux-arm64",
|
|
1512
|
-
"aarch64-unknown-linux-musl",
|
|
1513
|
-
],
|
|
1514
|
-
"android:x64": ["@openai/codex-linux-x64", "x86_64-unknown-linux-musl"],
|
|
1515
|
-
"darwin:arm64": ["@openai/codex-darwin-arm64", "aarch64-apple-darwin"],
|
|
1516
|
-
"darwin:x64": ["@openai/codex-darwin-x64", "x86_64-apple-darwin"],
|
|
1517
|
-
"linux:arm64": ["@openai/codex-linux-arm64", "aarch64-unknown-linux-musl"],
|
|
1518
|
-
"linux:x64": ["@openai/codex-linux-x64", "x86_64-unknown-linux-musl"],
|
|
1519
|
-
"win32:arm64": ["@openai/codex-win32-arm64", "aarch64-pc-windows-msvc"],
|
|
1520
|
-
"win32:x64": ["@openai/codex-win32-x64", "x86_64-pc-windows-msvc"],
|
|
1521
|
-
}[key];
|
|
1522
|
-
if (target === undefined) {
|
|
1523
|
-
throw new PluginBootstrapError(`Codex does not support this platform: ${platform} (${architecture}).`);
|
|
1524
|
-
}
|
|
1525
|
-
return { packageName: target[0], targetTriple: target[1] };
|
|
1492
|
+
return { command };
|
|
1526
1493
|
}
|
|
1527
1494
|
export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
1528
1495
|
const root = await realpath(pluginRoot);
|
|
1529
1496
|
const { name, version } = await pluginMetadata(root);
|
|
1530
|
-
const
|
|
1531
|
-
let upgradeExistingPlugin = false;
|
|
1532
|
-
let repairIncompletePlugin = false;
|
|
1533
|
-
let installedRoot = null;
|
|
1534
|
-
try {
|
|
1535
|
-
await verifyPluginRegistration(codexHome, existingMarketplace);
|
|
1536
|
-
installedRoot = await findInstalledPlugin(codexHome);
|
|
1537
|
-
}
|
|
1538
|
-
catch (error) {
|
|
1539
|
-
throwIfSignalAborted(options.signal);
|
|
1540
|
-
if (!(error instanceof PluginBootstrapError) &&
|
|
1541
|
-
nodeErrorCode(error) !== "ENOENT") {
|
|
1542
|
-
throw error;
|
|
1543
|
-
}
|
|
1544
|
-
const marketplace = await lstat(existingMarketplace).catch((failure) => {
|
|
1545
|
-
if (nodeErrorCode(failure) === "ENOENT")
|
|
1546
|
-
return null;
|
|
1547
|
-
throw failure;
|
|
1548
|
-
});
|
|
1549
|
-
if (marketplace !== null &&
|
|
1550
|
-
(!marketplace.isDirectory() || marketplace.isSymbolicLink())) {
|
|
1551
|
-
throw new PluginBootstrapError(`Codex Security marketplace is not a safe directory: ${existingMarketplace}`);
|
|
1552
|
-
}
|
|
1553
|
-
const registration = await codexSecurityPluginRegistration(codexHome);
|
|
1554
|
-
repairIncompletePlugin =
|
|
1555
|
-
marketplace !== null || registration.marketplace || registration.plugin;
|
|
1556
|
-
}
|
|
1557
|
-
if (installedRoot !== null) {
|
|
1558
|
-
const installed = await pluginMetadata(installedRoot);
|
|
1559
|
-
if (installed.name === name && installed.version === version) {
|
|
1560
|
-
return {
|
|
1561
|
-
pluginRoot: root,
|
|
1562
|
-
marketplaceRoot: existingMarketplace,
|
|
1563
|
-
installedRoot,
|
|
1564
|
-
marketplaceName: MARKETPLACE_NAME,
|
|
1565
|
-
name,
|
|
1566
|
-
version,
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
upgradeExistingPlugin = true;
|
|
1570
|
-
}
|
|
1497
|
+
const marketplace = join(codexHome, "sdk-marketplace");
|
|
1571
1498
|
throwIfSignalAborted(options.signal);
|
|
1572
|
-
const command = options.codexCommand ?? resolveCodexCommand();
|
|
1499
|
+
const command = options.codexCommand ?? resolveCodexCommand(options.environment);
|
|
1573
1500
|
const environment = {
|
|
1574
1501
|
...(options.environment ?? process.env),
|
|
1575
1502
|
CODEX_HOME: codexHome,
|
|
1576
1503
|
};
|
|
1577
|
-
const run = options.runCodex ??
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
await
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1504
|
+
const run = options.runCodex ?? runPluginCommand;
|
|
1505
|
+
const existing = await lstat(marketplace).catch((error) => {
|
|
1506
|
+
if (nodeErrorCode(error) === "ENOENT")
|
|
1507
|
+
return null;
|
|
1508
|
+
throw error;
|
|
1509
|
+
});
|
|
1510
|
+
if (existing !== null && !existing.isDirectory()) {
|
|
1511
|
+
throw new PluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
|
|
1512
|
+
}
|
|
1513
|
+
const staged = existing === null
|
|
1514
|
+
? null
|
|
1515
|
+
: await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
|
|
1516
|
+
if (staged?.version !== version) {
|
|
1517
|
+
if (existing !== null) {
|
|
1518
|
+
await rm(marketplace, { recursive: true, force: true });
|
|
1519
|
+
}
|
|
1520
|
+
await createMarketplace(codexHome, root, options.signal);
|
|
1521
|
+
}
|
|
1522
|
+
const config = await readFile(join(codexHome, "config.toml"), "utf8").catch((error) => {
|
|
1523
|
+
if (nodeErrorCode(error) === "ENOENT")
|
|
1524
|
+
return "";
|
|
1525
|
+
throw error;
|
|
1526
|
+
});
|
|
1527
|
+
const marketplaces = parse(config)["marketplaces"];
|
|
1528
|
+
const registration = isRecord(marketplaces)
|
|
1529
|
+
? marketplaces[MARKETPLACE_NAME]
|
|
1530
|
+
: undefined;
|
|
1531
|
+
if (!isRecord(registration) ||
|
|
1532
|
+
registration["source_type"] !== "local" ||
|
|
1533
|
+
typeof registration["source"] !== "string" ||
|
|
1534
|
+
!(await sameFile(registration["source"], marketplace))) {
|
|
1535
|
+
await run(command, ["plugin", "marketplace", "add", marketplace], environment, options.signal);
|
|
1536
|
+
}
|
|
1537
|
+
const output = await run(command, ["plugin", "add", "--json", `${PLUGIN_NAME}@${MARKETPLACE_NAME}`], environment, options.signal);
|
|
1538
|
+
let installed;
|
|
1539
|
+
try {
|
|
1540
|
+
installed = JSON.parse(output);
|
|
1541
|
+
}
|
|
1542
|
+
catch (error) {
|
|
1543
|
+
throw new PluginBootstrapError("Codex plugin install did not return a valid JSON result.", { cause: error });
|
|
1544
|
+
}
|
|
1545
|
+
if (!isRecord(installed) ||
|
|
1546
|
+
typeof installed["installedPath"] !== "string" ||
|
|
1547
|
+
installed["version"] !== version) {
|
|
1548
|
+
throw new PluginBootstrapError("Codex plugin install did not return the selected plugin path and version.");
|
|
1600
1549
|
}
|
|
1601
1550
|
return {
|
|
1602
1551
|
pluginRoot: root,
|
|
1603
1552
|
marketplaceRoot: marketplace,
|
|
1604
|
-
installedRoot:
|
|
1553
|
+
installedRoot: installed["installedPath"],
|
|
1605
1554
|
marketplaceName: MARKETPLACE_NAME,
|
|
1606
1555
|
name,
|
|
1607
1556
|
version,
|
|
@@ -1677,19 +1626,53 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
|
1677
1626
|
return {
|
|
1678
1627
|
...environment,
|
|
1679
1628
|
PYTHON: python,
|
|
1680
|
-
CODEX_CLI_PATH:
|
|
1629
|
+
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1681
1630
|
};
|
|
1682
1631
|
}
|
|
1683
1632
|
export async function cleanupSdkDirectory(path) {
|
|
1684
1633
|
await rm(path, { recursive: true, force: true });
|
|
1685
1634
|
}
|
|
1686
|
-
async function
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1635
|
+
export async function runCodexCommand(command, args, environment, input, signal) {
|
|
1636
|
+
const child = spawn(command.command, [...args], {
|
|
1637
|
+
env: environment,
|
|
1638
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1639
|
+
windowsHide: true,
|
|
1640
|
+
signal,
|
|
1641
|
+
});
|
|
1642
|
+
let stdout = "";
|
|
1643
|
+
let stderr = "";
|
|
1644
|
+
let processError;
|
|
1645
|
+
child.stdout.setEncoding("utf8");
|
|
1646
|
+
child.stderr.setEncoding("utf8");
|
|
1647
|
+
child.stdout.on("data", (chunk) => {
|
|
1648
|
+
stdout += chunk;
|
|
1649
|
+
});
|
|
1650
|
+
child.stderr.on("data", (chunk) => {
|
|
1651
|
+
stderr += chunk;
|
|
1652
|
+
});
|
|
1653
|
+
const completion = new Promise((resolve, reject) => {
|
|
1654
|
+
child.once("error", (error) => {
|
|
1655
|
+
processError = error;
|
|
1656
|
+
});
|
|
1657
|
+
child.stdin.on("error", (error) => {
|
|
1658
|
+
if (!["EPIPE", "ECONNRESET", "EOF", "ERR_STREAM_DESTROYED"].includes(error.code ?? ""))
|
|
1659
|
+
processError = error;
|
|
1692
1660
|
});
|
|
1661
|
+
child.once("close", (exitCode) => processError === undefined
|
|
1662
|
+
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
1663
|
+
: reject(processError));
|
|
1664
|
+
});
|
|
1665
|
+
child.stdin.end(input);
|
|
1666
|
+
return await completion;
|
|
1667
|
+
}
|
|
1668
|
+
async function runPluginCommand(command, args, environment, signal) {
|
|
1669
|
+
try {
|
|
1670
|
+
const { success, exitCode, stdout, stderr } = await runCodexCommand(command, args, environment, undefined, signal);
|
|
1671
|
+
if (!success) {
|
|
1672
|
+
throw new Error(stderr.trim() ||
|
|
1673
|
+
stdout.trim() ||
|
|
1674
|
+
`Codex exited with status ${exitCode}.`);
|
|
1675
|
+
}
|
|
1693
1676
|
return stdout;
|
|
1694
1677
|
}
|
|
1695
1678
|
catch (error) {
|
|
@@ -1699,21 +1682,6 @@ async function runCodex(command, args, environment, signal) {
|
|
|
1699
1682
|
});
|
|
1700
1683
|
}
|
|
1701
1684
|
}
|
|
1702
|
-
async function findInstalledPlugin(codexHome) {
|
|
1703
|
-
const root = join(codexHome, "plugins", "cache", MARKETPLACE_NAME, PLUGIN_NAME);
|
|
1704
|
-
const candidates = [];
|
|
1705
|
-
for (const entry of await readdir(root, { withFileTypes: true }).catch(() => [])) {
|
|
1706
|
-
if (entry.isDirectory()) {
|
|
1707
|
-
const candidate = join(root, entry.name);
|
|
1708
|
-
if (await hasPluginManifest(candidate))
|
|
1709
|
-
candidates.push(candidate);
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
if (candidates.length !== 1) {
|
|
1713
|
-
throw new PluginBootstrapError("Codex plugin install did not produce one installed Codex Security plugin.");
|
|
1714
|
-
}
|
|
1715
|
-
return await realpath(candidates[0]);
|
|
1716
|
-
}
|
|
1717
1685
|
async function discoverPluginRoot(root) {
|
|
1718
1686
|
if (await hasPluginManifest(root))
|
|
1719
1687
|
return await validatePluginRoot(root);
|
|
@@ -1729,154 +1697,29 @@ async function validatePluginRoot(root) {
|
|
|
1729
1697
|
await pluginMetadata(root);
|
|
1730
1698
|
return await realpath(root);
|
|
1731
1699
|
}
|
|
1732
|
-
async function verifyPluginRegistration(codexHome, marketplace) {
|
|
1733
|
-
const configPath = join(codexHome, "config.toml");
|
|
1734
|
-
let config;
|
|
1735
|
-
try {
|
|
1736
|
-
config = parse(await readFile(configPath, "utf8"));
|
|
1737
|
-
}
|
|
1738
|
-
catch (error) {
|
|
1739
|
-
throw new PluginBootstrapError("Codex plugin bootstrap produced an unreadable config.toml.", {
|
|
1740
|
-
cause: error,
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
|
-
const marketplaces = isRecord(config) ? config["marketplaces"] : undefined;
|
|
1744
|
-
const plugins = isRecord(config) ? config["plugins"] : undefined;
|
|
1745
|
-
const marketplaceConfig = isRecord(marketplaces)
|
|
1746
|
-
? marketplaces[MARKETPLACE_NAME]
|
|
1747
|
-
: undefined;
|
|
1748
|
-
const pluginConfig = isRecord(plugins)
|
|
1749
|
-
? plugins[`${PLUGIN_NAME}@${MARKETPLACE_NAME}`]
|
|
1750
|
-
: undefined;
|
|
1751
|
-
if (!isRecord(marketplaceConfig) || !isRecord(pluginConfig)) {
|
|
1752
|
-
throw new PluginBootstrapError("Codex plugin bootstrap did not preserve plugin registration.");
|
|
1753
|
-
}
|
|
1754
|
-
const registeredSource = String(marketplaceConfig["source"] ?? "");
|
|
1755
|
-
if (!(await sameFile(registeredSource, marketplace))) {
|
|
1756
|
-
throw new PluginBootstrapError("Codex plugin marketplace registration has the wrong source.");
|
|
1757
|
-
}
|
|
1758
|
-
if (pluginConfig["enabled"] !== true) {
|
|
1759
|
-
throw new PluginBootstrapError("Codex Security plugin is not enabled after bootstrap.");
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
1700
|
async function copyPluginTree(source, destination, signal) {
|
|
1763
|
-
const pending = [
|
|
1764
|
-
{ source, destination },
|
|
1765
|
-
];
|
|
1766
|
-
const directories = new Map();
|
|
1767
1701
|
await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
|
1768
1702
|
try {
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
for await (const entry of pluginDirectoryEntries(current.source, signal)) {
|
|
1779
|
-
const childSource = join(current.source, entry);
|
|
1780
|
-
pending.push({
|
|
1781
|
-
source: childSource,
|
|
1782
|
-
destination: join(current.destination, entry),
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
const afterRead = await lstat(current.source);
|
|
1786
|
-
if (!samePluginFile(metadata, afterRead)) {
|
|
1787
|
-
throw new PluginBootstrapError(`Plugin directory changed while it was being copied: ${current.source}`);
|
|
1788
|
-
}
|
|
1789
|
-
directories.set(current.source, afterRead);
|
|
1790
|
-
await mkdir(current.destination, { mode: 0o700 });
|
|
1791
|
-
continue;
|
|
1792
|
-
}
|
|
1793
|
-
if (!metadata.isFile()) {
|
|
1794
|
-
throw new PluginBootstrapError(`Plugin contains a non-regular file: ${current.source}`);
|
|
1795
|
-
}
|
|
1796
|
-
const input = await open(current.source, constants.O_RDONLY |
|
|
1797
|
-
(process.platform === "win32"
|
|
1798
|
-
? 0
|
|
1799
|
-
: constants.O_NOFOLLOW | constants.O_NONBLOCK));
|
|
1800
|
-
let output;
|
|
1801
|
-
try {
|
|
1802
|
-
if (!samePluginFile(metadata, await input.stat())) {
|
|
1803
|
-
throw new PluginBootstrapError(`Plugin source changed before it could be copied: ${current.source}`);
|
|
1804
|
-
}
|
|
1805
|
-
await requirePluginAncestors(source, current.source, directories, signal);
|
|
1806
|
-
const bytes = await readExactly(input, metadata.size, 0, signal);
|
|
1807
|
-
if (!samePluginFile(metadata, await input.stat())) {
|
|
1808
|
-
throw new PluginBootstrapError(`Plugin source changed while it was being copied: ${current.source}`);
|
|
1703
|
+
await cp(source, destination, {
|
|
1704
|
+
recursive: true,
|
|
1705
|
+
force: false,
|
|
1706
|
+
filter: async (path) => {
|
|
1707
|
+
throwIfSignalAborted(signal);
|
|
1708
|
+
const metadata = await lstat(path);
|
|
1709
|
+
if ((!metadata.isDirectory() && !metadata.isFile()) ||
|
|
1710
|
+
(await realpath(path)) !== path) {
|
|
1711
|
+
throw new PluginBootstrapError(`Plugin contains an unsafe source path: ${path}`);
|
|
1809
1712
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
(process.platform === "win32" ? 0 : constants.O_NOFOLLOW), 0o600);
|
|
1815
|
-
await output.writeFile(bytes);
|
|
1816
|
-
await output.chmod(metadata.mode & 0o777);
|
|
1817
|
-
}
|
|
1818
|
-
finally {
|
|
1819
|
-
await output?.close();
|
|
1820
|
-
await input.close();
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1713
|
+
throwIfSignalAborted(signal);
|
|
1714
|
+
return true;
|
|
1715
|
+
},
|
|
1716
|
+
});
|
|
1823
1717
|
}
|
|
1824
1718
|
catch (error) {
|
|
1825
1719
|
await rm(destination, { recursive: true, force: true });
|
|
1826
1720
|
throw error;
|
|
1827
1721
|
}
|
|
1828
1722
|
}
|
|
1829
|
-
async function* pluginDirectoryEntries(path, signal) {
|
|
1830
|
-
throwIfSignalAborted(signal);
|
|
1831
|
-
const directory = await opendir(path);
|
|
1832
|
-
try {
|
|
1833
|
-
for (;;) {
|
|
1834
|
-
throwIfSignalAborted(signal);
|
|
1835
|
-
const entry = await directory.read();
|
|
1836
|
-
throwIfSignalAborted(signal);
|
|
1837
|
-
if (entry === null)
|
|
1838
|
-
return;
|
|
1839
|
-
yield entry.name;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
finally {
|
|
1843
|
-
await directory.close();
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
async function requirePluginAncestors(root, path, directories, signal) {
|
|
1847
|
-
const relativePath = relative(root, path);
|
|
1848
|
-
if (relativePath === ".." ||
|
|
1849
|
-
relativePath.startsWith(`..${sep}`) ||
|
|
1850
|
-
isAbsolute(relativePath)) {
|
|
1851
|
-
throw new PluginBootstrapError(`Plugin source path escapes its root: ${path}`);
|
|
1852
|
-
}
|
|
1853
|
-
if (relativePath === "")
|
|
1854
|
-
return;
|
|
1855
|
-
let ancestor = root;
|
|
1856
|
-
const parents = ["", ...relativePath.split(sep).slice(0, -1)];
|
|
1857
|
-
for (const component of parents) {
|
|
1858
|
-
throwIfSignalAborted(signal);
|
|
1859
|
-
if (component !== "")
|
|
1860
|
-
ancestor = join(ancestor, component);
|
|
1861
|
-
const expected = directories.get(ancestor);
|
|
1862
|
-
const actual = await lstat(ancestor);
|
|
1863
|
-
if (expected === undefined ||
|
|
1864
|
-
actual.isSymbolicLink() ||
|
|
1865
|
-
!actual.isDirectory() ||
|
|
1866
|
-
!samePluginFile(expected, actual)) {
|
|
1867
|
-
throw new PluginBootstrapError(`Plugin source directory changed while it was being copied: ${ancestor}`);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
function samePluginFile(first, second) {
|
|
1872
|
-
return (first.dev === second.dev &&
|
|
1873
|
-
first.ino === second.ino &&
|
|
1874
|
-
first.size === second.size &&
|
|
1875
|
-
first.mtimeMs === second.mtimeMs &&
|
|
1876
|
-
first.mode === second.mode &&
|
|
1877
|
-
first.isFile() === second.isFile() &&
|
|
1878
|
-
first.isDirectory() === second.isDirectory());
|
|
1879
|
-
}
|
|
1880
1723
|
async function readExactly(handle, length, position, signal) {
|
|
1881
1724
|
const buffer = Buffer.alloc(length);
|
|
1882
1725
|
let offset = 0;
|