Repository navigation
fix(server): accept case-insensitive Bearer auth scheme - #699
Open
KVR Vishnu (VISHNU0906) wants to merge 1 commit into
Open
KVR Vishnu (VISHNU0906) wants to merge 1 commit into
KVR Vishnu (VISHNU0906) wants to merge 1 commit into
Conversation
RFC 7235 makes the Authorization auth-scheme case-insensitive. Compare the scheme with casefold() and allow one or more spaces before the key so lowercase/mixed-case clients authenticate. Fixes microsoft#671 Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change enabling case-insensitive Bearer authentication while preserving exact API-key matching.
No open issues 🎉
What changed in this PR
Fixes #671 by allowing case-insensitive Bearer authentication schemes in the server while preserving exact API-key matching and existing x-api-key support.
Changes:
- Splits the Authorization header into scheme and token, accepting mixed-case schemes and extra separator spaces.
- Adds endpoint regression tests for valid Bearer variants, invalid credentials, and
x-api-keyauthentication.
| File | Description |
|---|---|
tests/server/test_endpoints.py |
Adds authentication acceptance and rejection tests through the real endpoint dependency. |
agentlightning/server/app.py |
Parses Bearer credentials and compares the scheme case-insensitively. |
Review effort: Balanced
This branch has not been deployed
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.
What
The server auth dependency treated the Authorization scheme as case-sensitive (
startswith("Bearer ")), so a correct key sent asbearer …,BEARER …, orBeArEr …got a 401. RFC 7235 §2.1 makes the auth-scheme case-insensitive and allows one or more spaces before the credentials.This change splits the header into scheme and token, compares the scheme with
casefold()againstbearer, and keeps an exact match on the key. The existingx-api-keypath is unchanged.Why
Clients and gateways that normalize the scheme to lowercase (or otherwise change casing) could not authenticate even with a valid key. Reported by Chen Yufeiyang (@feiiiiii5) in #671.
Fixes #671
Verification
Results locally: pre-commit / ruff / headers / pyright clean; full suite
255 passed, 4 skipped.Regression coverage through the real TestClient auth path for
Bearer/bearer/BEARER/BeArEr/ extra spaces, plus wrong key, missing header, wrong scheme, andx-api-key. Reverting the casefold match makes the mixed/lowercase cases fail again.I used AI assistance for parts of this change and tested it locally against the full test suite.