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
+16 -7
View File
@@ -1,25 +1,23 @@
"""Opt-in: automatic IP-collision bans run only with IISHKO_ENTRY_AUTOBAN=1.
A shared IP (NAT, mobile CGNAT, family Wi-Fi) is otherwise only an operator alert.
Manual operator bans (ban_cluster) are not gated by this flag."""
import json
import logging
import os
from pathlib import Path
import re
import sqlite3
from runtime_config import bot_db_path, env_enabled, gateway_db_path, skin_db_path
log = logging.getLogger("entry_autoban")
BOT_DB = os.environ.get("IISHKO_BOT_DB", "/opt/grok-bot/bot.db")
GW_DB = os.environ.get("IISHKO_GW_DB", "/opt/grok-gateway/new-api/one-api.db")
SKIN_DB = os.environ.get("IISHKO_SKIN_DB") or os.environ.get("GATE_TG_DB", "/opt/grok-web-skin-tg.db")
BOT_DB = bot_db_path()
GW_DB = gateway_db_path()
SKIN_DB = skin_db_path()
PROTECT = tuple(int(v) for v in os.environ.get("IISHKO_PROTECTED_UIDS", "").replace(";", ",").split(",")
if v.strip().isdigit())
def enabled():
return os.environ.get("IISHKO_ENTRY_AUTOBAN", "0").strip().lower() in ("1", "on", "yes", "true")
return env_enabled("IISHKO_ENTRY_AUTOBAN")
def _connect(path):
@@ -97,6 +95,11 @@ def _processed(g, con, uid, was_banned):
def ban_user(uid, reason="entry_ip_collision", taken=None):
"""Legacy enforcement; an omitted reason or a shared IP never authorizes sanctions."""
# An IP match is evidence for review, not account ownership or fraud.
if reason == "entry_ip_collision":
log.info("[ENTRY-AUTOBAN] shared-IP ban skipped uid=%s", uid)
return False
uid = int(uid)
if uid in PROTECT:
return False
@@ -200,7 +203,13 @@ def ban_user(uid, reason="entry_ip_collision", taken=None):
def ban_cluster(uids, reason="entry_ip_collision"):
if reason == "entry_ip_collision":
log.info("[ENTRY-AUTOBAN] shared network recorded without sanctions")
return []
uids = [int(u) for u in uids]
if reason != "admin_button" and not enabled():
log.warning("[ENTRY-AUTOBAN] disabled")
return []
out = []
for uid in dict.fromkeys(uids):
try: