From 3494eab1208dc18478485e02c61e292556502fa6 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 16:42:44 +0100 Subject: 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. --- webmentions_ssg/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'webmentions_ssg/models.py') 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. -- cgit v1.3.1