diff --git a/MEMORY.md b/MEMORY.md index 72b2d63..0c98d6c 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -23,6 +23,7 @@ - GitLab CI/CD now builds SHA/latest tags and deploys `deploy/k8s/production.yaml` from `main`. The ignored `.gitlab.variables.env` is a local handoff for GitLab Variables; CI uses namespace-scoped ServiceAccount `belki/gitlab-deploy`, not cluster-admin credentials. - 2026-08-21: applications use a separate store/table from calculator history. `/applications` and VK `/заявка` collect typed data; `/admin` accepts it. The bot can automatically notify only VK submissions, because a web form has no known reply peer. - 2026-08-21: Google Sheets export is intentionally disabled by default. Application create/accept events go to a durable outbox and will be delivered through an explicitly configured Apps Script Web App endpoint once the feature flag is enabled. +- 2026-08-25: Google Sheets export will activate only for a valid HTTPS endpoint; an HTTP/malformed environment URL leaves the outbox untouched and avoids sending its bearer token. - 2026-08-21: CI final images use immutable registry base images. Any runtime dependency change requires rebuilding/pushing the matching base (`Dockerfile.base` for `requirements.txt`, `Dockerfile.gateway-base` for `nginx.conf`) and changing the tag used by the final Dockerfile. - 2026-08-21: use Context7 for fresh official integration documentation and `prevent-eol` before dependency changes; lifecycle status is not a vulnerability verdict. - 2026-08-21: project-local frontend instructions include `frontend-craft`, `frontend-design`, and `ui-ux-pro-max`; use them together for UI work. diff --git a/app/belki/google_sheets_export.py b/app/belki/google_sheets_export.py index fab04c6..5c52b57 100644 --- a/app/belki/google_sheets_export.py +++ b/app/belki/google_sheets_export.py @@ -6,6 +6,7 @@ import json import os from dataclasses import dataclass from urllib.error import URLError +from urllib.parse import urlparse from urllib.request import Request, urlopen from .applications import ApplicationStore @@ -29,7 +30,8 @@ class GoogleSheetsExportConfig: @property def ready(self) -> bool: - return self.enabled and bool(self.url) + parsed = urlparse(self.url) + return self.enabled and parsed.scheme == "https" and bool(parsed.hostname) class GoogleSheetsExportService: diff --git a/project_mind_map.md b/project_mind_map.md index ecd9d57..da541e6 100644 --- a/project_mind_map.md +++ b/project_mind_map.md @@ -65,7 +65,7 @@ mindmap Viewer img.nyan404.ru Integrations VK API - Optional Google Sheets export + Optional Google Sheets export (HTTPS only) Deployment Docker Immutable Belki base image diff --git a/structure_and_data.md b/structure_and_data.md index c40ca25..f8014bd 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -58,6 +58,7 @@ - 2026-08-17: web-selected screenshots are sent through `/api/web/upload` to `BELKI_IMAGE_HOST_API_URL` (production API `https://nyan.nyan404.ru`, viewer `https://img.nyan404.ru`) and persisted as report attachments. The image-host API requires an explicit Belki `User-Agent`; the default Python `urllib` header is rejected with HTTP 403. - 2026-08-21: added structured community applications for feathers, kitten, flying-squirrel, and curator roles across VK, `/applications`, and the top-level `/admin` "Заявки" tab; acceptance is a status transition, not a generated forum post. - 2026-08-21: added a disabled durable Google Sheets export outbox for application-created and application-accepted events; no external request is attempted until an approved Apps Script URL and `BELKI_GOOGLE_EXPORT_ENABLED=1` are configured. +- 2026-08-25: the optional Google Sheets export considers a configured endpoint ready only when it is a valid HTTPS URL, preventing its optional bearer token from crossing plaintext HTTP. - 2026-08-25: fixed separator-free bulk parsing around time ranges, scoped web quick input to coaching, changed web inspection resources to `+N name`, corrected Russian inspection-count grammar, enabled VK image mirroring fallback, and added the standalone goal calculator mode/API. - 2026-08-25: added the goal calculator to the VK menu as `/цель` and `/калькулятор`; the bot now runs the same goal calculation interactively with step prompts, choice buttons, and confirmation without report attachments. - 2026-08-25: hardened the public goal calculator: point values must be finite, one session is limited to 1–1440 minutes, and one calculation to 1–50 kittens. The same validation is applied by the domain, JSON API, and VK dialogue, with regression tests for `NaN`, infinity, and excessive values. diff --git a/tests/test_applications.py b/tests/test_applications.py index ea1f6f3..8af2d0a 100644 --- a/tests/test_applications.py +++ b/tests/test_applications.py @@ -93,6 +93,15 @@ class ApplicationTests(unittest.TestCase): self.assertEqual(exporter.sync_pending(), 0) self.assertEqual(len(store.pending_exports()), 2) + def test_google_export_refuses_an_insecure_endpoint_even_when_enabled(self) -> None: + with tempfile.TemporaryDirectory() as directory: + store = ApplicationStore(sqlite_path=Path(directory) / "applications.sqlite3") + exporter = GoogleSheetsExportService( + store, GoogleSheetsExportConfig(enabled=True, url="http://example.test/export", token="secret"), + ) + self.assertFalse(exporter.config.ready) + self.assertEqual(exporter.sync_pending(), 0) + def test_vk_kitten_application_uses_profile_and_saves(self) -> None: with tempfile.TemporaryDirectory() as directory: store = ApplicationStore(sqlite_path=Path(directory) / "applications.sqlite3")