From 7c870733a10497bf14f0789b362578446e99f3b3 Mon Sep 17 00:00:00 2001 From: lloydchang Date: Wed, 11 Dec 2024 02:18:04 -0800 Subject: [PATCH] Fix code scanning alert no. 1: Incomplete URL substring sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/api/providers/openai.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 57cab17..3912fa4 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -17,7 +17,8 @@ export class OpenAiHandler implements ApiHandler { constructor(options: ApiHandlerOptions) { this.options = options // Azure API shape slightly differs from the core API shape: https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai - if (this.options.openAiBaseUrl?.toLowerCase().includes("azure.com")) { + const urlHost = new URL(this.options.openAiBaseUrl).host; + if (urlHost === "azure.com" || urlHost.endsWith(".azure.com")) { this.client = new AzureOpenAI({ baseURL: this.options.openAiBaseUrl, apiKey: this.options.openAiApiKey,