Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

test(security): fix CodeQL #689 — Kimi Web URL host substring sanitization (#6048)

Diego Rodrigues de Sa e Souza5bc11f4d0e4b
diff --git a/tests/unit/web-cookie-providers-new.test.ts b/tests/unit/web-cookie-providers-new.test.ts
index 1a9d340484..2cc59bcd23 100644
--- a/tests/unit/web-cookie-providers-new.test.ts
+++ b/tests/unit/web-cookie-providers-new.test.ts
@@ -679,8 +679,13 @@ test("Kimi Web: targets www.kimi.com (international)", async () => {
credentials: { apiKey: "kimi-auth=eyJ.eyJzdWI.signature" },
});
assert.ok(result.response instanceof Response);
- assert.ok(result.url.includes("www.kimi.com"), `got ${result.url}`);
- assert.ok(!result.url.includes("moonshot.cn"));
+ // Parse the URL and assert on the exact hostname rather than a substring
+ // match — `includes("www.kimi.com")` would also accept a hostile host like
+ // `www.kimi.com.evil.net` or `evil.net/?x=www.kimi.com` (CodeQL
+ // js/incomplete-url-substring-sanitization).
+ const host = new URL(result.url).hostname;
+ assert.equal(host, "www.kimi.com", `got ${result.url}`);
+ assert.notEqual(host, "www.moonshot.cn", `got ${result.url}`);
} finally {
restore.restore();
}