Skip to content

fix(proxy): allow custom auth routes to bypass route authorization ch… - #22662

Merged
Harshit28j merged 1 commit into
mainfrom
litellm_custm_auth
Mar 3, 2026
Merged

fix(proxy): allow custom auth routes to bypass route authorization ch…#22662
Harshit28j merged 1 commit into
mainfrom
litellm_custm_auth

Conversation

@Harshit28j

@Harshit28j Harshit28j commented Mar 3, 2026

Copy link
Copy Markdown
Contributor
image

…ecks

Custom user-added routes (e.g. /ldap/ngs/ready) used with Depends(user_api_key_auth) were being rejected as admin-only after _run_post_custom_auth_checks was introduced in commit 14badde.

The route authorization check in common_checks is designed for LiteLLM's own management routes. Custom auth flows that add their own routes should be trusted since the custom auth function already validated the request. Budget and expiry checks still run.

Add skip_route_check parameter to common_checks() and pass skip_route_check=True from _run_post_custom_auth_checks() to skip route authorization while preserving budget/team/model checks.

Regression test added: test_common_checks_skip_route_check_for_custom_auth

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Building Building Preview, Comment Mar 3, 2026 2:51pm

Request Review

@Harshit28j
Harshit28j merged commit 7d322e0 into main Mar 3, 2026
21 of 88 checks passed
@greptile-apps

greptile-apps Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression where custom user-defined auth routes (e.g., /ldap/ngs/ready) were being rejected by the standard route authorization checks in common_checks(). After _run_post_custom_auth_checks was introduced, custom auth handlers that return a UserAPIKeyAuth would then run through common_checks, which would reject unrecognized routes as unauthorized. The fix adds a skip_route_check parameter to common_checks(), set to True only in _run_post_custom_auth_checks, since the custom auth function has already validated the request and knows which routes are valid.

  • Adds skip_route_check: bool = False parameter to common_checks() to conditionally skip _is_allowed_route enforcement
  • Passes skip_route_check=True only in _run_post_custom_auth_checks, leaving all other call sites (JWT auth, key-based auth) unchanged
  • Includes a regression test verifying that custom routes pass with skip_route_check=True and fail without it

Confidence Score: 4/5

  • This PR is safe to merge — it's a targeted fix for a regression with minimal blast radius and includes a regression test.
  • The change is small, well-scoped, and only affects the custom auth path. The skip_route_check parameter defaults to False, preserving existing behavior for all other callers (JWT and key-based auth). The custom auth function has already validated the request before this code path is reached, so skipping the route check is appropriate. A regression test is included.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/auth/auth_checks.py Adds skip_route_check parameter to common_checks() and wraps the _is_allowed_route call in a conditional block. Clean, minimal change that doesn't affect other callers.
litellm/proxy/auth/user_api_key_auth.py Passes skip_route_check=True to common_checks() in _run_post_custom_auth_checks, the only call site that handles custom auth flows.
tests/test_litellm/proxy/auth/test_auth_checks.py Adds a regression test using mocks to verify custom routes pass with skip_route_check=True and fail without it. No real network calls.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Request arrives] --> B{Custom auth configured?}
    B -->|Yes| C[enterprise_custom_auth / user_custom_auth validates request]
    B -->|No| D[Standard JWT / Key-based auth]
    C --> E["_run_post_custom_auth_checks()"]
    E --> F["common_checks(skip_route_check=True)"]
    F --> G[Budget checks, team checks, etc.]
    G --> H[Skip _is_allowed_route]
    H --> I[Vector store checks]
    I --> J[Return True]
    D --> K["common_checks(skip_route_check=False)"]
    K --> L[Budget checks, team checks, etc.]
    L --> M["_is_allowed_route() — enforces route authorization"]
    M --> N[Vector store checks]
    N --> J
Loading

Last reviewed commit: 6d535e5

Harshit28j added a commit to Harshit28j/litellm that referenced this pull request Mar 3, 2026
…_run_common_checks

Replaces the skip_route_check approach from PR BerriAI#22662 with a configurable
opt-in flag. By default, common_checks() is not run for custom auth flows,
preserving backwards compatibility with pre-BerriAI#22164 behavior.

Users who want budget/team/route enforcement on custom auth can enable it:
  general_settings:
    custom_auth_run_common_checks: true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ishaan-berri
ishaan-berri deleted the litellm_custm_auth branch March 26, 2026 22:29
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…_run_common_checks

Replaces the skip_route_check approach from PR BerriAI#22662 with a configurable
opt-in flag. By default, common_checks() is not run for custom auth flows,
preserving backwards compatibility with pre-BerriAI#22164 behavior.

Users who want budget/team/route enforcement on custom auth can enable it:
  general_settings:
    custom_auth_run_common_checks: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant