diff options
| author | Dennis Fink | 2026-11-12 19:57:08 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-12 19:57:08 +0100 |
| commit | 4bd1d9e348918b2e55db47a1ac3489d035cf55e2 (patch) | |
| tree | f7ed41a374a8a4136792039a262dc62aa8cf8c59 /webmentions_ssg/security.py | |
| parent | 7035e9f9467684cccae2b7ff3faaa62e6a9f91aa (diff) | |
| download | webmentions-ssg-4bd1d9e348918b2e55db47a1ac3489d035cf55e2.tar.gz webmentions-ssg-4bd1d9e348918b2e55db47a1ac3489d035cf55e2.zip | |
refactor(core): split modules by responsibility
Break up monolithic views, task helpers, networking, CLI, and
application extension setup so each module owns a focused concern.
Reorganize the test suite around the new boundaries while preserving
existing Webmention behavior and coverage.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/security.py | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/webmentions_ssg/security.py b/webmentions_ssg/security.py deleted file mode 100644 index f4841a4..0000000 --- a/webmentions_ssg/security.py +++ /dev/null @@ -1,51 +0,0 @@ -# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> -# -# SPDX-License-Identifier: BSD-3-Clause - -"""Validate persistent signing keys and administrator passwords.""" - -MIN_PASSWORD_LENGTH = 8 -MIN_SECRET_KEY_LENGTH = 32 - - -def validate_secret_key(value: object) -> None: - """Require a non-placeholder, sufficiently long deployment signing key.""" - if not isinstance(value, (str, bytes)): - raise TypeError( - "Configure a persistent SECRET_KEY of at least 32 random bytes " - "before starting." - ) - - # Flask accepts either text or bytes as its signing key. Reject common - # example/development values even when their lengths look sufficient. - key = value.encode("utf-8") if isinstance(value, str) else value - if len(key) < MIN_SECRET_KEY_LENGTH or not key.strip(): - raise RuntimeError( - "Configure a persistent SECRET_KEY of at least 32 random bytes " - "before starting." - ) - - normalized = key.strip().lower() - if normalized.startswith( - (b"replace_with", b"changeme", b"change_me", b"your_", b"insecure_") - ): - raise RuntimeError( - "SECRET_KEY is an example/development placeholder; " - "generate and configure a real random key." - ) - - -def validate_password(password: str) -> None: - """Validate newly chosen passwords without arbitrary composition rules. - - Allow Unicode, whitespace-only passwords, and arbitrarily long passphrases, - but reject empty passwords and control characters. - """ - if not password: - raise ValueError("Password must not be empty.") - if len(password) < MIN_PASSWORD_LENGTH: - raise ValueError( - f"Password must be at least {MIN_PASSWORD_LENGTH} characters long." - ) - if any(ord(char) < 32 or ord(char) == 127 for char in password): - raise ValueError("Password must not contain control characters.") |
