Harden entry safety, unify runtime config, bound document unpacking
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:
@@ -28,6 +28,7 @@ from gateway_features import install as install_gateway_features
|
||||
from gateway_provider_relay import relay_selected
|
||||
from gateway_providers import ProviderError, ProviderRegistry
|
||||
from gateway_policy import denial_response
|
||||
from runtime_config import bot_config_path, bot_db_path, effective_bot_config, skin_db_path
|
||||
# [MODELMETA 2026-10-28] vendor-reference limits: static JSON, read-only, no network.
|
||||
# Optional import: the gateway must boot even if the reference file/module is absent.
|
||||
try:
|
||||
@@ -99,7 +100,12 @@ async def _models_catalogue_response(req, upstream):
|
||||
|
||||
PROVIDER_KEY = web.AppKey("iishko_providers", ProviderRegistry)
|
||||
|
||||
UPSTREAM = os.environ.get("IISHKO_UPSTREAM", "http://127.0.0.1:48000")
|
||||
try:
|
||||
with open(bot_config_path(), encoding="utf-8-sig") as config_file:
|
||||
_runtime_cfg = effective_bot_config(json.load(config_file))
|
||||
except FileNotFoundError:
|
||||
_runtime_cfg = effective_bot_config({})
|
||||
UPSTREAM = _runtime_cfg["newapi_url"].rstrip("/")
|
||||
TIMEOUT = aiohttp.ClientTimeout(total=None, connect=10, sock_connect=10, sock_read=860)
|
||||
# Preserve the existing 64 generation slots; reserve independent capacity for reads.
|
||||
GENERATION_CONNECTIONS = 256
|
||||
@@ -109,10 +115,8 @@ MAX_BODY = 40 * 1024 * 1024
|
||||
MAX_SSE_FRAME = 65536
|
||||
LOG = logging.getLogger("gateway_proxy")
|
||||
|
||||
# ---------- [GATE] daily checkin + chat subscription enforcement (owner 2026-10-08) ----------
|
||||
# Reads current bot-account policy; unavailable databases temporarily deny access.
|
||||
GATE_BOT_DB = os.environ.get("GATE_BOT_DB", os.environ.get("IISHKO_BOT_DB", "/opt/grok-bot/bot.db"))
|
||||
GATE_NEWAPI_DB = os.environ.get("GATE_NEWAPI_DB", os.environ.get("IISHKO_GW_DB", "/opt/grok-gateway/new-api/one-api.db"))
|
||||
GATE_NEWAPI_DB = _runtime_cfg["newapi_db"]
|
||||
GATE_BOT_DB = bot_db_path(_runtime_cfg["bot_db"])
|
||||
GATE_TTL = 60
|
||||
_gate_cache = {}
|
||||
_gate_err_ts = [0.0]
|
||||
@@ -1075,9 +1079,9 @@ async def brand_asset(req):
|
||||
# injected JS POSTs it to /api/tg_widget_login.
|
||||
# Provision: new-api user "tg<id>" via admin API, password kept in skin-local store (0600).
|
||||
# Login: server-side POST /api/user/login, Set-Cookie forwarded to the browser.
|
||||
TG_BOT_CONFIG = os.environ.get("GATE_BOT_CONFIG", "/opt/grok-bot/config.json")
|
||||
TG_BOT_CONFIG = bot_config_path()
|
||||
TG_ADMIN_TOKEN_FILE = "/root/.secrets/newapi_admin_token"
|
||||
TG_PROVISION_DB = os.environ.get("IISHKO_SKIN_DB") or os.environ.get("GATE_TG_DB", "/opt/grok-web-skin-tg.db")
|
||||
TG_PROVISION_DB = skin_db_path()
|
||||
TG_AUTH_MAX_AGE = 900
|
||||
TG_SID_SECRET_FILE = os.environ.get("TG_SID_SECRET_FILE", "/root/.secrets/iishko_tg_sid_secret")
|
||||
_TG_SID_SECRET = None
|
||||
@@ -1464,8 +1468,8 @@ def _key_share_seize(user_id, attacker_name, owner_name, key):
|
||||
|
||||
|
||||
def _tg_bot_token():
|
||||
with open(TG_BOT_CONFIG, encoding="utf-8") as fh:
|
||||
return json.load(fh)["bot_token"]
|
||||
with open(TG_BOT_CONFIG, encoding="utf-8-sig") as fh:
|
||||
return effective_bot_config(json.load(fh))["bot_token"]
|
||||
|
||||
|
||||
def _tg_check_hash(data):
|
||||
|
||||
Reference in New Issue
Block a user