mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
fix: always prioritize messages for prompt redaction to prevent bypass
- Remove conditional check that could discard message-based redactions - Always use messages as source of truth after guardrail processing - Fixes MEDIUM severity: prompt precedence bypass when multiple guardrails apply different masks
This commit is contained in:
parent
11b31dc37a
commit
58b5df4aa0
1 changed files with 5 additions and 6 deletions
|
|
@ -145,12 +145,11 @@ async def image_generation(
|
|||
user_api_key_dict=user_api_key_dict, data=data, call_type="image_generation"
|
||||
)
|
||||
|
||||
# Guardrails may redact data["prompt"] directly. Only rebuild from messages if prompt wasn't modified.
|
||||
prompt_after_hook: Final = data.get("prompt")
|
||||
if prompt_after_hook == prompt_value:
|
||||
messages: Final = data.get("messages")
|
||||
if isinstance(messages, list) and messages:
|
||||
data["prompt"] = get_str_from_messages(messages)
|
||||
# Guardrails may redact messages. Always use messages as source of truth if they exist.
|
||||
# If both prompt and messages were modified, prefer messages since that's what guardrails processed.
|
||||
messages: Final = data.get("messages")
|
||||
if isinstance(messages, list) and messages:
|
||||
data["prompt"] = get_str_from_messages(messages)
|
||||
data.pop("messages", None)
|
||||
|
||||
## ROUTE TO CORRECT ENDPOINT ##
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue