diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-06-26 12:02:05 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-06-26 12:02:05 -0500 |
| commit | 4268c2f8774e8c8a45e5c596b89dcf62570c12f8 (patch) | |
| tree | 87dd4436a123192f915ff1b418d3c28147166427 | |
| parent | 0d0d4169d4ae71240f8d943465dac5193b3aa407 (diff) | |
| download | genenetwork3-4268c2f8774e8c8a45e5c596b89dcf62570c12f8.tar.gz | |
Bug: Check for valid "Bearer" section.
| -rw-r--r-- | gn3/oauth2/authorisation.py | 8 |
1 files 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", |
