Skip to content

Commit 08e2b24

Browse files
committed
fix: add SSRF guard inside generateEmbeddings and generateSearchEmbedding
1 parent 2c8cbb4 commit 08e2b24

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

apps/sim/lib/knowledge/embeddings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ export async function generateEmbeddings(
400400
if (embeddingModel.startsWith('ollama/')) {
401401
const modelName = embeddingModel.slice(7)
402402
const baseUrl = getOllamaBaseUrl(ollamaBaseUrl)
403+
if (!isAllowedOllamaUrl(baseUrl)) {
404+
throw new Error(
405+
`Ollama base URL "${baseUrl}" is not allowed. Must point to localhost, a private IP address, or host.docker.internal.`
406+
)
407+
}
403408
logger.info(`Using Ollama (${baseUrl}) for embedding generation with model ${modelName}`)
404409

405410
// Use pre-queried context length if provided, otherwise query it
@@ -509,6 +514,11 @@ export async function generateSearchEmbedding(
509514
if (embeddingModel.startsWith('ollama/')) {
510515
const modelName = embeddingModel.slice(7)
511516
const baseUrl = getOllamaBaseUrl(ollamaBaseUrl)
517+
if (!isAllowedOllamaUrl(baseUrl)) {
518+
throw new Error(
519+
`Ollama base URL "${baseUrl}" is not allowed. Must point to localhost, a private IP address, or host.docker.internal.`
520+
)
521+
}
512522
logger.info(`Using Ollama (${baseUrl}) for search embedding with model ${modelName}`)
513523
const embeddings = await retryWithExponentialBackoff(
514524
() => callOllamaEmbeddingAPI([query], modelName, baseUrl),

0 commit comments

Comments
 (0)