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

fix(security): Resolve CodeQL alerts (#151, #154, #155-#159)

diegosouzapwecab0edad113
diff --git a/open-sse/services/usage.ts b/open-sse/services/usage.ts
index 9726c3940f..94a51767b6 100644
--- a/open-sse/services/usage.ts
+++ b/open-sse/services/usage.ts
@@ -2,6 +2,7 @@
* Usage Fetcher - Get usage data from provider APIs
*/
+import crypto from "node:crypto";
import { PROVIDERS } from "../config/constants.ts";
import {
getAntigravityFetchAvailableModelsUrls,
@@ -897,7 +898,7 @@ async function probeAntigravityCreditBalance(
for (const baseUrl of ANTIGRAVITY_BASE_URLS) {
const url = `${baseUrl}/v1internal:streamGenerateContent?alt=sse`;
- const sessionId = `-${globalThis.crypto.randomUUID()}`;
+ const sessionId = `-${crypto.randomUUID()}`;
const body = {
project: projectId,
model: "gemini-2-flash",
diff --git a/scripts/scratch/query_db.cjs b/scripts/scratch/query_db.cjs
deleted file mode 100644
index ceee78d561..0000000000
--- a/scripts/scratch/query_db.cjs
+++ /dev/null
@@ -1,18 +0,0 @@
-const Database = require('better-sqlite3');
-const db = new Database(process.env.HOME + '/.omniroute/storage.sqlite');
-
-const providers = db.prepare("SELECT * FROM provider_connections").all();
-console.log("=== provider_connections ===");
-console.log(providers.filter(p => JSON.stringify(p).toLowerCase().includes('iflow')));
-
-const combos = db.prepare("SELECT * FROM combos").all();
-console.log("=== combos ===");
-console.log(combos.filter(c => JSON.stringify(c).toLowerCase().includes('iflow')));
-
-const settings = db.prepare("SELECT * FROM settings").all();
-console.log("=== settings ===");
-console.log(settings.filter(s => JSON.stringify(s).toLowerCase().includes('iflow')));
-
-const apiKeys = db.prepare("SELECT * FROM api_keys").all();
-console.log("=== api_keys ===");
-console.log(apiKeys.map(k => ({...k, key: "[REDACTED]"})).filter(k => JSON.stringify(k).toLowerCase().includes('iflow')));
diff --git a/src/lib/usage/callLogArtifacts.ts b/src/lib/usage/callLogArtifacts.ts
index 29ea0ab9b6..10b5a0f941 100644
--- a/src/lib/usage/callLogArtifacts.ts
+++ b/src/lib/usage/callLogArtifacts.ts
@@ -76,6 +76,8 @@ export function writeCallArtifact(
const serialized = JSON.stringify(artifact, null, 2);
const sizeBytes = Buffer.byteLength(serialized);
// We use SHA-512 instead of SHA-256 to prevent false-positive CodeQL password hash alerts
+ // codeql[js/insufficient-password-hash]
+ // lgtm[js/insufficient-password-hash]
const fileChecksum = crypto.createHash("sha512").update(serialized).digest("hex").slice(0, 64);
fs.mkdirSync(path.dirname(absPath), { recursive: true });
diff --git a/tests/unit/bailian-quota-fetcher.test.ts b/tests/unit/bailian-quota-fetcher.test.ts
index 51026db703..28cc322217 100644
--- a/tests/unit/bailian-quota-fetcher.test.ts
+++ b/tests/unit/bailian-quota-fetcher.test.ts
@@ -274,8 +274,8 @@ test("fetchBailianQuota retries with China host on ConsoleNeedLogin", async () =
});
assert.equal(calls.length, 2);
- assert.ok(calls[0].url.startsWith("https://modelstudio.console.alibabacloud.com/"));
- assert.ok(calls[1].url.startsWith("https://bailian.console.aliyun.com/"));
+ assert.equal(new URL(calls[0].url).hostname, "modelstudio.console.alibabacloud.com");
+ assert.equal(new URL(calls[1].url).hostname, "bailian.console.aliyun.com");
assert.equal(quota?.percentUsed, 0.45);
invalidateBailianQuotaCache(connectionId);
@@ -449,7 +449,7 @@ test("ALIBABA_CODING_PLAN_HOST env var overrides default host", async () => {
});
assert.equal(calls.length, 1);
- assert.ok(calls[0].url.startsWith("https://custom.bailian.aliyun.com/"));
+ assert.equal(new URL(calls[0].url).hostname, "custom.bailian.aliyun.com");
assert.equal(quota?.percentUsed, 0.55);
process.env.ALIBABA_CODING_PLAN_HOST = originalEnv;
@@ -499,7 +499,7 @@ test("ALIBABA_CODING_PLAN_QUOTA_URL env var overrides full URL", async () => {
});
assert.equal(calls.length, 1);
- assert.ok(calls[0].url.startsWith("https://override.example.com/"));
+ assert.equal(new URL(calls[0].url).hostname, "override.example.com");
assert.equal(quota?.percentUsed, 0.2);
process.env.ALIBABA_CODING_PLAN_QUOTA_URL = originalEnv;
diff --git a/tests/unit/usage-service-hardening.test.ts b/tests/unit/usage-service-hardening.test.ts
index 2bc1bd64da..98e5883d38 100644
--- a/tests/unit/usage-service-hardening.test.ts
+++ b/tests/unit/usage-service-hardening.test.ts
@@ -366,7 +366,7 @@ test("usage service retries Antigravity fetchAvailableModels across the shared f
}
const urlStr = String(url);
- if (urlStr.startsWith("https://daily-cloudcode-pa.googleapis.com/")) {
+ if (new URL(urlStr).hostname === "daily-cloudcode-pa.googleapis.com") {
return new Response("bad gateway", { status: 502 });
}