diff options
| author | Dennis Fink | 2026-11-13 19:26:30 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-13 19:26:30 +0100 |
| commit | 2fbe1d383650cb31f3ef8d58c04e4d4095935833 (patch) | |
| tree | dc61624d393734a6a454a0be31b01f496ffc7da6 /webmentions_ssg | |
| parent | 5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232 (diff) | |
| download | webmentions-ssg-2fbe1d383650cb31f3ef8d58c04e4d4095935833.tar.gz webmentions-ssg-2fbe1d383650cb31f3ef8d58c04e4d4095935833.zip | |
refactor(core): simplify session fingerprint validation
Validate only the numeric user ID before lookup, then compare the
complete stored session identifier against the current user ID with a
constant-time byte check.
Diffstat (limited to 'webmentions_ssg')
| -rw-r--r-- | webmentions_ssg/auth.py | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/webmentions_ssg/auth.py b/webmentions_ssg/auth.py index edfc858..a5f3089 100644 --- a/webmentions_ssg/auth.py +++ b/webmentions_ssg/auth.py @@ -58,22 +58,12 @@ def load_user(session_id: object) -> User | None: 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) - ): + user_id, _, _ = session_id.partition(":") + if not (user_id.isascii() and user_id.isdecimal() and len(user_id) <= 19): return None user = db.session.get(User, int(user_id)) - if user is None: - return None - - if not compare_digest(session_id, user.get_id()): + if user is None or not compare_digest(session_id.encode(), user.get_id().encode()): return None return user |
