fix(proxy): reject nested guardrail patch body

This commit is contained in:
wzj1228516103 2026-09-08 17:53:52 +08:00
parent 1af7a403c6
commit a5dce43aba
2 changed files with 17 additions and 0 deletions

View file

@ -1215,6 +1215,8 @@ class ApplyGuardrailResponse(BaseModel):
class PatchGuardrailRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
guardrail_name: str | None = None
litellm_params: BaseLitellmParams | None = None
guardrail_info: dict[str, Any] | None = None

View file

@ -80,6 +80,21 @@ MOCK_PATCH_REQUEST = PatchGuardrailRequest(
)
def test_patch_guardrail_request_rejects_create_body_shape():
"""Do not silently accept the nested POST /guardrails request body."""
from pydantic import ValidationError
with pytest.raises(ValidationError, match="extra_forbidden"):
PatchGuardrailRequest.model_validate(
{
"guardrail": {
"guardrail_name": "nested-name",
"litellm_params": {},
}
}
)
@pytest.fixture
def mock_prisma_client(mocker):
"""Mock Prisma client for testing"""