From 761f01015f1342b20a81ce777d1237632f027d21 Mon Sep 17 00:00:00 2001 From: Joao Prado Maia Date: Tue, 10 Nov 2026 06:06:31 -0600 Subject: [PATCH 1/4] Reject, rather than crash on, Phorum crypt passwords with odd salts Phorum uses the first characters of the password as the DES salt, and glibc's crypt() raises OSError for salt characters outside [a-zA-Z0-9./] (macOS accepts them). A login with a password like '!secret' raised an exception instead of being rejected. --- auth/phorum_mysql_users.py | 7 ++++++- auth/phorum_pgsql_users.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/auth/phorum_mysql_users.py b/auth/phorum_mysql_users.py index 4c3db30..83cf0f9 100755 --- a/auth/phorum_mysql_users.py +++ b/auth/phorum_mysql_users.py @@ -38,7 +38,12 @@ def is_valid_user(self, username, password): if len(db_password) == 32: result = (db_password != hashlib.md5(password.encode('utf-8')).hexdigest()) else: - result = (db_password != crypt.crypt(password, password[:settings.PHP_CRYPT_SALT_LENGTH])) + try: + result = (db_password != crypt.crypt(password, password[:settings.PHP_CRYPT_SALT_LENGTH])) + except OSError: + # glibc rejects salt characters outside [a-zA-Z0-9./]; such a + # password can't match a DES-crypted one + result = True if result: settings.logEvent('Error - Authentication failed for username \'%s\' (incorrect password)' % (username)) return 0 diff --git a/auth/phorum_pgsql_users.py b/auth/phorum_pgsql_users.py index b099751..cf48a2b 100755 --- a/auth/phorum_pgsql_users.py +++ b/auth/phorum_pgsql_users.py @@ -40,7 +40,12 @@ def is_valid_user(self, username, password): if len(db_password) == 32: result = (db_password != hashlib.md5(password.encode('utf-8')).hexdigest()) else: - result = (db_password != crypt.crypt(password, password[:settings.PHP_CRYPT_SALT_LENGTH])) + try: + result = (db_password != crypt.crypt(password, password[:settings.PHP_CRYPT_SALT_LENGTH])) + except OSError: + # glibc rejects salt characters outside [a-zA-Z0-9./]; such a + # password can't match a DES-crypted one + result = True if result: settings.logEvent('Error - Authentication failed for username \'%s\' (incorrect password)' % (username)) return 0 From edb74c3d5930cf8a61f789b0339d09c53bab3320 Mon Sep 17 00:00:00 2001 From: Joao Prado Maia Date: Tue, 10 Nov 2026 06:06:31 -0600 Subject: [PATCH 2/4] Test Phorum crypt/MD5 logins; add standard-crypt to dev requirements The Phorum auth modules import crypt, which left the standard library in Python 3.13. --- requirements-dev.txt | 2 ++ tests/test_sql_backends.py | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8b17f72..4ad74d1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,5 @@ # Test dependencies (install with: pip install -r requirements-dev.txt) pytest pytest-cov +# the Phorum auth modules import crypt, removed from the stdlib in 3.13 +standard-crypt; python_version >= "3.13" diff --git a/tests/test_sql_backends.py b/tests/test_sql_backends.py index 87f7c0c..f807cf1 100644 --- a/tests/test_sql_backends.py +++ b/tests/test_sql_backends.py @@ -220,3 +220,42 @@ def test_check_statement_catches_problems(): assert check_statement("WHERE a=%s AND b=%s", ("x",)) assert check_statement("WHERE a=%s", None) assert check_statement("WHERE a=%s", ("x",)) == [] + + +class RowsCursor(FakeCursor): + """Cursor that returns a fixed password hash.""" + def __init__(self, stored): + super().__init__(1) + self.stored = stored + + def fetchone(self): + return (self.stored,) + + +@pytest.mark.parametrize("module_name", ["auth.phorum_mysql_users", "auth.phorum_pgsql_users"], + ids=lambda m: m.split(".")[1]) +@pytest.mark.parametrize("password, accepted", [ + ("secret", True), + ("wrong!", False), + # regression: glibc's crypt() raises OSError for salt characters outside + # [a-zA-Z0-9./], and Phorum uses the password's first characters as salt + ("!secret", False), + ("'; --", False), +]) +def test_phorum_crypt_passwords(load, module_name, password, accepted): + import crypt + module, _ = load(module_name) + auth = module.Papercut_Auth() + auth.cursor = RowsCursor(crypt.crypt("secret", "se")) + assert bool(auth.is_valid_user("alice", password)) == accepted + + +@pytest.mark.parametrize("module_name", ["auth.phorum_mysql_users", "auth.phorum_pgsql_users"], + ids=lambda m: m.split(".")[1]) +def test_phorum_md5_passwords(load, module_name): + import hashlib + module, _ = load(module_name) + auth = module.Papercut_Auth() + auth.cursor = RowsCursor(hashlib.md5(b"secret").hexdigest()) + assert auth.is_valid_user("alice", "secret") + assert not auth.is_valid_user("alice", "wrong") From 2bfdb152b19b83d3be02e366e4de9c0f07710d48 Mon Sep 17 00:00:00 2001 From: Joao Prado Maia Date: Tue, 10 Nov 2026 06:06:31 -0600 Subject: [PATCH 3/4] Run the unit tests on GitHub Actions Step 6 of docs/unit-testing-plan.md: unit tests on Python 3.10 to 3.15, with a coverage report uploaded from the 3.13 run. --- .github/workflows/tests.yml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ docs/unit-testing-plan.md | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..e94f1d3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,34 @@ +name: tests + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +jobs: + unit: + name: unit tests (Python ${{ matrix.python }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + allow-prereleases: true + cache: pip + cache-dependency-path: requirements-dev.txt + - run: pip install -r requirements-dev.txt + # the DB drivers and nntplib are replaced by fakes, so they aren't needed + - run: python -m pytest --cov=. --cov-report=term --cov-report=xml + - uses: actions/upload-artifact@v4 + if: matrix.python == '3.13' + with: + name: coverage + path: coverage.xml diff --git a/.gitignore b/.gitignore index 78ec7b1..68e6a15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ __pycache__/ *.py[co] +.coverage +coverage.xml +.pytest_cache/ diff --git a/docs/unit-testing-plan.md b/docs/unit-testing-plan.md index 570e77b..ad06719 100644 --- a/docs/unit-testing-plan.md +++ b/docs/unit-testing-plan.md @@ -1,6 +1,6 @@ # Plan: Unit tests -**Status:** in progress (steps 1-5 done) +**Status:** in progress (steps 1-6 done; Docker integration tests remain) **Related:** [integration testing plan](integration-testing-plan.md) ## Goal From 0359b87579576dc0b5acbbeada065b599ff5ceba Mon Sep 17 00:00:00 2001 From: Joao Prado Maia Date: Tue, 10 Nov 2026 06:07:39 -0600 Subject: [PATCH 4/4] Use the Node 24 versions of the GitHub actions checkout@v4, setup-python@v5 and upload-artifact@v4 target Node.js 20, which GitHub is retiring. --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e94f1d3..325b30e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,8 +17,8 @@ jobs: matrix: python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 with: python-version: ${{ matrix.python }} allow-prereleases: true @@ -27,7 +27,7 @@ jobs: - run: pip install -r requirements-dev.txt # the DB drivers and nntplib are replaced by fakes, so they aren't needed - run: python -m pytest --cov=. --cov-report=term --cov-report=xml - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 if: matrix.python == '3.13' with: name: coverage