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/cli/users.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 'webmentions_ssg/cli/users.py')
| -rw-r--r-- | webmentions_ssg/cli/users.py | 15 |
1 files changed, 10 insertions, 5 deletions
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 |
