@@ -45,9 +45,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
4545 const isAzureOpenAi = ! ! (
4646 this . options . azureApiVersion ||
4747 options . openAiUseAzure ||
48- ( urlHost &&
49- ( urlHost . includes ( "azure.com" ) || urlHost . includes ( "azure.us" ) ) &&
50- ! this . options . openAiModelId ?. toLowerCase ( ) . includes ( "deepseek" ) )
48+ ( urlHost && this . _isAzureHost ( urlHost ) && ! this . options . openAiModelId ?. toLowerCase ( ) . includes ( "deepseek" ) )
5149 )
5250
5351 const headers = {
@@ -97,7 +95,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
9795 const enabledLegacyFormat = this . options . openAiLegacyFormat ?? false
9896 const isAzureAiInference = this . _isAzureAiInference ( modelUrl )
9997 const deepseekReasoner = modelId . includes ( "deepseek-reasoner" ) || enabledR1Format
100- const ark = modelUrl . includes ( ".volces.com" )
98+ const ark = this . _isVolcesHost ( modelUrl )
10199
102100 // Handle reasoning models (o1, o3, o4) separately
103101 // These models don't support system messages in the traditional way
@@ -337,7 +335,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
337335 const isAzureOpenAi = ! ! (
338336 this . options . azureApiVersion ||
339337 this . options . openAiUseAzure ||
340- ( urlHost && ( urlHost . includes ( "azure.com" ) || urlHost . includes ( "azure.us" ) ) )
338+ ( urlHost && this . _isAzureHost ( urlHost ) )
341339 )
342340
343341 if ( this . options . openAiStreamingEnabled ?? true ) {
@@ -516,6 +514,25 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
516514 requestOptions . max_completion_tokens = this . options . modelMaxTokens || modelInfo . maxTokens
517515 }
518516 }
517+
518+ /**
519+ * Checks if the host is an Azure domain
520+ * Properly validates the hostname to prevent security issues
521+ */
522+ private _isAzureHost ( host : string ) : boolean {
523+ // Check for exact Azure domain suffixes
524+ return host . endsWith ( ".azure.com" ) || host . endsWith ( ".azure.us" ) || host === "azure.com" || host === "azure.us"
525+ }
526+
527+ /**
528+ * Checks if the URL is from Volces (Ark) service
529+ * Properly validates the hostname to prevent security issues
530+ */
531+ private _isVolcesHost ( baseUrl ?: string ) : boolean {
532+ const urlHost = this . _getUrlHost ( baseUrl )
533+ // Check for exact Volces domain suffix
534+ return urlHost . endsWith ( ".volces.com" ) || urlHost === "volces.com"
535+ }
519536}
520537
521538export async function getOpenAiModels ( baseUrl ?: string , apiKey ?: string , openAiHeaders ?: Record < string , string > ) {
0 commit comments