The vulnerability described in GHSA-p44q-vqpr-4xmg lies in how Flask-HTTPAuth handles missing authentication tokens. The advisory states that when a client makes a request without a token or with an empty one, the application's token verification callback is invoked with an empty string. This could lead to an improper authentication vulnerability if any user in the database has an empty string as their token.
To pinpoint the vulnerable function, I analyzed the changes between the last vulnerable version (4.8.0) and the first patched version (4.8.1). The key change was found in commit b15ffe9e50e110d7174ccd944f642079e1dcf9ee, titled "Do not accept empty tokens".
This commit modifies the authenticate method within the HTTPTokenAuth class in src/flask_httpauth.py. The vulnerable code was:
token = getattr(auth, 'token', '')
if self.verify_token_callback:
return self.ensure_sync(self.verify_token_callback)(token)
This code retrieves the token, defaults to an empty string ('') if it's not present, and then unconditionally calls the verification callback.
The patch changes this logic to:
token = getattr(auth, 'token', None)
if token and self.verify_token_callback:
return self.ensure_sync(self.verify_token_callback)(token)
Now, if the token is missing, it defaults to None, and the if token and ... check prevents the verification callback from being executed. This directly remediates the described vulnerability. Therefore, the HTTPTokenAuth.authenticate function is the precise location of the vulnerability.