[Bounty proposal] fix(database): sanitize review config inputs and harden version gating ($50 proposed)
Problem Description
The server-driven review configuration module (backend/database/app_review_config.py) toggles subscription-surface visibility for Apple and macOS app reviewers. However, it suffers from several critical input sanitization, error-handling, and testability shortcomings:
- Header Whitespace Rejection:
platformheaders from HTTP requests (X-App-Platform) frequently contain trailing or leading whitespace (e.g."ios "," ios", or"MacOS "). The current(platform or "").lower()check misses_SUPPORTED_PLATFORMS = {"ios", "macos"}, causing subscription UI to be exposed during app review and risking App Store rejection. - UID Whitespace Mismatch: User IDs and configured
reviewer_uidsare checked without whitespace stripping, causing review accounts with surrounding whitespace to bypass the gating. - Firestore Unhandled Failures:
_fetch_review_configdirectly queries Firestore without error handling or dependency injection. If Firestore experiences transient unavailability or connection timeouts, calling/v1/storefrontor/v1/users/mecrashes with HTTP 500 instead of failing safely. - Malformed Version Collisions: Unparseable or malformed version strings (e.g.
"malformed..version", empty strings) causecompare_versionsto fall back to((0, 0, 0), 0, False). Comparing two unparseable entries evaluates to0(equal), causing non-semantic strings to collide and erroneously hide subscription surfaces. - Zero Unit Test Coverage:
backend/database/app_review_config.pycurrently has zero dedicated unit tests.
Proposed Solution
- Normalize Platform: Strip and lowercase
platforminput so" iOS "or"macos "correctly resolves to supported platforms. - Sanitize UID Matching: Strip UIDs and
reviewer_uidsinto a sanitized set to ensure exact $O(1)$ canonical matching. - Plausible Version Validation: Guard semantic version comparison with
_is_plausible_versionand wrap comparison in an error boundary to prevent unparseable collisions while preserving exact identifier matching and build comparison. - Firestore Fault Tolerance & DI: Add
firestore_client=Nonedependency injection and wrap Firestore queries in resilient try/except blocks returning safe empty fallbacks. - Unit Tests: Add comprehensive unit tests in
backend/tests/unit/test_app_review_config.pycovering all edge cases.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
Claiming the $50 bounty on this issue.
Implemented in #23048 (branch cut directly from upstream main, two files only):
backend/database/app_review_config.py— strips/lowercasesX-App-Platform, trims reviewer UIDs into a set for exact matching, guardscompare_versionswith_is_plausible_versionso unparseable strings can no longer collide at((0,0,0),0,False), and fails closed to{}with a server-sidelogger.warningwhen Firestore or the cache raises.firestore_clientis an optional injection point for tests.backend/tests/unit/test_app_review_config.py— the module’s first unit tests (8, hermetic): whitespace platform headers, unknown/missing platform, UID trimming, semver match across builds, pinned build comparison, malformed-version non-collision, Firestore outage fallback, and per-normalized-platform cache keying.
Verification: all six backend unit shards, Backend unit suite, Hygiene, Formatting, and PR Metadata Preflight are green; the PR is mergeable.
Ready for maintainer review. I will follow the contribution guide’s payment process (email after merge).
Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏