OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(action): preserve literal scan paths (#2617)
Michael D'Angeloed649f6337b8
diff --git a/github-action/dist/index.cjs b/github-action/dist/index.cjsindex 45cd0743b..eb3367bf2 100644--- a/github-action/dist/index.cjs+++ b/github-action/dist/index.cjs@@ -53751,13 +53751,12 @@ function parseInputs(read, workspace) {}return n;};- const list = (name) => str(name).split(/\r?\n/).map((v) => v.trim()).filter(Boolean);const safeRelative = (name, value) => {if (value.startsWith("/") || /^[A-Za-z]:/.test(value) || value.includes("\\") || value.split("/").includes("..") || /[\x00-\x1f\x7f]/.test(value))- throw new Error(`${name} must contain literal repository-relative paths, without '..'.`);+ throw new Error(`${name} must contain literal repository-relative paths without '..', backslashes or control characters.`);return value;};- const paths = [...new Set(list("paths").map((v) => safeRelative("paths", v).split("/").filter((part) => part && part !== ".").join("/") || "."))];+ const paths = [...new Set(read("paths").split(/\r?\n/).filter(Boolean).map((v) => safeRelative("paths", v).split("/").filter((part) => part && part !== ".").join("/") || "."))];const scope = choice("scope", ["repository", "diff"], "repository");if (scope !== "repository" && paths.length)throw new Error(`paths cannot be combined with scope: ${scope}. Remove paths to scan changes, or use scope: repository to scan selected paths.`);@@ -97640,7 +97639,7 @@ async function runAction(actionRoot, overrides = {}) {setOutput("report-status", "failed");setOutput("sarif-upload-ready", "false");try {- inputs = parseInputs((name) => getInput(name), process.env.GITHUB_WORKSPACE ?? "");+ inputs = parseInputs((name) => getInput(name, { trimWhitespace: false }), process.env.GITHUB_WORKSPACE ?? "");const credentials = scanCredentials(inputs.provider, process.env);const event = await context5();target = await resolveTarget(inputs, event);diff --git a/github-action/scripts/cli-integration.ts b/github-action/scripts/cli-integration.tsindex e8b09fb0c..e4fbab0b7 100644--- a/github-action/scripts/cli-integration.ts+++ b/github-action/scripts/cli-integration.ts@@ -225,8 +225,10 @@ try {assert.deepEqual(pathPreflight.target.paths, ['--help']);// Existing glob, tilde, and colon filenames are literal repository scopes.- const literalFiles = ['src/[slug]/page.tsx', 'src/star*file.ts', 'src/question?file.ts', '~/example.ts', 'module:handler.ts'];- const decoys = ['src/s/page.tsx', 'src/l/page.tsx', 'src/starOtherfile.ts', 'src/questionXfile.ts'];+ const literalFiles = ['src/[slug]/page.tsx', 'src/star*file.ts', 'src/question?file.ts', '~/example.ts', 'module:handler.ts',+ ' leading.ts', 'trailing.ts ', ' '];+ const decoys = ['src/s/page.tsx', 'src/l/page.tsx', 'src/starOtherfile.ts', 'src/questionXfile.ts',+ 'leading.ts', 'trailing.ts'];for (const path of [...literalFiles, ...decoys]) {await mkdir(dirname(join(repository, path)), {recursive:true});await writeFile(join(repository, path), 'export const synthetic = 1;\n');@@ -254,6 +256,15 @@ try {const selectedFiles = (await readFile(sourceInput, 'utf8')).trim().split('\n').map(row => JSON.parse(row).path).sort();assert.deepEqual(selectedFiles, [...literalFiles].sort(), 'Real scope selection must preserve literal names and exclude glob-matching decoys');+ const spaces = [' leading.ts', 'trailing.ts ', ' '];+ const completedDirectory = join(root, 'literal-completed');+ const completedInputs: Record<string, string> = {paths: spaces.join('\n'), 'cyber-access-program':'standard'};+ const completedArguments = scanArguments(parseInputs(name => completedInputs[name] ?? '', repository),+ {repository}, completedDirectory);+ const completed = JSON.parse(run([...completedArguments, '--mock'], 0));+ assert.deepEqual(completed.manifest.scan.scope.includePaths, spaces);+ assert.equal(completed.sarifPath, join(completedDirectory, 'exports/results.sarif'));+// Preserve the runner-selected virtualenv through Action preflight and the// pinned CLI's resolver, which otherwise canonicalizes explicit Python paths.const venv = join(root, 'venv');diff --git a/github-action/src/inputs.ts b/github-action/src/inputs.tsindex 7e6335968..1761d6cec 100644--- a/github-action/src/inputs.ts+++ b/github-action/src/inputs.ts@@ -20,14 +20,13 @@ export function parseInputs(read: (name: string) => string, workspace: string) {}return n;};- const list = (name: string) => str(name).split(/\r?\n/).map(v => v.trim()).filter(Boolean);const safeRelative = (name: string, value: string) => {if (value.startsWith('/') || /^[A-Za-z]:/.test(value) || value.includes('\\') || value.split('/').includes('..') || /[\x00-\x1f\x7f]/.test(value))- throw new Error(`${name} must contain literal repository-relative paths, without '..'.`);+ throw new Error(`${name} must contain literal repository-relative paths without '..', backslashes or control characters.`);return value;};// Match the CLI's scope spelling before constructing arguments or checking reports.- const paths = [...new Set(list('paths').map(v =>+ const paths = [...new Set(read('paths').split(/\r?\n/).filter(Boolean).map(v =>safeRelative('paths', v).split('/').filter(part => part && part !== '.').join('/') || '.'))];const scope = choice('scope', ['repository', 'diff'], 'repository');if (scope !== 'repository' && paths.length)diff --git a/github-action/src/main.ts b/github-action/src/main.tsindex ed46d5b74..706df580c 100644--- a/github-action/src/main.ts+++ b/github-action/src/main.ts@@ -66,7 +66,7 @@ export async function runAction(actionRoot: string, overrides: Partial<Dependenccore.setOutput('report-status', 'failed');core.setOutput('sarif-upload-ready', 'false');try {- inputs = parseInputs(name => core.getInput(name), process.env.GITHUB_WORKSPACE ?? '');+ inputs = parseInputs(name => core.getInput(name, {trimWhitespace: false}), process.env.GITHUB_WORKSPACE ?? '');const credentials = scanCredentials(inputs.provider, process.env);const event = await context();target = await resolveTarget(inputs, event);diff --git a/github-action/tests/inputs.test.ts b/github-action/tests/inputs.test.tsindex 119ae0564..787e32ca6 100644--- a/github-action/tests/inputs.test.ts+++ b/github-action/tests/inputs.test.ts@@ -97,7 +97,8 @@ test('path lists accept literal filenames but reject unsafe locations and optionassert.deepEqual(parse({paths:'src/my folder\nlib'}).paths, ['src/my folder','lib']);assert.deepEqual(parse({paths:'src/[slug]/page.tsx\nsrc/star*file.ts\nsrc/question?file.ts'}).paths,['src/[slug]/page.tsx', 'src/star*file.ts', 'src/question?file.ts']);- for (const paths of ['/etc','../other','src/../../other','a\\b','C:/other','x\u0000'])+ assert.deepEqual(parse({paths:' leading\r\n \r\ntrailing \n'}).paths, [' leading', ' ', 'trailing ']);+ for (const paths of ['/etc','../other','src/../../other','C:/other','a\\b','\tlab\t','x\u0000','x\u001b'])assert.throws(() => parse({paths}));});test('CLI path arguments use normalized, deduplicated repository-relative paths', () => {diff --git a/github-action/tests/main.test.ts b/github-action/tests/main.test.tsindex e5a0c8d67..8478f550c 100644--- a/github-action/tests/main.test.ts+++ b/github-action/tests/main.test.ts@@ -635,6 +635,31 @@ test('disabled summary leaves requested artifact upload and scan outcome intact'assert.equal(result.outputs['report-status'], 'ready');});+test('Action path input preserves leading and trailing filename spaces', async t => {+ const app = await harness(t);+ app.setInput('dry-run', 'true');+ const requested = [' leading.txt', ' ', 'trailing.txt '];+ const decoys = ['leading.txt', 'trailing.txt'];+ for (const filename of [...requested, ...decoys])+ await writeFile(join(app.repository, filename), filename);+ app.git('add', '.'); app.git('commit', '-qm', 'Literal filename fixtures');+ process.env.GITHUB_SHA = app.git('rev-parse', 'HEAD');+ app.setInput('paths', requested.join('\r\n'));+ const result = await app.run();+ assert.equal(result.exitCode, 0, result.logs);+ assert.deepEqual(result.args.filter(arg => arg.startsWith('--path=')),+ requested.map(path => '--path=./' + path));+});++for (const path of ['slash\\name.txt', '\tname.txt\t']) test('Action rejects an unsupported scan path before setup: ' + JSON.stringify(path), async t => {+ const app = await harness(t);+ app.setInput('paths', path);+ const result = await app.run();+ assert.equal(result.exitCode, 1);+ assert.equal(result.setups, 0);+ assert.match(result.logs, /backslashes or control characters/u);+});+test('scope conflict fails without runtime setup', async (t) => {const app = await harness(t, 'pr'); app.setInput('paths', 'app.txt'); const result = await app.run();assert.equal(result.exitCode, 1); assert.equal(result.setups, 0); assert.match(result.logs, /paths cannot be combined/u);