Reject non-ASCII Basic payloads before decoding
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
date: 2026-11-05T23:17:40.020055+00:00 commit: f7bfd1d4731baf70eef18d3f95a4a655128990ba
|
||||
Application code unchanged from d60e29221a553c62ee5dc27615c17fdaa6d27895; new regression tests in working tree.
|
||||
$ .venv/bin/pytest -q student-tests/unit/test_authentication.py -k non_ascii --tb=short
|
||||
FFFFFFFF [100%]
|
||||
=================================== FAILURES ===================================
|
||||
___________________ test_basic_rejects_non_ascii[Basic \x80] ___________________
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\x80' in position 0: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:60: in test_basic_rejects_non_ascii
|
||||
assert basic_credentials(raw.decode("latin-1")) is None
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
___________________ test_basic_rejects_non_ascii[Basic \xff] ___________________
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\xff' in position 0: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:60: in test_basic_rejects_non_ascii
|
||||
assert basic_credentials(raw.decode("latin-1")) is None
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
_________________ test_basic_rejects_non_ascii[Basic \xc3\xa9] _________________
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:60: in test_basic_rejects_non_ascii
|
||||
assert basic_credentials(raw.decode("latin-1")) is None
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
___________ test_basic_rejects_non_ascii[Basic YWxpY2U6c2VjcmV0\xff] ___________
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\xff' in position 16: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:60: in test_basic_rejects_non_ascii
|
||||
assert basic_credentials(raw.decode("latin-1")) is None
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
____ test_non_ascii_basic_returns_401_without_credential_lookup[Basic \x80] ____
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\x80' in position 0: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:76: in test_non_ascii_basic_returns_401_without_credential_lookup
|
||||
await pipeline(scope, AsyncMock(), send)
|
||||
src/messenger/shared/entrypoints/pipeline.py:118: in __call__
|
||||
rejection = self._oversized(scope) or await self._guard(scope)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:65: in guard
|
||||
credentials = basic_credentials(raw)
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
____ test_non_ascii_basic_returns_401_without_credential_lookup[Basic \xff] ____
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\xff' in position 0: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:76: in test_non_ascii_basic_returns_401_without_credential_lookup
|
||||
await pipeline(scope, AsyncMock(), send)
|
||||
src/messenger/shared/entrypoints/pipeline.py:118: in __call__
|
||||
rejection = self._oversized(scope) or await self._guard(scope)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:65: in guard
|
||||
credentials = basic_credentials(raw)
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
__ test_non_ascii_basic_returns_401_without_credential_lookup[Basic \xc3\xa9] __
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:76: in test_non_ascii_basic_returns_401_without_credential_lookup
|
||||
await pipeline(scope, AsyncMock(), send)
|
||||
src/messenger/shared/entrypoints/pipeline.py:118: in __call__
|
||||
rejection = self._oversized(scope) or await self._guard(scope)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:65: in guard
|
||||
credentials = basic_credentials(raw)
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
_ test_non_ascii_basic_returns_401_without_credential_lookup[Basic YWxpY2U6c2VjcmV0\xff] _
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:34: in _bytes_from_decode_data
|
||||
return s.encode('ascii')
|
||||
^^^^^^^^^^^^^^^^^
|
||||
E UnicodeEncodeError: 'ascii' codec can't encode character '\xff' in position 16: ordinal not in range(128)
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
student-tests/unit/test_authentication.py:76: in test_non_ascii_basic_returns_401_without_credential_lookup
|
||||
await pipeline(scope, AsyncMock(), send)
|
||||
src/messenger/shared/entrypoints/pipeline.py:118: in __call__
|
||||
rejection = self._oversized(scope) or await self._guard(scope)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:65: in guard
|
||||
credentials = basic_credentials(raw)
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
src/messenger/identity/entrypoints/authentication.py:36: in basic_credentials
|
||||
decoded = b64decode(encoded.strip(), validate=True).decode("utf-8")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:80: in b64decode
|
||||
s = _bytes_from_decode_data(s)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
../../../../../.local/share/uv/python/cpython-3.14.5-macos-aarch64-none/lib/python3.14/base64.py:36: in _bytes_from_decode_data
|
||||
raise ValueError('string argument should contain only ASCII characters')
|
||||
E ValueError: string argument should contain only ASCII characters
|
||||
=========================== short test summary info ============================
|
||||
FAILED student-tests/unit/test_authentication.py::test_basic_rejects_non_ascii[Basic \x80]
|
||||
FAILED student-tests/unit/test_authentication.py::test_basic_rejects_non_ascii[Basic \xff]
|
||||
FAILED student-tests/unit/test_authentication.py::test_basic_rejects_non_ascii[Basic \xc3\xa9]
|
||||
FAILED student-tests/unit/test_authentication.py::test_basic_rejects_non_ascii[Basic YWxpY2U6c2VjcmV0\xff]
|
||||
FAILED student-tests/unit/test_authentication.py::test_non_ascii_basic_returns_401_without_credential_lookup[Basic \x80]
|
||||
FAILED student-tests/unit/test_authentication.py::test_non_ascii_basic_returns_401_without_credential_lookup[Basic \xff]
|
||||
FAILED student-tests/unit/test_authentication.py::test_non_ascii_basic_returns_401_without_credential_lookup[Basic \xc3\xa9]
|
||||
FAILED student-tests/unit/test_authentication.py::test_non_ascii_basic_returns_401_without_credential_lookup[Basic YWxpY2U6c2VjcmV0\xff]
|
||||
8 failed, 21 deselected in 0.12s
|
||||
|
||||
exit_code: 1
|
||||
Reference in New Issue
Block a user