fix(security): раунд-2 SMTP-01 — отвергать управляющие символы в email

email с внутренним \r\n/табом/пробелом → header/SMTP-инъекция в письмо подтверждения.
Отвергаем (краевые пробелы .strip() и так чистит). Тест на внутренние control-chars.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-19 21:24:59 +10:00
co-authored by Claude Opus 4.8
parent 706037379b
commit b17443609a
3 changed files with 13 additions and 2 deletions
+3 -1
View File
@@ -182,7 +182,9 @@ def register_user(email: str, password: str, invite_token: str) -> dict:
from db import get_user_by_email, create_user, use_invite, set_verify_code
email = email.lower().strip()
if not email or "@" not in email or "/" in email or "\\" in email:
# Управляющие символы/пробелы → header/SMTP-инъекция в письмо подтверждения (пентест
# SMTP-01); '/'/'\\' → path-компонент в work_dir. Отвергаем.
if not email or "@" not in email or any(c in email for c in "/\\\r\n\t "):
return {"ok": False, "error": "Некорректный email"}
if len(password) < 6:
return {"ok": False, "error": "Пароль минимум 6 символов"}
+1 -1
View File
@@ -151,7 +151,7 @@ MAX_MESSAGE_LEN = 10_000
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
APP_VERSION = "2026-07-19l"
APP_VERSION = "2026-07-19m"
# Audit: path → action name mapping
_AUDIT_MAP = [
+9
View File
@@ -135,6 +135,15 @@ def test_verify_email_rate_limited(a):
# ---- инвайт не сгорает на существующем email ----
def test_email_control_chars_rejected(a):
"""SMTP-01: email с ВНУТРЕННИМ \\r\\n/табом/пробелом → header-инъекция в письмо, отвергается.
(краевые пробелы .strip() чистит — не инъекция.)"""
auth, _ = a
for bad in ["a@x.com\r\nBcc: victim@x.com", "a\t@x.com", "a@x\ncom", "a b@x.com"]:
r = auth.register_user(bad, "Secret123", "inv")
assert not r["ok"] and "email" in r["error"].lower(), f"{bad!r} → {r}"
def test_invite_not_burned_on_existing_email(a, monkeypatch):
auth, db = a
calls = {"used": []}