diff options
| author | Dennis Fink | 2026-10-31 16:42:44 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-31 16:42:44 +0100 |
| commit | 3494eab1208dc18478485e02c61e292556502fa6 (patch) | |
| tree | 5d9e95d709b119a0245d0294837f9b6a7e38bff1 /webmentions_ssg/models.py | |
| parent | fdb1762715658eae987dd104a0e6d3cb92a4a8d7 (diff) | |
| download | webmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.tar.gz webmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.zip | |
fix(core): harden session and credential security
Require persistent non-placeholder signing keys outside local
development and bind login sessions to the current password hash so
password changes revoke existing cookies.
Enforce a minimal password policy for user administration while
preserving long Unicode passphrases without arbitrary composition
limits.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/models.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py index 58f95bc..7cab879 100644 --- a/webmentions_ssg/models.py +++ b/webmentions_ssg/models.py @@ -9,6 +9,7 @@ from __future__ import annotations import uuid from datetime import UTC, datetime from enum import StrEnum +from hashlib import sha256 from typing import Never from flask_login import UserMixin @@ -77,6 +78,16 @@ class User(UserMixin, Base): """ self.password_hash = generate_password_hash(password) + def get_id(self) -> str: + """Bind the login session to the current stored password hash. + + Only a one-way fingerprint is placed in Flask's signed cookie, never + the password hash itself. Rehashing the password invalidates all + previously issued session identifiers without a schema change. + """ + fingerprint = sha256(self.password_hash.encode("utf-8")).hexdigest() + return f"{self.id}:{fingerprint}" + def check_password(self, password: str) -> bool: """ Check a plain-text password against the stored password hash. |
