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(sdk): preserve CODEOWNERS token grammar (#1787)
Michael D'Angeloda20c3dd3633
diff --git a/sdk/typescript/src/codeowners.ts b/sdk/typescript/src/codeowners.tsindex 4c3f10bc2..675928a69 100644--- a/sdk/typescript/src/codeowners.ts+++ b/sdk/typescript/src/codeowners.ts@@ -14,7 +14,7 @@ export interface CodeownersRule {export function parseCodeowners(source: string): CodeownersRule[] {const rules: CodeownersRule[] = [];for (const [index, line] of source.split(/\r?\n/u).entries()) {- const value = line.trim();+ const value = line.trimStart();if (!value || value.startsWith("#")) continue;const token = /^(?:\\.|[^\s])+/u.exec(value)![0];const matches = codeownersPattern(token);@@ -28,7 +28,7 @@ export function parseCodeowners(source: string): CodeownersRule[] {const owners: CodeownerIdentity[] = [];let valid = true;for (const handle of handles) {- if (/^@[a-z\d](?:[a-z\d_-]*[a-z\d])?(?:\/[a-z\d_.-]+)?$/iu.test(handle)) {+ if (/^@[a-z\d](?:[a-z\d_-]*[a-z\d])?(?:\/[a-z\d_.-]+)?$/i.test(handle)) {owners.push(handle.includes("/")? { kind: "group", provider: "github", handle: handle.slice(1) }diff --git a/sdk/typescript/tests-ts/codeowners.test.ts b/sdk/typescript/tests-ts/codeowners.test.tsindex 5fd12d86e..90ebf25ca 100644--- a/sdk/typescript/tests-ts/codeowners.test.ts+++ b/sdk/typescript/tests-ts/codeowners.test.ts@@ -90,6 +90,55 @@ test("uses the last matching rule and preserves all owners and ownerless overridexpect(codeownersForPath(rules, "apps/generated/api.ts")?.owners).toEqual([]);});+test.each([" ", "\t"])(+ "preserves escaped trailing whitespace %j in ownerless rules",+ (whitespace) => {+ const pattern = `/file\\${whitespace}`;+ const rule = ` ${pattern}`;+ const rules = parseCodeowners(`* @default\n${rule}\n`);+ expect(codeownersForPath(rules, `file${whitespace}`)).toMatchObject({+ pattern,+ line: 2,+ rule,+ owners: [],+ });+ for (const path of ["file", "file\\"]) {+ expect(codeownersForPath(rules, path)?.owners).toEqual([+ { kind: "person", provider: "github", handle: "default" },+ ]);+ }+ },+);++test("rejects Unicode case-fold aliases in GitHub handles under Node", async () => {+ const module = new URL("../src/codeowners.ts", import.meta.url).href;+ const { stdout } = await promisify(execFile)("node", [+ "--experimental-strip-types",+ "--input-type=module",+ "--eval",+ `+ import { parseCodeowners, codeownersForPath } from ${JSON.stringify(module)};+ const owners = [+ "@ſam", "@Kai", "@alſ", "@alK", "@org/ſquad", "@org/Kit",+ "@Sam", "@Kai", "@alex_corp", "@Org/Team_1.test-x", "é@example.test",+ ];+ console.log(JSON.stringify(owners.map(owner =>+ codeownersForPath(parseCodeowners("* @default\\n/é.ts " + owner), "é.ts")?.owners+ )));+ `,+ ]);+ expect(JSON.parse(stdout)).toEqual([+ ...Array.from({ length: 6 }, () => [+ { kind: "person", provider: "github", handle: "default" },+ ]),+ [{ kind: "person", provider: "github", handle: "Sam" }],+ [{ kind: "person", provider: "github", handle: "Kai" }],+ [{ kind: "person", provider: "github", handle: "alex_corp" }],+ [{ kind: "group", provider: "github", handle: "Org/Team_1.test-x" }],+ [{ kind: "person", email: "é@example.test" }],+ ]);+});+test.each(["@alex_corp", "@example/app-team @alex_corp"])("preserves a rule containing the managed user: %s",(owners) => {