This commit is contained in:
+6
-2
@@ -34,7 +34,9 @@ if "DATABASE_PASSWORD" in os.environ:
|
||||
)
|
||||
REDIS_URL = os.environ.get("REDIS_URL", "redis://localhost:6379/0")
|
||||
SESSION_TTL = int(os.environ.get("SESSION_TTL_SECONDS", "3600"))
|
||||
MAX_BODY = int(os.environ.get("MAX_HTTP_BODY_BYTES", "16384"))
|
||||
MAX_BODY = int(os.environ.get("MAX_HTTP_BODY_BYTES", "65536"))
|
||||
if MAX_BODY < 65536:
|
||||
raise ValueError("MAX_HTTP_BODY_BYTES must be at least 65536")
|
||||
POOL_SIZE = int(os.environ.get("DB_POOL_SIZE", "10"))
|
||||
CACHE_ENABLED = os.environ.get("CACHE_ENABLED", "1") == "1"
|
||||
CACHE_LOCK_ENABLED = os.environ.get("CACHE_LOCK_ENABLED", "1") == "1"
|
||||
@@ -321,7 +323,7 @@ async def create_user(request: Request):
|
||||
invalid("Некорректный username")
|
||||
display = text_field(data["display_name"], 100)
|
||||
password = data["password"]
|
||||
if not isinstance(password, str) or not 12 <= len(password) <= 128:
|
||||
if not isinstance(password, str) or not 12 <= len(password) <= 128 or not password.strip():
|
||||
invalid("Некорректный пароль")
|
||||
try:
|
||||
return await asyncio.to_thread(insert_user, name, display, password)
|
||||
@@ -347,6 +349,8 @@ async def login(request: Request):
|
||||
raise ValueError()
|
||||
decoded = base64.b64decode(auth[6:], validate=True).decode("utf-8")
|
||||
name, password = decoded.split(":", 1)
|
||||
if not re.fullmatch(r"[a-z0-9_]{3,32}", name) or not 12 <= len(password) <= 128 or not password.strip():
|
||||
raise ValueError()
|
||||
except (ValueError, UnicodeError, binascii.Error):
|
||||
raise ApiError(401, "unauthorized", "Неверные учётные данные", 'Basic realm="messenger", charset="UTF-8"') from None
|
||||
return await asyncio.to_thread(create_session, name, password)
|
||||
|
||||
Reference in New Issue
Block a user