@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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { lstat, mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { stdin } from "node:process";
|
|
6
|
+
import { Writable } from "node:stream";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import { confirm, input, search } from "@inquirer/prompts";
|
|
9
|
+
import { Octokit } from "@octokit/core";
|
|
10
|
+
import Papa from "papaparse";
|
|
11
|
+
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
12
|
+
const execFile = promisify(execFileCallback);
|
|
13
|
+
const GITHUB_REPOSITORIES_QUERY = `
|
|
14
|
+
query($owner: String!, $cursor: String) {
|
|
15
|
+
repositoryOwner(login: $owner) {
|
|
16
|
+
repositories(
|
|
17
|
+
first: 100
|
|
18
|
+
after: $cursor
|
|
19
|
+
isArchived: false
|
|
20
|
+
isFork: false
|
|
21
|
+
orderBy: { field: PUSHED_AT, direction: DESC }
|
|
22
|
+
) {
|
|
23
|
+
nodes {
|
|
24
|
+
nameWithOwner
|
|
25
|
+
pushedAt
|
|
26
|
+
defaultBranchRef { target { oid } }
|
|
27
|
+
}
|
|
28
|
+
pageInfo { hasNextPage endCursor }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
export function createBulkScanDiscoveryDependencies(options) {
|
|
34
|
+
return {
|
|
35
|
+
prompt: createTerminalPrompt(options.output),
|
|
36
|
+
now: options.now,
|
|
37
|
+
currentDirectory: options.currentDirectory,
|
|
38
|
+
...(process.env["GH_HOST"]?.trim()
|
|
39
|
+
? { githubHost: process.env["GH_HOST"].trim() }
|
|
40
|
+
: {}),
|
|
41
|
+
createGitHub: async (host, signal) => {
|
|
42
|
+
const trusted = await resolveTrustedExecutable("gh", process.env, options.currentDirectory());
|
|
43
|
+
if (trusted === null) {
|
|
44
|
+
throw new Error("GitHub CLI is required. Install gh and sign in first.");
|
|
45
|
+
}
|
|
46
|
+
let token;
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await execFile(trusted.executable, ["auth", "token", "--hostname", host], { env: trusted.environment, signal });
|
|
49
|
+
token = stdout.trim();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
signal?.throwIfAborted();
|
|
53
|
+
throw new Error("GitHub sign-in is required. Run 'gh auth login' first.");
|
|
54
|
+
}
|
|
55
|
+
return new Octokit({
|
|
56
|
+
auth: token,
|
|
57
|
+
...(host === "github.com" ? {} : { baseUrl: `https://${host}/api/v3` }),
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function runBulkScanWizard(dependencies, signal) {
|
|
63
|
+
const { prompt } = dependencies;
|
|
64
|
+
if (!prompt.isInteractive()) {
|
|
65
|
+
throw new Error("Interactive repository selection requires a terminal. Provide a CSV with 'codex-security bulk-scan repositories.csv --output-dir ./security-scans'.");
|
|
66
|
+
}
|
|
67
|
+
signal?.throwIfAborted();
|
|
68
|
+
const githubHost = dependencies.githubHost ?? "github.com";
|
|
69
|
+
const github = await dependencies.createGitHub(githubHost, signal);
|
|
70
|
+
const owner = await selectGitHubOwner(github, prompt, signal);
|
|
71
|
+
prompt.write("\nFinding active repositories...\n");
|
|
72
|
+
const discovered = await discoverGitHubRepositories(github, githubHost, owner, dependencies.now() - 90 * 86_400_000, signal);
|
|
73
|
+
if (discovered.length === 0) {
|
|
74
|
+
prompt.write("\nNo repositories matched your selection.\n");
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
prompt.write(`\nFound ${discovered.length} repositories.\n`);
|
|
78
|
+
const repositories = await selectGitHubRepositories(discovered, prompt);
|
|
79
|
+
const outputDir = resolve(dependencies.currentDirectory(), await prompt.input("Where should scan results be saved?", "./security-scans"));
|
|
80
|
+
const inputPath = join(outputDir, "repositories.csv");
|
|
81
|
+
await validateWizardOutput(outputDir);
|
|
82
|
+
prompt.write(`\nReady to scan ${repositories.length} repositories?\n` +
|
|
83
|
+
`Results: ${outputDir}\nRepository list: ${inputPath}\n`);
|
|
84
|
+
if (!(await prompt.confirm("Start scanning?"))) {
|
|
85
|
+
prompt.write("\nScan canceled.\n");
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
signal?.throwIfAborted();
|
|
89
|
+
await mkdir(outputDir, { recursive: true, mode: 0o700 });
|
|
90
|
+
await writeFile(inputPath, `${Papa.unparse(repositories.map(({ fullName, url, revision }) => ({
|
|
91
|
+
id: repositoryId(fullName),
|
|
92
|
+
repository: url,
|
|
93
|
+
revision,
|
|
94
|
+
})))}\n`, { flag: "wx", mode: 0o600, ...(signal === undefined ? {} : { signal }) });
|
|
95
|
+
return { inputPath, outputDir, githubHost };
|
|
96
|
+
}
|
|
97
|
+
async function selectGitHubOwner(github, prompt, signal) {
|
|
98
|
+
const { data } = await github.request("GET /user/orgs", {
|
|
99
|
+
per_page: 100,
|
|
100
|
+
request: { signal },
|
|
101
|
+
});
|
|
102
|
+
const organizations = data.map(({ login }) => login).sort();
|
|
103
|
+
if (organizations.length > 1) {
|
|
104
|
+
return await prompt.select("Which account or organization should we scan?", organizations.map((owner) => ({ label: owner, value: owner })));
|
|
105
|
+
}
|
|
106
|
+
const owner = organizations[0] ??
|
|
107
|
+
(await github.request("GET /user", { request: { signal } })).data.login;
|
|
108
|
+
prompt.write(`\nFinding repositories in ${owner}.\n`);
|
|
109
|
+
return owner;
|
|
110
|
+
}
|
|
111
|
+
async function selectGitHubRepositories(repositories, prompt) {
|
|
112
|
+
const selected = new Set();
|
|
113
|
+
while (selected.size < repositories.length) {
|
|
114
|
+
const choice = await prompt.select("Select repositories to scan (type to filter)", [
|
|
115
|
+
{
|
|
116
|
+
label: selected.size
|
|
117
|
+
? `Done (${selected.size} selected)`
|
|
118
|
+
: `All ${repositories.length} repositories`,
|
|
119
|
+
value: "",
|
|
120
|
+
},
|
|
121
|
+
...repositories
|
|
122
|
+
.filter(({ fullName }) => !selected.has(fullName))
|
|
123
|
+
.map(({ fullName }) => ({ label: fullName, value: fullName })),
|
|
124
|
+
]);
|
|
125
|
+
if (!choice)
|
|
126
|
+
break;
|
|
127
|
+
selected.add(choice);
|
|
128
|
+
}
|
|
129
|
+
return selected.size
|
|
130
|
+
? repositories.filter(({ fullName }) => selected.has(fullName))
|
|
131
|
+
: repositories;
|
|
132
|
+
}
|
|
133
|
+
async function discoverGitHubRepositories(github, host, owner, cutoff, signal) {
|
|
134
|
+
const repositories = [];
|
|
135
|
+
let cursor = null;
|
|
136
|
+
do {
|
|
137
|
+
signal?.throwIfAborted();
|
|
138
|
+
const result = await github.graphql(GITHUB_REPOSITORIES_QUERY, { owner, cursor, request: { signal } });
|
|
139
|
+
const connection = result.repositoryOwner?.repositories;
|
|
140
|
+
if (connection === undefined) {
|
|
141
|
+
throw new Error("GitHub could not list repositories for this account.");
|
|
142
|
+
}
|
|
143
|
+
for (const repository of connection.nodes) {
|
|
144
|
+
if (Date.parse(repository.pushedAt) < cutoff)
|
|
145
|
+
return repositories;
|
|
146
|
+
if (repository.defaultBranchRef === null)
|
|
147
|
+
continue;
|
|
148
|
+
repositories.push({
|
|
149
|
+
fullName: repository.nameWithOwner,
|
|
150
|
+
url: `https://${host}/${repository.nameWithOwner}.git`,
|
|
151
|
+
revision: repository.defaultBranchRef.target.oid.toLowerCase(),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
cursor = connection.pageInfo.hasNextPage
|
|
155
|
+
? connection.pageInfo.endCursor
|
|
156
|
+
: null;
|
|
157
|
+
} while (cursor !== null);
|
|
158
|
+
return repositories;
|
|
159
|
+
}
|
|
160
|
+
function repositoryId(fullName) {
|
|
161
|
+
const id = fullName.replace("/", "--");
|
|
162
|
+
if (id.length <= 128)
|
|
163
|
+
return id;
|
|
164
|
+
const hash = createHash("sha256").update(fullName).digest("hex").slice(0, 16);
|
|
165
|
+
return `${id.slice(0, 111)}-${hash}`;
|
|
166
|
+
}
|
|
167
|
+
async function validateWizardOutput(outputDir) {
|
|
168
|
+
let metadata;
|
|
169
|
+
try {
|
|
170
|
+
metadata = await lstat(outputDir);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error.code === "ENOENT")
|
|
174
|
+
return;
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
if (!metadata.isDirectory()) {
|
|
178
|
+
throw new Error("The scan output must be a real directory.");
|
|
179
|
+
}
|
|
180
|
+
for (const name of ["repositories.csv", "manifest.json"]) {
|
|
181
|
+
try {
|
|
182
|
+
await lstat(join(outputDir, name));
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error.code === "ENOENT")
|
|
186
|
+
continue;
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
throw new Error("The selected output directory already contains a repository list or scan. Choose a new directory or resume the existing scan.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function createTerminalPrompt(output) {
|
|
193
|
+
const context = () => ({
|
|
194
|
+
input: stdin,
|
|
195
|
+
output: new Writable({
|
|
196
|
+
write(chunk, _encoding, callback) {
|
|
197
|
+
output.write(chunk.toString("utf8"));
|
|
198
|
+
callback();
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
isInteractive: () => stdin.isTTY === true && output.isTTY === true,
|
|
204
|
+
write: (value) => {
|
|
205
|
+
output.write(value);
|
|
206
|
+
},
|
|
207
|
+
confirm: (message, defaultValue = false) => confirm({ message, default: defaultValue }, context()),
|
|
208
|
+
input: (message, defaultValue) => input({ message, default: defaultValue }, context()),
|
|
209
|
+
select: (message, options) => search({
|
|
210
|
+
message,
|
|
211
|
+
source: (term) => options
|
|
212
|
+
.filter(({ label }) => label.toLowerCase().includes(term?.toLowerCase() ?? ""))
|
|
213
|
+
.map(({ label, value }) => ({ name: label, value })),
|
|
214
|
+
}, context()),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=bulk-scan-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-scan-discovery.js","sourceRoot":"","sources":["../src/bulk-scan-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;A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EAAE,CAAC;YACb,CAAC;SACF,CAAC;KACH,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI;QAClE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,EAAE,EAAE,CACzC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC;QACxD,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,CAC/B,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC;QACtD,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3B,MAAM,CACJ;YACE,OAAO;YACP,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACf,OAAO;iBACJ,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACpB,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CACxD;iBACA,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;SACzD,EACD,OAAO,EAAE,CACV;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { lstat, mkdir, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { stdin } from \"node:process\";\nimport { Writable } from \"node:stream\";\nimport { promisify } from \"node:util\";\nimport { confirm, input, search } from \"@inquirer/prompts\";\nimport { Octokit } from \"@octokit/core\";\nimport Papa from \"papaparse\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\n\nconst execFile = promisify(execFileCallback);\nconst GITHUB_REPOSITORIES_QUERY = `\n query($owner: String!, $cursor: String) {\n repositoryOwner(login: $owner) {\n repositories(\n first: 100\n after: $cursor\n isArchived: false\n isFork: false\n orderBy: { field: PUSHED_AT, direction: DESC }\n ) {\n nodes {\n nameWithOwner\n pushedAt\n defaultBranchRef { target { oid } }\n }\n pageInfo { hasNextPage endCursor }\n }\n }\n }\n`;\n\ninterface GitHubRepository {\n fullName: string;\n url: string;\n revision: string;\n}\n\ninterface GitHubRepositoriesResponse {\n repositoryOwner: {\n repositories: {\n nodes: Array<{\n nameWithOwner: string;\n pushedAt: string;\n defaultBranchRef: { target: { oid: string } } | null;\n }>;\n pageInfo: { hasNextPage: boolean; endCursor: string | null };\n };\n } | null;\n}\n\nexport interface BulkScanPrompt {\n isInteractive(): boolean;\n write(value: string): void;\n confirm(question: string, defaultValue?: boolean): Promise<boolean>;\n input(question: string, defaultValue?: string): Promise<string>;\n select<Value extends string>(\n question: string,\n options: readonly { label: string; value: Value }[],\n ): Promise<Value>;\n}\n\nexport interface BulkScanDiscoveryDependencies {\n prompt: BulkScanPrompt;\n now(): number;\n currentDirectory(): string;\n githubHost?: string;\n createGitHub(host: string, signal?: AbortSignal): Promise<Octokit>;\n}\n\nexport interface BulkScanWizardResult {\n inputPath: string;\n outputDir: string;\n githubHost: string;\n}\n\ninterface PromptOutput {\n write(value: string): unknown;\n readonly isTTY?: boolean;\n}\n\nexport function createBulkScanDiscoveryDependencies(options: {\n output: PromptOutput;\n now(): number;\n currentDirectory(): string;\n}): BulkScanDiscoveryDependencies {\n return {\n prompt: createTerminalPrompt(options.output),\n now: options.now,\n currentDirectory: options.currentDirectory,\n ...(process.env[\"GH_HOST\"]?.trim()\n ? { githubHost: process.env[\"GH_HOST\"].trim() }\n : {}),\n createGitHub: async (host, signal) => {\n const trusted = await resolveTrustedExecutable(\n \"gh\",\n process.env,\n options.currentDirectory(),\n );\n if (trusted === null) {\n throw new Error(\n \"GitHub CLI is required. Install gh and sign in first.\",\n );\n }\n\n let token: string;\n try {\n const { stdout } = await execFile(\n trusted.executable,\n [\"auth\", \"token\", \"--hostname\", host],\n { env: trusted.environment, signal },\n );\n token = stdout.trim();\n } catch {\n signal?.throwIfAborted();\n throw new Error(\n \"GitHub sign-in is required. Run 'gh auth login' first.\",\n );\n }\n return new Octokit({\n auth: token,\n ...(host === \"github.com\" ? {} : { baseUrl: `https://${host}/api/v3` }),\n });\n },\n };\n}\n\nexport async function runBulkScanWizard(\n dependencies: BulkScanDiscoveryDependencies,\n signal?: AbortSignal,\n): Promise<BulkScanWizardResult | null> {\n const { prompt } = dependencies;\n if (!prompt.isInteractive()) {\n throw new Error(\n \"Interactive repository selection requires a terminal. Provide a CSV with 'codex-security bulk-scan repositories.csv --output-dir ./security-scans'.\",\n );\n }\n signal?.throwIfAborted();\n\n const githubHost = dependencies.githubHost ?? \"github.com\";\n const github = await dependencies.createGitHub(githubHost, signal);\n const owner = await selectGitHubOwner(github, prompt, signal);\n prompt.write(\"\\nFinding active repositories...\\n\");\n const discovered = await discoverGitHubRepositories(\n github,\n githubHost,\n owner,\n dependencies.now() - 90 * 86_400_000,\n signal,\n );\n if (discovered.length === 0) {\n prompt.write(\"\\nNo repositories matched your selection.\\n\");\n return null;\n }\n\n prompt.write(`\\nFound ${discovered.length} repositories.\\n`);\n const repositories = await selectGitHubRepositories(discovered, prompt);\n\n const outputDir = resolve(\n dependencies.currentDirectory(),\n await prompt.input(\n \"Where should scan results be saved?\",\n \"./security-scans\",\n ),\n );\n const inputPath = join(outputDir, \"repositories.csv\");\n await validateWizardOutput(outputDir);\n prompt.write(\n `\\nReady to scan ${repositories.length} repositories?\\n` +\n `Results: ${outputDir}\\nRepository list: ${inputPath}\\n`,\n );\n if (!(await prompt.confirm(\"Start scanning?\"))) {\n prompt.write(\"\\nScan canceled.\\n\");\n return null;\n }\n signal?.throwIfAborted();\n\n await mkdir(outputDir, { recursive: true, mode: 0o700 });\n await writeFile(\n inputPath,\n `${Papa.unparse(\n repositories.map(({ fullName, url, revision }) => ({\n id: repositoryId(fullName),\n repository: url,\n revision,\n })),\n )}\\n`,\n { flag: \"wx\", mode: 0o600, ...(signal === undefined ? {} : { signal }) },\n );\n return { inputPath, outputDir, githubHost };\n}\n\nasync function selectGitHubOwner(\n github: Octokit,\n prompt: BulkScanPrompt,\n signal?: AbortSignal,\n): Promise<string> {\n const { data } = await github.request(\"GET /user/orgs\", {\n per_page: 100,\n request: { signal },\n });\n const organizations = data.map(({ login }) => login).sort();\n if (organizations.length > 1) {\n return await prompt.select(\n \"Which account or organization should we scan?\",\n organizations.map((owner) => ({ label: owner, value: owner })),\n );\n }\n const owner =\n organizations[0] ??\n (await github.request(\"GET /user\", { request: { signal } })).data.login;\n prompt.write(`\\nFinding repositories in ${owner}.\\n`);\n return owner;\n}\n\nasync function selectGitHubRepositories(\n repositories: GitHubRepository[],\n prompt: BulkScanPrompt,\n): Promise<GitHubRepository[]> {\n const selected = new Set<string>();\n while (selected.size < repositories.length) {\n const choice = await prompt.select(\n \"Select repositories to scan (type to filter)\",\n [\n {\n label: selected.size\n ? `Done (${selected.size} selected)`\n : `All ${repositories.length} repositories`,\n value: \"\",\n },\n ...repositories\n .filter(({ fullName }) => !selected.has(fullName))\n .map(({ fullName }) => ({ label: fullName, value: fullName })),\n ],\n );\n if (!choice) break;\n selected.add(choice);\n }\n return selected.size\n ? repositories.filter(({ fullName }) => selected.has(fullName))\n : repositories;\n}\n\nasync function discoverGitHubRepositories(\n github: Octokit,\n host: string,\n owner: string,\n cutoff: number,\n signal?: AbortSignal,\n): Promise<GitHubRepository[]> {\n const repositories: GitHubRepository[] = [];\n let cursor: string | null = null;\n\n do {\n signal?.throwIfAborted();\n const result: GitHubRepositoriesResponse = await github.graphql(\n GITHUB_REPOSITORIES_QUERY,\n { owner, cursor, request: { signal } },\n );\n const connection = result.repositoryOwner?.repositories;\n if (connection === undefined) {\n throw new Error(\"GitHub could not list repositories for this account.\");\n }\n\n for (const repository of connection.nodes) {\n if (Date.parse(repository.pushedAt) < cutoff) return repositories;\n if (repository.defaultBranchRef === null) continue;\n repositories.push({\n fullName: repository.nameWithOwner,\n url: `https://${host}/${repository.nameWithOwner}.git`,\n revision: repository.defaultBranchRef.target.oid.toLowerCase(),\n });\n }\n cursor = connection.pageInfo.hasNextPage\n ? connection.pageInfo.endCursor\n : null;\n } while (cursor !== null);\n\n return repositories;\n}\n\nfunction repositoryId(fullName: string): string {\n const id = fullName.replace(\"/\", \"--\");\n if (id.length <= 128) return id;\n const hash = createHash(\"sha256\").update(fullName).digest(\"hex\").slice(0, 16);\n return `${id.slice(0, 111)}-${hash}`;\n}\n\nasync function validateWizardOutput(outputDir: string): Promise<void> {\n let metadata;\n try {\n metadata = await lstat(outputDir);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw error;\n }\n if (!metadata.isDirectory()) {\n throw new Error(\"The scan output must be a real directory.\");\n }\n\n for (const name of [\"repositories.csv\", \"manifest.json\"]) {\n try {\n await lstat(join(outputDir, name));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") continue;\n throw error;\n }\n throw new Error(\n \"The selected output directory already contains a repository list or scan. Choose a new directory or resume the existing scan.\",\n );\n }\n}\n\nfunction createTerminalPrompt(output: PromptOutput): BulkScanPrompt {\n const context = () => ({\n input: stdin,\n output: new Writable({\n write(chunk: Buffer, _encoding, callback) {\n output.write(chunk.toString(\"utf8\"));\n callback();\n },\n }),\n });\n\n return {\n isInteractive: () => stdin.isTTY === true && output.isTTY === true,\n write: (value) => {\n output.write(value);\n },\n confirm: (message, defaultValue = false) =>\n confirm({ message, default: defaultValue }, context()),\n input: (message, defaultValue) =>\n input({ message, default: defaultValue }, context()),\n select: (message, options) =>\n search(\n {\n message,\n source: (term) =>\n options\n .filter(({ label }) =>\n label.toLowerCase().includes(term?.toLowerCase() ?? \"\"),\n )\n .map(({ label, value }) => ({ name: label, value })),\n },\n context(),\n ),\n };\n}\n"]}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CodexSecurity } from "./api.js";
|
|
3
|
+
import { type BulkScanDiscoveryDependencies } from "./bulk-scan-discovery.js";
|
|
4
|
+
import { type CodexSecurityConfig, type JsonObject } from "./config.js";
|
|
5
|
+
import { type CodexCommand } from "./runtime.js";
|
|
6
|
+
import { matchScanFindings } from "./scan-comparison.js";
|
|
7
|
+
type Writable = Pick<NodeJS.WriteStream, "write"> & {
|
|
8
|
+
readonly isTTY?: boolean;
|
|
9
|
+
readonly fd?: number;
|
|
10
|
+
readonly columns?: number;
|
|
11
|
+
};
|
|
12
|
+
type SignalName = "SIGINT" | "SIGTERM";
|
|
13
|
+
declare const EXPORT_DEFAULT_OUTPUTS: {
|
|
14
|
+
readonly csv: "findings.csv";
|
|
15
|
+
readonly json: "findings.json";
|
|
16
|
+
readonly sarif: "results.sarif";
|
|
17
|
+
};
|
|
18
|
+
interface ExportArguments {
|
|
19
|
+
scanDir: string;
|
|
20
|
+
format: keyof typeof EXPORT_DEFAULT_OUTPUTS;
|
|
21
|
+
output: string;
|
|
22
|
+
sourceRoot?: string;
|
|
23
|
+
pythonPath?: string;
|
|
24
|
+
}
|
|
25
|
+
interface SkillCommandOutput {
|
|
26
|
+
readonly command: "validate" | "patch";
|
|
27
|
+
readonly stdout: Writable;
|
|
28
|
+
readonly stderr: Writable;
|
|
29
|
+
}
|
|
30
|
+
interface CliDependencies {
|
|
31
|
+
createSecurity(config: CodexSecurityConfig): Pick<CodexSecurity, "run" | "preflight" | "close">;
|
|
32
|
+
environment: NodeJS.ProcessEnv;
|
|
33
|
+
currentDirectory(): string;
|
|
34
|
+
now(): number;
|
|
35
|
+
setInterval(callback: () => void, milliseconds: number): NodeJS.Timeout;
|
|
36
|
+
clearInterval(timer: NodeJS.Timeout): void;
|
|
37
|
+
addSignalListener(signal: SignalName, listener: () => void): void;
|
|
38
|
+
removeSignalListener(signal: SignalName, listener: () => void): void;
|
|
39
|
+
writeSynchronously(stream: Writable, value: string): void;
|
|
40
|
+
forceExit(signal: SignalName): void;
|
|
41
|
+
exportFindings(arguments_: ExportArguments, output?: Writable): Promise<Uint8Array | undefined>;
|
|
42
|
+
runCodex(args: readonly string[], output?: SkillCommandOutput): Promise<number>;
|
|
43
|
+
bulkScan?: BulkScanDiscoveryDependencies;
|
|
44
|
+
runWorkbench(args: readonly string[]): Promise<JsonObject>;
|
|
45
|
+
matchFindings: typeof matchScanFindings;
|
|
46
|
+
}
|
|
47
|
+
export declare function runCodexSkillCommand(args: readonly string[], output?: SkillCommandOutput, command?: CodexCommand): Promise<number>;
|
|
48
|
+
export declare function exportEnvironment(environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
49
|
+
export declare function main(argv?: readonly string[], output?: Writable, errorOutput?: Writable, dependencies?: CliDependencies): Promise<number>;
|
|
50
|
+
export declare function readSkillCommandOutput(stream: AsyncIterable<Buffer | string>): Promise<{
|
|
51
|
+
message?: string;
|
|
52
|
+
error?: string;
|
|
53
|
+
malformed: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
export declare function skillCommandFailure(command: "validate" | "patch", status: number, detail: string): string;
|
|
56
|
+
export declare function parseCodexOverrides(values: readonly string[], model?: string): JsonObject;
|
|
57
|
+
export declare class Progress {
|
|
58
|
+
#private;
|
|
59
|
+
constructor(stream?: Writable, dependencies?: Pick<CliDependencies, "now" | "setInterval" | "clearInterval">, interactive?: boolean);
|
|
60
|
+
get interactive(): boolean;
|
|
61
|
+
get elapsedSeconds(): number;
|
|
62
|
+
stage(message: string): void;
|
|
63
|
+
startTimer(message: string): void;
|
|
64
|
+
stopTimer(): void;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=cli.d.ts.map
|
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