Skip to content

Commit

Permalink
Fix JWT in headers followed by a comma raises IndexError (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
Landon Gilbert-Bland committed May 2, 2021
1 parent a0f206e commit 39eba9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_jwt_extended/view_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _decode_jwt_from_headers():
header_type = config.header_type

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

Expand Down
12 changes: 12 additions & 0 deletions tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def test_default_headers(app):
assert response.get_json() == {"foo": "bar"}


def test_header_with_trailing_spaces_and_commas(app):
test_client = app.test_client()

with app.test_request_context():
access_token = create_access_token("username")

access_headers = {"Authorization": "Bearer {}, ".format(access_token)}
response = test_client.get("/protected", headers=access_headers)
assert response.status_code == 200
assert response.get_json() == {"foo": "bar"}


def test_custom_header_name(app):
app.config["JWT_HEADER_NAME"] = "Foo"
test_client = app.test_client()
Expand Down

0 comments on commit 39eba9c

Please sign in to comment.