Skip to content

fix(auth): guard JWTHandler.is_jwt() against None token#24706

Merged
ryan-crabbe-berri merged 2 commits intolitellm_ryan-march-26from
litellm_fix-jwt-none-guard
Mar 28, 2026
Merged

fix(auth): guard JWTHandler.is_jwt() against None token#24706
ryan-crabbe-berri merged 2 commits intolitellm_ryan-march-26from
litellm_fix-jwt-none-guard

Conversation

@ryan-crabbe-berri
Copy link
Copy Markdown
Collaborator

Summary

  • Guard JWTHandler.is_jwt() against None token to prevent AttributeError when no Authorization header is present (e.g. health checks, monitoring probes on JWT-enabled proxies)
  • Add -> bool return type annotation
  • Add regression tests for the None case in both tests/proxy_unit_tests/test_jwt.py and tests/test_litellm/proxy/auth/test_user_api_key_auth.py

When JWT auth is enabled and a request arrives without an Authorization
header (e.g. health checks, monitoring), api_key is None due to
APIKeyHeader(auto_error=False). The is_jwt() call crashes with
AttributeError: 'NoneType' object has no attribute 'split'.

Return False for None tokens since they are not JWTs.
Add None-token test cases to both proxy_unit_tests and test_litellm
to cover the guard added in the previous commit. Also add -> bool
return type annotation to is_jwt().
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 27, 2026 11:53pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR adds a one-line None guard to JWTHandler.is_jwt() to prevent an AttributeError crash when no Authorization header is present (e.g., health-check or monitoring probes on JWT-enabled proxies). A -> bool return-type annotation is also added. Regression tests covering the None case are added to both tests/proxy_unit_tests/test_jwt.py and tests/test_litellm/proxy/auth/test_user_api_key_auth.py.

  • Fix is minimal, correct, and backwards-compatible — callers that already passed a string token are unaffected.
  • The call sites in user_api_key_auth.py (lines 653 and 680) and _types.py (line 2510) continue to work without modification.
  • Tests are purely local (no network calls) and additive — existing assertions are unchanged.

Confidence Score: 5/5

Safe to merge — tiny, focused bug fix with adequate test coverage and no behavioural change for existing callers.

The change is a single None-check in a static utility method, backed by two independent test assertions. No existing tests were weakened, no backwards-incompatible changes were introduced, and the fix directly addresses the reported AttributeError. All remaining observations are P2 or lower.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/auth/handle_jwt.py Adds None guard and return type annotation to is_jwt() — minimal, correct fix that prevents AttributeError when no Authorization header is present.
tests/proxy_unit_tests/test_jwt.py Adds a None-token assertion to the existing test_jwt_handler_is_jwt_static_method test — additive, no weakening of coverage.
tests/test_litellm/proxy/auth/test_user_api_key_auth.py Adds a new test_is_jwt_returns_false_for_none test method — purely local, no network calls, correctly validates the fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["JWTHandler.is_jwt(token)"] --> B{token is None?}
    B -->|Yes| C["return False"]
    B -->|No| D["parts = token.split('.')"]
    D --> E{"len(parts) == 3?"}
    E -->|Yes| F["return True"]
    E -->|No| G["return False"]
Loading

Reviews (1): Last reviewed commit: "test(auth): add regression tests for JWT..." | Re-trigger Greptile

@ryan-crabbe-berri ryan-crabbe-berri merged commit 5b65104 into litellm_ryan-march-26 Mar 28, 2026
5 of 50 checks passed
@ryan-crabbe-berri ryan-crabbe-berri deleted the litellm_fix-jwt-none-guard branch March 28, 2026 01:06
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