From 947cebc256a67cd2572f652b18517886927977c7 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Tue, 25 Aug 2026 04:02:09 +0300 Subject: [PATCH] fix(applications): reject boolean numeric input --- app/belki/applications.py | 2 ++ structure_and_data.md | 1 + tests/test_applications.py | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/app/belki/applications.py b/app/belki/applications.py index 880f8dc..39a78f6 100644 --- a/app/belki/applications.py +++ b/app/belki/applications.py @@ -29,6 +29,8 @@ class ApplicationError(ValueError): def _positive_id(value: Any, label: str) -> int: + if isinstance(value, bool): + raise ApplicationError(f"{label} должно быть числом") try: result = int(value) except (TypeError, ValueError) as exc: diff --git a/structure_and_data.md b/structure_and_data.md index f966e9c..b231ead 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -68,6 +68,7 @@ - 2026-08-25: `BelkiHTTPServer` supersedes the unbounded standard threaded server. It rejects oversized declared JSON before reading, times out a slow client after 15 seconds, and serves at most 32 concurrent connections. - 2026-08-25: long-lived authenticated admin refresh WebSockets now have a separate eight-connection pool, so they cannot consume all 32 request workers; additional connections receive an explicit temporary-unavailable response. - 2026-08-25: application validation now bounds names, attachment and feather rows, and descriptive text for both web and VK submissions. Stored attachment and review links must be HTTPS; the optional profile link is restricted to a real VK host. +- 2026-08-25: application numeric fields explicitly reject JSON booleans, which Python would otherwise coerce to `1` or `0`. - 2026-08-25: admin history sorting now tolerates legacy records whose IDs were stored as strings, preserving numeric order for valid IDs instead of failing the complete history view. - 2026-08-25: coaching sessions now validate a real calendar date in `ДД.ММ` form before any calculation or persistence; free-form dates remain accepted after parser normalization. - 2026-08-25: one-line VK/web recognition now gives explicit role labels priority over position. `сопровождающий`/`наставник`/`учитель` identify the escort, while `ученик`/`котёнок`/`бельчонок`/`подопечный` identify the ward; unlabeled pairs retain the original order-based fallback. diff --git a/tests/test_applications.py b/tests/test_applications.py index a58877b..a88eff9 100644 --- a/tests/test_applications.py +++ b/tests/test_applications.py @@ -36,6 +36,15 @@ class ApplicationTests(unittest.TestCase): "practiced_before": False, "vk_link": link, }) + def test_application_rejects_boolean_character_and_feather_ids(self) -> None: + with self.assertRaisesRegex(ApplicationError, "ID персонажа должно быть числом"): + validate_application({"type": "kitten", "name": "Муся", "character_id": True, "attachments": [{"url": "https://img.example.test/a.jpg"}]}) + with self.assertRaisesRegex(ApplicationError, "Количество перьев должно быть числом"): + validate_application({ + "type": "feather_donation", "name": "Муся", "character_id": 1337, + "feathers": [{"amount": True, "color": "синее", "source": "запасы"}], + }) + def test_application_bounds_attachment_and_feather_fan_out(self) -> None: too_many_attachments = [{"url": "https://img.example.test/photo.jpg"}] * (MAX_APPLICATION_ATTACHMENTS + 1) with self.assertRaisesRegex(ApplicationError, "не более"):