Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codex/injected-marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function tomlStringPattern(key: string): RegExp {
// A basic string escapes backslashes, so a Windows path is stored doubled; reading
// the raw bytes back returned a path that matched nothing on disk and made the
// journal's recorded catalog path un-restorable (#1798).
return new RegExp(`^\\s*${keyToken}\\s*=\\s*("(?:\\\\.|[^"])*"|'[^']*')\\s*(?:#.*)?$`);
return new RegExp(`^\\s*${keyToken}\\s*=\\s*("(?:\\\\.|[^"\\\\])*"|'[^']*')\\s*(?:#.*)?$`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Harden the remaining root TOML matcher

When config.toml contains an unterminated model_catalog_json basic string followed by a backslash run, this change protects only rootTomlString and providerTableString; readRootTomlString in src/codex/paths.ts:136 retains the same overlapping (?:\\.|[^"])* alternatives. The catalog and routing paths call that helper, so even a few dozen backslashes still cause exponential matching and can stall the proxy. Apply the same backslash exclusion to that matcher and cover the exported helper in the regression test.

Useful? React with 👍 / 👎.

}

export function rootTomlString(content: string, key: string): string | null {
Expand Down
17 changes: 17 additions & 0 deletions tests/codex-injected-marker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from "bun:test";
import { providerTableString, rootTomlString } from "../src/codex/injected-marker";

describe("Codex injected marker TOML strings", () => {
test("decodes escaped basic strings", () => {
expect(rootTomlString('model_catalog_json = "C:\\\\Users\\\\ocx\\\\catalog.json"', "model_catalog_json"))
.toBe("C:\\Users\\ocx\\catalog.json");
});

test("rejects unterminated basic strings with long backslash runs", () => {
const malformed = `model_provider = "${"\\".repeat(10_000)}`;
expect(rootTomlString(malformed, "model_provider")).toBeNull();

const providerConfig = `[model_providers.opencodex]\nbase_url = "${"\\".repeat(10_000)}`;
expect(providerTableString(providerConfig, "opencodex", "base_url")).toBeNull();
});
});
Loading