litellm/tests/proxy_unit_tests
user 75d1a0116e
fix(static-assets): use async_safe_get; drop SVG; serve bytes inline on cache miss
Three review items addressed:

* **Veria (Medium): SSRF via redirect.** ``fetch_validated_image_bytes``
  was calling ``validate_url(url)`` once and then fetching with the
  default httpx client, so a 3xx to an internal IP would have been
  followed unvalidated. Switched to ``async_safe_get`` (the existing
  SSRF primitive used elsewhere in the codebase) which walks each
  redirect hop, re-validates, and rejects redirects to blocked
  networks. Default ``litellm.user_url_validation`` is True so
  protection is on out of the box.

* **Greptile (P2): SVG can embed JS.** Removed ``image/svg+xml`` from
  the allowed-Content-Type set. The hardcoded response media type
  (``image/jpeg`` / ``image/x-icon``) means a real SVG body wouldn't
  render as SVG anyway in modern browsers — the allowlist entry was
  giving up XSS surface for no actual SVG-rendering benefit. If real
  SVG support is wanted later, that's a deliberate feature PR with CSP
  / nosniff bundled.

* **Greptile (P2): cache-write OSError drops validated bytes.** When
  the upstream fetch succeeded but ``open(cache_path, "wb")`` raised
  (read-only assets dir), the bytes were discarded and the default
  logo was served — a silent regression for that deployment. Now
  serve the validated bytes inline via ``Response(...)`` as a fallback
  before falling back to default.

Tests:

- Replaced low-level mocks of ``validate_url`` with mocks of
  ``async_safe_get`` directly, exercising the helper's contract
  rather than the SSRF primitive's internals.
- New ``test_rejects_svg_content_type`` confirms SVG is blocked.
- ``test_get_image_cache_logic`` fixture now sets
  ``mock_response.is_redirect = False`` so ``async_safe_get`` doesn't
  treat the Mock's truthy attribute as a redirect.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 21:57:22 +00:00
..
example_config_yaml test: test 2026-03-28 19:17:38 -07:00
test_configs test: test 2026-03-28 19:17:38 -07:00
test_model_response_typing
azure_fine_tune.jsonl
batch_job_results_furniture.jsonl
conftest copy.py
conftest.py [Fix] conftest: flush cache instances and warn on silent skips 2026-04-20 22:19:36 -07:00
data_map.txt
eagle.wav
gettysburg.wav
large_text.py
messages_with_counts.py
model_cost.json
openai_batch_completions_router.jsonl
openai_batch_completions.jsonl
speech_vertex.mp3
test_aproxy_startup.py
test_audit_logs_proxy.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_auth_checks.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_banned_keyword_list.py
test_blog_posts_endpoint.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_check_batch_cost.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_check_responses_cost.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_custom_callback_input.py
test_custom_logger_s3_gcs.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_custom_tokenizer_bug.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_db_schema_changes.py
test_db_schema_migration.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_default_end_user_budget_simple.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_deployed_proxy_keygen.py
test_e2e_pod_lock_manager.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_get_favicon.py feat(proxy): add custom favicon support\n\nAdd ability to configure a custom favicon for the litellm proxy UI.\n\n- Add favicon_url field to UIThemeConfig model\n- Add LITELLM_FAVICON_URL env var support\n- Add /get_favicon endpoint to serve custom favicons\n- Update ThemeContext to dynamically set favicon\n- Add favicon URL input to UI theme settings page\n- Add comprehensive tests\n\nCloses #8323 (#21653) 2026-02-21 00:46:51 -08:00
test_get_image.py fix(static-assets): use async_safe_get; drop SVG; serve bytes inline on cache miss 2026-04-29 21:57:22 +00:00
test_google_endpoint_routing.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_google_gemini_proxy_request.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_jwt_key_mapping.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_jwt.py retain ui_routes enum alias for JWT config backwards compatibility 2026-04-10 08:55:32 -07:00
test_key_generate_dynamodb.py
test_key_generate_prisma.py fix(auth): centralize common_checks to close authorization bypass 2026-04-23 00:04:42 +00:00
test_models_fallback_endpoint.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_prisma_client_backoff_retry.py fix(tests): mock prisma.Prisma in backoff retry tests to avoid 'prisma generate' 2026-02-17 19:29:20 -03:00
test_prompt_test_endpoint.py
test_proxy_config_unit_test.py fix: enable JSON logging via configuration and add regression test 2026-01-13 09:38:19 -07:00
test_proxy_custom_auth.py
test_proxy_custom_logger.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_proxy_encrypt_decrypt.py
test_proxy_exception_mapping.py
test_proxy_gunicorn.py
test_proxy_pass_user_config.py test: test 2026-03-28 19:17:38 -07:00
test_proxy_reject_logging.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_proxy_routes.py Revert "lazy-load optional feature routers on first request (#26534)" (#26727) 2026-04-29 00:21:41 +00:00
test_proxy_server_caching.py
test_proxy_server_keys.py
test_proxy_server_langfuse.py
test_proxy_server_spend.py
test_proxy_server.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_proxy_setting_guardrails.py fix(lakera-guardrail): use os.environ.get() to avoid KeyError on missing LAKERA_API_KEY 2026-02-17 19:30:22 -03:00
test_proxy_token_counter.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_proxy_utils.py test: tighten prepare_key_update_data mock and apply black 2026-04-25 09:08:55 -07:00
test_realtime_cache.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_response_polling_handler.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_response_polling_pre_call_checks.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_search_api_logging.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_server_root_path.py fix: server rooth path (#19790) 2026-01-26 09:48:06 -08:00
test_skills_db.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_ui_path_detection.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_unit_test_max_model_budget_limiter.py fix(proxy): use model_group for model_max_budget spend tracking cache key (#25549) 2026-04-11 19:37:58 -07:00
test_unit_test_proxy_hooks.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_update_daily_tag_spend.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_update_spend.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_user_api_key_auth.py [Fix] Restrict /global/spend/* routes to admin roles 2026-04-24 22:46:07 -07:00
test_zero_cost_model_budget_bypass.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
vertex_key.json test: update to new vertex ai keys 2026-03-28 20:19:05 -07:00