Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Invalid authorization headers raise an exception #174

Open
azmeuk opened this issue Mar 11, 2024 · 1 comment
Open

Invalid authorization headers raise an exception #174

azmeuk opened this issue Mar 11, 2024 · 1 comment

Comments

@azmeuk
Copy link

azmeuk commented Mar 11, 2024

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)
@infohash
Copy link
Contributor

I'll add exception handling there to let the user know that it's a bad access token format. I have an open PR which does few changes to these methods, I'll add this fix there.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants