diff options
Diffstat (limited to 'webmentions_ssg/auth.py')
| -rw-r--r-- | webmentions_ssg/auth.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/webmentions_ssg/auth.py b/webmentions_ssg/auth.py index 1707917..6d4fe95 100644 --- a/webmentions_ssg/auth.py +++ b/webmentions_ssg/auth.py @@ -44,26 +44,27 @@ def validate_password(password: str) -> None: @AUTH.user_loader -def load_user(session_id: str) -> User | None: +def load_user(session_id: object) -> User | None: """Load a user from the database by identifier. :param session_id: Database ID and password-hash fingerprint stored in the session. :return: Matching user, or ``None`` if no user exists with the identifier. """ - try: - user_id, fingerprint = session_id.split(":", 1) - if ( - not user_id.isascii() - or not user_id.isdecimal() - or len(user_id) > 19 - or len(fingerprint) != 64 - or any(char not in "0123456789abcdef" for char in fingerprint) - ): - return None - user = db.session.get(User, int(user_id)) - except AttributeError, TypeError, ValueError: + if not isinstance(session_id, str): + return None + + user_id, separator, fingerprint = session_id.partition(":") + if ( + not separator + or not user_id.isascii() + or not user_id.isdecimal() + or len(user_id) > 19 + or len(fingerprint) != 64 + or any(char not in "0123456789abcdef" for char in fingerprint) + ): return None + user = db.session.get(User, int(user_id)) if user is None: return None @@ -90,8 +91,7 @@ def is_safe_next_url(next_url: str) -> bool: except ValueError: return False return ( - not target.scheme - and not target.netloc + not target.netloc and target.path.startswith("/") and not target.path.startswith("//") ) |
