flask-simpleldap
flask-simpleldap copied to clipboard
Proposing that get_user_groups always returns a list
Proposing that get_user_groups(self, user) always returns a list, or that the example is changed to recommend that you check for a None before setting g.ldap_groups.
Having g.ldap_groups be None is dangerous since the group_required() decorator will crash if it tries to iterate over g.ldap_groups.
I just tried having a valid user be without a group, and this lead to to a None, and not an empty list which would have been safe.
Specifically, this issue ends up causing an Internal Error if you have a user with no group per the traceback below.
[2020-11-30 15:42:28,344] ERROR in app: Exception on / [GET] Traceback (most recent call last): File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask_simpleldap/__init__.py", line 299, in wrapped return func(*args, **kwargs) File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask_simpleldap/__init__.py", line 325, in wrapped match = [group for group in groups if group in g.ldap_groups] File "/Users/dgearhart/.local/share/virtualenvs/TeamViewerMapping-cIPbCUo0/lib/python3.8/site-packages/flask_simpleldap/__init__.py", line 325, in <listcomp> match = [group for group in groups if group in g.ldap_groups] TypeError: argument of type 'NoneType' is not iterable 127.0.0.1 - - [30/Nov/2020 15:42:28] "GET / HTTP/1.1" 500 -