mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-21 15:05:56 +00:00
Compare commits
3 Commits
docs/agent
...
fix/codeql
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6441b5b6f3 | ||
|
|
b03f265540 | ||
|
|
909af20270 |
1
changelog.d/fixes/20823-codeql-redos-model-ids.md
Normal file
1
changelog.d/fixes/20823-codeql-redos-model-ids.md
Normal file
@@ -0,0 +1 @@
|
||||
- **fix(security):** GitHub Copilot Responses-only inference, model display names and the Context7 library id check use linear regexes, so a long crafted model or library id no longer blocks the event loop for seconds (CodeQL js/polynomial-redos #1325, #1324, #1296)
|
||||
197
tests/unit/model-id-regex-redos.test.ts
Normal file
197
tests/unit/model-id-regex-redos.test.ts
Normal file
@@ -0,0 +1,197 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// CodeQL js/polynomial-redos #1325, #1324, #1296: three model/library id regexes backtracked in
|
||||
// O(n^2) on crafted ids. Each id reaches its regex without a length cap (a client model id
|
||||
// "gh/<id>", an upstream /v1/models id, a raw Context7 search item id).
|
||||
//
|
||||
// Two checks per function:
|
||||
// - a 50k-char pathological id returns fast (measured on the exported function);
|
||||
// - a truth table generated by running the pre-fix functions (git show of the base) stays the
|
||||
// same, so the linear rewrites keep the exact accept/reject behavior.
|
||||
|
||||
const { inferGithubUnsyncedTargetFormat } =
|
||||
await import("../../src/sse/services/githubResponsesFallback.ts");
|
||||
const { modelDisplayName } = await import("../../src/shared/utils/modelDisplayName.ts");
|
||||
const { isValidContext7LibraryId } = await import("../../open-sse/executors/context7-fetch.ts");
|
||||
|
||||
const PATHOLOGICAL_LENGTH = 50_000;
|
||||
const BUDGET_MS = 200;
|
||||
|
||||
function elapsedMs(fn: () => unknown): number {
|
||||
const start = performance.now();
|
||||
fn();
|
||||
return performance.now() - start;
|
||||
}
|
||||
|
||||
const GITHUB_TABLE: Array<[string, string, string | null]> = [
|
||||
["gh", "gpt-6", "openai-responses"],
|
||||
["gh", "gpt-6.1-sol", "openai-responses"],
|
||||
["gh", "GPT-7-mini", "openai-responses"],
|
||||
["gh", "gpt-9", "openai-responses"],
|
||||
["gh", "gpt-60", "openai-responses"],
|
||||
["gh", "gpt-5.5", "openai-responses"],
|
||||
["gh", "gpt-5.9-codex", "openai-responses"],
|
||||
["gh", "GPT-5.5", "openai-responses"],
|
||||
["gh", "gpt-5.4", null],
|
||||
["gh", "gpt-5", null],
|
||||
["gh", "gpt-5.10", null],
|
||||
["gh", "gpt-5-codex", "openai-responses"],
|
||||
["gh", "gpt-4o", null],
|
||||
["gh", "gpt-4.1", null],
|
||||
["gh", "gpt-10", null],
|
||||
["gh", "gpt-", null],
|
||||
["gh", "gpt_6", null],
|
||||
["gh", "agpt-6", null],
|
||||
["gh", " gpt-6", null],
|
||||
["gh", "gpt-6 ", "openai-responses"],
|
||||
["gh", "codex-mini", "openai-responses"],
|
||||
["gh", "my-CODEX", "openai-responses"],
|
||||
["gh", "codex", "openai-responses"],
|
||||
["gh", "Codex-Max", "openai-responses"],
|
||||
["gh", "code-x", null],
|
||||
["gh", "claude-codex", null],
|
||||
["gh", "gemini-codex", null],
|
||||
["gh", "gpt-6-claude", null],
|
||||
["gh", "o3", null],
|
||||
["gh", "", null],
|
||||
["gh", "gpt-6\n", null],
|
||||
["gh", "gpt-6\nx", null],
|
||||
["gh", "\ngpt-6", null],
|
||||
["gh", "codex\r", null],
|
||||
["gh", "gpt-6\u2028x", null],
|
||||
["gh", "x\u2029codex", null],
|
||||
["gh", "codex\t", "openai-responses"],
|
||||
["gh", "gpt-6\u0085", "openai-responses"],
|
||||
["gh", "gh/gpt-6", "openai-responses"],
|
||||
["gh", "github/gpt-6.1", "openai-responses"],
|
||||
["gh", "GH/codex", "openai-responses"],
|
||||
["gh", "ghe-copilot/gpt-5.5", "openai-responses"],
|
||||
["github", "gpt-6", "openai-responses"],
|
||||
["ghe-copilot", "gpt-5.6-codex", "openai-responses"],
|
||||
["github", "claude-opus-5-5", null],
|
||||
["openai", "gpt-6", null],
|
||||
["codex", "codex-mini", null],
|
||||
["gh", "openai/gpt-6", null],
|
||||
["gh", "x/codex", "openai-responses"],
|
||||
];
|
||||
|
||||
const DISPLAY_TABLE: Array<[string, string]> = [
|
||||
["deepseek-v4.1-flash", "DeepSeek V4.1 Flash"],
|
||||
["gpt-v2", "GPT-V2"],
|
||||
["gpt-V2.6", "GPT-V2.6"],
|
||||
["gpt-v", "GPT V"],
|
||||
["gpt-v.", "GPT V."],
|
||||
["gpt-v.1", "GPT V.1"],
|
||||
["gpt-v1.", "GPT-V1."],
|
||||
["gpt-v1..2", "GPT-V1..2"],
|
||||
["gpt-v1x", "GPT V1x"],
|
||||
["gpt-vx1", "GPT Vx1"],
|
||||
["gpt-v12.3.4", "GPT-V12.3.4"],
|
||||
["gpt-v1-turbo", "GPT-V1 Turbo"],
|
||||
["gpt-vv1", "GPT Vv1"],
|
||||
["gpt-4-v1", "GPT-4 V1"],
|
||||
["foo-v2.6-bar", "Foo V2.6 Bar"],
|
||||
["v1", "V1"],
|
||||
["v", "V"],
|
||||
["mistral-v0.1", "Mistral V0.1"],
|
||||
["model-V2.6", "Model V2.6"],
|
||||
["gpt-6.1-sol", "GPT-6.1 Sol"],
|
||||
["claude-opus-5-5", "Claude Opus 5.5"],
|
||||
["glm-5.3-flash", "GLM 5.3 Flash"],
|
||||
["claude-3-5-sonnet-20241022", "Claude 3.5 Sonnet"],
|
||||
["qwen3.8", "Qwen 3.8"],
|
||||
["cmc/deepseek/deepseek-v4.1-flash", "DeepSeek V4.1 Flash"],
|
||||
["gpt-v1 x", "GPT-V1 X"],
|
||||
["", ""],
|
||||
];
|
||||
|
||||
const CONTEXT7_TABLE: Array<[string, boolean]> = [
|
||||
["/vercel/next.js", true],
|
||||
["/upstash/context7", true],
|
||||
["/a/b", true],
|
||||
["/a.b/c-d_e", true],
|
||||
["/a/b/c", false],
|
||||
["//a", false],
|
||||
["/a//b", false],
|
||||
["/a/", false],
|
||||
["a/b", false],
|
||||
["/a/b/", false],
|
||||
["/a/b\n", false],
|
||||
["/a\n/b", false],
|
||||
["/\n/b", false],
|
||||
["/a/\n", false],
|
||||
["/a/b\r", false],
|
||||
["/a/b\u2028", false],
|
||||
["/a\u2029/b", false],
|
||||
["/./b", false],
|
||||
["/a/..", false],
|
||||
["/a/b..c", false],
|
||||
["/-a/b", false],
|
||||
["/a/b.", false],
|
||||
["/a/.b", false],
|
||||
["", false],
|
||||
["/", false],
|
||||
["//", false],
|
||||
["///", false],
|
||||
["/a", false],
|
||||
["/a/b c", false],
|
||||
["/A1/B2", true],
|
||||
["/_a/b", false],
|
||||
];
|
||||
|
||||
test("#1325 GitHub Responses-only inference is linear on a 'codex' run ending in a line break", () => {
|
||||
const id = "codex".repeat(PATHOLOGICAL_LENGTH / 5) + "\n!";
|
||||
let result: unknown = "unset";
|
||||
const ms = elapsedMs(() => {
|
||||
result = inferGithubUnsyncedTargetFormat("gh", id);
|
||||
});
|
||||
assert.equal(result, undefined);
|
||||
assert.ok(ms < BUDGET_MS, `took ${ms.toFixed(1)}ms`);
|
||||
});
|
||||
|
||||
test("#1325 GitHub Responses-only inference keeps the pre-fix truth table", () => {
|
||||
for (const [providerId, modelId, expected] of GITHUB_TABLE) {
|
||||
assert.equal(
|
||||
inferGithubUnsyncedTargetFormat(providerId, modelId) ?? null,
|
||||
expected,
|
||||
JSON.stringify([providerId, modelId])
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("#1324 model display name is linear on a long version-marker token", () => {
|
||||
const id = "gpt-v" + "0".repeat(PATHOLOGICAL_LENGTH - 6) + "x";
|
||||
let result = "";
|
||||
const ms = elapsedMs(() => {
|
||||
result = modelDisplayName(id);
|
||||
});
|
||||
assert.ok(result.startsWith("GPT V0"));
|
||||
assert.ok(ms < BUDGET_MS, `took ${ms.toFixed(1)}ms`);
|
||||
});
|
||||
|
||||
test("#1324 model display name keeps the pre-fix truth table", () => {
|
||||
for (const [id, expected] of DISPLAY_TABLE) {
|
||||
assert.equal(modelDisplayName(id), expected, JSON.stringify(id));
|
||||
}
|
||||
});
|
||||
|
||||
test("#1296 Context7 library id check is linear on a run of slashes ending in a line break", () => {
|
||||
for (const id of [
|
||||
"/".repeat(PATHOLOGICAL_LENGTH - 1) + "\n",
|
||||
"/a".repeat(PATHOLOGICAL_LENGTH / 2 - 1) + "\n",
|
||||
]) {
|
||||
let result: unknown = "unset";
|
||||
const ms = elapsedMs(() => {
|
||||
result = isValidContext7LibraryId(id);
|
||||
});
|
||||
assert.equal(result, false);
|
||||
assert.ok(ms < BUDGET_MS, `took ${ms.toFixed(1)}ms`);
|
||||
}
|
||||
});
|
||||
|
||||
test("#1296 Context7 library id check keeps the pre-fix truth table", () => {
|
||||
for (const [id, expected] of CONTEXT7_TABLE) {
|
||||
assert.equal(isValidContext7LibraryId(id), expected, JSON.stringify(id));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user