mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-06 06:49:23 +00:00
Security: validate outbound llm URLs and block internal endpoints
This commit is contained in:
11 files changed
+192
-61
No files matched your search
@@ -12,6 +12,7 @@ from documents.models import Document
|
||||
from documents.models import Note
|
||||
from paperless.config import AIConfig
|
||||
from paperless.models import LLMEmbeddingBackend
|
||||
from paperless.network import validate_outbound_http_url
|
||||
|
||||
|
||||
def get_embedding_model() -> "BaseEmbedding":
|
||||
@@ -21,10 +22,16 @@ def get_embedding_model() -> "BaseEmbedding":
|
||||
case LLMEmbeddingBackend.OPENAI:
|
||||
from llama_index.embeddings.openai import OpenAIEmbedding
|
||||
|
||||
endpoint = config.llm_endpoint or None
|
||||
if endpoint:
|
||||
validate_outbound_http_url(
|
||||
endpoint,
|
||||
allow_internal=config.llm_allow_internal_endpoints,
|
||||
)
|
||||
return OpenAIEmbedding(
|
||||
model=config.llm_embedding_model or "text-embedding-3-small",
|
||||
api_key=config.llm_api_key,
|
||||
api_base=config.llm_endpoint or None,
|
||||
api_base=endpoint,
|
||||
)
|
||||
case LLMEmbeddingBackend.HUGGINGFACE:
|
||||
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
||||
|
||||
Reference in new issue
Block a user