litellm/tests/test_litellm/proxy/common_utils
Varun Chawla e587370f67 fix(proxy): add regression tests for #20441 - <script> tags in messages (#20573)
* fix: empty guardrails/policies arrays should not trigger enterprise license check (#20304)

The UI sends empty arrays for enterprise-only fields (guardrails, policies,
logging) even when the user has not configured these features. The backend
`is not None` check treated `[]` as a truthy intent to use the feature,
falsely requiring an enterprise license for basic team operations.

Backend: Add `and updated_kv[field] != [] and updated_kv[field] != {}`
guards in `_update_metadata_fields` so empty collections are skipped.

UI: Conditionally omit guardrails, logging, and policies from the
payload when empty instead of defaulting to `[]`.

Fixes #20304

* fix: allow clearing fields with empty collections while skipping enterprise check

Address PR review feedback:

1. Move the empty-collection guard into _update_metadata_field (singular)
   so that empty lists/dicts skip only the premium license check but still
   get written into metadata. This lets users intentionally clear a
   previously-set field (e.g. guardrails: []) without being blocked, while
   the UI's default empty arrays still don't trigger a false enterprise
   error.

2. Remove sys.path hack from test file; use standard imports that work
   with pytest discovery.

3. Add tests verifying that empty collections are moved into metadata
   (field clearing works) even though they bypass the premium check.

Fixes #20304

* fix(proxy): add regression tests for #20441 - ensure <script> tags in LLM messages are not blocked

The 403 Forbidden error when sending messages containing `<script>` is caused
by external WAF/reverse proxy infrastructure (confirmed by the standard nginx
HTML 403 response format), not by LiteLLM's own content filtering. However,
these regression tests ensure that:

1. The content filter guardrail's built-in patterns do not match HTML tags
2. Messages containing <script> and other HTML tags pass through the content
   filter unchanged when no explicit HTML-blocking rules are configured
3. The HTTP request body parser correctly handles JSON payloads containing
   HTML content without modification

These tests guard against accidentally introducing HTML/XSS filtering that
would break legitimate LLM API usage (e.g., discussing HTML/JavaScript code).

Closes #20441

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:57:40 +05:30
..
test_callback_utils.py Working setting generic callbacks on UI 2025-12-05 14:37:48 -08:00
test_custom_openapi_spec.py Refactor add_schema_to_components to move definitions to components/schemas and add corresponding unit test (#17389) 2025-12-02 21:57:07 -08:00
test_get_routes.py [Bug Fix] - Get Routes (#13466) 2025-08-09 12:52:23 -07:00
test_http_parsing_utils.py fix(proxy): add regression tests for #20441 - <script> tags in messages (#20573) 2026-02-12 19:57:40 +05:30
test_key_rotation_integration.py fix: ensure auto-rotation updates existing AWS secret instead of creating new one (#19455) 2026-01-20 18:30:36 -08:00
test_key_rotation_manager.py [Feat] UI - Allow scheduling key rotations when creating virtual keys (#14960) 2025-09-26 16:24:40 -07:00
test_load_config_utils.py [Bug Fix] s3 config.yaml file - ensure yaml safe load is used (#12373) 2025-07-07 14:42:33 -07:00
test_openai_endpoint_utils.py [Fix] Exclude litellm_credential_name from Sensitive Data Masker (Updated) (#16958) 2025-11-21 19:09:48 -08:00
test_reset_budget_job.py Prevent writing default user setting updates to yaml (error in non-root env) + Use central team member budget when max_budget_in_team set on UI (#12533) 2025-07-12 10:13:07 -07:00
test_timezone_utils.py Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
test_upsert_budget_membership.py [Feat] UI - Allow editing team member rpm/tpm limits (#13669) 2025-08-15 17:29:44 -07:00