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

fix(config): URL-encode generated schema references (#981)

Dipesh Babud2111ba6e231
diff --git a/sdk/typescript/src/project-config.ts b/sdk/typescript/src/project-config.ts
index 97f369314..46850489d 100644
--- a/sdk/typescript/src/project-config.ts
+++ b/sdk/typescript/src/project-config.ts
@@ -186,9 +186,9 @@ export function projectConfigStarter(
);
const schema = isAbsolute(relativeSchema)
? pathToFileURL(schemaPath).href
- : `${relativeSchema.startsWith(".") ? "" : "./"}${relativeSchema
- .split(sep)
- .join("/")}`;
+ : `${relativeSchema.startsWith(".") ? "" : "./"}${encodeURI(
+ relativeSchema.split(sep).join("/"),
+ ).replace(/[#?]/gu, encodeURIComponent)}`;
if (projectConfigExtension(path) === ".json")
return `${JSON.stringify({ $schema: schema }, null, 2)}\n`;
return [
diff --git a/sdk/typescript/tests-ts/cli-project-config.test.ts b/sdk/typescript/tests-ts/cli-project-config.test.ts
index f004016dd..d744e4ca1 100644
--- a/sdk/typescript/tests-ts/cli-project-config.test.ts
+++ b/sdk/typescript/tests-ts/cli-project-config.test.ts
@@ -1,6 +1,7 @@
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
import { execFileSync } from "node:child_process";
import { join } from "node:path";
+import { pathToFileURL } from "node:url";
import { afterEach, expect, test, mock } from "bun:test";
import { ScanCostTracker } from "../src/cost.js";
import type { ScanTokenUsage } from "../src/index.js";
@@ -75,6 +76,46 @@ test.each([
},
);
+test.each(["yaml", "json"])(
+ "init preserves URI-sensitive directory names in the %s schema reference",
+ async (extension) => {
+ const input = await fixture({});
+ const workspace = join(
+ input.root,
+ process.platform === "win32"
+ ? "project #draft %25"
+ : 'project #draft %25 ?review: "quoted"',
+ );
+ const schemaDirectory = join(
+ workspace,
+ "node_modules",
+ "@openai",
+ "codex-security",
+ "schemas",
+ );
+ await mkdir(schemaDirectory, { recursive: true });
+ const schema = join(schemaDirectory, "project-config.schema.json");
+ const contents = '{"type":"object"}\n';
+ await writeFile(schema, contents);
+ const path = join(input.configDirectory, `starter.${extension}`);
+
+ expect(
+ await runCapturedCli(
+ main,
+ ["init", path, "--json"],
+ dependencies({ currentDirectory: workspace }),
+ ),
+ ).toBe(0);
+
+ const selected = await readProjectConfig(path);
+ const reference = new URL(selected.input.$schema!, pathToFileURL(path));
+ expect(reference.hash).toBe("");
+ expect(reference.search).toBe("");
+ expect(await readFile(reference, "utf8")).toBe(contents);
+ expect(reference.href).toBe(pathToFileURL(schema).href);
+ },
+);
+
test("info resolves a config and its sources without a target, prompt reads, or runtime", async () => {
const input = await fixture({
scan: {