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:
@@ -1,4 +1,4 @@
|
||||
"""PPTX: many highly-compressible slides must not be decompressed past the budgets."""
|
||||
"""PPTX extraction stops on text and actual decompression budgets."""
|
||||
import io
|
||||
from pathlib import Path
|
||||
import sys
|
||||
@@ -20,19 +20,36 @@ def _pptx(slides: int, text: str) -> bytes:
|
||||
|
||||
|
||||
class PptxBudgetTest(unittest.TestCase):
|
||||
def test_stops_reading_after_text_budget(self):
|
||||
data = _pptx(200, "x" * 5000)
|
||||
with mock.patch.object(file_intake, "_read_entry", wraps=file_intake._read_entry) as rd:
|
||||
res = file_intake.extract("deck.pptx", data)
|
||||
self.assertTrue(res.ok)
|
||||
self.assertTrue(res.truncated)
|
||||
self.assertLess(rd.call_count, 10)
|
||||
def _extract_with_budget(self, data, total_limit=None):
|
||||
readers = []
|
||||
original = file_intake._OfficeBudget
|
||||
|
||||
def test_total_unpacked_budget_rejects(self):
|
||||
data = _pptx(20, "<b/>" * 262144) # 20 MiB of markup, no text
|
||||
with mock.patch.object(file_intake, "_MAX_UNPACKED_BYTES", 8 * 1024 * 1024):
|
||||
res = file_intake.extract("deck.pptx", data)
|
||||
self.assertFalse(res.ok)
|
||||
def factory(zf):
|
||||
kwargs = {} if total_limit is None else {"total_limit": total_limit}
|
||||
reader = original(zf, **kwargs)
|
||||
readers.append(reader)
|
||||
return reader
|
||||
|
||||
with mock.patch.object(file_intake, "_OfficeBudget", side_effect=factory):
|
||||
result = file_intake.extract("deck.pptx", data)
|
||||
self.assertEqual(len(readers), 1)
|
||||
return result, readers[0]
|
||||
|
||||
def test_stops_reading_after_text_budget(self):
|
||||
result, reader = self._extract_with_budget(_pptx(200, "x" * 5000))
|
||||
self.assertTrue(result.ok)
|
||||
self.assertTrue(result.truncated)
|
||||
self.assertLess(reader.entries_read, 10)
|
||||
self.assertLessEqual(len(result.text), file_intake.TEXT_BUDGET)
|
||||
|
||||
def test_total_unpacked_budget_rejects_textless_archive(self):
|
||||
limit = 8 * 1024 * 1024
|
||||
result, reader = self._extract_with_budget(_pptx(20, "<b/>" * 262144), limit)
|
||||
self.assertFalse(result.ok)
|
||||
self.assertTrue(result.truncated)
|
||||
self.assertEqual(reader.consumed, limit)
|
||||
self.assertLess(reader.entries_read, 20)
|
||||
self.assertTrue(result.warnings)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user