@openai/codex-security 0.1.11 → 0.1.12
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 +50 -33
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/examples/completed-scan/coverage.json +1 -1
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +2 -2
- 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 +1 -34
- package/_bundled_plugin/references/config-preflight.md +11 -13
- package/_bundled_plugin/references/core-scan.md +94 -0
- package/_bundled_plugin/references/final-report.md +6 -6
- package/_bundled_plugin/references/scan-artifacts.md +15 -14
- package/_bundled_plugin/references/scan-prologue.md +27 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +1 -106
- package/_bundled_plugin/scripts/config_preflight.py +40 -3
- package/_bundled_plugin/scripts/deep_scan_config.py +8 -5
- package/_bundled_plugin/scripts/deep_scan_workbench.py +103 -35
- package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -17
- package/_bundled_plugin/scripts/finding_preview.py +122 -6
- package/_bundled_plugin/scripts/generate_in_scope_files.py +39 -17
- package/_bundled_plugin/scripts/generate_rank_input.py +21 -3
- package/_bundled_plugin/scripts/normalize_candidates.py +5 -5
- package/_bundled_plugin/scripts/report_projection.py +1 -19
- package/_bundled_plugin/scripts/workbench_db.py +22 -29
- package/_bundled_plugin/scripts/workbench_progress.py +0 -5
- package/_bundled_plugin/scripts/workbench_scan_usage.py +43 -8
- package/_bundled_plugin/scripts/workbench_schema.py +1 -20
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +8 -11
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +24 -110
- package/_bundled_plugin/skills/security-scan/SKILL.md +5 -88
- package/_bundled_plugin/skills/threat-model/SKILL.md +4 -2
- package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
- package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -6
- package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +6 -7
- package/_bundled_plugin/skills/validation/SKILL.md +9 -12
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +3 -2
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +1 -1
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +179 -56
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.js +14 -2
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +6 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +188 -42
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +10 -1
- package/dist/cost.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +10 -3
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +1 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +77 -18
- package/dist/multiscan.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -44
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts +5 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +65 -16
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts +2 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +97 -37
- package/dist/scan-logs.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +20 -11
- package/dist/targets.js.map +1 -1
- package/dist/trusted-executable.js +1 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +3 -3
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +6 -4
- package/dist/version.js.map +1 -1
- package/package.json +4 -4
- package/_bundled_plugin/references/shared-hard-rules.md +0 -15
- package/_bundled_plugin/scripts/validate_report_format.py +0 -138
- package/_bundled_plugin/skills/security-scan/references/repository-wide-scan.md +0 -33
|
@@ -95,12 +95,24 @@ export async function runBulkScanWizard(dependencies, signal) {
|
|
|
95
95
|
return { inputPath, outputDir, githubHost };
|
|
96
96
|
}
|
|
97
97
|
async function selectGitHubOwner(github, prompt, signal) {
|
|
98
|
-
const [
|
|
98
|
+
const [firstPage, user] = await Promise.all([
|
|
99
99
|
github.request("GET /user/orgs", { per_page: 100, request: { signal } }),
|
|
100
100
|
github.request("GET /user", { request: { signal } }),
|
|
101
101
|
]);
|
|
102
|
+
const organizations = [...firstPage.data];
|
|
103
|
+
let response = firstPage;
|
|
104
|
+
let page = 1;
|
|
105
|
+
while (response.headers.link?.includes('rel="next"')) {
|
|
106
|
+
signal?.throwIfAborted();
|
|
107
|
+
response = await github.request("GET /user/orgs", {
|
|
108
|
+
per_page: 100,
|
|
109
|
+
page: ++page,
|
|
110
|
+
request: { signal },
|
|
111
|
+
});
|
|
112
|
+
organizations.push(...response.data);
|
|
113
|
+
}
|
|
102
114
|
const personal = user.data.login;
|
|
103
|
-
const owners = [personal, ...
|
|
115
|
+
const owners = [personal, ...organizations.map(({ login }) => login)].sort();
|
|
104
116
|
if (owners.length > 1) {
|
|
105
117
|
return await prompt.select("Which account or organization should we scan?", owners.map((owner) => ({ label: owner, value: owner })));
|
|
106
118
|
}
|
|
@@ -1 +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,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,QAAQ;gBACtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;gBACrC,QAAQ,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 [orgs, user] = await Promise.all([\n github.request(\"GET /user/orgs\", { per_page: 100, request: { signal } }),\n github.request(\"GET /user\", { request: { signal } }),\n ]);\n const personal = user.data.login;\n const owners = [personal, ...orgs.data.map(({ login }) => login)].sort();\n if (owners.length > 1) {\n return await prompt.select(\n \"Which account or organization should we scan?\",\n owners.map((owner) => ({ label: owner, value: owner })),\n );\n }\n prompt.write(`\\nFinding repositories in ${personal}.\\n`);\n return personal;\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"]}
|
|
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;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAC7C,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;CAmBjC,CAAC;AAmDF,MAAM,UAAU,mCAAmC,CAAC,OAInD;IACC,OAAO;QACL,MAAM,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC;QAC5C,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C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,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 [firstPage, user] = await Promise.all([\n github.request(\"GET /user/orgs\", { per_page: 100, request: { signal } }),\n github.request(\"GET /user\", { request: { signal } }),\n ]);\n const organizations = [...firstPage.data];\n let response = firstPage;\n let page = 1;\n while (response.headers.link?.includes('rel=\"next\"')) {\n signal?.throwIfAborted();\n response = await github.request(\"GET /user/orgs\", {\n per_page: 100,\n page: ++page,\n request: { signal },\n });\n organizations.push(...response.data);\n }\n const personal = user.data.login;\n const owners = [personal, ...organizations.map(({ login }) => login)].sort();\n if (owners.length > 1) {\n return await prompt.select(\n \"Which account or organization should we scan?\",\n owners.map((owner) => ({ label: owner, value: owner })),\n );\n }\n prompt.write(`\\nFinding repositories in ${personal}.\\n`);\n return personal;\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
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { ModelReasoningEffort } from "@openai/codex-sdk";
|
|
3
2
|
import { CodexSecurity } from "./api.js";
|
|
4
3
|
import { type BulkScanDiscoveryDependencies, type BulkScanPrompt } from "./bulk-scan-discovery.js";
|
|
5
4
|
import { type CodexSecurityConfig, type ExternalModelProvider, type JsonObject } from "./config.js";
|
|
@@ -7,11 +6,15 @@ import { type CodexCommand } from "./runtime.js";
|
|
|
7
6
|
import { type matchScanFindings } from "./scan-comparison.js";
|
|
8
7
|
import { type UpdateNotice } from "./version.js";
|
|
9
8
|
type Writable = Pick<NodeJS.WriteStream, "write"> & {
|
|
9
|
+
on?(event: "error", listener: (error: Error) => void): unknown;
|
|
10
|
+
off?(event: "error", listener: (error: Error) => void): unknown;
|
|
10
11
|
readonly isTTY?: boolean;
|
|
11
12
|
readonly fd?: number;
|
|
12
13
|
readonly columns?: number;
|
|
13
14
|
};
|
|
14
15
|
type SignalName = "SIGINT" | "SIGTERM";
|
|
16
|
+
declare const MODEL_REASONING_EFFORTS: readonly ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
17
|
+
type ScanReasoningEffort = (typeof MODEL_REASONING_EFFORTS)[number];
|
|
15
18
|
declare const EXPORT_DEFAULT_OUTPUTS: {
|
|
16
19
|
readonly csv: "findings.csv";
|
|
17
20
|
readonly json: "findings.json";
|
|
@@ -48,7 +51,7 @@ interface CliDependencies {
|
|
|
48
51
|
bulkScan?: BulkScanDiscoveryDependencies;
|
|
49
52
|
runWorkbench(args: readonly string[]): Promise<JsonObject>;
|
|
50
53
|
matchFindings: typeof matchScanFindings;
|
|
51
|
-
checkForUpdate(): Promise<UpdateNotice | undefined>;
|
|
54
|
+
checkForUpdate(signal: AbortSignal): Promise<UpdateNotice | undefined>;
|
|
52
55
|
}
|
|
53
56
|
export declare function runCodexSkillCommand(args: readonly string[], output?: SkillCommandOutput, command?: CodexCommand, processEnvironment?: NodeJS.ProcessEnv): Promise<number>;
|
|
54
57
|
export declare function exportEnvironment(environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
@@ -59,7 +62,7 @@ export declare function readSkillCommandOutput(stream: AsyncIterable<Buffer | st
|
|
|
59
62
|
malformed: boolean;
|
|
60
63
|
}>;
|
|
61
64
|
export declare function skillCommandFailure(command: "validate" | "patch", status: number, detail: string): string;
|
|
62
|
-
export declare function parseCodexOverrides(values: readonly string[], model?: string, effort?:
|
|
65
|
+
export declare function parseCodexOverrides(values: readonly string[], model?: string, effort?: ScanReasoningEffort, provider?: "openai" | "amazon-bedrock" | ExternalModelProvider): JsonObject;
|
|
63
66
|
export declare class Progress {
|
|
64
67
|
#private;
|
|
65
68
|
constructor(stream?: Writable, dependencies?: Pick<CliDependencies, "now" | "setInterval" | "clearInterval">, interactive?: boolean);
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAsCA,OAAO,EAEL,aAAa,EASd,MAAM,UAAU,CAAC;AAElB,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAOL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AAiBrB,OAAO,EAUL,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,KAAK,iBAAiB,EAEvB,MAAM,sBAAsB,CAAC;AAc9B,OAAO,EAOL,KAAK,YAAY,E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aAAa,GAAG,eAAe,CACjB,EACxB,WAAW,UAAO;IAQpB,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED,IAAW,cAAc,IAAI,MAAM,CAKlC;IAEM,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK5B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAiBjC,SAAS,IAAI,IAAI;IAwCjB,eAAe,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,IAAI;CAoChD"}
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync, spawn } from "node:child_process";
|
|
3
3
|
import { accessSync, constants, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
|
|
4
|
-
import { mkdir, readFile, realpath,
|
|
4
|
+
import { lstat, mkdir, open, readFile, realpath, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep, win32, } from "node:path";
|
|
6
6
|
import { cwd } from "node:process";
|
|
7
7
|
import { createInterface } from "node:readline";
|
|
@@ -47,6 +47,7 @@ const MODEL_REASONING_EFFORTS = [
|
|
|
47
47
|
"medium",
|
|
48
48
|
"high",
|
|
49
49
|
"xhigh",
|
|
50
|
+
"max",
|
|
50
51
|
];
|
|
51
52
|
const DEFAULT_SCAN_MODEL_CONFIGURATION = scanModelConfiguration(DEFAULT_CODEX_CONFIG);
|
|
52
53
|
const CODEX_OVERRIDE_DESCRIPTION = 'Repeat TOML KEY=VALUE; e.g. model_reasoning_effort="high" or features.multi_agent_v2.max_concurrent_threads_per_session=4.';
|
|
@@ -102,7 +103,7 @@ function optionValue(flag) {
|
|
|
102
103
|
function effortOption() {
|
|
103
104
|
return z
|
|
104
105
|
.enum(MODEL_REASONING_EFFORTS, {
|
|
105
|
-
error: "--effort must be minimal, low, medium, high, or
|
|
106
|
+
error: "--effort must be minimal, low, medium, high, xhigh, or max.",
|
|
106
107
|
})
|
|
107
108
|
.optional()
|
|
108
109
|
.describe(`Model reasoning effort (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort}).`);
|
|
@@ -139,25 +140,58 @@ const DEEP_SCAN_OPTION_SCHEMAS = {
|
|
|
139
140
|
.optional()
|
|
140
141
|
.describe("Maximum deep-scan discovery hours (default: 96; maximum: 96)."),
|
|
141
142
|
};
|
|
142
|
-
async function readPromptFiles(directory, scanPromptFile, postScanPromptFile) {
|
|
143
|
+
async function readPromptFiles(directory, scanPromptFile, postScanPromptFile, repository = directory) {
|
|
143
144
|
const [scanPrompt, postScanPrompt] = await Promise.all([
|
|
144
145
|
scanPromptFile === undefined
|
|
145
146
|
? undefined
|
|
146
|
-
:
|
|
147
|
+
: readRegularInputFile(resolve(directory, scanPromptFile), repository),
|
|
147
148
|
postScanPromptFile === undefined
|
|
148
149
|
? undefined
|
|
149
|
-
:
|
|
150
|
+
: readRegularInputFile(resolve(directory, postScanPromptFile), repository),
|
|
150
151
|
]);
|
|
151
152
|
return {
|
|
152
153
|
...(scanPrompt?.trim() ? { scanPrompt } : {}),
|
|
153
154
|
...(postScanPrompt?.trim() ? { postScanPrompt } : {}),
|
|
154
155
|
};
|
|
155
156
|
}
|
|
157
|
+
async function readRegularInputFile(path, repository, metadata) {
|
|
158
|
+
const selected = metadata ?? (await lstat(path));
|
|
159
|
+
if (!selected.isFile()) {
|
|
160
|
+
throw new CodexSecurityError("Input files must be regular files.");
|
|
161
|
+
}
|
|
162
|
+
const canonicalRepository = await realpath(repository);
|
|
163
|
+
const canonicalParent = await realpath(dirname(path));
|
|
164
|
+
if (isOutsidePath(relative(canonicalRepository, canonicalParent))) {
|
|
165
|
+
for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
|
|
166
|
+
if (!isOutsidePath(relative(canonicalRepository, await realpath(ancestor)))) {
|
|
167
|
+
throw new CodexSecurityError("Input files must not follow repository directory links outside the selected repository.");
|
|
168
|
+
}
|
|
169
|
+
if (dirname(ancestor) === ancestor) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const file = await open(join(canonicalParent, basename(path)), constants.O_RDONLY |
|
|
175
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
176
|
+
(constants.O_NONBLOCK ?? 0));
|
|
177
|
+
try {
|
|
178
|
+
const opened = await file.stat();
|
|
179
|
+
if (!opened.isFile() ||
|
|
180
|
+
opened.dev !== selected.dev ||
|
|
181
|
+
opened.ino !== selected.ino) {
|
|
182
|
+
throw new CodexSecurityError("Input files must remain regular files.");
|
|
183
|
+
}
|
|
184
|
+
return await file.readFile({ encoding: "utf8" });
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
await file.close();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
156
190
|
const DEFAULT_DEPENDENCIES = {
|
|
157
191
|
createSecurity: (config) => createSecurityInternal(config, { surface: "cli" }),
|
|
158
192
|
environment: process.env,
|
|
159
193
|
prepareAuthenticationHome: prepareCodexSecurityCredentialHome,
|
|
160
|
-
checkForUpdate: () => checkForUpdate({ environment: process.env }),
|
|
194
|
+
checkForUpdate: (signal) => checkForUpdate({ environment: process.env, signal }),
|
|
161
195
|
hasStoredChatGPTSignIn: async () => {
|
|
162
196
|
const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "OPENAI_API_KEY" &&
|
|
163
197
|
name.toUpperCase() !== "CODEX_API_KEY"));
|
|
@@ -431,6 +465,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
431
465
|
errorOutput.write(`codex-security: ${argumentError}\n`);
|
|
432
466
|
return 2;
|
|
433
467
|
}
|
|
468
|
+
const updateController = new AbortController();
|
|
434
469
|
const pendingUpdate = errorOutput.isTTY === true &&
|
|
435
470
|
argv.length > 0 &&
|
|
436
471
|
argv[0] !== "completions" &&
|
|
@@ -444,7 +479,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
444
479
|
"--dry-run",
|
|
445
480
|
].includes(argument)) &&
|
|
446
481
|
updateNoticeEnabled(dependencies.environment)
|
|
447
|
-
? dependencies
|
|
482
|
+
? dependencies
|
|
483
|
+
.checkForUpdate(updateController.signal)
|
|
484
|
+
.catch(() => undefined)
|
|
448
485
|
: undefined;
|
|
449
486
|
let exitCode = 0;
|
|
450
487
|
let frameworkExit;
|
|
@@ -642,6 +679,14 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
642
679
|
scanId: scan.scanId,
|
|
643
680
|
threadId,
|
|
644
681
|
codexHome: codexSecurityCredentialHome(dependencies.environment),
|
|
682
|
+
scanDirectory: scan.mode === "deep" ? scan.scanDir : undefined,
|
|
683
|
+
completedAt: scan.progress?.status === "running"
|
|
684
|
+
? null
|
|
685
|
+
: scan.progress?.status === "complete" ||
|
|
686
|
+
scan.progress?.status === "failed" ||
|
|
687
|
+
scan.progress?.status === "canceled"
|
|
688
|
+
? scan.progress.updatedAt ?? ""
|
|
689
|
+
: "",
|
|
645
690
|
}));
|
|
646
691
|
});
|
|
647
692
|
},
|
|
@@ -1051,6 +1096,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1051
1096
|
.positive()
|
|
1052
1097
|
.default(1)
|
|
1053
1098
|
.describe("Maximum scan attempts per repository."),
|
|
1099
|
+
maxCost: z
|
|
1100
|
+
.number()
|
|
1101
|
+
.positive()
|
|
1102
|
+
.optional()
|
|
1103
|
+
.describe("Stop each repository attempt if estimated USD cost exceeds AMOUNT."),
|
|
1054
1104
|
pluginPath: z
|
|
1055
1105
|
.string()
|
|
1056
1106
|
.min(1)
|
|
@@ -1120,6 +1170,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1120
1170
|
workers: options.workers,
|
|
1121
1171
|
mode: options.mode,
|
|
1122
1172
|
maxAttempts: options.maxAttempts,
|
|
1173
|
+
...(options.maxCost === undefined
|
|
1174
|
+
? {}
|
|
1175
|
+
: { maxCostUsd: options.maxCost }),
|
|
1123
1176
|
knowledgeBasePaths: options.knowledgeBase,
|
|
1124
1177
|
...prompts,
|
|
1125
1178
|
config: {
|
|
@@ -1379,21 +1432,27 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1379
1432
|
};
|
|
1380
1433
|
},
|
|
1381
1434
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
if (
|
|
1395
|
-
|
|
1435
|
+
let notice;
|
|
1436
|
+
try {
|
|
1437
|
+
await cli.serve(argv.flatMap((argument) => argument.startsWith("--format=")
|
|
1438
|
+
? ["--format", argument.slice("--format=".length)]
|
|
1439
|
+
: [argument]), {
|
|
1440
|
+
stdout: (value) => {
|
|
1441
|
+
frameworkOutput += value;
|
|
1442
|
+
},
|
|
1443
|
+
exit: (code) => {
|
|
1444
|
+
frameworkExit = code;
|
|
1445
|
+
},
|
|
1446
|
+
});
|
|
1447
|
+
if (pendingUpdate !== undefined) {
|
|
1448
|
+
notice = await Promise.race([pendingUpdate, undefined]);
|
|
1449
|
+
}
|
|
1396
1450
|
}
|
|
1451
|
+
finally {
|
|
1452
|
+
updateController.abort();
|
|
1453
|
+
}
|
|
1454
|
+
if (notice !== undefined)
|
|
1455
|
+
errorOutput.write(formatUpdateNotice(notice));
|
|
1397
1456
|
if (frameworkExit !== undefined) {
|
|
1398
1457
|
if (exitCode !== 0)
|
|
1399
1458
|
return exitCode;
|
|
@@ -1736,7 +1795,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
1736
1795
|
localDeviceRoot !== normalizedDeviceRoot);
|
|
1737
1796
|
if (!windowsNetworkPath) {
|
|
1738
1797
|
const path = resolve(directory, input);
|
|
1739
|
-
const metadata = await
|
|
1798
|
+
const metadata = await lstat(path).catch((error) => {
|
|
1740
1799
|
if (typeof error === "object" &&
|
|
1741
1800
|
error !== null &&
|
|
1742
1801
|
"code" in error &&
|
|
@@ -1753,7 +1812,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
1753
1812
|
throw new CodexSecurityError("Finding and issue inputs must be files or literal text.");
|
|
1754
1813
|
}
|
|
1755
1814
|
try {
|
|
1756
|
-
contentsOrLiteral = await
|
|
1815
|
+
contentsOrLiteral = await readRegularInputFile(path, directory, metadata);
|
|
1757
1816
|
}
|
|
1758
1817
|
catch {
|
|
1759
1818
|
throw new CodexSecurityError("Could not read the finding or issue input.");
|
|
@@ -1938,6 +1997,29 @@ function diagnosticValue(value) {
|
|
|
1938
1997
|
return errorMessage(value).replaceAll(/[\u0000-\u001F\u007F\u0085\u2028\u2029]/gu, " ");
|
|
1939
1998
|
}
|
|
1940
1999
|
async function runScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
2000
|
+
const observeTerminalErrors = typeof errorOutput.on === "function" &&
|
|
2001
|
+
typeof errorOutput.off === "function";
|
|
2002
|
+
const ignoreTerminalError = () => { };
|
|
2003
|
+
if (observeTerminalErrors) {
|
|
2004
|
+
errorOutput.on?.("error", ignoreTerminalError);
|
|
2005
|
+
}
|
|
2006
|
+
try {
|
|
2007
|
+
return await executeScan(arguments_, errorOutput, dependencies, interactive);
|
|
2008
|
+
}
|
|
2009
|
+
finally {
|
|
2010
|
+
if (observeTerminalErrors) {
|
|
2011
|
+
try {
|
|
2012
|
+
errorOutput.write("", () => {
|
|
2013
|
+
queueMicrotask(() => errorOutput.off?.("error", ignoreTerminalError));
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
catch {
|
|
2017
|
+
errorOutput.off?.("error", ignoreTerminalError);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
async function executeScan(arguments_, errorOutput, dependencies, interactive = true) {
|
|
1941
2023
|
let scanDir = null;
|
|
1942
2024
|
let requestedSignal = null;
|
|
1943
2025
|
let firstSignalAt = 0;
|
|
@@ -1974,6 +2056,16 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1974
2056
|
});
|
|
1975
2057
|
};
|
|
1976
2058
|
const preparationAbortController = new AbortController();
|
|
2059
|
+
const stopPresentation = () => {
|
|
2060
|
+
try {
|
|
2061
|
+
dashboard?.stop();
|
|
2062
|
+
}
|
|
2063
|
+
catch { }
|
|
2064
|
+
try {
|
|
2065
|
+
progress?.stopTimer();
|
|
2066
|
+
}
|
|
2067
|
+
catch { }
|
|
2068
|
+
};
|
|
1977
2069
|
const signalListener = (signal) => () => {
|
|
1978
2070
|
if (requestedSignal !== null) {
|
|
1979
2071
|
// Launchers and terminals can deliver the same initial signal twice.
|
|
@@ -1983,8 +2075,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
1983
2075
|
return;
|
|
1984
2076
|
}
|
|
1985
2077
|
requestedSignal = signal;
|
|
1986
|
-
|
|
1987
|
-
progress?.stopTimer();
|
|
2078
|
+
stopPresentation();
|
|
1988
2079
|
if (progress?.interactive === true) {
|
|
1989
2080
|
try {
|
|
1990
2081
|
dependencies.writeSynchronously(errorOutput, SHOW_CURSOR);
|
|
@@ -2018,9 +2109,10 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2018
2109
|
let failed = false;
|
|
2019
2110
|
let failure;
|
|
2020
2111
|
try {
|
|
2021
|
-
const
|
|
2112
|
+
const directory = dependencies.currentDirectory();
|
|
2113
|
+
const repository = arguments_.repository ?? directory;
|
|
2022
2114
|
const target = targetFromArguments(arguments_);
|
|
2023
|
-
const prompts = await readPromptFiles(
|
|
2115
|
+
const prompts = await readPromptFiles(directory, arguments_.scanPromptFile, arguments_.postScanPromptFile, resolve(directory, repository));
|
|
2024
2116
|
const config = {
|
|
2025
2117
|
pluginPath: arguments_.pluginPath,
|
|
2026
2118
|
pythonPath: arguments_.pythonPath,
|
|
@@ -2089,6 +2181,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2089
2181
|
if (progress.interactive && !arguments_.dryRun && !verbose) {
|
|
2090
2182
|
dashboard = new ScanDashboard(errorOutput, {
|
|
2091
2183
|
repository,
|
|
2184
|
+
mode: arguments_.mode,
|
|
2092
2185
|
model: scanModelConfiguration(await mergedCodexConfig(config)),
|
|
2093
2186
|
...(arguments_.maxCostUsd === undefined
|
|
2094
2187
|
? {}
|
|
@@ -2130,7 +2223,14 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2130
2223
|
progress.startTimer(arguments_.dryRun ? "Validating scan inputs" : "Preparing scan");
|
|
2131
2224
|
}
|
|
2132
2225
|
else {
|
|
2133
|
-
|
|
2226
|
+
try {
|
|
2227
|
+
dashboard.start();
|
|
2228
|
+
}
|
|
2229
|
+
catch {
|
|
2230
|
+
dashboard = null;
|
|
2231
|
+
progress = new Progress(errorOutput, dependencies, false);
|
|
2232
|
+
progress.startTimer("Preparing scan");
|
|
2233
|
+
}
|
|
2134
2234
|
}
|
|
2135
2235
|
security = dependencies.createSecurity(config);
|
|
2136
2236
|
const options = {
|
|
@@ -2372,8 +2472,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2372
2472
|
failure = error;
|
|
2373
2473
|
}
|
|
2374
2474
|
finally {
|
|
2375
|
-
|
|
2376
|
-
progress?.stopTimer();
|
|
2475
|
+
stopPresentation();
|
|
2377
2476
|
if (security !== null) {
|
|
2378
2477
|
diagnostic("runtime.cleanup.started");
|
|
2379
2478
|
await security.close().then(() => diagnostic("runtime.cleanup.completed"), (error) => {
|
|
@@ -2440,6 +2539,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2440
2539
|
: undefined,
|
|
2441
2540
|
verified: effectivePreflight.authentication.verified,
|
|
2442
2541
|
});
|
|
2542
|
+
progress?.stopTimer();
|
|
2443
2543
|
return { exitCode: 0, data: { dryRun: true, ...effectivePreflight } };
|
|
2444
2544
|
}
|
|
2445
2545
|
if (result === null) {
|
|
@@ -2472,14 +2572,17 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
|
|
|
2472
2572
|
});
|
|
2473
2573
|
if (targetWarnings.length > 0) {
|
|
2474
2574
|
errorOutput.write("codex-security: Scan target changed during execution; results do not represent the current checkout.\n");
|
|
2575
|
+
progress?.stopTimer();
|
|
2475
2576
|
return { exitCode: 2, data: scanData };
|
|
2476
2577
|
}
|
|
2477
2578
|
if (incomplete) {
|
|
2478
2579
|
errorOutput.write(threshold === undefined
|
|
2479
2580
|
? `codex-security: Scan coverage is ${result.coverage.completeness}; results may be incomplete.\n`
|
|
2480
2581
|
: `codex-security: Cannot evaluate the failure policy: coverage is ${result.coverage.completeness}.\n`);
|
|
2582
|
+
progress?.stopTimer();
|
|
2481
2583
|
return { exitCode: 2, data: scanData };
|
|
2482
2584
|
}
|
|
2585
|
+
progress?.stopTimer();
|
|
2483
2586
|
return { exitCode: blockingCount > 0 ? 1 : 0, data: scanData };
|
|
2484
2587
|
}
|
|
2485
2588
|
// Filesystem and OS syscall failures cannot originate from the model transport,
|
|
@@ -2837,6 +2940,10 @@ export class Progress {
|
|
|
2837
2940
|
#timerMessage = null;
|
|
2838
2941
|
#timerLineActive = false;
|
|
2839
2942
|
#cursorHidden = false;
|
|
2943
|
+
#observingStreamErrors = false;
|
|
2944
|
+
#streamErrorsActive = false;
|
|
2945
|
+
#streamErrorGeneration = 0;
|
|
2946
|
+
#onStreamError = () => { };
|
|
2840
2947
|
constructor(stream = process.stderr, dependencies = DEFAULT_DEPENDENCIES, interactive = true) {
|
|
2841
2948
|
this.#stream = stream;
|
|
2842
2949
|
this.#dependencies = dependencies;
|
|
@@ -2850,9 +2957,11 @@ export class Progress {
|
|
|
2850
2957
|
return Math.max(0, Math.floor((this.#dependencies.now() - this.#startedAt) / 1_000));
|
|
2851
2958
|
}
|
|
2852
2959
|
stage(message) {
|
|
2960
|
+
this.#observeStreamErrors();
|
|
2853
2961
|
this.#stream.write(`${this.#line(message)}\n`);
|
|
2854
2962
|
}
|
|
2855
2963
|
startTimer(message) {
|
|
2964
|
+
this.#observeStreamErrors();
|
|
2856
2965
|
if (!this.interactive) {
|
|
2857
2966
|
this.stage(message);
|
|
2858
2967
|
return;
|
|
@@ -2860,22 +2969,51 @@ export class Progress {
|
|
|
2860
2969
|
this.#stream.write(HIDE_CURSOR);
|
|
2861
2970
|
this.#cursorHidden = true;
|
|
2862
2971
|
this.#renderTimer(message);
|
|
2863
|
-
this.#timer = this.#dependencies.setInterval(() =>
|
|
2972
|
+
this.#timer = this.#dependencies.setInterval(() => {
|
|
2973
|
+
try {
|
|
2974
|
+
this.#renderTimer(message);
|
|
2975
|
+
}
|
|
2976
|
+
catch { }
|
|
2977
|
+
}, PROGRESS_REFRESH_MILLISECONDS);
|
|
2864
2978
|
this.#timerMessage = message;
|
|
2865
2979
|
}
|
|
2866
2980
|
stopTimer() {
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
this.#
|
|
2874
|
-
|
|
2981
|
+
try {
|
|
2982
|
+
if (this.#timer !== null) {
|
|
2983
|
+
this.#dependencies.clearInterval(this.#timer);
|
|
2984
|
+
this.#timer = null;
|
|
2985
|
+
}
|
|
2986
|
+
this.#timerMessage = null;
|
|
2987
|
+
if (this.#timerLineActive) {
|
|
2988
|
+
this.#stream.write("\n");
|
|
2989
|
+
this.#timerLineActive = false;
|
|
2990
|
+
}
|
|
2991
|
+
if (this.#cursorHidden) {
|
|
2992
|
+
this.#stream.write(SHOW_CURSOR);
|
|
2993
|
+
this.#cursorHidden = false;
|
|
2994
|
+
}
|
|
2875
2995
|
}
|
|
2876
|
-
|
|
2877
|
-
this.#
|
|
2878
|
-
|
|
2996
|
+
finally {
|
|
2997
|
+
if (this.#observingStreamErrors) {
|
|
2998
|
+
this.#streamErrorsActive = false;
|
|
2999
|
+
const generation = this.#streamErrorGeneration;
|
|
3000
|
+
try {
|
|
3001
|
+
this.#stream.write("", () => {
|
|
3002
|
+
queueMicrotask(() => {
|
|
3003
|
+
if (generation === this.#streamErrorGeneration &&
|
|
3004
|
+
!this.#streamErrorsActive &&
|
|
3005
|
+
this.#observingStreamErrors) {
|
|
3006
|
+
this.#stream.off?.("error", this.#onStreamError);
|
|
3007
|
+
this.#observingStreamErrors = false;
|
|
3008
|
+
}
|
|
3009
|
+
});
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
catch {
|
|
3013
|
+
this.#stream.off?.("error", this.#onStreamError);
|
|
3014
|
+
this.#observingStreamErrors = false;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
2879
3017
|
}
|
|
2880
3018
|
}
|
|
2881
3019
|
writeAboveTimer(write) {
|
|
@@ -2898,6 +3036,14 @@ export class Progress {
|
|
|
2898
3036
|
const seconds = elapsedSeconds % 60;
|
|
2899
3037
|
return `[${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}] ${message}`;
|
|
2900
3038
|
}
|
|
3039
|
+
#observeStreamErrors() {
|
|
3040
|
+
this.#streamErrorsActive = true;
|
|
3041
|
+
this.#streamErrorGeneration += 1;
|
|
3042
|
+
if (!this.#observingStreamErrors && this.#stream.on !== undefined) {
|
|
3043
|
+
this.#stream.on("error", this.#onStreamError);
|
|
3044
|
+
this.#observingStreamErrors = true;
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
2901
3047
|
#renderTimer(message) {
|
|
2902
3048
|
this.#stream.write(`${this.#timerLineActive ? "\r" : ""}${this.#line(message)}`);
|
|
2903
3049
|
this.#timerLineActive = true;
|