From 3496b3882ca08e74c108d5abe417eccec5ed4f48 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 08:39:18 +0100 Subject: fix(core): reject all Unicode control characters Use shared Unicode category validation so passwords reject C1 controls in addition to C0 and DEL, and reuse the same helper for URL validation. --- tests/test_auth.py | 8 +++++++- tests/test_cli.py | 1 + tests/test_forms.py | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_auth.py b/tests/test_auth.py index 008382a..c302e8f 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -8,10 +8,16 @@ import pytest from flask import Flask from webmentions_ssg import db -from webmentions_ssg.auth import AUTH, is_safe_next_url, load_user +from webmentions_ssg.auth import AUTH, is_safe_next_url, load_user, validate_password from webmentions_ssg.models import User +@pytest.mark.parametrize("character", ["\x00", "\x1f", "\x7f", "\x80", "\x9f"]) +def test_validate_password_rejects_unicode_controls(character: str) -> None: + with pytest.raises(ValueError, match="control characters"): + validate_password(f"valid passphrase{character}") + + def test_user_loader_is_registered(app: Flask) -> None: assert AUTH._user_callback is load_user diff --git a/tests/test_cli.py b/tests/test_cli.py index e6214f2..ac673b4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -608,6 +608,7 @@ def test_users_cli_create_rolls_back_on_duplicate_race(app: Flask) -> None: [ ("short", "at least 8 characters"), ("good passphrase with\tab", "control characters"), + ("good passphrase with\x80c1", "control characters"), ], ) @pytest.mark.parametrize("operation", ["create", "set-password"]) diff --git a/tests/test_forms.py b/tests/test_forms.py index 20e655c..a37a6d0 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -222,6 +222,7 @@ def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields( pytest.param("https://example.com/a b", id="ascii-space"), pytest.param("https://example.com/a\u00a0b", id="unicode-whitespace"), pytest.param("https://example.com/\x7fb", id="del"), + pytest.param("https://example.com/a\x80b", id="c1-control"), ], ) def test_endpoint_rejects_invalid_httpx_urls_and_whitespace( -- cgit v1.3.1