Skip to content

Commit

Permalink
Fix configuration without authentication
Browse files Browse the repository at this point in the history
If an empty password was configured in the user interface configuration,
instead of requiring no authentication, pyCA would throw an internal
server error:

```
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lars/dev/opencast/pyCA/pyca/ui/utils.py", line 16, in decorated
    or auth.username != config('ui', 'username') \
       ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'username'
```

This patch fixes the issue.
  • Loading branch information
lkiesow committed Aug 18, 2023
1 parent 1f36b1e commit 613d4f0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pyca/ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
headers = {'WWW-Authenticate': 'Basic realm="pyCA Login"'}
auth = request.authorization
if config('ui', 'password') and not auth \
or auth.username != config('ui', 'username') \
or auth.password != config('ui', 'password'):
return Response('pyCA: Login required\n', 401,
{'WWW-Authenticate': 'Basic realm="pyCA Login"'})
if config('ui', 'password'):
auth_provided = (auth.username, auth.password) if auth else None
auth_expected = config('ui', 'username'), config('ui', 'password')
if auth_provided != auth_expected:
return Response('pyCA: Login required\n', 401, headers)
return f(*args, **kwargs)
return decorated

Expand Down

0 comments on commit 613d4f0

Please sign in to comment.