fix(auth): guard JWTHandler.is_jwt() against None token#24706
fix(auth): guard JWTHandler.is_jwt() against None token#24706ryan-crabbe-berri merged 2 commits intolitellm_ryan-march-26from
Conversation
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().
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds a one-line
Confidence Score: 5/5Safe 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.
|
| 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"]
Reviews (1): Last reviewed commit: "test(auth): add regression tests for JWT..." | Re-trigger Greptile
5b65104
into
litellm_ryan-march-26
Summary
JWTHandler.is_jwt()againstNonetoken to preventAttributeErrorwhen no Authorization header is present (e.g. health checks, monitoring probes on JWT-enabled proxies)-> boolreturn type annotationNonecase in bothtests/proxy_unit_tests/test_jwt.pyandtests/test_litellm/proxy/auth/test_user_api_key_auth.py