Harden Telegram login, callback spinner and Mini App escaping
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled

- skin: tg_login rejects cross-site Origin; hash compared as bytes; tg_* cookies Secure
- bot: answer callback on fast handler failure; cap MENU_OWNER; image retries stop on
  terminal errors; upstream error texts sent without HTML parse mode
- Mini App: escape ids in action buttons and task rows; refresh in Neurolab empty state
- tests for spinner and tg login hardening
This commit is contained in:
2026-10-31 02:16:16 +03:00
parent af292ff15d
commit a05a36aa7b
5 changed files with 122 additions and 15 deletions
+10 -5
View File
@@ -1485,7 +1485,7 @@ def _tg_check_hash(data):
check = "\n".join("{}={}".format(k, pairs[k]) for k in sorted(pairs))
secret = hashlib.sha256(_tg_bot_token().encode()).digest()
digest = hmac.new(secret, check.encode(), hashlib.sha256).hexdigest()
return hmac.compare_digest(digest, received)
return hmac.compare_digest(digest.encode(), received.encode("utf-8", "replace"))
async def _newapi_call(session, method, path, bearer=None, json_body=None):
@@ -1720,13 +1720,13 @@ async def tg_callback(req):
if _tg_id and _tg_id.isdigit():
_row = await asyncio.to_thread(_tg_link_by_tgid, int(_tg_id))
if _row:
resp.set_cookie("tg_linked", "1", max_age=31536000,
resp.set_cookie("tg_linked", "1", max_age=31536000, secure=True,
httponly=False, samesite="Lax")
resp.set_cookie("tg_token", _row[1] or "", max_age=31536000,
resp.set_cookie("tg_token", _row[1] or "", max_age=31536000, secure=True,
httponly=True, samesite="Lax")
resp.set_cookie("tg_points", str(_row[2] or 0), max_age=31536000,
resp.set_cookie("tg_points", str(_row[2] or 0), max_age=31536000, secure=True,
httponly=False, samesite="Lax")
resp.set_cookie("tg_vip", str(_row[3] or 0), max_age=31536000,
resp.set_cookie("tg_vip", str(_row[3] or 0), max_age=31536000, secure=True,
httponly=False, samesite="Lax")
return resp
@@ -1764,6 +1764,11 @@ def _tg_normalize(data):
async def tg_login(req):
# Login CSRF: a cross-site form must not plant the attacker's signed session.
if req.headers.get("Origin") not in (
"https://reformboss.com", "https://api.reformboss.com", "https://" + req.host):
return web.json_response({"success": False, "error": "bad_origin"},
status=403, headers={"Cache-Control": "no-store"})
raw_body = await req.text()
try:
data = json.loads(raw_body)