From 4268c2f8774e8c8a45e5c596b89dcf62570c12f8 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 26 Jun 2026 12:02:05 -0500 Subject: Bug: Check for valid "Bearer" section. --- gn3/oauth2/authorisation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gn3/oauth2/authorisation.py b/gn3/oauth2/authorisation.py index b2dd1ae..7699e39 100644 --- a/gn3/oauth2/authorisation.py +++ b/gn3/oauth2/authorisation.py @@ -15,7 +15,11 @@ def require_token(func): bearer = request.headers.get("Authorization", "") if bearer.startswith("Bearer"): # validate token and return it - _extra, token = [item.strip() for item in bearer.split(" ")] + bearer_parts = bearer.split(" ") + if len(bearer_parts) != 2: + raise TokenValidationError( + "Authorisation header specified but no bearer token provided!") + _extra, token = [item.strip() for item in bearer_parts] _jwt = jwks.validate_token( token, jwks.fetch_jwks(app.config["AUTH_SERVER_URL"], @@ -24,7 +28,7 @@ def require_token(func): error_message = "We expected a bearer token but did not get one." except TokenValidationError as _tve: app.logger.debug("Token validation failed.", exc_info=True) - error_message = "The token was found to be invalid." + error_message = "The provided token is invalid." return jsonify({ "error": "TokenValidationError", -- cgit 1.4.1