Skip to content

Invalid authorization headers raise an exception #174

@azmeuk

Description

@azmeuk

I stumbled upon a crash to an endpoint protected by token_auth, with a curl request for which I forgot to provide a token.

$ curl -H "Authorization: Bearer " -H "Accept: application/json" "http://localhost:5000/my_api_endpoint"
...
web     |   File "/usr/local/lib/python3.11/site-packages/flask_pyoidc/flask_pyoidc.py", line 455, in wrapper
web     |     token_introspection_result = self.introspect_token(
web     |                                  ^^^^^^^^^^^^^^^^^^^^^^
web     |   File "/usr/local/lib/python3.11/site-packages/flask_pyoidc/flask_pyoidc.py", line 388, in introspect_token
web     |     received_access_token = self._parse_access_token(request)
web     |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web     |   File "/usr/local/lib/python3.11/site-packages/flask_pyoidc/flask_pyoidc.py", line 362, in _parse_access_token
web     |     _, access_token = request.headers['Authorization'].split(maxsplit=1)

The faulty line is this one:

_, access_token = request.headers['Authorization'].split(maxsplit=1)

This is reproducible in a repr:

>>> a, b, = "Bearer ".split(maxsplit=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions