mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 13:42:09 +03:00
- Replace polynomial regex /\/+$/ with loop-based stripTrailingSlashes() across 8 enterprise provider configs (azure-openai, azureAi, bedrock, datarobot, oci, sap, watsonx, audioSpeech) — fixes js/polynomial-redos - Add prototype-pollution denylist guard in usageHistory.ts to reject __proto__/constructor/prototype as model keys — fixes js/prototype-polluting-assignment (#167, #168) - Suppress 3 false-positive js/insufficient-password-hash alerts in chatgpt-web.ts and builtins.ts where SHA-256 is used for cache-key derivation, not password storage (#176, #177, #178) - Add stripTrailingSlashes unit tests with ReDoS regression check
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { stripTrailingSlashes } from "../utils/urlSanitize.ts";
|
|
|
|
export const AZURE_AI_DEFAULT_BASE_URL = "https://example-resource.services.ai.azure.com/openai/v1";
|
|
|
|
function normalizeBaseUrl(value: string | null | undefined): string {
|
|
return stripTrailingSlashes((value || "").trim());
|
|
}
|
|
|
|
export function normalizeAzureAiBaseUrl(value: string | null | undefined): string {
|
|
const normalized = normalizeBaseUrl(value || AZURE_AI_DEFAULT_BASE_URL);
|
|
if (!normalized) return AZURE_AI_DEFAULT_BASE_URL;
|
|
|
|
if (
|
|
normalized.endsWith("/chat/completions") ||
|
|
normalized.endsWith("/responses") ||
|
|
normalized.endsWith("/models")
|
|
) {
|
|
return normalized.replace(/\/(?:chat\/completions|responses|models)$/i, "");
|
|
}
|
|
|
|
if (normalized.endsWith("/openai/v1") || normalized.endsWith("/v1")) {
|
|
return normalized;
|
|
}
|
|
|
|
if (normalized.endsWith("/openai")) {
|
|
return `${normalized}/v1`;
|
|
}
|
|
|
|
const parsed = new URL(normalized);
|
|
if (
|
|
parsed.hostname.endsWith(".services.ai.azure.com") ||
|
|
parsed.hostname.endsWith(".openai.azure.com")
|
|
) {
|
|
if (!parsed.pathname || parsed.pathname === "/") {
|
|
parsed.pathname = "/openai/v1";
|
|
return stripTrailingSlashes(parsed.toString());
|
|
}
|
|
}
|
|
|
|
return normalized;
|
|
}
|
|
|
|
export function buildAzureAiChatUrl(
|
|
value: string | null | undefined,
|
|
apiType: "chat" | "responses" = "chat"
|
|
): string {
|
|
const normalized = normalizeAzureAiBaseUrl(value);
|
|
return `${normalized}/${apiType === "responses" ? "responses" : "chat/completions"}`;
|
|
}
|
|
|
|
export function buildAzureAiModelsUrl(value: string | null | undefined): string {
|
|
return `${normalizeAzureAiBaseUrl(value)}/models`;
|
|
}
|