@openai/codex-security 0.1.30 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +386 -37
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/artifact-storage.md +4 -4
- package/_bundled_plugin/references/config-preflight.md +1 -1
- package/_bundled_plugin/references/core-scan.md +14 -2
- package/_bundled_plugin/references/final-report.md +4 -2
- package/_bundled_plugin/references/scan-artifacts.md +2 -2
- package/_bundled_plugin/references/scan-contract.md +2 -2
- package/_bundled_plugin/references/threat-model.md +2 -2
- package/_bundled_plugin/schemas/coverage.schema.json +22 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +100 -85
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +19 -4
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +116 -102
- package/_bundled_plugin/scripts/config_preflight.py +4 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +83 -217
- package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
- package/_bundled_plugin/scripts/finalize_scan_contract.py +441 -166
- package/_bundled_plugin/scripts/finding_preview.py +42 -82
- package/_bundled_plugin/scripts/generate_in_scope_files.py +30 -34
- package/_bundled_plugin/scripts/generate_rank_input.py +58 -99
- package/_bundled_plugin/scripts/launch_codex_security_mcp +5 -1
- package/_bundled_plugin/scripts/rank_preview.py +86 -68
- package/_bundled_plugin/scripts/report_projection.py +37 -58
- package/_bundled_plugin/scripts/threat_model_projection.py +164 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +11 -6
- package/_bundled_plugin/scripts/workbench/storage.py +11 -0
- package/_bundled_plugin/scripts/workbench_cli.py +11 -17
- package/_bundled_plugin/scripts/workbench_constants.py +6 -14
- package/_bundled_plugin/scripts/workbench_db.py +116 -228
- package/_bundled_plugin/scripts/workbench_finding_index.py +1 -6
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -4
- package/_bundled_plugin/scripts/workbench_progress.py +12 -34
- package/_bundled_plugin/scripts/workbench_publication.py +47 -62
- package/_bundled_plugin/scripts/workbench_remediation.py +2 -20
- package/_bundled_plugin/scripts/workbench_saved_results.py +1246 -230
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -11
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -15
- package/_bundled_plugin/scripts/workbench_schema.py +86 -271
- package/_bundled_plugin/scripts/workbench_severity.py +3 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +5 -6
- package/_bundled_plugin/scripts/workbench_target.py +98 -10
- package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
- package/_bundled_plugin/scripts/workbench_validation.py +6 -20
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +3 -3
- package/_bundled_plugin/skills/security-scan/SKILL.md +2 -2
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
- package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
- package/dist/api.d.ts +3 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +201 -207
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +70 -0
- package/dist/artifact-export.d.ts.map +1 -0
- package/dist/artifact-export.js +277 -0
- package/dist/artifact-export.js.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +9 -4
- package/dist/auth.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +1 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +8 -9
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/classify-scan-severity.d.ts.map +1 -1
- package/dist/classify-scan-severity.js +2 -5
- package/dist/classify-scan-severity.js.map +1 -1
- package/dist/classify-severity.d.ts +2 -8
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -5
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +281 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +21 -22
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +673 -701
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +1 -8
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-prompt.d.ts.map +1 -1
- package/dist/codex-prompt.js +1 -2
- package/dist/codex-prompt.js.map +1 -1
- package/dist/codex-sdk-environment.d.ts +2 -0
- package/dist/codex-sdk-environment.d.ts.map +1 -0
- package/dist/codex-sdk-environment.js +30 -0
- package/dist/codex-sdk-environment.js.map +1 -0
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +2 -6
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts +1 -0
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +31 -9
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -33
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +2 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +63 -122
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +65 -34
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +15 -31
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +4 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +17 -16
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +10 -11
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +2 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +3 -3
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +2 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.js +40 -62
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +1 -4
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +2 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +24 -6
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/review.d.ts +7 -0
- package/dist/deduplication/review.d.ts.map +1 -1
- package/dist/deduplication/review.js.map +1 -1
- package/dist/deduplication/scan.js +3 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +3 -19
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +0 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +22 -40
- package/dist/deep-progress.js.map +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -7
- package/dist/errors.js.map +1 -1
- package/dist/finding-catalogue.d.ts.map +1 -1
- package/dist/finding-catalogue.js +22 -22
- package/dist/finding-catalogue.js.map +1 -1
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +4 -7
- package/dist/finding-workflow.js.map +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +7 -17
- package/dist/findings-import.js.map +1 -1
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +2 -3
- package/dist/github.js.map +1 -1
- package/dist/import-scan.js +2 -2
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.js +7 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +2 -3
- package/dist/linear.js.map +1 -1
- package/dist/models.d.ts +24 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +36 -31
- package/dist/multiscan.js.map +1 -1
- package/dist/owner-evidence.d.ts +29 -0
- package/dist/owner-evidence.d.ts.map +1 -0
- package/dist/owner-evidence.js +192 -0
- package/dist/owner-evidence.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -4
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +10 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/prompt-files.d.ts +0 -1
- package/dist/prompt-files.d.ts.map +1 -1
- package/dist/prompt-files.js +2 -4
- package/dist/prompt-files.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +15 -29
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -13
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +11 -14
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +31 -41
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +4 -0
- package/dist/record.js.map +1 -0
- package/dist/result.d.ts +4 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +10 -13
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +230 -145
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts.map +1 -1
- package/dist/saved-scan.js +10 -20
- package/dist/saved-scan.js.map +1 -1
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +8 -22
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +4 -4
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +38 -73
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts +0 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +10 -19
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +1 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +2 -6
- package/dist/scan-logs.js.map +1 -1
- package/dist/scan-sessions.d.ts.map +1 -1
- package/dist/scan-sessions.js +1 -3
- package/dist/scan-sessions.js.map +1 -1
- package/dist/scan-settings.d.ts +5 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/security-policy-cli.d.ts.map +1 -1
- package/dist/security-policy-cli.js +8 -6
- package/dist/security-policy-cli.js.map +1 -1
- package/dist/security-policy.d.ts +8 -4
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +98 -84
- package/dist/security-policy.js.map +1 -1
- package/dist/server/dashboard/app.js +5 -5
- package/dist/server/embeddings.d.ts.map +1 -1
- package/dist/server/embeddings.js +1 -0
- package/dist/server/embeddings.js.map +1 -1
- package/dist/server/routes.d.ts +3 -2
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +19 -7
- package/dist/server/routes.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +2 -3
- package/dist/server/server.js.map +1 -1
- package/dist/server/sqlite-store.d.ts.map +1 -1
- package/dist/server/sqlite-store.js +4 -14
- package/dist/server/sqlite-store.js.map +1 -1
- package/dist/severity-store.js +8 -15
- package/dist/severity-store.js.map +1 -1
- package/dist/suggest-owners.d.ts +37 -0
- package/dist/suggest-owners.d.ts.map +1 -0
- package/dist/suggest-owners.js +111 -0
- package/dist/suggest-owners.js.map +1 -0
- package/dist/targets.d.ts +7 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +29 -25
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.js.map +1 -1
- package/dist/trusted-executable.d.ts +5 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +22 -5
- package/dist/trusted-executable.js.map +1 -1
- package/dist/value.d.ts +2 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +20 -0
- package/dist/value.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -6
- package/dist/version.js.map +1 -1
- package/dist/windows-path.d.ts.map +1 -1
- package/dist/windows-path.js +1 -2
- package/dist/windows-path.js.map +1 -1
- package/dist/worker-progress.d.ts +1 -0
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +13 -34
- package/dist/worker-progress.js.map +1 -1
- package/docs/dedupe-records.md +24 -0
- package/package.json +15 -13
- package/schemas/project-config.schema.json +5 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
- package/dist/server/findings-service.d.ts +0 -20
- package/dist/server/findings-service.d.ts.map +0 -1
- package/dist/server/findings-service.js +0 -31
- package/dist/server/findings-service.js.map +0 -1
package/dist/runtime.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
import { isNonEmptyString } from "./value.js";
|
|
1
2
|
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { chmodSync, constants, existsSync, readdirSync, } from "node:fs";
|
|
4
|
+
import { chmodSync, constants, createWriteStream, existsSync, readdirSync, } from "node:fs";
|
|
4
5
|
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
5
6
|
import { homedir, tmpdir } from "node:os";
|
|
6
7
|
import { createRequire } from "node:module";
|
|
7
|
-
import { basename, dirname, extname,
|
|
8
|
-
import { createInterface } from "node:readline";
|
|
8
|
+
import { basename, dirname, extname, join, relative, resolve, win32, } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { promisify } from "node:util";
|
|
11
|
+
import { pipeline } from "node:stream/promises";
|
|
11
12
|
import { crc32 } from "node:zlib";
|
|
12
13
|
import { setTimeout as delay } from "node:timers/promises";
|
|
13
|
-
import
|
|
14
|
+
import { openPromise as openZip } from "yauzl";
|
|
14
15
|
import { parse } from "smol-toml";
|
|
15
|
-
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, errorMessage, } from "./errors.js";
|
|
16
|
-
import {
|
|
16
|
+
import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
|
|
17
|
+
import { isRecord } from "./record.js";
|
|
18
|
+
import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
|
|
17
19
|
import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
|
|
18
20
|
const execFile = promisify(execFileCallback);
|
|
19
21
|
export const MARKETPLACE_NAME = "codex-security-sdk";
|
|
@@ -31,6 +33,7 @@ const CREDENTIAL_LOCK_POLL_MILLISECONDS = 25;
|
|
|
31
33
|
const INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS = 30_000;
|
|
32
34
|
const MAX_PROCESS_ID = 2_147_483_647;
|
|
33
35
|
const MAX_WINDOWS_CREDENTIAL_ACL_STDERR = 64 * 1024;
|
|
36
|
+
const SANDBOX_PROBE_TIMEOUT_MILLISECONDS = 10_000;
|
|
34
37
|
const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
|
|
35
38
|
"OPENAI_API_KEY",
|
|
36
39
|
"CODEX_API_KEY",
|
|
@@ -97,9 +100,7 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
|
|
|
97
100
|
}
|
|
98
101
|
catch (error) {
|
|
99
102
|
if (nodeErrorCode(error) === "EEXIST") {
|
|
100
|
-
|
|
101
|
-
if (existing !== null &&
|
|
102
|
-
(!existing.isDirectory() || existing.isSymbolicLink())) {
|
|
103
|
+
if ((await lstat(path).catch(() => null))?.isDirectory() === false) {
|
|
103
104
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`, { cause: error });
|
|
104
105
|
}
|
|
105
106
|
}
|
|
@@ -108,7 +109,7 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
|
|
|
108
109
|
if ((process.umask() & 0o700) !== 0)
|
|
109
110
|
await chmod(path, 0o700);
|
|
110
111
|
const metadata = await lstat(path, { bigint: true });
|
|
111
|
-
if (!metadata.isDirectory()
|
|
112
|
+
if (!metadata.isDirectory()) {
|
|
112
113
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`);
|
|
113
114
|
}
|
|
114
115
|
const canonical = await realpath(path);
|
|
@@ -155,7 +156,7 @@ export async function requireSecureCredentialHome(path, options = {}) {
|
|
|
155
156
|
throw new OutputDirectoryError(`Codex Security credential home was replaced: ${canonical}`);
|
|
156
157
|
}
|
|
157
158
|
metadata = canonicalMetadata;
|
|
158
|
-
if (!metadata.isDirectory()
|
|
159
|
+
if (!metadata.isDirectory()) {
|
|
159
160
|
throw new OutputDirectoryError(`Codex Security credential home is not a directory: ${path}`);
|
|
160
161
|
}
|
|
161
162
|
if (options.expectedDevice !== undefined &&
|
|
@@ -200,9 +201,7 @@ function windowsCredentialAclFailure(error) {
|
|
|
200
201
|
: undefined;
|
|
201
202
|
const detail = typeof stderr === "string" && stderr.trim() !== ""
|
|
202
203
|
? stderr
|
|
203
|
-
: error
|
|
204
|
-
? error.message
|
|
205
|
-
: String(error);
|
|
204
|
+
: errorMessage(error);
|
|
206
205
|
const normalized = errorMessage(detail)
|
|
207
206
|
.replace(/\s+/gu, " ")
|
|
208
207
|
.trim()
|
|
@@ -477,20 +476,25 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
477
476
|
reject(Object.assign(new Error(`Windows credential ACL inspection failed with ${reason}`), { code, signal, stderr }));
|
|
478
477
|
});
|
|
479
478
|
});
|
|
480
|
-
let descriptors = 0;
|
|
481
479
|
try {
|
|
482
480
|
await Promise.all([
|
|
483
481
|
completion,
|
|
484
482
|
(async () => {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
for await (const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
483
|
+
// Consume chunks directly: readline can resume its queued-line
|
|
484
|
+
// iterator after EOF and throw instead of draining the last lines.
|
|
485
|
+
child.stdout.setEncoding("utf8");
|
|
486
|
+
let pending = "";
|
|
487
|
+
for await (const chunk of child.stdout) {
|
|
488
|
+
const lines = (pending + chunk).split(/[\r\n]/u);
|
|
489
|
+
pending = lines.pop();
|
|
490
|
+
for (const descriptor of lines) {
|
|
491
|
+
if (descriptor === "")
|
|
492
|
+
continue;
|
|
493
|
+
await inspectDescriptor(descriptor);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (pending !== "") {
|
|
497
|
+
await inspectDescriptor(pending);
|
|
494
498
|
}
|
|
495
499
|
})(),
|
|
496
500
|
]);
|
|
@@ -504,7 +508,6 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
504
508
|
// Finish descriptor callbacks before allowing another snapshot attempt.
|
|
505
509
|
throw new WindowsCredentialDescendantsChangedError("Windows credential descendants changed during ACL inspection");
|
|
506
510
|
}
|
|
507
|
-
return descriptors;
|
|
508
511
|
}
|
|
509
512
|
export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
|
|
510
513
|
let ancestors = 0;
|
|
@@ -783,11 +786,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
783
786
|
const ownerPath = join(lock, "owner.json");
|
|
784
787
|
const token = randomUUID();
|
|
785
788
|
const databasePath = join(codexHome, CREDENTIAL_LOCK_DATABASE);
|
|
786
|
-
const existingDatabaseMetadata = await lstat(databasePath).catch(
|
|
787
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
788
|
-
return null;
|
|
789
|
-
throw error;
|
|
790
|
-
});
|
|
789
|
+
const existingDatabaseMetadata = await lstat(databasePath).catch(nullIfMissingFileError);
|
|
791
790
|
if (existingDatabaseMetadata !== null) {
|
|
792
791
|
requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
|
|
793
792
|
}
|
|
@@ -846,12 +845,7 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
|
|
|
846
845
|
}
|
|
847
846
|
databaseLocked = true;
|
|
848
847
|
}
|
|
849
|
-
|
|
850
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
851
|
-
return null;
|
|
852
|
-
throw error;
|
|
853
|
-
});
|
|
854
|
-
if (existingLock !== null) {
|
|
848
|
+
if ((await lstat(lock).catch(nullIfMissingFileError)) !== null) {
|
|
855
849
|
if (await recoverStaleCredentialHomeLock(lock))
|
|
856
850
|
continue;
|
|
857
851
|
await delay(CREDENTIAL_LOCK_POLL_MILLISECONDS, undefined, { signal });
|
|
@@ -924,14 +918,10 @@ function requireCredentialLockDatabaseFile(metadata, path) {
|
|
|
924
918
|
}
|
|
925
919
|
}
|
|
926
920
|
async function recoverStaleCredentialHomeLock(lock) {
|
|
927
|
-
const metadata = await lstat(lock).catch(
|
|
928
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
929
|
-
return null;
|
|
930
|
-
throw error;
|
|
931
|
-
});
|
|
921
|
+
const metadata = await lstat(lock).catch(nullIfMissingFileError);
|
|
932
922
|
if (metadata === null)
|
|
933
923
|
return true;
|
|
934
|
-
if (!metadata.isDirectory()
|
|
924
|
+
if (!metadata.isDirectory()) {
|
|
935
925
|
throw new OutputDirectoryError(`Codex Security credential-home lock is not a directory: ${lock}`);
|
|
936
926
|
}
|
|
937
927
|
let owner;
|
|
@@ -1008,8 +998,7 @@ export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
|
|
|
1008
998
|
export async function codexSecurityCredentialAllowsAmbientImport(codexHome) {
|
|
1009
999
|
await requireSecureCredentialHome(codexHome);
|
|
1010
1000
|
try {
|
|
1011
|
-
|
|
1012
|
-
if (!marker.isFile() || marker.isSymbolicLink()) {
|
|
1001
|
+
if (!(await lstat(join(codexHome, CREDENTIAL_LOGOUT_MARKER))).isFile()) {
|
|
1013
1002
|
throw new OutputDirectoryError(`Codex Security logout marker is not a regular file: ${codexHome}`);
|
|
1014
1003
|
}
|
|
1015
1004
|
return false;
|
|
@@ -1032,7 +1021,7 @@ export async function codexSecurityHasStoredFileCredentials(codexHome) {
|
|
|
1032
1021
|
return false;
|
|
1033
1022
|
throw error;
|
|
1034
1023
|
}
|
|
1035
|
-
if (!metadata.isFile()
|
|
1024
|
+
if (!metadata.isFile()) {
|
|
1036
1025
|
throw new OutputDirectoryError(`Codex Security stored authentication is not a regular file: ${path}`);
|
|
1037
1026
|
}
|
|
1038
1027
|
requirePrivateCredentialFile(metadata, path);
|
|
@@ -1088,16 +1077,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
|
|
|
1088
1077
|
};
|
|
1089
1078
|
}
|
|
1090
1079
|
export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
if (outputRelative === "" ||
|
|
1094
|
-
(outputRelative !== ".." &&
|
|
1095
|
-
!outputRelative.startsWith(`..${sep}`) &&
|
|
1096
|
-
!isAbsolute(outputRelative)) ||
|
|
1097
|
-
(pathKind === "output" &&
|
|
1098
|
-
repositoryRelative !== ".." &&
|
|
1099
|
-
!repositoryRelative.startsWith(`..${sep}`) &&
|
|
1100
|
-
!isAbsolute(repositoryRelative))) {
|
|
1080
|
+
if (isWithin(repository, outputDirectory) ||
|
|
1081
|
+
(pathKind === "output" && isWithin(outputDirectory, repository))) {
|
|
1101
1082
|
throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
|
|
1102
1083
|
}
|
|
1103
1084
|
}
|
|
@@ -1206,13 +1187,9 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
|
|
|
1206
1187
|
requireModelSafeOutputDir(outputDirectory);
|
|
1207
1188
|
const path = resolve(expandHome(outputDirectory));
|
|
1208
1189
|
try {
|
|
1209
|
-
const metadata = await lstat(path).catch(
|
|
1210
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1211
|
-
return null;
|
|
1212
|
-
throw error;
|
|
1213
|
-
});
|
|
1190
|
+
const metadata = await lstat(path).catch(nullIfMissingFileError);
|
|
1214
1191
|
if (metadata !== null) {
|
|
1215
|
-
if (!metadata.isDirectory()
|
|
1192
|
+
if (!metadata.isDirectory()) {
|
|
1216
1193
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1217
1194
|
}
|
|
1218
1195
|
if (!archiveExisting && (await readdir(path)).length !== 0) {
|
|
@@ -1277,8 +1254,7 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1277
1254
|
}
|
|
1278
1255
|
const prepared = JSON.parse(result.stdout);
|
|
1279
1256
|
if (!isRecord(prepared) ||
|
|
1280
|
-
|
|
1281
|
-
prepared["canonicalPath"].length === 0 ||
|
|
1257
|
+
!isNonEmptyString(prepared["canonicalPath"]) ||
|
|
1282
1258
|
typeof prepared["dev"] !== "string" ||
|
|
1283
1259
|
!/^(?:0|[1-9]\d*)$/u.test(prepared["dev"]) ||
|
|
1284
1260
|
typeof prepared["ino"] !== "string" ||
|
|
@@ -1309,7 +1285,7 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1309
1285
|
relativePath,
|
|
1310
1286
|
dev,
|
|
1311
1287
|
ino,
|
|
1312
|
-
], pluginHelperEnvironment(options.environment), contents
|
|
1288
|
+
], pluginHelperEnvironment(options.environment), contents);
|
|
1313
1289
|
if (!result.success) {
|
|
1314
1290
|
throw new Error(result.stderr.trim() ||
|
|
1315
1291
|
result.stdout.trim() ||
|
|
@@ -1317,8 +1293,6 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1317
1293
|
}
|
|
1318
1294
|
}
|
|
1319
1295
|
catch (error) {
|
|
1320
|
-
if (options.signal?.aborted)
|
|
1321
|
-
throw error;
|
|
1322
1296
|
throw new OutputDirectoryError("Could not safely restore a completed scan artifact.", { cause: error });
|
|
1323
1297
|
}
|
|
1324
1298
|
},
|
|
@@ -1327,18 +1301,13 @@ export async function prepareScanArtifactRestorer(options, scanDirectory) {
|
|
|
1327
1301
|
export async function planOutputArchive(outputDirectory) {
|
|
1328
1302
|
if (outputDirectory === null)
|
|
1329
1303
|
return null;
|
|
1330
|
-
const entries = await readdir(outputDirectory).catch(
|
|
1331
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1332
|
-
return null;
|
|
1333
|
-
throw error;
|
|
1334
|
-
});
|
|
1304
|
+
const entries = await readdir(outputDirectory).catch(nullIfMissingFileError);
|
|
1335
1305
|
if (entries === null || entries.length === 0)
|
|
1336
1306
|
return null;
|
|
1337
|
-
|
|
1307
|
+
return `${outputDirectory}.previous-${new Date()
|
|
1338
1308
|
.toISOString()
|
|
1339
1309
|
.replaceAll(/[-:]/g, "")
|
|
1340
|
-
.replace(/\.\d{3}Z$/, "")
|
|
1341
|
-
return `${outputDirectory}.previous-${timestamp}-${randomUUID().slice(0, 8)}`;
|
|
1310
|
+
.replace(/\.\d{3}Z$/, "")}-${randomUUID().slice(0, 8)}`;
|
|
1342
1311
|
}
|
|
1343
1312
|
export function requireModelSafeOutputDir(path) {
|
|
1344
1313
|
if (MODEL_UNSAFE_PATH.test(path)) {
|
|
@@ -1352,18 +1321,24 @@ export function requireModelSafeOutputDir(path) {
|
|
|
1352
1321
|
export async function canonicalizeModelSafePath(input) {
|
|
1353
1322
|
const path = resolve(expandHome(input));
|
|
1354
1323
|
requireModelSafeOutputDir(path);
|
|
1355
|
-
|
|
1324
|
+
const canonical = await canonicalConfigPath(path);
|
|
1325
|
+
requireModelSafeOutputDir(canonical);
|
|
1326
|
+
return canonical;
|
|
1327
|
+
}
|
|
1328
|
+
export async function canonicalConfigPath(path) {
|
|
1329
|
+
let existing = resolve(path);
|
|
1330
|
+
const missing = [];
|
|
1331
|
+
while (true) {
|
|
1356
1332
|
try {
|
|
1357
|
-
|
|
1358
|
-
const canonical = resolve(canonicalAncestor, relative(ancestor, path));
|
|
1359
|
-
requireModelSafeOutputDir(canonical);
|
|
1360
|
-
return canonical;
|
|
1333
|
+
return join(await realpath(existing), ...missing);
|
|
1361
1334
|
}
|
|
1362
1335
|
catch (error) {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1336
|
+
const parent = dirname(existing);
|
|
1337
|
+
if (error.code !== "ENOENT" ||
|
|
1338
|
+
parent === existing)
|
|
1366
1339
|
throw error;
|
|
1340
|
+
missing.unshift(basename(existing));
|
|
1341
|
+
existing = parent;
|
|
1367
1342
|
}
|
|
1368
1343
|
}
|
|
1369
1344
|
}
|
|
@@ -1388,11 +1363,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1388
1363
|
}
|
|
1389
1364
|
let createdRoot;
|
|
1390
1365
|
try {
|
|
1391
|
-
let existing = await lstat(path).catch(
|
|
1392
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1393
|
-
return null;
|
|
1394
|
-
throw error;
|
|
1395
|
-
});
|
|
1366
|
+
let existing = await lstat(path).catch(nullIfMissingFileError);
|
|
1396
1367
|
if (existing !== null && archiveExisting) {
|
|
1397
1368
|
const archiveDir = await planOutputArchive(path);
|
|
1398
1369
|
if (archiveDir !== null) {
|
|
@@ -1421,7 +1392,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
|
|
|
1421
1392
|
}
|
|
1422
1393
|
export async function validatePreparedOutputDir(path, validateLocation) {
|
|
1423
1394
|
const metadata = await lstat(path);
|
|
1424
|
-
if (!metadata.isDirectory()
|
|
1395
|
+
if (!metadata.isDirectory()) {
|
|
1425
1396
|
throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
|
|
1426
1397
|
}
|
|
1427
1398
|
const canonical = await realpath(path);
|
|
@@ -1474,7 +1445,7 @@ export async function requireSecureOutputAncestry(path, effectiveUid = process.g
|
|
|
1474
1445
|
catch (error) {
|
|
1475
1446
|
throw new OutputDirectoryError(`Unable to inspect scan output parent directory: ${current}`, { cause: error });
|
|
1476
1447
|
}
|
|
1477
|
-
if (!metadata.isDirectory()
|
|
1448
|
+
if (!metadata.isDirectory()) {
|
|
1478
1449
|
throw new OutputDirectoryError(`Scan output parent must be a non-symlink directory: ${current}`);
|
|
1479
1450
|
}
|
|
1480
1451
|
requireTrustedOutputAncestor(metadata, current, effectiveUid);
|
|
@@ -1589,15 +1560,15 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1589
1560
|
let expandedSize = 0;
|
|
1590
1561
|
const paths = new Set();
|
|
1591
1562
|
const checksums = [];
|
|
1592
|
-
await
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
defaultFileMode: 0o600,
|
|
1596
|
-
onEntry(entry, archive) {
|
|
1563
|
+
const zip = await openZip(archivePath, { strictFileNames: true });
|
|
1564
|
+
try {
|
|
1565
|
+
for await (const entry of zip.eachEntry()) {
|
|
1597
1566
|
throwIfSignalAborted(signal);
|
|
1598
|
-
if (
|
|
1599
|
-
throw new PluginBootstrapError(`Plugin ZIP contains too many entries: ${
|
|
1567
|
+
if (zip.entryCount > MAX_ZIP_ENTRIES) {
|
|
1568
|
+
throw new PluginBootstrapError(`Plugin ZIP contains too many entries: ${zip.entryCount}.`);
|
|
1600
1569
|
}
|
|
1570
|
+
if (entry.fileName.startsWith("__MACOSX/"))
|
|
1571
|
+
continue;
|
|
1601
1572
|
const path = safeArchivePath(entry.fileName);
|
|
1602
1573
|
const collisionKey = path.toLowerCase();
|
|
1603
1574
|
if (paths.has(collisionKey)) {
|
|
@@ -1619,11 +1590,23 @@ export async function extractPluginZip(archive, destination, signal) {
|
|
|
1619
1590
|
mode === 0o040000 ||
|
|
1620
1591
|
(entry.versionMadeBy >>> 8 === 0 &&
|
|
1621
1592
|
entry.externalFileAttributes === 16);
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1593
|
+
const output = join(staging, ...path.split("/"));
|
|
1594
|
+
const entryMode = (entry.externalFileAttributes >>> 16) & 0xffff;
|
|
1595
|
+
const permissions = (entryMode || (directory ? 0o700 : 0o600)) & 0o777;
|
|
1596
|
+
await mkdir(directory ? output : dirname(output), {
|
|
1597
|
+
recursive: true,
|
|
1598
|
+
...(directory ? { mode: permissions } : {}),
|
|
1599
|
+
});
|
|
1600
|
+
if (directory)
|
|
1601
|
+
continue;
|
|
1602
|
+
const stream = await zip.openReadStreamPromise(entry);
|
|
1603
|
+
await pipeline(stream, createWriteStream(output, { mode: permissions, flags: "wx" }), { signal });
|
|
1604
|
+
checksums.push({ path, checksum: entry.crc32 >>> 0 });
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
finally {
|
|
1608
|
+
zip.close();
|
|
1609
|
+
}
|
|
1627
1610
|
for (const { path, checksum } of checksums) {
|
|
1628
1611
|
throwIfSignalAborted(signal);
|
|
1629
1612
|
const bytes = await readFile(join(staging, ...path.split("/")));
|
|
@@ -1719,7 +1702,7 @@ export async function resolvePluginPath(pluginPath, workspace, signal) {
|
|
|
1719
1702
|
if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
|
|
1720
1703
|
return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
|
|
1721
1704
|
}
|
|
1722
|
-
if (metadata?.isDirectory()
|
|
1705
|
+
if (metadata?.isDirectory()) {
|
|
1723
1706
|
throwIfSignalAborted(signal);
|
|
1724
1707
|
return await validatePluginRoot(path);
|
|
1725
1708
|
}
|
|
@@ -1801,18 +1784,17 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1801
1784
|
CODEX_HOME: codexHome,
|
|
1802
1785
|
};
|
|
1803
1786
|
const run = options.runCodex ?? runPluginCommand;
|
|
1804
|
-
const existing = await lstat(marketplace).catch(
|
|
1805
|
-
if (nodeErrorCode(error) === "ENOENT")
|
|
1806
|
-
return null;
|
|
1807
|
-
throw error;
|
|
1808
|
-
});
|
|
1787
|
+
const existing = await lstat(marketplace).catch(nullIfMissingFileError);
|
|
1809
1788
|
if (existing !== null && !existing.isDirectory()) {
|
|
1810
1789
|
throw new PluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
|
|
1811
1790
|
}
|
|
1812
1791
|
const staged = existing === null
|
|
1813
1792
|
? null
|
|
1814
1793
|
: await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
|
|
1815
|
-
|
|
1794
|
+
const stagedRoot = join(marketplace, "plugins", PLUGIN_NAME);
|
|
1795
|
+
const stagedMatches = staged?.version === version &&
|
|
1796
|
+
(await pluginContentsMatch(root, stagedRoot, options.signal));
|
|
1797
|
+
if (!stagedMatches) {
|
|
1816
1798
|
if (existing !== null) {
|
|
1817
1799
|
await rm(marketplace, { recursive: true, force: true });
|
|
1818
1800
|
}
|
|
@@ -1823,16 +1805,50 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1823
1805
|
return "";
|
|
1824
1806
|
throw error;
|
|
1825
1807
|
});
|
|
1826
|
-
const
|
|
1808
|
+
const configuration = parse(config);
|
|
1809
|
+
const marketplaces = configuration["marketplaces"];
|
|
1827
1810
|
const registration = isRecord(marketplaces)
|
|
1828
1811
|
? marketplaces[MARKETPLACE_NAME]
|
|
1829
1812
|
: undefined;
|
|
1830
|
-
|
|
1831
|
-
registration["source_type"]
|
|
1832
|
-
typeof registration["source"]
|
|
1833
|
-
|
|
1813
|
+
const registered = isRecord(registration) &&
|
|
1814
|
+
registration["source_type"] === "local" &&
|
|
1815
|
+
typeof registration["source"] === "string" &&
|
|
1816
|
+
(await sameFile(registration["source"], marketplace));
|
|
1817
|
+
if (!registered) {
|
|
1834
1818
|
await run(command, ["plugin", "marketplace", "add", marketplace], environment, options.signal);
|
|
1835
1819
|
}
|
|
1820
|
+
const installRecord = join(marketplace, "installed-plugin.json");
|
|
1821
|
+
const previous = await readFile(installRecord, "utf8")
|
|
1822
|
+
.then((value) => JSON.parse(value))
|
|
1823
|
+
.catch((error) => {
|
|
1824
|
+
if (nodeErrorCode(error) === "ENOENT" || error instanceof SyntaxError) {
|
|
1825
|
+
return null;
|
|
1826
|
+
}
|
|
1827
|
+
throw error;
|
|
1828
|
+
});
|
|
1829
|
+
const plugins = configuration["plugins"];
|
|
1830
|
+
const plugin = isRecord(plugins)
|
|
1831
|
+
? plugins[`${PLUGIN_NAME}@${MARKETPLACE_NAME}`]
|
|
1832
|
+
: undefined;
|
|
1833
|
+
// Codex replaces the shared install even at the same version. Reuse it so
|
|
1834
|
+
// workers from an earlier scan can keep using their plugin files.
|
|
1835
|
+
if (stagedMatches &&
|
|
1836
|
+
registered &&
|
|
1837
|
+
isRecord(plugin) &&
|
|
1838
|
+
plugin["enabled"] === true &&
|
|
1839
|
+
isRecord(previous) &&
|
|
1840
|
+
typeof previous["installedPath"] === "string" &&
|
|
1841
|
+
previous["version"] === version &&
|
|
1842
|
+
(await pluginContentsMatch(root, previous["installedPath"], options.signal, true))) {
|
|
1843
|
+
return {
|
|
1844
|
+
pluginRoot: root,
|
|
1845
|
+
marketplaceRoot: marketplace,
|
|
1846
|
+
installedRoot: previous["installedPath"],
|
|
1847
|
+
marketplaceName: MARKETPLACE_NAME,
|
|
1848
|
+
name,
|
|
1849
|
+
version,
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1836
1852
|
const output = await run(command, ["plugin", "add", "--json", `${PLUGIN_NAME}@${MARKETPLACE_NAME}`], environment, options.signal);
|
|
1837
1853
|
let installed;
|
|
1838
1854
|
try {
|
|
@@ -1846,6 +1862,10 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1846
1862
|
installed["version"] !== version) {
|
|
1847
1863
|
throw new PluginBootstrapError("Codex plugin install did not return the selected plugin path and version.");
|
|
1848
1864
|
}
|
|
1865
|
+
await writeFile(installRecord, JSON.stringify({
|
|
1866
|
+
installedPath: installed["installedPath"],
|
|
1867
|
+
version,
|
|
1868
|
+
}), { mode: 0o600, signal: options.signal });
|
|
1849
1869
|
return {
|
|
1850
1870
|
pluginRoot: root,
|
|
1851
1871
|
marketplaceRoot: marketplace,
|
|
@@ -1855,12 +1875,48 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
|
1855
1875
|
version,
|
|
1856
1876
|
};
|
|
1857
1877
|
}
|
|
1878
|
+
async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false) {
|
|
1879
|
+
throwIfSignalAborted(signal);
|
|
1880
|
+
const sourceMetadata = await lstat(source);
|
|
1881
|
+
const destinationMetadata = await lstat(destination).catch((error) => {
|
|
1882
|
+
if (["ENOENT", "ENOTDIR"].includes(nodeErrorCode(error) ?? "")) {
|
|
1883
|
+
return null;
|
|
1884
|
+
}
|
|
1885
|
+
throw error;
|
|
1886
|
+
});
|
|
1887
|
+
if (destinationMetadata === null)
|
|
1888
|
+
return false;
|
|
1889
|
+
if (sourceMetadata.isFile() && destinationMetadata.isFile()) {
|
|
1890
|
+
if (sourceMetadata.size !== destinationMetadata.size ||
|
|
1891
|
+
(sourceMetadata.mode & 0o111) !== (destinationMetadata.mode & 0o111)) {
|
|
1892
|
+
return false;
|
|
1893
|
+
}
|
|
1894
|
+
const [sourceBytes, destinationBytes] = await Promise.all([
|
|
1895
|
+
readFile(source, { signal }),
|
|
1896
|
+
readFile(destination, { signal }),
|
|
1897
|
+
]);
|
|
1898
|
+
return sourceBytes.equals(destinationBytes);
|
|
1899
|
+
}
|
|
1900
|
+
if (!sourceMetadata.isDirectory() || !destinationMetadata.isDirectory()) {
|
|
1901
|
+
return false;
|
|
1902
|
+
}
|
|
1903
|
+
const entries = await readdir(source);
|
|
1904
|
+
if (!allowExtraFiles &&
|
|
1905
|
+
entries.length !== (await readdir(destination)).length) {
|
|
1906
|
+
return false;
|
|
1907
|
+
}
|
|
1908
|
+
for (const entry of entries) {
|
|
1909
|
+
if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles))) {
|
|
1910
|
+
return false;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
return true;
|
|
1914
|
+
}
|
|
1858
1915
|
export async function pluginMetadata(root) {
|
|
1859
1916
|
const manifestPath = join(root, ".codex-plugin", "plugin.json");
|
|
1860
1917
|
let manifest;
|
|
1861
1918
|
try {
|
|
1862
|
-
|
|
1863
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
1919
|
+
if (!(await lstat(manifestPath)).isFile()) {
|
|
1864
1920
|
throw new Error("plugin manifest is not a regular file");
|
|
1865
1921
|
}
|
|
1866
1922
|
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
@@ -1928,6 +1984,20 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
|
|
|
1928
1984
|
CODEX_CLI_PATH: resolveCodexCommand(environment).command,
|
|
1929
1985
|
};
|
|
1930
1986
|
}
|
|
1987
|
+
export function environmentWithGit(environment, git) {
|
|
1988
|
+
if (git === undefined)
|
|
1989
|
+
return environment;
|
|
1990
|
+
const result = { ...environment };
|
|
1991
|
+
for (const name of Object.keys(result)) {
|
|
1992
|
+
const normalized = name.toUpperCase();
|
|
1993
|
+
if (normalized === "CODEX_SECURITY_GIT" || normalized === "PATH") {
|
|
1994
|
+
delete result[name];
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
result["CODEX_SECURITY_GIT"] = git.executable ?? "";
|
|
1998
|
+
result["PATH"] = git.environment["PATH"] ?? "";
|
|
1999
|
+
return result;
|
|
2000
|
+
}
|
|
1931
2001
|
export function pythonUtf8Environment(environment) {
|
|
1932
2002
|
const normalized = { ...environment };
|
|
1933
2003
|
for (const name of Object.keys(normalized)) {
|
|
@@ -1976,6 +2046,29 @@ export async function runCodexCommand(command, args, environment, input, signal)
|
|
|
1976
2046
|
child.stdin.end(input);
|
|
1977
2047
|
return await completion;
|
|
1978
2048
|
}
|
|
2049
|
+
export async function probeCodexSandbox(command, environment, signal) {
|
|
2050
|
+
// This preflight covers the Unix sandbox backends.
|
|
2051
|
+
if (process.platform === "win32")
|
|
2052
|
+
return;
|
|
2053
|
+
// Reuse the resolved Codex executable instead of looking up a probe on PATH.
|
|
2054
|
+
const args = ["sandbox", "--", command.command, "--version"];
|
|
2055
|
+
const timeout = AbortSignal.timeout(SANDBOX_PROBE_TIMEOUT_MILLISECONDS);
|
|
2056
|
+
let detail;
|
|
2057
|
+
try {
|
|
2058
|
+
const result = await runCodexCommand(command, args, environment, undefined, signal === undefined ? timeout : AbortSignal.any([signal, timeout]));
|
|
2059
|
+
if (result.success)
|
|
2060
|
+
return;
|
|
2061
|
+
detail =
|
|
2062
|
+
result.stderr.trim() ||
|
|
2063
|
+
result.stdout.trim() ||
|
|
2064
|
+
`Codex exited with status ${result.exitCode}.`;
|
|
2065
|
+
}
|
|
2066
|
+
catch (error) {
|
|
2067
|
+
signal?.throwIfAborted();
|
|
2068
|
+
detail = processErrorDetail(error);
|
|
2069
|
+
}
|
|
2070
|
+
throw new SandboxUnavailableError(`Codex could not run a command in its sandbox; reproduce with '${command.command} ${args.join(" ")}'. On Linux this usually means unprivileged user namespaces are restricted (kernel.apparmor_restrict_unprivileged_userns=1 on Ubuntu 24.04 and later), which Bubblewrap needs; inside the container image, use the AppArmor profile and Compose override from the SDK README. Codex reported: ${detail}`);
|
|
2071
|
+
}
|
|
1979
2072
|
async function runPluginCommand(command, args, environment, signal) {
|
|
1980
2073
|
try {
|
|
1981
2074
|
const { success, exitCode, stdout, stderr } = await runCodexCommand(command, args, environment, undefined, signal);
|
|
@@ -2102,30 +2195,15 @@ export function isPythonPathCandidate(candidate) {
|
|
|
2102
2195
|
candidate.startsWith("."));
|
|
2103
2196
|
}
|
|
2104
2197
|
async function hasPluginManifest(root) {
|
|
2105
|
-
return await
|
|
2106
|
-
}
|
|
2107
|
-
async function isRegularFile(path) {
|
|
2108
|
-
try {
|
|
2109
|
-
const metadata = await lstat(path);
|
|
2110
|
-
return metadata.isFile() && !metadata.isSymbolicLink();
|
|
2111
|
-
}
|
|
2112
|
-
catch {
|
|
2113
|
-
return false;
|
|
2114
|
-
}
|
|
2198
|
+
return await lstat(join(root, ".codex-plugin", "plugin.json")).then((metadata) => metadata.isFile(), () => false);
|
|
2115
2199
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
return (leftMetadata.dev === rightMetadata.dev &&
|
|
2124
|
-
leftMetadata.ino === rightMetadata.ino);
|
|
2125
|
-
}
|
|
2126
|
-
catch {
|
|
2127
|
-
return false;
|
|
2128
|
-
}
|
|
2200
|
+
function sameFile(left, right) {
|
|
2201
|
+
// NTFS file IDs can exceed JavaScript's safe integer range.
|
|
2202
|
+
return Promise.all([
|
|
2203
|
+
stat(left, { bigint: true }),
|
|
2204
|
+
stat(right, { bigint: true }),
|
|
2205
|
+
]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
|
|
2206
|
+
leftMetadata.ino === rightMetadata.ino, () => false);
|
|
2129
2207
|
}
|
|
2130
2208
|
export function expandHome(value, environment = process.env) {
|
|
2131
2209
|
const home = (process.platform === "win32"
|
|
@@ -2160,20 +2238,27 @@ function processErrorDetail(error) {
|
|
|
2160
2238
|
}
|
|
2161
2239
|
return String(error) || "unknown error";
|
|
2162
2240
|
}
|
|
2163
|
-
function isRecord(value) {
|
|
2164
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2165
|
-
}
|
|
2166
2241
|
function nodeErrorCode(error) {
|
|
2167
2242
|
return isRecord(error) && typeof error["code"] === "string"
|
|
2168
2243
|
? error["code"]
|
|
2169
2244
|
: undefined;
|
|
2170
2245
|
}
|
|
2171
|
-
function abortReason(signal) {
|
|
2172
|
-
return (signal.reason ??
|
|
2173
|
-
new DOMException("The operation was aborted.", "AbortError"));
|
|
2174
|
-
}
|
|
2175
2246
|
function throwIfSignalAborted(signal) {
|
|
2176
2247
|
if (signal?.aborted)
|
|
2177
2248
|
throw abortReason(signal);
|
|
2178
2249
|
}
|
|
2250
|
+
function nullIfMissingFileError(error) {
|
|
2251
|
+
if (nodeErrorCode(error) === "ENOENT")
|
|
2252
|
+
return null;
|
|
2253
|
+
throw error;
|
|
2254
|
+
}
|
|
2255
|
+
/** @internal */
|
|
2256
|
+
export function workbenchEnvironment(environment) {
|
|
2257
|
+
return {
|
|
2258
|
+
...environment,
|
|
2259
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(environment),
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
/** @internal */
|
|
2263
|
+
export const resolveWorkbenchRuntime = (options) => Promise.all([resolvePluginPython(options), bundledPluginRoot()]);
|
|
2179
2264
|
//# sourceMappingURL=runtime.js.map
|