Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

chore(codex-security): sync public projection

ianw-oai380b395ffebc
diff --git a/README.md b/README.md
index bb5a2bd78..55b75aa6d 100644
--- a/README.md
+++ b/README.md
@@ -80,8 +80,8 @@ searched recursively for Markdown, text, PDF, and Word (`.docx`) files.
Sign in with `gh auth login`, then run `npx codex-security bulk-scan` to discover
GitHub repositories pushed in the last 90 days. Archived
-repositories and forks are excluded. Optionally filter by comma-separated
-repository-name keywords, review the matches, and confirm before scanning.
+repositories and forks are excluded. Search the repository list, select the
+repositories to scan, and confirm before scanning.
Private checkouts reuse your GitHub CLI sign-in without changing your global Git
configuration. For automation or an existing repository list, pass a CSV
containing `id`, `repository`, and full immutable `revision` columns and specify
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index cc0a113f7..1f166bb92 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -124,8 +124,8 @@ for the complete CLI references.
Sign in with `gh auth login`, then run `npx codex-security bulk-scan` to discover
GitHub repositories pushed in the last 90 days. Archived
-repositories and forks are excluded. Optionally filter by comma-separated
-repository-name keywords, review the matches, and confirm before scanning.
+repositories and forks are excluded. Search the repository list, select the
+repositories to scan, and confirm before scanning.
Private checkouts reuse your GitHub CLI sign-in without changing your global Git
configuration. The selected repositories are saved to
`<output-dir>/repositories.csv` for review or resumption.
diff --git a/sdk/typescript/src/bulk-scan-discovery.ts b/sdk/typescript/src/bulk-scan-discovery.ts
index e3c1848d3..b6670b5d0 100644
--- a/sdk/typescript/src/bulk-scan-discovery.ts
+++ b/sdk/typescript/src/bulk-scan-discovery.ts
@@ -5,7 +5,7 @@ import { join, resolve } from "node:path";
import { stdin } from "node:process";
import { Writable } from "node:stream";
import { promisify } from "node:util";
-import { confirm, input, select } from "@inquirer/prompts";
+import { confirm, input, search } from "@inquirer/prompts";
import { Octokit } from "@octokit/core";
import Papa from "papaparse";
import { resolveTrustedExecutable } from "./trusted-executable.js";
@@ -142,34 +142,21 @@ export async function runBulkScanWizard(
const githubHost = dependencies.githubHost ?? "github.com";
const github = await dependencies.createGitHub(githubHost, signal);
const owner = await selectGitHubOwner(github, prompt, signal);
- const names = await prompt.input(
- "Repository name contains (comma-separated; leave blank for all)",
- );
- const keywords = names
- .split(",")
- .map((name) => name.trim().toLowerCase())
- .filter(Boolean);
prompt.write("\nFinding active repositories...\n");
- const repositories = await discoverGitHubRepositories(
+ const discovered = await discoverGitHubRepositories(
github,
githubHost,
owner,
- keywords,
dependencies.now() - 90 * 86_400_000,
signal,
);
- if (repositories.length === 0) {
+ if (discovered.length === 0) {
prompt.write("\nNo repositories matched your selection.\n");
return null;
}
- prompt.write(`\nFound ${repositories.length} repositories:\n`);
- for (const { fullName } of repositories.slice(0, 10)) {
- prompt.write(` ${fullName}\n`);
- }
- if (repositories.length > 10) {
- prompt.write(` and ${repositories.length - 10} more\n`);
- }
+ prompt.write(`\nFound ${discovered.length} repositories.\n`);
+ const repositories = await selectGitHubRepositories(discovered, prompt);
const outputDir = resolve(
dependencies.currentDirectory(),
@@ -228,11 +215,38 @@ async function selectGitHubOwner(
return owner;
}
+async function selectGitHubRepositories(
+ repositories: GitHubRepository[],
+ prompt: BulkScanPrompt,
+): Promise<GitHubRepository[]> {
+ const selected = new Set<string>();
+ while (selected.size < repositories.length) {
+ const choice = await prompt.select(
+ "Select repositories to scan (type to filter)",
+ [
+ {
+ label: selected.size
+ ? `Done (${selected.size} selected)`
+ : `All ${repositories.length} repositories`,
+ value: "",
+ },
+ ...repositories
+ .filter(({ fullName }) => !selected.has(fullName))
+ .map(({ fullName }) => ({ label: fullName, value: fullName })),
+ ],
+ );
+ if (!choice) break;
+ selected.add(choice);
+ }
+ return selected.size
+ ? repositories.filter(({ fullName }) => selected.has(fullName))
+ : repositories;
+}
+
async function discoverGitHubRepositories(
github: Octokit,
host: string,
owner: string,
- keywords: string[],
cutoff: number,
signal?: AbortSignal,
): Promise<GitHubRepository[]> {
@@ -252,14 +266,7 @@ async function discoverGitHubRepositories(
for (const repository of connection.nodes) {
if (Date.parse(repository.pushedAt) < cutoff) return repositories;
- const name = repository.nameWithOwner.split("/").at(-1)!;
- if (
- repository.defaultBranchRef === null ||
- (keywords.length > 0 &&
- !keywords.some((keyword) => name.toLowerCase().includes(keyword)))
- ) {
- continue;
- }
+ if (repository.defaultBranchRef === null) continue;
repositories.push({
fullName: repository.nameWithOwner,
url: `https://${host}/${repository.nameWithOwner}.git`,
@@ -327,10 +334,15 @@ function createTerminalPrompt(output: PromptOutput): BulkScanPrompt {
input: (message, defaultValue) =>
input({ message, default: defaultValue }, context()),
select: (message, options) =>
- select(
+ search(
{
message,
- choices: options.map(({ label, value }) => ({ name: label, value })),
+ source: (term) =>
+ options
+ .filter(({ label }) =>
+ label.toLowerCase().includes(term?.toLowerCase() ?? ""),
+ )
+ .map(({ label, value }) => ({ name: label, value })),
},
context(),
),
diff --git a/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts b/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
index e3f21771d..48fef6a90 100644
--- a/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
+++ b/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
@@ -41,6 +41,7 @@ class FakePrompt implements BulkScanPrompt {
public confirms: boolean[] = [];
public inputs: string[] = [];
public choices: string[] = [];
+ public readonly searchOptions: string[][] = [];
public isInteractive(): boolean {
return this.interactive;
@@ -65,6 +66,7 @@ class FakePrompt implements BulkScanPrompt {
options: readonly { label: string; value: Value }[],
): Promise<Value> {
this.questions.push(question);
+ this.searchOptions.push(options.map(({ label }) => label));
const value = this.choices.shift();
return (options.find((option) => option.value === value) ?? options[0]!)
.value;
@@ -253,7 +255,7 @@ describe("bulk scan repository discovery", () => {
expect(csv).not.toContain("acme--old");
});
- test("filters repository names with case-insensitive keywords", async () => {
+ test("shows all repositories and scans only the selected ones", async () => {
const root = await temporaryDirectory();
const { dependencies, prompt } = discoveryDependencies(root, {
repositories: [
@@ -263,11 +265,17 @@ describe("bulk scan repository discovery", () => {
],
});
prompt.confirms = [true];
- prompt.inputs = [" OwL, OPENAI ", "./custom-results"];
+ prompt.inputs = ["./custom-results"];
+ prompt.choices = ["acme/owl", "acme/openai", ""];
const result = await runBulkScanWizard(dependencies);
expect(result?.outputDir).toBe(join(root, "custom-results"));
+ expect(prompt.searchOptions).toEqual([
+ ["All 3 repositories", "acme/owl", "acme/openai", "acme/unrelated"],
+ ["Done (1 selected)", "acme/openai", "acme/unrelated"],
+ ["Done (2 selected)", "acme/unrelated"],
+ ]);
const csv = await readFile(result!.inputPath, "utf8");
expect(csv).toContain("acme--owl");
expect(csv).toContain("acme--openai");
@@ -363,7 +371,7 @@ describe("bulk scan repository discovery", () => {
await mkdir(output);
await writeFile(inventory, "do not overwrite\n");
const { dependencies, prompt } = discoveryDependencies(root);
- prompt.inputs = ["", "./existing-results"];
+ prompt.inputs = ["./existing-results"];
await expect(runBulkScanWizard(dependencies)).rejects.toThrow(
"already contains a repository list or scan",