omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize review config inputs and harden version gating ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

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:

  1. Header Whitespace Rejection: platform headers 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.
  2. UID Whitespace Mismatch: User IDs and configured reviewer_uids are checked without whitespace stripping, causing review accounts with surrounding whitespace to bypass the gating.
  3. Firestore Unhandled Failures: _fetch_review_config directly queries Firestore without error handling or dependency injection. If Firestore experiences transient unavailability or connection timeouts, calling /v1/storefront or /v1/users/me crashes with HTTP 500 instead of failing safely.
  4. Malformed Version Collisions: Unparseable or malformed version strings (e.g. "malformed..version", empty strings) cause compare_versions to fall back to ((0, 0, 0), 0, False). Comparing two unparseable entries evaluates to 0 (equal), causing non-semantic strings to collide and erroneously hide subscription surfaces.
  5. Zero Unit Test Coverage: backend/database/app_review_config.py currently has zero dedicated unit tests.

Proposed Solution

  1. Normalize Platform: Strip and lowercase platform input so " iOS " or "macos " correctly resolves to supported platforms.
  2. Sanitize UID Matching: Strip UIDs and reviewer_uids into a sanitized set to ensure exact $O(1)$ canonical matching.
  3. Plausible Version Validation: Guard semantic version comparison with _is_plausible_version and wrap comparison in an error boundary to prevent unparseable collisions while preserving exact identifier matching and build comparison.
  4. Firestore Fault Tolerance & DI: Add firestore_client=None dependency injection and wrap Firestore queries in resilient try/except blocks returning safe empty fallbacks.
  5. Unit Tests: Add comprehensive unit tests in backend/tests/unit/test_app_review_config.py covering all edge cases.

Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])

Dragonire9 avatar Oct 16 '26 16:10 Dragonire9

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/lowercases X-App-Platform, trims reviewer UIDs into a set for exact matching, guards compare_versions with _is_plausible_version so unparseable strings can no longer collide at ((0,0,0),0,False), and fails closed to {} with a server-side logger.warning when Firestore or the cache raises. firestore_client is 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).

1132dadf avatar Oct 21 '26 13:10 1132dadf

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! 🙏

undivisible avatar Oct 22 '26 11:10 undivisible