Fix authentication bypass in multi-API deployments#674
Merged
bhimrazy merged 6 commits intoLightning-AI:mainfrom Apr 7, 2026
Merged
Fix authentication bypass in multi-API deployments#674bhimrazy merged 6 commits intoLightning-AI:mainfrom
bhimrazy merged 6 commits intoLightning-AI:mainfrom
Conversation
- setup_auth() now accepts optional lit_api parameter for per-endpoint auth - Each API endpoint uses its own authorize() method instead of only the first API's - Add tests for multi-API auth isolation with mixed and different auth methods Fixes Lightning-AI#659 Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
andyland
approved these changes
Apr 6, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #674 +/- ##
===================================
- Coverage 85% 85% -0%
===================================
Files 39 39
Lines 3278 3279 +1
===================================
- Hits 2774 2773 -1
- Misses 504 506 +2 🚀 New features to boost your workflow:
|
…I 403 vs 401 version difference HTTPBearer() raises 403 on missing Authorization header in FastAPI 0.112 (oldest CI) but 401 in newer versions. Sending a wrong token ensures authorize() itself raises 401 consistently across all supported FastAPI versions.
…data - Replace NoAuthAPI with SimpleLitAPI (already defined in the same file) - Inline json payload dicts directly in client.post() calls - Remove shadowing of Python builtin `input` variable
…itAPI class Collapse two identical auth API classes into one parameterized TokenAuthedLitAPI that inherits SimpleLitAPI and accepts a token argument.
bhimrazy
approved these changes
Apr 7, 2026
Collaborator
bhimrazy
left a comment
There was a problem hiding this comment.
Thanks @Lidang-Jiang for the fixes.
I also added a minor improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #659 — When serving multiple APIs via
LitServer([api1, api2, ...]), only the first API'sauthorize()method is checked. Subsequent APIs with custom authorization are left unprotected.Root cause
setup_auth()always usesself.lit_api(set to the first API at init), ignoring per-API auth methods:Fix (3 lines changed)
setup_auth()now accepts an optionallit_apiparameter_register_api_endpoints()and_register_spec_endpoints()pass the specificlit_api/,/health,/info) retain existing behaviorBefore (unmodified code — 3 new tests all FAIL)
SecureAPI returns 200 without credentials — auth bypass confirmed.
After (with fix — all 7 tests PASS)
Full suite: 76 passed, 3 skipped
Test plan
test_multi_api_second_api_auth_enforced— PublicAPI(no auth) + SecureAPI(auth) → second API properly protectedtest_multi_api_mixed_auth— auth API first, open API second → each works independentlytest_multi_api_both_with_different_auth— two APIs with different tokens → cross-token rejectedruff checkand pre-commit hooks pass