[BUGFIX] Skip bearer auth flow when Authorization header is absent#150
Open
uluzox wants to merge 1 commit into
Open
[BUGFIX] Skip bearer auth flow when Authorization header is absent#150uluzox wants to merge 1 commit into
uluzox wants to merge 1 commit into
Conversation
1919ff4 to
2c0df5b
Compare
authenticateBearerToken() destructures the scheme and token from the Authorization header. The existing guard returned early only when a scheme was present but did not equal "bearer". For requests without an Authorization header (or with an unparseable header that yields no scheme), $scheme is null, the guard did not trigger, and the function fell through to TokenRepository::findBackendUserIdByToken(null) which raised a TypeError because the argument is typed as string. Add an explicit null-check directly after the trimExplode destructure. The existing scheme/bearer comparison stays untouched. This mirrors the pattern used in getLoginFormData() of the same class, where the "no scheme provided" case is handled before the scheme value is compared.
2c0df5b to
566a3e2
Compare
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
HttpBackendUserAuthentication::checkAuthentication()unconditionally callsauthenticateBearerToken()on every incoming request. That method extracts anAuthorizationheader, destructures the scheme and token, and is supposed toearly-return for any auth scheme that is not
bearer— letting the parentauthentication handler take over.
The existing guard does not handle a missing
Authorizationheader:When the header is empty or absent,
trimExplode(' ', '', true)returns[],so
$schemeand$tokenare bothnull.is_string($scheme)is thenfalse,the guard does not trigger, and the function falls through to:
TokenRepository::findBackendUserIdByToken()is typedstring $token, so PHPraises a
TypeError:This surfaces in production whenever a request reaches the extension without a
forwardable
Authorizationheader — for example when an Apachemod_proxy_fcgideployment hasn't set
CGIPassAuth Onand silently drops the header before itgets to PHP. The TypeError is shown to the client instead of letting the parent
authentication flow respond normally.
Fix
Add an explicit null-check right after the
trimExplodedestructure. Theexisting scheme/bearer comparison stays untouched:
This mirrors the pattern used in
getLoginFormData()of the same class, wherethe "no scheme provided" case is handled before the scheme value is compared.
No behaviour change for valid
Bearer <token>headers; no behaviour change forother valid schemes (
Basic …etc. — still early-return via the second guard).The only newly handled case is the previously-crashing one: no scheme present.
Why no test in this PR
There is no existing unit/functional test for
HttpBackendUserAuthentication,and the class extends
TYPO3\CMS\Core\Authentication\BackendUserAuthentication,which makes constructing it in a unit test non-trivial (its parent does I/O).
Happy to add a test in a follow-up if reviewers prefer — likely a functional
test that issues a request without an
Authorizationheader against a routedendpoint and asserts no
TypeError.Repro (production)
— without
Authorizationheader → before this patch: 500 /TypeError;after: passes through to the parent auth flow as intended.