@openai/codex-security 0.1.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/LICENSE +201 -0
- package/README.md +306 -0
- package/_bundled_plugin/.app.json +20 -0
- package/_bundled_plugin/.codex-plugin/plugin.json +41 -0
- package/_bundled_plugin/.mcp.json +20 -0
- package/_bundled_plugin/assets/logo.png +0 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +22 -0
- package/_bundled_plugin/examples/completed-scan/findings.json +51 -0
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +43 -0
- package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
- package/_bundled_plugin/mcp/server.mjs +24 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/preflight/capability-profiles.toml +179 -0
- package/_bundled_plugin/references/config-preflight.md +115 -0
- package/_bundled_plugin/references/final-report.md +205 -0
- package/_bundled_plugin/references/finding-detail-fields.md +162 -0
- package/_bundled_plugin/references/sarif-adapter.md +26 -0
- package/_bundled_plugin/references/scan-artifacts.md +116 -0
- package/_bundled_plugin/references/scan-contract.md +164 -0
- package/_bundled_plugin/references/security-guidance.md +15 -0
- package/_bundled_plugin/references/shared-hard-rules.md +15 -0
- package/_bundled_plugin/references/static-finding-assessment.md +75 -0
- package/_bundled_plugin/schemas/coverage.schema.json +228 -0
- package/_bundled_plugin/schemas/findings.schema.json +359 -0
- package/_bundled_plugin/schemas/scan-manifest.schema.json +332 -0
- package/_bundled_plugin/scripts/config_preflight.py +901 -0
- package/_bundled_plugin/scripts/deep_scan_config.py +108 -0
- package/_bundled_plugin/scripts/deep_scan_workbench.py +1547 -0
- package/_bundled_plugin/scripts/filesystem_identity.py +30 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +2208 -0
- package/_bundled_plugin/scripts/finding_preview.py +270 -0
- package/_bundled_plugin/scripts/generate_rank_input.py +1013 -0
- package/_bundled_plugin/scripts/normalize_candidates.py +320 -0
- package/_bundled_plugin/scripts/rank_preview.py +968 -0
- package/_bundled_plugin/scripts/report_projection.py +844 -0
- package/_bundled_plugin/scripts/resolve_security_md.py +158 -0
- package/_bundled_plugin/scripts/snapshot_sqlite.py +26 -0
- package/_bundled_plugin/scripts/validate_report_format.py +138 -0
- package/_bundled_plugin/scripts/validate_scan_contract.py +108 -0
- package/_bundled_plugin/scripts/validate_tracking_source.py +92 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +612 -0
- package/_bundled_plugin/scripts/workbench/__init__.py +1 -0
- package/_bundled_plugin/scripts/workbench/handoff.py +238 -0
- package/_bundled_plugin/scripts/workbench_cli.py +325 -0
- package/_bundled_plugin/scripts/workbench_constants.py +81 -0
- package/_bundled_plugin/scripts/workbench_db.py +3728 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +242 -0
- package/_bundled_plugin/scripts/workbench_progress.py +226 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +125 -0
- package/_bundled_plugin/scripts/workbench_scan_history.py +829 -0
- package/_bundled_plugin/scripts/workbench_scan_start.py +149 -0
- package/_bundled_plugin/scripts/workbench_schema.py +714 -0
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +99 -0
- package/_bundled_plugin/scripts/workbench_target.py +469 -0
- package/_bundled_plugin/scripts/workbench_target_state.py +63 -0
- package/_bundled_plugin/scripts/workbench_validation.py +294 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +117 -0
- package/_bundled_plugin/skills/attack-path-analysis/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +76 -0
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +153 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +166 -0
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +93 -0
- package/_bundled_plugin/skills/define-security-policy/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +155 -0
- package/_bundled_plugin/skills/finding-discovery/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +112 -0
- package/_bundled_plugin/skills/fix-finding/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +240 -0
- package/_bundled_plugin/skills/propose-security-hardening/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +424 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +167 -0
- package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +42 -0
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +48 -0
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +85 -0
- package/_bundled_plugin/skills/threat-model/SKILL.md +59 -0
- package/_bundled_plugin/skills/threat-model/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model/references/threat-model-guidance.md +48 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +222 -0
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +6 -0
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +54 -0
- package/_bundled_plugin/skills/track-findings/references/jira.md +77 -0
- package/_bundled_plugin/skills/triage-finding/SKILL.md +342 -0
- package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +168 -0
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +62 -0
- package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +108 -0
- package/_bundled_plugin/skills/validation/SKILL.md +110 -0
- package/_bundled_plugin/skills/validation/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/validation/references/validation-guidance.md +122 -0
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +263 -0
- package/_bundled_plugin/skills/vulnerability-writeup/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +104 -0
- package/bin/codex-security.mjs +26 -0
- package/dist/api.d.ts +112 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +1051 -0
- package/dist/api.js.map +1 -0
- package/dist/auth.d.ts +29 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +246 -0
- package/dist/auth.js.map +1 -0
- package/dist/bulk-scan-discovery.d.ts +35 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -0
- package/dist/bulk-scan-discovery.js +217 -0
- package/dist/bulk-scan-discovery.js.map +1 -0
- package/dist/cli.d.ts +67 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2128 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +199 -0
- package/dist/config.js.map +1 -0
- package/dist/contract.d.ts +21 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +848 -0
- package/dist/contract.js.map +1 -0
- package/dist/cost.d.ts +30 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +280 -0
- package/dist/cost.js.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +52 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge-base.d.ts +7 -0
- package/dist/knowledge-base.d.ts.map +1 -0
- package/dist/knowledge-base.js +181 -0
- package/dist/knowledge-base.js.map +1 -0
- package/dist/models.d.ts +231 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +3 -0
- package/dist/models.js.map +1 -0
- package/dist/multiscan.d.ts +30 -0
- package/dist/multiscan.d.ts.map +1 -0
- package/dist/multiscan.js +397 -0
- package/dist/multiscan.js.map +1 -0
- package/dist/result.d.ts +39 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +71 -0
- package/dist/result.js.map +1 -0
- package/dist/runtime.d.ts +69 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +997 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scan-comparison.d.ts +42 -0
- package/dist/scan-comparison.d.ts.map +1 -0
- package/dist/scan-comparison.js +153 -0
- package/dist/scan-comparison.js.map +1 -0
- package/dist/scan-history-renderer.d.ts +13 -0
- package/dist/scan-history-renderer.d.ts.map +1 -0
- package/dist/scan-history-renderer.js +297 -0
- package/dist/scan-history-renderer.js.map +1 -0
- package/dist/targets.d.ts +39 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/targets.js +295 -0
- package/dist/targets.js.map +1 -0
- package/dist/trusted-executable.d.ts +6 -0
- package/dist/trusted-executable.d.ts.map +1 -0
- package/dist/trusted-executable.js +77 -0
- package/dist/trusted-executable.js.map +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +42 -0
- package/dist/version.js.map +1 -0
- package/dist/worker-progress.d.ts +13 -0
- package/dist/worker-progress.d.ts.map +1 -0
- package/dist/worker-progress.js +113 -0
- package/dist/worker-progress.js.map +1 -0
- package/package.json +74 -0
package/dist/targets.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { lstat, realpath, stat } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { InvalidTargetError } from "./errors.js";
|
|
8
|
+
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
9
|
+
const execFile = promisify(execFileCallback);
|
|
10
|
+
const UNSUPPORTED_GIT_ENVIRONMENT = new Set([
|
|
11
|
+
"GIT_DIR",
|
|
12
|
+
"GIT_WORK_TREE",
|
|
13
|
+
"GIT_INDEX_FILE",
|
|
14
|
+
"GIT_OBJECT_DIRECTORY",
|
|
15
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
16
|
+
"GIT_COMMON_DIR",
|
|
17
|
+
"GIT_REPLACE_REF_BASE",
|
|
18
|
+
]);
|
|
19
|
+
export class DiffTarget {
|
|
20
|
+
#brand = "DiffTarget";
|
|
21
|
+
kind;
|
|
22
|
+
base;
|
|
23
|
+
head;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
void this.#brand;
|
|
26
|
+
this.kind = options.kind;
|
|
27
|
+
this.base = options.base;
|
|
28
|
+
this.head = options.head;
|
|
29
|
+
if (this.kind !== "refs" && this.kind !== "working_tree") {
|
|
30
|
+
throw new InvalidTargetError(`Unsupported diff target kind: ${String(this.kind)}`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof this.base !== "string" || this.base.length === 0) {
|
|
33
|
+
throw new InvalidTargetError("The diff base ref must be non-empty.");
|
|
34
|
+
}
|
|
35
|
+
if (this.kind === "refs" &&
|
|
36
|
+
(typeof this.head !== "string" || this.head.length === 0)) {
|
|
37
|
+
throw new InvalidTargetError("Git diff refs must include a non-empty head ref.");
|
|
38
|
+
}
|
|
39
|
+
if (this.kind === "working_tree" && this.head !== undefined) {
|
|
40
|
+
throw new InvalidTargetError("Working-tree targets cannot specify a head ref.");
|
|
41
|
+
}
|
|
42
|
+
Object.freeze(this);
|
|
43
|
+
}
|
|
44
|
+
static refs({ base, head = "HEAD", }) {
|
|
45
|
+
return new DiffTarget({ kind: "refs", base, head });
|
|
46
|
+
}
|
|
47
|
+
static workingTree({ base = "HEAD", } = {}) {
|
|
48
|
+
return new DiffTarget({ kind: "working_tree", base });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function normalizeRepository(repository, signal) {
|
|
52
|
+
const candidate = resolveRepositoryPath(repository);
|
|
53
|
+
let canonical;
|
|
54
|
+
try {
|
|
55
|
+
canonical = await abortable(() => realpath(candidate), signal);
|
|
56
|
+
if (!(await abortable(() => stat(canonical), signal)).isDirectory()) {
|
|
57
|
+
throw new Error("not a directory");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throwIfAborted(signal);
|
|
62
|
+
throw new InvalidTargetError(`Repository is not a directory: ${candidate}`, {
|
|
63
|
+
cause: error,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return canonical;
|
|
67
|
+
}
|
|
68
|
+
export function resolveRepositoryPath(repository) {
|
|
69
|
+
return resolve(expandHome(repository));
|
|
70
|
+
}
|
|
71
|
+
export async function enclosingGitWorktreeRoot(repository, signal) {
|
|
72
|
+
try {
|
|
73
|
+
const root = await gitOutput(repository, ["rev-parse", "--show-toplevel"], signal);
|
|
74
|
+
return await abortable(() => realpath(root), signal);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throwIfAborted(signal);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function validatedGitEnvironment(environment = process.env) {
|
|
82
|
+
const unsupported = Object.entries(environment).find(([name, value]) => UNSUPPORTED_GIT_ENVIRONMENT.has(name.toUpperCase()) &&
|
|
83
|
+
value !== undefined &&
|
|
84
|
+
value.trim() !== "");
|
|
85
|
+
if (unsupported !== undefined) {
|
|
86
|
+
throw new InvalidTargetError(`${unsupported[0]} is not supported for Codex Security scans.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function normalizeTarget(repository, target, signal) {
|
|
90
|
+
const root = await normalizeRepository(repository, signal);
|
|
91
|
+
throwIfAborted(signal);
|
|
92
|
+
if (target === "repository") {
|
|
93
|
+
return { kind: "repository", paths: [] };
|
|
94
|
+
}
|
|
95
|
+
if (target instanceof DiffTarget) {
|
|
96
|
+
if (target.kind !== "refs" && target.kind !== "working_tree") {
|
|
97
|
+
throw new InvalidTargetError(`Unsupported diff target kind: ${String(target.kind)}`);
|
|
98
|
+
}
|
|
99
|
+
if (typeof target.base !== "string" || target.base.length === 0) {
|
|
100
|
+
throw new InvalidTargetError("The diff base ref must be non-empty.");
|
|
101
|
+
}
|
|
102
|
+
if (target.kind === "refs" &&
|
|
103
|
+
(typeof target.head !== "string" || target.head.length === 0)) {
|
|
104
|
+
throw new InvalidTargetError("Git diff refs must include a non-empty head ref.");
|
|
105
|
+
}
|
|
106
|
+
if (target.kind === "working_tree" && target.head !== undefined) {
|
|
107
|
+
throw new InvalidTargetError("Working-tree targets cannot specify a head ref.");
|
|
108
|
+
}
|
|
109
|
+
await requireGitRepository(root, signal);
|
|
110
|
+
const base = await resolveGitRef(root, target.base, signal);
|
|
111
|
+
if (target.kind === "refs") {
|
|
112
|
+
const head = target.head;
|
|
113
|
+
if (typeof head !== "string" || head.length === 0) {
|
|
114
|
+
throw new InvalidTargetError("Git diff refs must include a non-empty head ref.");
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
kind: "refs",
|
|
118
|
+
paths: [],
|
|
119
|
+
base,
|
|
120
|
+
head: await resolveGitRef(root, head, signal),
|
|
121
|
+
baseRef: target.base,
|
|
122
|
+
headRef: head,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
kind: "working_tree",
|
|
127
|
+
paths: [],
|
|
128
|
+
base,
|
|
129
|
+
head: await resolveGitRef(root, "HEAD", signal),
|
|
130
|
+
baseRef: target.base,
|
|
131
|
+
headRef: "HEAD",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (!Array.isArray(target)) {
|
|
135
|
+
throw new InvalidTargetError("Scan target must be 'repository', a DiffTarget, or an array of paths.");
|
|
136
|
+
}
|
|
137
|
+
if (target.length === 0) {
|
|
138
|
+
throw new InvalidTargetError("A path scan target must contain at least one path.");
|
|
139
|
+
}
|
|
140
|
+
const paths = [];
|
|
141
|
+
for (const value of target) {
|
|
142
|
+
throwIfAborted(signal);
|
|
143
|
+
if (typeof value !== "string") {
|
|
144
|
+
throw new InvalidTargetError("Path scan targets must contain only strings.");
|
|
145
|
+
}
|
|
146
|
+
if (value.length === 0) {
|
|
147
|
+
throw new InvalidTargetError("Path scan targets must not contain an empty path.");
|
|
148
|
+
}
|
|
149
|
+
const candidate = isAbsolute(expandHome(value))
|
|
150
|
+
? resolve(expandHome(value))
|
|
151
|
+
: resolve(root, expandHome(value));
|
|
152
|
+
if (!existsSync(candidate)) {
|
|
153
|
+
throw new InvalidTargetError(`Path target does not exist: ${value}`);
|
|
154
|
+
}
|
|
155
|
+
let canonical;
|
|
156
|
+
try {
|
|
157
|
+
canonical = await abortable(() => realpath(candidate), signal);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
throwIfAborted(signal);
|
|
161
|
+
throw new InvalidTargetError(`Path target does not exist: ${value}`, {
|
|
162
|
+
cause: error,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const relativePath = relative(root, canonical);
|
|
166
|
+
if (relativePath === ".." ||
|
|
167
|
+
relativePath.startsWith(`..${sep}`) ||
|
|
168
|
+
isAbsolute(relativePath)) {
|
|
169
|
+
throw new InvalidTargetError(`Path target is outside the repository: ${value}`);
|
|
170
|
+
}
|
|
171
|
+
const normalized = relativePath.split(sep).join("/") || ".";
|
|
172
|
+
if (!paths.includes(normalized)) {
|
|
173
|
+
paths.push(normalized);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { kind: "paths", paths };
|
|
177
|
+
}
|
|
178
|
+
export function validateMode(target, mode) {
|
|
179
|
+
if (mode !== "standard" && mode !== "deep") {
|
|
180
|
+
throw new InvalidTargetError(`Unsupported scan mode: ${String(mode)}`);
|
|
181
|
+
}
|
|
182
|
+
if (mode === "deep" &&
|
|
183
|
+
(target.kind === "refs" || target.kind === "working_tree")) {
|
|
184
|
+
throw new InvalidTargetError("Deep mode supports repository and path targets only.");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export async function repositoryRevision(repository, signal) {
|
|
188
|
+
try {
|
|
189
|
+
return await gitOutput(repository, ["rev-parse", "--verify", "HEAD^{commit}"], signal);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
throwIfAborted(signal);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async function requireGitRepository(repository, signal) {
|
|
197
|
+
let root;
|
|
198
|
+
try {
|
|
199
|
+
root = await gitOutput(repository, ["rev-parse", "--show-toplevel"], signal);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throwIfAborted(signal);
|
|
203
|
+
throw new InvalidTargetError(`Diff targets require a Git repository: ${repository}`, {
|
|
204
|
+
cause: error,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const canonicalRoot = await abortable(() => realpath(root), signal);
|
|
208
|
+
if (canonicalRoot !== repository) {
|
|
209
|
+
throw new InvalidTargetError(`Diff target repository must be the Git worktree root: ${canonicalRoot}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function resolveGitRef(repository, ref, signal) {
|
|
213
|
+
try {
|
|
214
|
+
return await gitOutput(repository, ["rev-parse", "--verify", "--end-of-options", `${ref}^{commit}`], signal);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throwIfAborted(signal);
|
|
218
|
+
throw new InvalidTargetError(`unknown Git ref: ${ref}`, { cause: error });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function gitOutput(repository, args, signal) {
|
|
222
|
+
throwIfAborted(signal);
|
|
223
|
+
const command = await resolveTrustedExecutable("git", isolatedGitEnvironment(), await outermostGitMarkerRoot(repository, signal));
|
|
224
|
+
if (command === null)
|
|
225
|
+
throw new Error("Git is not available on a trusted PATH.");
|
|
226
|
+
throwIfAborted(signal);
|
|
227
|
+
const { stdout } = await execFile(command.executable, ["-C", repository, ...args], {
|
|
228
|
+
encoding: "utf8",
|
|
229
|
+
signal,
|
|
230
|
+
env: command.environment,
|
|
231
|
+
});
|
|
232
|
+
return stdout.trim();
|
|
233
|
+
}
|
|
234
|
+
async function outermostGitMarkerRoot(repository, signal) {
|
|
235
|
+
let current = repository;
|
|
236
|
+
let root = repository;
|
|
237
|
+
while (true) {
|
|
238
|
+
throwIfAborted(signal);
|
|
239
|
+
try {
|
|
240
|
+
await lstat(join(current, ".git"));
|
|
241
|
+
root = current;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (error.code !== "ENOENT")
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
const parent = dirname(current);
|
|
248
|
+
if (parent === current)
|
|
249
|
+
return root;
|
|
250
|
+
current = parent;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function isolatedGitEnvironment() {
|
|
254
|
+
const environment = { ...process.env };
|
|
255
|
+
for (const name of Object.keys(environment)) {
|
|
256
|
+
if (name.toUpperCase().startsWith("GIT_")) {
|
|
257
|
+
delete environment[name];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return environment;
|
|
261
|
+
}
|
|
262
|
+
async function abortable(operation, signal) {
|
|
263
|
+
if (signal === undefined)
|
|
264
|
+
return await operation();
|
|
265
|
+
throwIfAborted(signal);
|
|
266
|
+
return await new Promise((resolvePromise, reject) => {
|
|
267
|
+
const onAbort = () => reject(abortReason(signal));
|
|
268
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
269
|
+
void operation().then((value) => {
|
|
270
|
+
signal.removeEventListener("abort", onAbort);
|
|
271
|
+
resolvePromise(value);
|
|
272
|
+
}, (error) => {
|
|
273
|
+
signal.removeEventListener("abort", onAbort);
|
|
274
|
+
reject(error);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function throwIfAborted(signal) {
|
|
279
|
+
if (signal?.aborted === true)
|
|
280
|
+
throw abortReason(signal);
|
|
281
|
+
}
|
|
282
|
+
function abortReason(signal) {
|
|
283
|
+
return (signal.reason ??
|
|
284
|
+
new DOMException("The operation was aborted.", "AbortError"));
|
|
285
|
+
}
|
|
286
|
+
function expandHome(value) {
|
|
287
|
+
if (value === "~") {
|
|
288
|
+
return homedir();
|
|
289
|
+
}
|
|
290
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
291
|
+
return resolve(homedir(), value.slice(2).replace(/^[/\\]+/, ""));
|
|
292
|
+
}
|
|
293
|
+
return value;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAC7C,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC;IAC1C,SAAS;IACT,eAAe;IACf,gBAAgB;IAChB,sBAAsB;IACtB,kCAAkC;IAClC,gBAAgB;IAChB,sBAAsB;CACvB,CAAC,CAAC;AAWH,MAAM,OAAO,UAAU;IACZ,MAAM,GAAG,YAAY,CAA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,MAAM,EAAE,OAAO,KAAK,IAAI;QAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,CACL,MAAM,CAAC,MAAM;QACb,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;QAClB,OAAO,OAAO,EAAE,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { lstat, realpath, stat } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { InvalidTargetError } from \"./errors.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\n\nconst execFile = promisify(execFileCallback);\nconst UNSUPPORTED_GIT_ENVIRONMENT = new Set([\n \"GIT_DIR\",\n \"GIT_WORK_TREE\",\n \"GIT_INDEX_FILE\",\n \"GIT_OBJECT_DIRECTORY\",\n \"GIT_ALTERNATE_OBJECT_DIRECTORIES\",\n \"GIT_COMMON_DIR\",\n \"GIT_REPLACE_REF_BASE\",\n]);\n\nexport type ScanMode = \"standard\" | \"deep\";\nexport type DiffTargetKind = \"refs\" | \"working_tree\";\n\nexport interface DiffTargetOptions {\n kind: DiffTargetKind;\n base: string;\n head?: string;\n}\n\nexport class DiffTarget {\n readonly #brand = \"DiffTarget\";\n public readonly kind: DiffTargetKind;\n public readonly base: string;\n public readonly head?: string;\n\n public constructor(options: DiffTargetOptions) {\n void this.#brand;\n this.kind = options.kind;\n this.base = options.base;\n this.head = options.head;\n if (this.kind !== \"refs\" && this.kind !== \"working_tree\") {\n throw new InvalidTargetError(\n `Unsupported diff target kind: ${String(this.kind)}`,\n );\n }\n if (typeof this.base !== \"string\" || this.base.length === 0) {\n throw new InvalidTargetError(\"The diff base ref must be non-empty.\");\n }\n if (\n this.kind === \"refs\" &&\n (typeof this.head !== \"string\" || this.head.length === 0)\n ) {\n throw new InvalidTargetError(\n \"Git diff refs must include a non-empty head ref.\",\n );\n }\n if (this.kind === \"working_tree\" && this.head !== undefined) {\n throw new InvalidTargetError(\n \"Working-tree targets cannot specify a head ref.\",\n );\n }\n Object.freeze(this);\n }\n\n public static refs({\n base,\n head = \"HEAD\",\n }: {\n base: string;\n head?: string;\n }): DiffTarget {\n return new DiffTarget({ kind: \"refs\", base, head });\n }\n\n public static workingTree({\n base = \"HEAD\",\n }: { base?: string } = {}): DiffTarget {\n return new DiffTarget({ kind: \"working_tree\", base });\n }\n}\n\nexport type ScanTarget = \"repository\" | DiffTarget | readonly string[];\nexport type NormalizedTargetKind =\n | \"repository\"\n | \"paths\"\n | \"refs\"\n | \"working_tree\";\n\nexport interface NormalizedTarget {\n kind: NormalizedTargetKind;\n paths: readonly string[];\n base?: string;\n head?: string;\n baseRef?: string;\n headRef?: string;\n}\n\nexport async function normalizeRepository(\n repository: string,\n signal?: AbortSignal,\n): Promise<string> {\n const candidate = resolveRepositoryPath(repository);\n let canonical: string;\n try {\n canonical = await abortable(() => realpath(candidate), signal);\n if (!(await abortable(() => stat(canonical), signal)).isDirectory()) {\n throw new Error(\"not a directory\");\n }\n } catch (error) {\n throwIfAborted(signal);\n throw new InvalidTargetError(\n `Repository is not a directory: ${candidate}`,\n {\n cause: error,\n },\n );\n }\n return canonical;\n}\n\nexport function resolveRepositoryPath(repository: string): string {\n return resolve(expandHome(repository));\n}\n\nexport async function enclosingGitWorktreeRoot(\n repository: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n const root = await gitOutput(\n repository,\n [\"rev-parse\", \"--show-toplevel\"],\n signal,\n );\n return await abortable(() => realpath(root), signal);\n } catch {\n throwIfAborted(signal);\n return null;\n }\n}\n\nexport function validatedGitEnvironment(\n environment: Readonly<Record<string, string | undefined>> = process.env,\n): void {\n const unsupported = Object.entries(environment).find(\n ([name, value]) =>\n UNSUPPORTED_GIT_ENVIRONMENT.has(name.toUpperCase()) &&\n value !== undefined &&\n value.trim() !== \"\",\n );\n if (unsupported !== undefined) {\n throw new InvalidTargetError(\n `${unsupported[0]} is not supported for Codex Security scans.`,\n );\n }\n}\n\nexport async function normalizeTarget(\n repository: string,\n target: ScanTarget,\n signal?: AbortSignal,\n): Promise<NormalizedTarget> {\n const root = await normalizeRepository(repository, signal);\n throwIfAborted(signal);\n if (target === \"repository\") {\n return { kind: \"repository\", paths: [] };\n }\n\n if (target instanceof DiffTarget) {\n if (target.kind !== \"refs\" && target.kind !== \"working_tree\") {\n throw new InvalidTargetError(\n `Unsupported diff target kind: ${String(target.kind)}`,\n );\n }\n if (typeof target.base !== \"string\" || target.base.length === 0) {\n throw new InvalidTargetError(\"The diff base ref must be non-empty.\");\n }\n if (\n target.kind === \"refs\" &&\n (typeof target.head !== \"string\" || target.head.length === 0)\n ) {\n throw new InvalidTargetError(\n \"Git diff refs must include a non-empty head ref.\",\n );\n }\n if (target.kind === \"working_tree\" && target.head !== undefined) {\n throw new InvalidTargetError(\n \"Working-tree targets cannot specify a head ref.\",\n );\n }\n await requireGitRepository(root, signal);\n const base = await resolveGitRef(root, target.base, signal);\n if (target.kind === \"refs\") {\n const head = target.head;\n if (typeof head !== \"string\" || head.length === 0) {\n throw new InvalidTargetError(\n \"Git diff refs must include a non-empty head ref.\",\n );\n }\n return {\n kind: \"refs\",\n paths: [],\n base,\n head: await resolveGitRef(root, head, signal),\n baseRef: target.base,\n headRef: head,\n };\n }\n return {\n kind: \"working_tree\",\n paths: [],\n base,\n head: await resolveGitRef(root, \"HEAD\", signal),\n baseRef: target.base,\n headRef: \"HEAD\",\n };\n }\n\n if (!Array.isArray(target)) {\n throw new InvalidTargetError(\n \"Scan target must be 'repository', a DiffTarget, or an array of paths.\",\n );\n }\n if (target.length === 0) {\n throw new InvalidTargetError(\n \"A path scan target must contain at least one path.\",\n );\n }\n\n const paths: string[] = [];\n for (const value of target) {\n throwIfAborted(signal);\n if (typeof value !== \"string\") {\n throw new InvalidTargetError(\n \"Path scan targets must contain only strings.\",\n );\n }\n if (value.length === 0) {\n throw new InvalidTargetError(\n \"Path scan targets must not contain an empty path.\",\n );\n }\n const candidate = isAbsolute(expandHome(value))\n ? resolve(expandHome(value))\n : resolve(root, expandHome(value));\n if (!existsSync(candidate)) {\n throw new InvalidTargetError(`Path target does not exist: ${value}`);\n }\n let canonical: string;\n try {\n canonical = await abortable(() => realpath(candidate), signal);\n } catch (error) {\n throwIfAborted(signal);\n throw new InvalidTargetError(`Path target does not exist: ${value}`, {\n cause: error,\n });\n }\n const relativePath = relative(root, canonical);\n if (\n relativePath === \"..\" ||\n relativePath.startsWith(`..${sep}`) ||\n isAbsolute(relativePath)\n ) {\n throw new InvalidTargetError(\n `Path target is outside the repository: ${value}`,\n );\n }\n const normalized = relativePath.split(sep).join(\"/\") || \".\";\n if (!paths.includes(normalized)) {\n paths.push(normalized);\n }\n }\n return { kind: \"paths\", paths };\n}\n\nexport function validateMode(target: NormalizedTarget, mode: ScanMode): void {\n if (mode !== \"standard\" && mode !== \"deep\") {\n throw new InvalidTargetError(`Unsupported scan mode: ${String(mode)}`);\n }\n if (\n mode === \"deep\" &&\n (target.kind === \"refs\" || target.kind === \"working_tree\")\n ) {\n throw new InvalidTargetError(\n \"Deep mode supports repository and path targets only.\",\n );\n }\n}\n\nexport async function repositoryRevision(\n repository: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n return await gitOutput(\n repository,\n [\"rev-parse\", \"--verify\", \"HEAD^{commit}\"],\n signal,\n );\n } catch {\n throwIfAborted(signal);\n return null;\n }\n}\n\nasync function requireGitRepository(\n repository: string,\n signal?: AbortSignal,\n): Promise<void> {\n let root: string;\n try {\n root = await gitOutput(\n repository,\n [\"rev-parse\", \"--show-toplevel\"],\n signal,\n );\n } catch (error) {\n throwIfAborted(signal);\n throw new InvalidTargetError(\n `Diff targets require a Git repository: ${repository}`,\n {\n cause: error,\n },\n );\n }\n const canonicalRoot = await abortable(() => realpath(root), signal);\n if (canonicalRoot !== repository) {\n throw new InvalidTargetError(\n `Diff target repository must be the Git worktree root: ${canonicalRoot}`,\n );\n }\n}\n\nasync function resolveGitRef(\n repository: string,\n ref: string,\n signal?: AbortSignal,\n): Promise<string> {\n try {\n return await gitOutput(\n repository,\n [\"rev-parse\", \"--verify\", \"--end-of-options\", `${ref}^{commit}`],\n signal,\n );\n } catch (error) {\n throwIfAborted(signal);\n throw new InvalidTargetError(`unknown Git ref: ${ref}`, { cause: error });\n }\n}\n\nasync function gitOutput(\n repository: string,\n args: readonly string[],\n signal?: AbortSignal,\n): Promise<string> {\n throwIfAborted(signal);\n const command = await resolveTrustedExecutable(\n \"git\",\n isolatedGitEnvironment(),\n await outermostGitMarkerRoot(repository, signal),\n );\n if (command === null)\n throw new Error(\"Git is not available on a trusted PATH.\");\n throwIfAborted(signal);\n const { stdout } = await execFile(\n command.executable,\n [\"-C\", repository, ...args],\n {\n encoding: \"utf8\",\n signal,\n env: command.environment,\n },\n );\n return stdout.trim();\n}\n\nasync function outermostGitMarkerRoot(\n repository: string,\n signal?: AbortSignal,\n): Promise<string> {\n let current = repository;\n let root = repository;\n while (true) {\n throwIfAborted(signal);\n try {\n await lstat(join(current, \".git\"));\n root = current;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n const parent = dirname(current);\n if (parent === current) return root;\n current = parent;\n }\n}\n\nfunction isolatedGitEnvironment(): NodeJS.ProcessEnv {\n const environment = { ...process.env };\n for (const name of Object.keys(environment)) {\n if (name.toUpperCase().startsWith(\"GIT_\")) {\n delete environment[name];\n }\n }\n return environment;\n}\n\nasync function abortable<T>(\n operation: () => Promise<T>,\n signal?: AbortSignal,\n): Promise<T> {\n if (signal === undefined) return await operation();\n throwIfAborted(signal);\n return await new Promise<T>((resolvePromise, reject) => {\n const onAbort = (): void => reject(abortReason(signal));\n signal.addEventListener(\"abort\", onAbort, { once: true });\n void operation().then(\n (value) => {\n signal.removeEventListener(\"abort\", onAbort);\n resolvePromise(value);\n },\n (error: unknown) => {\n signal.removeEventListener(\"abort\", onAbort);\n reject(error);\n },\n );\n });\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted === true) throw abortReason(signal);\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n return (\n signal.reason ??\n new DOMException(\"The operation was aborted.\", \"AbortError\")\n );\n}\n\nfunction expandHome(value: string): string {\n if (value === \"~\") {\n return homedir();\n }\n if (value.startsWith(\"~/\") || value.startsWith(\"~\\\\\")) {\n return resolve(homedir(), value.slice(2).replace(/^[/\\\\]+/, \"\"));\n }\n return value;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface TrustedExecutable {
|
|
2
|
+
executable: string;
|
|
3
|
+
environment: Record<string, string | undefined>;
|
|
4
|
+
}
|
|
5
|
+
export declare function resolveTrustedExecutable(candidate: string, environment: Readonly<Record<string, string | undefined>>, protectedRoot: string): Promise<TrustedExecutable | null>;
|
|
6
|
+
//# sourceMappingURL=trusted-executable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-executable.d.ts","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACjD;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACzD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAqEnC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { delimiter, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
export async function resolveTrustedExecutable(candidate, environment, protectedRoot) {
|
|
5
|
+
const root = await realpath(protectedRoot).catch(() => resolve(protectedRoot));
|
|
6
|
+
const path = Object.entries(environment).find(([name]) => name.toUpperCase() === "PATH")?.[1];
|
|
7
|
+
const entries = [];
|
|
8
|
+
for (const entry of path?.split(delimiter) ?? []) {
|
|
9
|
+
if (entry.length === 0 || !isAbsolute(entry))
|
|
10
|
+
continue;
|
|
11
|
+
const canonical = await realpath(entry).catch(() => null);
|
|
12
|
+
if (canonical === null || isWithin(root, canonical))
|
|
13
|
+
continue;
|
|
14
|
+
if (!entries.includes(canonical))
|
|
15
|
+
entries.push(canonical);
|
|
16
|
+
}
|
|
17
|
+
// execFile cannot launch batch files, but their symlink targets still affect PATH trust.
|
|
18
|
+
const extensions = process.platform === "win32"
|
|
19
|
+
? /\.(?:exe|com)$/iu.test(candidate)
|
|
20
|
+
? [{ suffix: "", runnable: true }]
|
|
21
|
+
: [
|
|
22
|
+
{ suffix: ".exe", runnable: true },
|
|
23
|
+
{ suffix: ".com", runnable: true },
|
|
24
|
+
{ suffix: ".bat", runnable: false },
|
|
25
|
+
{ suffix: ".cmd", runnable: false },
|
|
26
|
+
{ suffix: "", runnable: false },
|
|
27
|
+
]
|
|
28
|
+
: [{ suffix: "", runnable: true }];
|
|
29
|
+
const pathLike = candidate.includes("/") || candidate.includes("\\");
|
|
30
|
+
const candidates = pathLike
|
|
31
|
+
? [{ entry: null, path: resolve(candidate), runnable: true }]
|
|
32
|
+
: entries.flatMap((entry) => extensions.map((extension) => ({
|
|
33
|
+
entry,
|
|
34
|
+
path: join(entry, `${candidate}${extension.suffix}`),
|
|
35
|
+
runnable: extension.runnable,
|
|
36
|
+
})));
|
|
37
|
+
const unsafeEntries = new Set();
|
|
38
|
+
let executable = null;
|
|
39
|
+
for (const current of candidates) {
|
|
40
|
+
const canonical = await realpath(current.path).catch(() => null);
|
|
41
|
+
if (canonical === null)
|
|
42
|
+
continue;
|
|
43
|
+
if (isWithin(root, canonical)) {
|
|
44
|
+
if (current.entry !== null)
|
|
45
|
+
unsafeEntries.add(current.entry);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (!current.runnable)
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
await access(canonical, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
52
|
+
if (!(await stat(canonical)).isFile())
|
|
53
|
+
continue;
|
|
54
|
+
executable ??= canonical;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (executable === null)
|
|
61
|
+
return null;
|
|
62
|
+
const sanitizedEnvironment = { ...environment };
|
|
63
|
+
for (const name of Object.keys(sanitizedEnvironment)) {
|
|
64
|
+
if (name.toUpperCase() === "PATH")
|
|
65
|
+
delete sanitizedEnvironment[name];
|
|
66
|
+
}
|
|
67
|
+
sanitizedEnvironment["PATH"] = entries
|
|
68
|
+
.filter((entry) => !unsafeEntries.has(entry))
|
|
69
|
+
.join(delimiter);
|
|
70
|
+
return { executable, environment: sanitizedEnvironment };
|
|
71
|
+
}
|
|
72
|
+
function isWithin(root, candidate) {
|
|
73
|
+
const path = relative(root, candidate);
|
|
74
|
+
return (path === "" ||
|
|
75
|
+
(path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path)));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AAC,CAAC;IACvE,CAAC;IACD,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO;SACnC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,IAAI,CAAC,SAAS,CAAC,CAAC;IACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CACL,IAAI,KAAK,EAAE;QACX,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access, realpath, stat } from \"node:fs/promises\";\nimport { delimiter, isAbsolute, join, relative, resolve, sep } from \"node:path\";\n\nexport interface TrustedExecutable {\n executable: string;\n environment: Record<string, string | undefined>;\n}\n\nexport async function resolveTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string,\n): Promise<TrustedExecutable | null> {\n const root = await realpath(protectedRoot).catch(() =>\n resolve(protectedRoot),\n );\n const path = Object.entries(environment).find(\n ([name]) => name.toUpperCase() === \"PATH\",\n )?.[1];\n const entries: string[] = [];\n for (const entry of path?.split(delimiter) ?? []) {\n if (entry.length === 0 || !isAbsolute(entry)) continue;\n const canonical = await realpath(entry).catch(() => null);\n if (canonical === null || isWithin(root, canonical)) continue;\n if (!entries.includes(canonical)) entries.push(canonical);\n }\n\n // execFile cannot launch batch files, but their symlink targets still affect PATH trust.\n const extensions =\n process.platform === \"win32\"\n ? /\\.(?:exe|com)$/iu.test(candidate)\n ? [{ suffix: \"\", runnable: true }]\n : [\n { suffix: \".exe\", runnable: true },\n { suffix: \".com\", runnable: true },\n { suffix: \".bat\", runnable: false },\n { suffix: \".cmd\", runnable: false },\n { suffix: \"\", runnable: false },\n ]\n : [{ suffix: \"\", runnable: true }];\n const pathLike = candidate.includes(\"/\") || candidate.includes(\"\\\\\");\n const candidates = pathLike\n ? [{ entry: null, path: resolve(candidate), runnable: true }]\n : entries.flatMap((entry) =>\n extensions.map((extension) => ({\n entry,\n path: join(entry, `${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n })),\n );\n const unsafeEntries = new Set<string>();\n let executable: string | null = null;\n for (const current of candidates) {\n const canonical = await realpath(current.path).catch(() => null);\n if (canonical === null) continue;\n if (isWithin(root, canonical)) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n if (!current.runnable) continue;\n try {\n await access(\n canonical,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n if (!(await stat(canonical)).isFile()) continue;\n executable ??= canonical;\n } catch {\n continue;\n }\n }\n if (executable === null) return null;\n\n const sanitizedEnvironment = { ...environment };\n for (const name of Object.keys(sanitizedEnvironment)) {\n if (name.toUpperCase() === \"PATH\") delete sanitizedEnvironment[name];\n }\n sanitizedEnvironment[\"PATH\"] = entries\n .filter((entry) => !unsafeEntries.has(entry))\n .join(delimiter);\n return { executable, environment: sanitizedEnvironment };\n}\n\nfunction isWithin(root: string, candidate: string): boolean {\n const path = relative(root, candidate);\n return (\n path === \"\" ||\n (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n );\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** npm-compatible successor to the Python package version 0.1.0b3. */
|
|
2
|
+
export declare const VERSION: string;
|
|
3
|
+
export declare const CODEX_SDK_VERSION: string;
|
|
4
|
+
export declare const CODEX_EXECUTABLE_VERSION: string;
|
|
5
|
+
export declare const BUNDLED_PLUGIN_VERSION: "0.1.14";
|
|
6
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,sEAAsE;AACtE,eAAO,MAAM,OAAO,QAA2B,CAAC;AAChD,eAAO,MAAM,iBAAiB,QAAuB,CAAC;AACtD,eAAO,MAAM,wBAAwB,QAA8B,CAAC;AACpE,eAAO,MAAM,sBAAsB,EAAG,QAAiB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const PACKAGE_VERSIONS = packageVersions(new URL("../package.json", import.meta.url));
|
|
3
|
+
/** npm-compatible successor to the Python package version 0.1.0b3. */
|
|
4
|
+
export const VERSION = PACKAGE_VERSIONS.package;
|
|
5
|
+
export const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;
|
|
6
|
+
export const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;
|
|
7
|
+
export const BUNDLED_PLUGIN_VERSION = "0.1.14";
|
|
8
|
+
function packageVersions(url) {
|
|
9
|
+
try {
|
|
10
|
+
const manifest = JSON.parse(readFileSync(url, "utf8"));
|
|
11
|
+
if (typeof manifest !== "object" ||
|
|
12
|
+
manifest === null ||
|
|
13
|
+
!("version" in manifest) ||
|
|
14
|
+
typeof manifest.version !== "string" ||
|
|
15
|
+
manifest.version.length === 0) {
|
|
16
|
+
throw new Error("version must be a non-empty string");
|
|
17
|
+
}
|
|
18
|
+
const dependencies = "dependencies" in manifest ? manifest.dependencies : undefined;
|
|
19
|
+
if (typeof dependencies !== "object" || dependencies === null) {
|
|
20
|
+
throw new Error("dependencies must be an object");
|
|
21
|
+
}
|
|
22
|
+
const sdk = "@openai/codex-sdk" in dependencies
|
|
23
|
+
? dependencies["@openai/codex-sdk"]
|
|
24
|
+
: undefined;
|
|
25
|
+
const executable = "@openai/codex" in dependencies
|
|
26
|
+
? dependencies["@openai/codex"]
|
|
27
|
+
: undefined;
|
|
28
|
+
if (typeof sdk !== "string" ||
|
|
29
|
+
sdk.length === 0 ||
|
|
30
|
+
typeof executable !== "string" ||
|
|
31
|
+
executable.length === 0) {
|
|
32
|
+
throw new Error("Codex dependencies must have non-empty versions");
|
|
33
|
+
}
|
|
34
|
+
return { package: manifest.version, sdk, executable };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error("Unable to read Codex Security package versions.", {
|
|
38
|
+
cause: error,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,gBAAgB,GAAG,eAAe,CACtC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC5C,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC;AACtD,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,UAAU,CAAC;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,QAAiB,CAAC;AAExD,SAAS,eAAe,CAAC,GAAQ;IAK/B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;QAChE,IACE,OAAO,QAAQ,KAAK,QAAQ;YAC5B,QAAQ,KAAK,IAAI;YACjB,CAAC,CAAC,SAAS,IAAI,QAAQ,CAAC;YACxB,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ;YACpC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAC7B,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,YAAY,GAChB,cAAc,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;QACjE,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,GAAG,GACP,mBAAmB,IAAI,YAAY;YACjC,CAAC,CAAC,YAAY,CAAC,mBAAmB,CAAC;YACnC,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,UAAU,GACd,eAAe,IAAI,YAAY;YAC7B,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC;YAC/B,CAAC,CAAC,SAAS,CAAC;QAChB,IACE,OAAO,GAAG,KAAK,QAAQ;YACvB,GAAG,CAAC,MAAM,KAAK,CAAC;YAChB,OAAO,UAAU,KAAK,QAAQ;YAC9B,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iDAAiD,EAAE;YACjE,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\n\nconst PACKAGE_VERSIONS = packageVersions(\n new URL(\"../package.json\", import.meta.url),\n);\n\n/** npm-compatible successor to the Python package version 0.1.0b3. */\nexport const VERSION = PACKAGE_VERSIONS.package;\nexport const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;\nexport const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;\nexport const BUNDLED_PLUGIN_VERSION = \"0.1.14\" as const;\n\nfunction packageVersions(url: URL): {\n package: string;\n sdk: string;\n executable: string;\n} {\n try {\n const manifest: unknown = JSON.parse(readFileSync(url, \"utf8\"));\n if (\n typeof manifest !== \"object\" ||\n manifest === null ||\n !(\"version\" in manifest) ||\n typeof manifest.version !== \"string\" ||\n manifest.version.length === 0\n ) {\n throw new Error(\"version must be a non-empty string\");\n }\n const dependencies =\n \"dependencies\" in manifest ? manifest.dependencies : undefined;\n if (typeof dependencies !== \"object\" || dependencies === null) {\n throw new Error(\"dependencies must be an object\");\n }\n const sdk =\n \"@openai/codex-sdk\" in dependencies\n ? dependencies[\"@openai/codex-sdk\"]\n : undefined;\n const executable =\n \"@openai/codex\" in dependencies\n ? dependencies[\"@openai/codex\"]\n : undefined;\n if (\n typeof sdk !== \"string\" ||\n sdk.length === 0 ||\n typeof executable !== \"string\" ||\n executable.length === 0\n ) {\n throw new Error(\"Codex dependencies must have non-empty versions\");\n }\n return { package: manifest.version, sdk, executable };\n } catch (error) {\n throw new Error(\"Unable to read Codex Security package versions.\", {\n cause: error,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ScanWorkerPhase = "ranking" | "file_review" | "validation" | "attack_path";
|
|
2
|
+
export type ScanWorkerStatus = {
|
|
3
|
+
kind: "preflight";
|
|
4
|
+
delegation: "available" | "unavailable" | "unknown";
|
|
5
|
+
configuredSlots: number | null;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "dispatch";
|
|
8
|
+
phase: ScanWorkerPhase;
|
|
9
|
+
planned: number;
|
|
10
|
+
started: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function workerStatusFromEvent(event: Readonly<Record<string, unknown>>): ScanWorkerStatus | null;
|
|
13
|
+
//# sourceMappingURL=worker-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-progress.d.ts","sourceRoot":"","sources":["../src/worker-progress.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,aAAa,GACb,YAAY,GACZ,aAAa,CAAC;AAElB,MAAM,MAAM,gBAAgB,GACxB;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAAC;IACpD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACvC,gBAAgB,GAAG,IAAI,CAQzB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const MAX_WORKER_STATUS_BYTES = 64 * 1024;
|
|
2
|
+
const MAX_WORKER_COUNT = 1024;
|
|
3
|
+
const WORKER_STATUS_PREFIX = "CODEX_SECURITY_WORKER_STATUS ";
|
|
4
|
+
const PREFLIGHT_COMMAND = /(?:^|[\\/])config_preflight\.py(?=$|["'\s])/u;
|
|
5
|
+
const WORKER_PHASES = new Set([
|
|
6
|
+
"ranking",
|
|
7
|
+
"file_review",
|
|
8
|
+
"validation",
|
|
9
|
+
"attack_path",
|
|
10
|
+
]);
|
|
11
|
+
export function workerStatusFromEvent(event) {
|
|
12
|
+
if (event["type"] !== "item.completed" || !isRecord(event["item"])) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const item = event["item"];
|
|
16
|
+
if (item["type"] === "command_execution")
|
|
17
|
+
return preflightStatus(item);
|
|
18
|
+
if (item["type"] === "agent_message")
|
|
19
|
+
return dispatchStatus(item);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function preflightStatus(item) {
|
|
23
|
+
if (typeof item["command"] !== "string" ||
|
|
24
|
+
!PREFLIGHT_COMMAND.test(item["command"]) ||
|
|
25
|
+
typeof item["aggregated_output"] !== "string" ||
|
|
26
|
+
Buffer.byteLength(item["aggregated_output"], "utf8") >
|
|
27
|
+
MAX_WORKER_STATUS_BYTES) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
let payload;
|
|
31
|
+
try {
|
|
32
|
+
payload = JSON.parse(item["aggregated_output"]);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (!isRecord(payload) ||
|
|
38
|
+
(payload["profile"] !== "security_scan" &&
|
|
39
|
+
payload["profile"] !== "security_diff_scan") ||
|
|
40
|
+
!Array.isArray(payload["results"])) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const results = payload["results"];
|
|
44
|
+
const delegated = results.filter((result) => isRecord(result) && result["capability"] === "delegated_workers");
|
|
45
|
+
const delegatedResult = delegated[0];
|
|
46
|
+
if (delegated.length !== 1 || delegatedResult === undefined)
|
|
47
|
+
return null;
|
|
48
|
+
const delegation = delegatedResult["status"] === "pass"
|
|
49
|
+
? "available"
|
|
50
|
+
: delegatedResult["status"] === "fail"
|
|
51
|
+
? "unavailable"
|
|
52
|
+
: delegatedResult["status"] === "unknown"
|
|
53
|
+
? "unknown"
|
|
54
|
+
: null;
|
|
55
|
+
if (delegation === null)
|
|
56
|
+
return null;
|
|
57
|
+
const capacity = results.filter((result) => isRecord(result) &&
|
|
58
|
+
typeof result["capability"] === "string" &&
|
|
59
|
+
result["capability"].startsWith("usable_worker_slots_"));
|
|
60
|
+
if (capacity.length > 1)
|
|
61
|
+
return null;
|
|
62
|
+
const capacityResult = capacity[0];
|
|
63
|
+
const configuredSlots = capacity.length === 1 &&
|
|
64
|
+
capacityResult !== undefined &&
|
|
65
|
+
isWorkerCount(capacityResult["actual"])
|
|
66
|
+
? capacityResult["actual"]
|
|
67
|
+
: null;
|
|
68
|
+
return { kind: "preflight", delegation, configuredSlots };
|
|
69
|
+
}
|
|
70
|
+
function dispatchStatus(item) {
|
|
71
|
+
if (typeof item["text"] !== "string" ||
|
|
72
|
+
Buffer.byteLength(item["text"], "utf8") > MAX_WORKER_STATUS_BYTES) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const markers = item["text"]
|
|
76
|
+
.split(/\r?\n/u)
|
|
77
|
+
.filter((line) => line.startsWith(WORKER_STATUS_PREFIX));
|
|
78
|
+
const marker = markers[0];
|
|
79
|
+
if (markers.length !== 1 || marker === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
let payload;
|
|
82
|
+
try {
|
|
83
|
+
payload = JSON.parse(marker.slice(WORKER_STATUS_PREFIX.length));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (!isRecord(payload) ||
|
|
89
|
+
Object.keys(payload).length !== 3 ||
|
|
90
|
+
typeof payload["phase"] !== "string" ||
|
|
91
|
+
!WORKER_PHASES.has(payload["phase"]) ||
|
|
92
|
+
!isWorkerCount(payload["planned"]) ||
|
|
93
|
+
!isWorkerCount(payload["started"]) ||
|
|
94
|
+
payload["started"] > payload["planned"]) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
kind: "dispatch",
|
|
99
|
+
phase: payload["phase"],
|
|
100
|
+
planned: payload["planned"],
|
|
101
|
+
started: payload["started"],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function isWorkerCount(value) {
|
|
105
|
+
return (typeof value === "number" &&
|
|
106
|
+
Number.isSafeInteger(value) &&
|
|
107
|
+
value >= 0 &&
|
|
108
|
+
value <= MAX_WORKER_COUNT);
|
|
109
|
+
}
|
|
110
|
+
function isRecord(value) {
|
|
111
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=worker-progress.js.map
|