forked from mtusi2026/mtusi2026lab2
Reject NUL input before authentication and text persistence
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user