Skip to content

Commit 39eba9c

Browse files
author
Landon Gilbert-Bland
committed
Fix JWT in headers followed by a comma raises IndexError (#347)
1 parent a0f206e commit 39eba9c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

flask_jwt_extended/view_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _decode_jwt_from_headers():
141141
header_type = config.header_type
142142

143143
# Verify we have the auth header
144-
auth_header = request.headers.get(header_name, None)
144+
auth_header = request.headers.get(header_name, "").strip().strip(",")
145145
if not auth_header:
146146
raise NoAuthorizationError("Missing {} Header".format(header_name))
147147

tests/test_headers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def test_default_headers(app):
5454
assert response.get_json() == {"foo": "bar"}
5555

5656

57+
def test_header_with_trailing_spaces_and_commas(app):
58+
test_client = app.test_client()
59+
60+
with app.test_request_context():
61+
access_token = create_access_token("username")
62+
63+
access_headers = {"Authorization": "Bearer {}, ".format(access_token)}
64+
response = test_client.get("/protected", headers=access_headers)
65+
assert response.status_code == 200
66+
assert response.get_json() == {"foo": "bar"}
67+
68+
5769
def test_custom_header_name(app):
5870
app.config["JWT_HEADER_NAME"] = "Foo"
5971
test_client = app.test_client()

0 commit comments

Comments
 (0)