Harden entry safety, unify runtime config, bound document unpacking
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled

Shared-IP safety: entry autoban and entry notifications default off, and a
shared IP is treated as review evidence only. ban_user/ban_cluster refuse
reason=entry_ip_collision (also with the legacy flag set to 1), so token status
and quota are never touched; explicit admin moderation still works.

Reproducible startup: new bot/runtime_config.py and scripts/run.py load the
repository .env (or --env-file) without shell interpolation, normalize
config/DB/upstream aliases, and make the bot, Mini App, gateway, econ cap,
account admin, mk_daemon, entry admin and key notifications resolve the same
paths. "run.py <target> --check" is an offline preflight that starts nothing
and reports placeholders, missing upstream DB and invalid data directories.

Resource limits: aggregate Office decompression, a 400 read-entry cap and a
per-row XLSX cell budget stop early; truncated or corrupt archives are
reported instead of raising.

Deploy and docs: only source-backed systemd units remain, and
deploy/runtime.env.example documents the environment contract including the
0600 session-secret file rules. Removed the destructive
"cp bot/iishko_bot.py bot/grok_bot.py" instruction, the unused generated site/
snapshot and the unsupported iishko-ts staging unit; corrected .env.example,
README, ARCHITECTURE, SECURITY, docs/native-gateway.md and iishko-ts/README.md.

Tests: entry safety, runtime bootstrap, economy paths, file intake, deploy
contract, abilities_guard CLI, and a startup smoke that launches all three
components through scripts/run.py with non-loopback network blocked. Every
config reader, selfcheck included, accepts a UTF-8 BOM.

Verified on this tree: pytest 716 passed + 322 subtests, node --test 73/73,
go test and go vet clean, selfcheck --source-only ok, gitleaks worktree and
history 0 findings. No production or live-split changes are included.
This commit is contained in:
Vlad Gothbreach
2026-10-31 00:39:35 +03:00
parent 52018ca568
commit af292ff15d
52 changed files with 2858 additions and 551 deletions
+3 -14
View File
@@ -7,7 +7,6 @@ import hmac
import ipaddress
import json
import math
import os
from pathlib import Path
import re
import secrets
@@ -20,6 +19,7 @@ import logging
log = logging.getLogger("entry_telemetry")
from support_store import NotificationError
from runtime_config import notifications_enabled
WINDOW = 86400
# Known shared reverse-proxy/WARP networks; operators may add their own NAT/relay ranges.
@@ -75,9 +75,7 @@ def public_ip(value):
def delivery_enabled():
# The existing support switch is also a hard entry-delivery kill switch for old fixtures.
return all(os.environ.get(name, "1") != "0" for name in (
"IISHKO_NOTIFICATIONS_ENABLED", "IISHKO_SUPPORT_DELIVERY_ENABLED", "IISHKO_ENTRY_DELIVERY_ENABLED"))
return notifications_enabled("entry")
def _label(value, length):
@@ -209,7 +207,6 @@ class EntryTelemetry:
if type(uid) is not int or not 0 < uid <= 2**63 - 1:
raise EntryError(403, "entry_forbidden", "Не удалось подтвердить аккаунт.")
now = int(self.clock())
ban_uids = []
with closing(self.connect()) as con:
self._eligible(con, uid)
ip = public_ip(ip)
@@ -245,15 +242,7 @@ class EntryTelemetry:
"VALUES(?,?,?,?,?,?)", (tag, now, payload, geo["country"], geo["city"], geo["source"]))
con.executemany("INSERT INTO wa_entry_outbox(alert_id,owner_id) VALUES(?,?)",
[(alert.lastrowid, owner) for owner in self.owners])
ban_uids = [row["uid"] for row in accounts]
con.commit()
if ban_uids:
try:
import entry_autoban
if entry_autoban.enabled(): # opt-in; otherwise the alert above is the only effect
entry_autoban.ban_cluster(ban_uids, reason="entry_ip_collision")
except Exception:
log.exception("entry autoban failed")
def claim(self):
now = self.clock()
@@ -303,7 +292,7 @@ def notification_text(claim, tags=()):
observed = time.strftime("%Y-%m-%d %H:%M UTC", time.gmtime(claim["created_at"]))
text = ("Mini App: совпадение сети за 24 часа\nНаблюдение: %s\n%s\nПримерный регион: %s\nИсточник: %s\n"
"Сеть #%s. Совпадение IP не доказывает общего владельца: возможны Wi-Fi, NAT, VPN или relay. "
"Автобан применён автоматически (все аккаунты сети, кроме админов).\nГеоданные: IP Geolocation by DB-IP, CC BY 4.0 — https://db-ip.com" %
"Автобан не применяется; требуется проверка администратором.\nГеоданные: IP Geolocation by DB-IP, CC BY 4.0 — https://db-ip.com" %
(observed, users, place, source, claim["ip_hmac"][:12]))[:3000]
# Operator tags always survive truncation: they are the fastest way to recognise a network.
marks = " · ".join(str(tag) for tag in list(tags or ())[:12] if tag)