[Bounty proposal] fix(database): sanitize phone call overrides and add fault-tolerant client injection ($50 proposed)
Problem Description
The catalog-backed phone call configuration module (backend/database/phone_call_config.py) overlays live Firestore settings onto catalog defaults. However, it suffers from several sanitization, validation, error-handling, and testability shortcomings:
- Unsanitized Allowed Countries: In
_declared_override,allowed_countriesis taken directly from the Firestore document without validation. If the override contains non-string elements (e.g.None, numbers), lowercase or unpadded codes (" us ","ca"), or a non-list type ("US"), country restriction checks and callers encounter subtle bugs or runtime exceptions. - Boolean and Negative Limit Coercion:
monthly_call_limitandmax_duration_secondsdo not reject booleans (Trueevaluates to1in Python'sisinstance(val, int)), nor negative values (-1), which can cause unintended limit lockouts or negative allowances. - Firestore Outage Fragility:
_fetch_configcalls Firestore without atry/exceptboundary or dependency injection (firestore_client=None). If Firestore experiences transient latency or connectivity failures, phone call policy resolution crashes callers instead of falling back to safe defaults. - Zero Unit Test Coverage:
backend/database/phone_call_config.pycurrently has zero dedicated unit tests.
Proposed Solution
- Sanitize Country Codes: In
_declared_override, ensureallowed_countriesis a list, stripping and uppercasing 2-letter ISO codes while ignoring malformed items. - Strict Limit Validation: Explicitly reject booleans and negative integers for
monthly_call_limitandmax_duration_seconds, while preserving valid non-negative ints and explicitNone(unlimited). - Resilient Firestore Fetch & DI: Add
firestore_client=Noneparameter and wrap Firestore access intry/exceptreturning{}safely on error. - Unit Tests: Add comprehensive test cases in
backend/tests/unit/test_phone_call_config.pycovering defaults, overrides, sanitization, and fallback boundaries.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
Hi maintainers, is #21895 still available for a complete paid contribution? I would cover all four requested parts: normalize and validate the country-code list, reject boolean/negative limits while preserving valid non-negative integers and explicit None, add injectable Firestore access with safe outage fallback, and add regression tests for defaults, overrides, malformed inputs and failure paths. The catalog defaults, overlay metadata/cache and existing callers should remain compatible.
I see the proposed $50 and an existing claim. Is there remaining work you are commissioning, and which target revision and acceptance checks should a new contribution satisfy? Please confirm the approved amount/currency and official payout route, including contributor eligibility, fees and payment timing. I can then give a fixed-scope quote and delivery estimate before starting.
Thanks!
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! 🙏