Skip to content

Commit 1505233

Browse files
committed
fix(vllm): validate compatible base URLs
1 parent ccaaf55 commit 1505233

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

apps/sim/providers/openai-compat/base-url.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ describe('getOpenAICompatibleApiBaseUrl', () => {
1010
])('normalizes %s to %s', (input, expected) => {
1111
expect(getOpenAICompatibleApiBaseUrl(input)).toBe(expected)
1212
})
13+
14+
it.each(['http://localhost:8000?token=value', 'http://localhost:8000#models'])(
15+
'rejects unsupported URL components in %s',
16+
(input) => {
17+
expect(() => getOpenAICompatibleApiBaseUrl(input)).toThrow(
18+
'OpenAI-compatible base URL must not include query parameters or a fragment'
19+
)
20+
}
21+
)
1322
})
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
/**
22
* Normalizes a server root or versioned OpenAI-compatible URL to the `/v1` API base.
3+
*
4+
* @throws When the URL contains query parameters or a fragment.
35
*/
46
export function getOpenAICompatibleApiBaseUrl(baseUrl: string): string {
5-
const normalized = baseUrl.trim().replace(/\/+$/, '')
6-
return normalized.endsWith('/v1') ? normalized : `${normalized}/v1`
7+
const url = new URL(baseUrl.trim())
8+
if (url.search || url.hash) {
9+
throw new Error('OpenAI-compatible base URL must not include query parameters or a fragment')
10+
}
11+
12+
const pathname = url.pathname.replace(/\/+$/, '')
13+
url.pathname = pathname.endsWith('/v1') ? pathname : `${pathname}/v1`
14+
return url.toString()
715
}

0 commit comments

Comments
 (0)