aboutsummaryrefslogtreecommitdiff
path: root/tests/test_auth.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 19:13:48 +0100
committerDennis Fink2026-11-13 19:13:48 +0100
commitc421d269313d6623926954935a680fe4acb1dc86 (patch)
treeee68db5d127808c544c218027cd117e7062e97d1 /tests/test_auth.py
parentfd61299d8a4d54836f0aa082aa47d02a786c7d93 (diff)
downloadwebmentions-ssg-c421d269313d6623926954935a680fe4acb1dc86.tar.gz
webmentions-ssg-c421d269313d6623926954935a680fe4acb1dc86.zip
fix(core): harden session and redirect validation
Reject non-string session identifiers explicitly and simplify fingerprint parsing so malformed authentication state fails closed. Tighten local redirect checks against control-character and backslash host tricks without relying on an unnecessary scheme check.
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index c302e8f..34df8ce 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -35,6 +35,12 @@ def test_load_user_returns_none_for_unknown_id(app: Flask) -> None:
assert load_user("99999:" + "a" * 64) is None
+@pytest.mark.parametrize("identifier", [None, 123, b"1:" + b"a" * 64])
+def test_load_user_rejects_non_string_sessions(app: Flask, identifier: object) -> None:
+ with app.app_context():
+ assert load_user(identifier) is None
+
+
def test_load_user_rejects_legacy_and_malformed_sessions(app: Flask) -> None:
with app.app_context():
user = User(username="account", password="secret")
@@ -122,6 +128,9 @@ def test_password_change_invalidates_existing_session(app: Flask) -> None:
pytest.param(r"/\evil.example", False, id="slash-backslash-host"),
pytest.param(r"/received\evil.example", False, id="backslash-in-path"),
pytest.param(r"\/evil.example", False, id="backslash-slash-host"),
+ pytest.param("/\n/evil.example", False, id="newline-host"),
+ pytest.param("/\r/evil.example", False, id="carriage-return-host"),
+ pytest.param("/\t/evil.example", False, id="tab-host"),
],
)
def test_is_safe_next_url(next_url: str, expected: bool) -> None: