[Security] Reject local verifier references in Speculators metadata (#61587)
Signed-off-by: Juan Pérez de Algaba <jperezde@redhat.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
bf6c80c7e8
commit
5d88c034f6
@@ -10,11 +10,17 @@ runtime fields from the user are preserved while ``model`` stays auto-detected
|
||||
from the speculators format.
|
||||
"""
|
||||
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.engine.arg_utils import AsyncEngineArgs, EngineArgs
|
||||
from vllm.transformers_utils.config import maybe_override_with_speculators
|
||||
|
||||
_SPECULATORS_CONFIG_DICT = {
|
||||
_SPECULATORS_CONFIG_DICT: dict[str, Any] = {
|
||||
"architectures": ["DFlashDraftModel"],
|
||||
"speculators_config": {
|
||||
"algorithm": "dflash",
|
||||
@@ -154,3 +160,78 @@ def test_non_speculators_model_passes_user_config_through_unchanged():
|
||||
assert model == "fake-org/plain-llama"
|
||||
assert tok is None
|
||||
assert spec == user_overrides
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"verifier",
|
||||
[
|
||||
"/abs/path/to/other_tenant_private",
|
||||
"../private-model",
|
||||
"./private-model",
|
||||
"file:///private-model",
|
||||
"C:\\private-model",
|
||||
"",
|
||||
None,
|
||||
[],
|
||||
{},
|
||||
1,
|
||||
],
|
||||
)
|
||||
def test_speculators_rejects_invalid_verifier_references(verifier):
|
||||
config = deepcopy(_SPECULATORS_CONFIG_DICT)
|
||||
config["speculators_config"]["verifier"]["name_or_path"] = verifier
|
||||
with (
|
||||
_patched_get_config_dict(config),
|
||||
pytest.raises(ValueError, match="Speculators verifier must"),
|
||||
):
|
||||
maybe_override_with_speculators("fake-org/draft", None, False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("verifier", ["private-model", "fake-org/fake-verifier"])
|
||||
@pytest.mark.parametrize("symlink", [False, True])
|
||||
def test_speculators_rejects_local_verifiers_with_valid_repo_names(
|
||||
tmp_path, monkeypatch, verifier, symlink
|
||||
):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
local_verifier = tmp_path / verifier
|
||||
local_verifier.parent.mkdir(parents=True, exist_ok=True)
|
||||
if symlink:
|
||||
local_verifier.symlink_to(tmp_path / "private-target", target_is_directory=True)
|
||||
else:
|
||||
local_verifier.mkdir()
|
||||
|
||||
config = deepcopy(_SPECULATORS_CONFIG_DICT)
|
||||
config["speculators_config"]["verifier"]["name_or_path"] = verifier
|
||||
with (
|
||||
_patched_get_config_dict(config),
|
||||
pytest.raises(ValueError, match="Speculators verifier must"),
|
||||
):
|
||||
maybe_override_with_speculators("fake-org/draft", None, False)
|
||||
|
||||
|
||||
def test_non_speculators_local_model_remains_operator_selected(tmp_path):
|
||||
plain_config = {"architectures": ["LlamaForCausalLM"], "hidden_size": 64}
|
||||
with _patched_get_config_dict(plain_config):
|
||||
model, tokenizer, _ = maybe_override_with_speculators(
|
||||
str(tmp_path),
|
||||
str(tmp_path),
|
||||
False,
|
||||
vllm_speculative_config={"model": "fake-org/draft", "method": "eagle3"},
|
||||
)
|
||||
assert model == tokenizer == str(tmp_path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("engine_args_cls", [EngineArgs, AsyncEngineArgs])
|
||||
def test_speculators_rejects_local_verifier_before_model_loading(
|
||||
tmp_path, engine_args_cls
|
||||
):
|
||||
private_model = tmp_path / "private-model"
|
||||
private_model.mkdir()
|
||||
config = deepcopy(_SPECULATORS_CONFIG_DICT)
|
||||
config["speculators_config"]["verifier"]["name_or_path"] = str(private_model)
|
||||
draft = tmp_path / "draft"
|
||||
draft.mkdir()
|
||||
(draft / "config.json").write_text(json.dumps(config), encoding="utf-8")
|
||||
|
||||
with pytest.raises(ValueError, match="Speculators verifier must"):
|
||||
engine_args_cls(model=str(draft)).create_engine_config()
|
||||
|
||||
Reference in New Issue
Block a user