Reject NUL input before authentication and text persistence

This commit is contained in:
Artyom
2026-11-06 02:05:09 +03:00
parent 5c561eac26
commit e66e2d7d68
6 changed files with 202 additions and 6 deletions
+2
View File
@@ -30,6 +30,8 @@ class DisplayName:
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidUserData("поле display_name должно быть строкой")
if "\x00" in self.value:
raise InvalidUserData("поле display_name не может содержать NUL")
if not self.value.strip():
raise InvalidUserData("поле display_name не может быть пустым или состоять из пробелов")
if len(self.value) > DISPLAY_NAME_MAX:
@@ -37,7 +37,7 @@ def basic_credentials(value: str) -> tuple[str, str] | None:
except Base64Error, UnicodeDecodeError:
return None
username, separator, password = decoded.partition(":")
if not separator or not username.isascii():
if not separator or not username.isascii() or "\x00" in username:
return None
return username, password
+4
View File
@@ -14,6 +14,8 @@ class ChatTitle:
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidChatData("поле title должно быть строкой")
if "\x00" in self.value:
raise InvalidChatData("поле title не может содержать NUL")
if not self.value.strip():
raise InvalidChatData("поле title не может быть пустым или состоять из пробелов")
if len(self.value) > CHAT_TITLE_MAX:
@@ -30,6 +32,8 @@ class MessageText:
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidMessageText("поле text должно быть строкой")
if "\x00" in self.value:
raise InvalidMessageText("поле text не может содержать NUL")
if not self.value.strip():
raise InvalidMessageText("поле text не может быть пустым или состоять из пробелов")
if len(self.value) > MESSAGE_TEXT_MAX: