From 03b05fe8c8a4b945a0856945df5cdabb9ca0715e Mon Sep 17 00:00:00 2001 From: ajitsharmas2007 Date: Wed, 30 Sep 2026 19:18:28 +0530 Subject: [PATCH] test(proxy): pin that another route's guardrail cannot gate this body A proxy registers every callback globally in one list: loggers, and the guardrails of every route. `_reads_the_request_body` must therefore look only at the guardrails this route configured, and nothing was checking that. Another route's pre_call guardrail making this route refuse a body would be a real bug. Registers a plain CustomLogger and a pre_call guardrail named for someone else, then sends a non-object body to a route whose own guardrail is post-call only, and asserts it still reaches the provider verbatim. Covers the last line Codecov flagged. --- .../test_pass_through_endpoints.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py index 57859e27bc9..afd59063e2f 100644 --- a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py +++ b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py @@ -7870,3 +7870,20 @@ async def test_non_object_json_under_a_multipart_content_type_is_left_to_the_mul ) assert (query_params_data, custom_body_data, file_data, stream) == (None, None, None, None) + + +@pytest.mark.asyncio +async def test_another_routes_request_guardrail_does_not_gate_this_route(): + """A proxy registers every callback globally, so this route must look only at the + guardrails it configured. Another route's pre_call guardrail, or a plain logger, must not + make this route turn a body away.""" + body = b'[{"role": "user", "content": "hi"}]' + unrelated_logger = CustomLogger() + litellm.callbacks.append(unrelated_logger) + try: + with _registered_guardrail("someone-elses-guard", GuardrailEventHooks.pre_call): + upstream = await _capture_upstream_request(body, guardrails=["postcall-guard"]) + finally: + litellm.callbacks.remove(unrelated_logger) + + assert upstream.content == body