fix: use Bearer for token credentials with Basic-only challenge#792
Closed
hrhee wants to merge 2 commits into
Closed
fix: use Bearer for token credentials with Basic-only challenge#792hrhee wants to merge 2 commits into
hrhee wants to merge 2 commits into
Conversation
added 2 commits
May 15, 2026 14:40
…server When a server responds to an unauthenticated request with 'WWW-Authenticate: Basic realm=\"\"' and the stored credential is of type 'token' (Bearer), handle_401 crashes with IndexError: list index out of range. Fix by: - Splitting the ascheme-is-None block so http_auth_scheme from the credential is checked first and not immediately overwritten - Guarding the list comprehension against an empty result - Adding a fallback: if credential type is 'token' and no matching scheme was advertised, try Bearer"
Member
|
Thanks! I cherry-picked these commits into the main branch. I am planning to release a new version soon. |
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.
Problem
When a server responds to an unauthenticated request with
WWW-Authenticate: Basic realm=""and the stored credential is of typetoken(Bearer),handle_401crashes withIndexError: list index out of range.The root cause is in the
if ascheme is Noneblock:Two bugs:
http_auth_schemevalue from the credential is overwrittenunconditionally by the list comprehension below it.
[0]without guardingagainst an empty list.
Error
Fix
if ascheme is Nonechecks sohttp_auth_schemefrom the credential is honoured before the list comprehension runs.
if matching:instead of bare[0].tokenand no matching schemewas found, try Bearer anyway.
Steps to reproduce
tokenfor an HTTP endpoint:WWW-Authenticate: Basic realm=""but accepts Bearer tokens:IndexError: list index out of rangeinhandle_401This combination occurs with dCache WebDAV endpoints using OIDC
authentication: dCache advertises only Basic in its 401 challenge but
requires a Bearer token.
TODO
type=tokencredential meets aBasic-onlyWWW-AuthenticateheaderTested with