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/cli/users.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'webmentions_ssg/cli') diff --git a/webmentions_ssg/cli/users.py b/webmentions_ssg/cli/users.py index 7c6afde..a48fc71 100644 --- a/webmentions_ssg/cli/users.py +++ b/webmentions_ssg/cli/users.py @@ -10,6 +10,7 @@ from flask.cli import AppGroup from sqlalchemy.exc import IntegrityError from .. import DATABASE +from ..security import validate_password USERS_CLI = AppGroup("users", help="Manage users.") @@ -41,8 +42,10 @@ def create_user(username: str, password: str) -> None: if not username: raise click.ClickException("Username must not be empty.") - if not password: - raise click.ClickException("Password must not be empty.") + try: + validate_password(password) + except ValueError as exc: + raise click.ClickException(str(exc)) from exc if DATABASE.session.scalar(sa.select(User).where(User.username == username)): raise click.ClickException(f"User {username!r} already exists.") @@ -81,10 +84,12 @@ def set_user_password(username: str, password: str) -> None: :param username: Username of the account to update. :param password: New plain-text password to hash and store. - :raises click.ClickException: If the account is missing or the password is empty. + :raises click.ClickException: If the account is missing or the password is invalid. """ - if not password: - raise click.ClickException("Password must not be empty.") + try: + validate_password(password) + except ValueError as exc: + raise click.ClickException(str(exc)) from exc user = _require_user(username) user.password = password -- cgit v1.3.1