Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions open-sse/executors/gemini-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ const GEMINI_URL = "https://gemini.google.com/app";
*/
export function isMissingBrowserExecutable(message: string): boolean {
if (!message) return false;
return /executable doesn't exist|executablenotfound|playwright install|chromium.*download/i.test(
message
const lower = message.toLowerCase();
return (
lower.includes("executable doesn't exist") ||
lower.includes("executablenotfound") ||
lower.includes("playwright install") ||
(lower.includes("chromium") && lower.includes("download"))
);
}
const GEMINI_USER_AGENT =
Expand Down
3 changes: 2 additions & 1 deletion open-sse/services/conversationTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@

// ── Fingerprint (identity, O(1) regardless of history size) ─────────────

// Content fingerprint for conversation identity, not a password/credential hash.
function hashHex(text: string): string {
return createHash("sha256").update(text).digest("hex");
return createHash("sha256").update(text).digest("hex"); // codeql[js/insufficient-password-hash]
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

function extractToolNames(body: JsonRecord | null | undefined): string[] {
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/v1/models/catalogCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
/** Fingerprint an API key for the catalog memo Map. Never store the raw secret. */
export function fingerprintCatalogAuthKey(apiKey: string): string {
if (!apiKey) return "";
return createHash("sha256").update(apiKey).digest("hex").slice(0, 16);
// Memo-map cache key fingerprint, not a password/credential hash.
return createHash("sha256").update(apiKey).digest("hex").slice(0, 16); // codeql[js/insufficient-password-hash]
}

export type CachedCatalog = {
Expand Down
5 changes: 4 additions & 1 deletion src/mitm/handlers/antigravity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ export class AntigravityHandler extends MitmHandlerBase {
await this.pipeSSE(upstream, res, (chunk) => {
let chunkStr = chunk.toString();
for (const [lower, capitalized] of Object.entries(TOOL_RENAME_MAP)) {
chunkStr = chunkStr.replace(new RegExp(`"name"\s*:\s*"${lower}"`, 'g'), `"name":"${capitalized}"`);
chunkStr = chunkStr.replace(
new RegExp(`"name"\\s*:\\s*"${lower}"`, "g"),
`"name":"${capitalized}"`
);
}
collected += chunkStr;
});
Expand Down
15 changes: 9 additions & 6 deletions src/shared/middleware/chatBodyAdmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,21 @@
const authHeader = request.headers.get("authorization") || "";
const bearerMatch = /^bearer\s+(\S+)$/i.exec(authHeader.trim());
if (bearerMatch) {
// codeql[js/insufficient-password-hash]
return "key_" + createHash("sha256").update(bearerMatch[1]).digest("hex").slice(0, 16); // nosemgrep: insufficient-password-hash
// Fingerprint for the admission-budget bucket key, not a password/credential hash.
// nosemgrep: insufficient-password-hash
return "key_" + createHash("sha256").update(bearerMatch[1]).digest("hex").slice(0, 16); // codeql[js/insufficient-password-hash]
}
const xApiKey = request.headers.get("x-api-key") || "";
if (xApiKey.trim().length > 0) {
// codeql[js/insufficient-password-hash]
return "key_" + createHash("sha256").update(xApiKey.trim()).digest("hex").slice(0, 16); // nosemgrep: insufficient-password-hash
// Fingerprint for the admission-budget bucket key, not a password/credential hash.
// nosemgrep: insufficient-password-hash
return "key_" + createHash("sha256").update(xApiKey.trim()).digest("hex").slice(0, 16); // codeql[js/insufficient-password-hash]
}
const xGoogApiKey = request.headers.get("x-goog-api-key") || "";
if (xGoogApiKey.trim().length > 0) {
// codeql[js/insufficient-password-hash]
return "key_" + createHash("sha256").update(xGoogApiKey.trim()).digest("hex").slice(0, 16); // nosemgrep: insufficient-password-hash
// Fingerprint for the admission-budget bucket key, not a password/credential hash.
// nosemgrep: insufficient-password-hash
return "key_" + createHash("sha256").update(xGoogApiKey.trim()).digest("hex").slice(0, 16); // codeql[js/insufficient-password-hash]
}
return "anonymous";
}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/cloudflare-playground-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ test("cloudflare-playground is present in NOAUTH_PROVIDERS (noAuth category)", (
assert.equal(p.hasFree, true);
assert.ok(typeof p.freeNote === "string" && (p.freeNote as string).length > 0);
assert.ok(typeof p.authHint === "string" && (p.authHint as string).length > 0);
assert.ok(typeof p.website === "string" && (p.website as string).includes("cloudflare.com"));
assert.ok(typeof p.website === "string");
assert.ok(new URL(p.website as string).hostname.endsWith(".cloudflare.com"));
});

test("cloudflare-playground registry entry has no-auth shape and curated models", () => {
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/qwen-token-plan-console-site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ test("an Alibaba console cookie resolves to the Model Studio console", () => {
const site = resolveConsoleSite("cna=x; login_aliyunid_ticket=abc; aui=1", undefined);
assert.equal(site.consoleSite, "ALIYUN");
assert.equal(site.domain, "modelstudio.console.alibabacloud.com");
assert.ok(site.gatewayHost.includes("bailian-singapore-cs.alibabacloud.com"));
assert.ok(site.origin.includes("modelstudio.console.alibabacloud.com"));
assert.equal(new URL(site.gatewayHost).hostname, "bailian-singapore-cs.alibabacloud.com");
assert.equal(new URL(site.origin).hostname, "modelstudio.console.alibabacloud.com");
});

test("a QwenCloud console cookie resolves to the QwenCloud console", () => {
const site = resolveConsoleSite("cna=x; login_qwencloud_ticket=abc", undefined);
assert.equal(site.consoleSite, "QWENCLOUD");
assert.equal(site.domain, "home.qwencloud.com");
assert.ok(site.gatewayHost.includes("cs-data.qwencloud.com"));
assert.equal(new URL(site.gatewayHost).hostname, "cs-data.qwencloud.com");
});

test("the provider decides when the cookie carries no console marker", () => {
Expand Down Expand Up @@ -93,12 +93,13 @@ test("fetch sends the Alibaba console identity for an aliyun cookie", async () =

const usageCall = calls.find((c) => c.url.includes("%2Fusage"));
assert.ok(usageCall, "usage call missing");
assert.ok(
usageCall.url.includes("bailian-singapore-cs.alibabacloud.com"),
assert.equal(
new URL(usageCall.url).hostname,
"bailian-singapore-cs.alibabacloud.com",
`wrong gateway host: ${usageCall.url}`
);
const headers = usageCall.init?.headers as Record<string, string>;
assert.ok(String(headers.Referer).includes("modelstudio.console.alibabacloud.com"));
assert.equal(new URL(String(headers.Referer)).hostname, "modelstudio.console.alibabacloud.com");
const params = JSON.parse(
new URLSearchParams(String(usageCall.init?.body)).get("params") ?? "{}"
);
Expand Down
Loading