fix(security): bound completion prompt list to prevent unbounded engine fan-out (#47845)
Signed-off-by: jperezde <jperezde@redhat.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Annotated, Any, Literal
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.config.utils import replace
|
||||
from vllm.entrypoints.openai.engine.protocol import (
|
||||
@@ -35,6 +36,7 @@ from vllm.sampling_params import (
|
||||
ThinkingTokenBudget,
|
||||
)
|
||||
from vllm.utils import random_uuid
|
||||
from vllm.utils.collection_utils import is_list_of
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -497,6 +499,38 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
|
||||
return data
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_prompt_list_length(cls, data):
|
||||
max_prompts = envs.VLLM_MAX_COMPLETION_PROMPTS
|
||||
|
||||
prompt = data.get("prompt")
|
||||
if (
|
||||
isinstance(prompt, list)
|
||||
and len(prompt) > 0
|
||||
and not is_list_of(prompt, int)
|
||||
and len(prompt) > max_prompts
|
||||
):
|
||||
raise VLLMValidationError(
|
||||
f"prompt list length {len(prompt)} exceeds the maximum "
|
||||
f"allowed count of {max_prompts}. To increase this "
|
||||
"limit, set the VLLM_MAX_COMPLETION_PROMPTS "
|
||||
"environment variable.",
|
||||
parameter="prompt",
|
||||
)
|
||||
|
||||
prompt_embeds = data.get("prompt_embeds")
|
||||
if isinstance(prompt_embeds, list) and len(prompt_embeds) > max_prompts:
|
||||
raise VLLMValidationError(
|
||||
f"prompt_embeds list length {len(prompt_embeds)} exceeds "
|
||||
f"the maximum allowed count of {max_prompts}. To increase "
|
||||
"this limit, set the VLLM_MAX_COMPLETION_PROMPTS "
|
||||
"environment variable.",
|
||||
parameter="prompt_embeds",
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_cache_salt_support(cls, data):
|
||||
|
||||
Reference in New Issue
Block a user