[Bounty proposal] fix(database): sanitize uid and protect session streams in channel visibility ($50 proposed)
Problem Description
The first-party session visibility module (backend/database/channel_visibility.py) streams user channel links and chat sessions from Firestore. However, it currently has several input sanitization, error resilience, performance, and testability shortcomings:
- Unsanitized UID Path Skew: If caller
uidcontains leading or trailing whitespace,user = db.collection('users').document(uid)streams from an orphaned document path (e.g./users/ uid123 /) instead of the canonical user root, completely missing existing channel links and sessions. - Missing Client & Stream Exception Safety:
visible_sessionsperforms Firestore operations without error handling. If the Firestore client isNoneor if.stream()experiences network interruptions or timeouts, calls crash with unhandled exceptions instead of failing safely with[]. - Double Deserialization & None Vulnerability: In
chat_sessionsiteration,d.to_dict()is evaluated twice per document (dict(d.to_dict(), id=d.id)and.get('channel_link_id')), doubling serialization overhead. Furthermore, if a document payload isNoneor non-dict, callingdict(None, id=d.id)raisesTypeError: 'NoneType' object is not iterable. - Missing Type Annotations:
visible_sessionslacks type annotations for parameters and return values (list[dict[str, Any]]). - Zero Unit Test Coverage:
backend/database/channel_visibility.pycurrently has zero dedicated unit tests.
Proposed Solution
- Sanitize UID: Strip whitespace from
uidand return[]immediately ifuidis empty or blank. - Resilient Firestore Error Handling: Guard against
Noneclients and wrap streams in atry/exceptboundary returning[]on error. - Single Deserialization & Payload Validation: Evaluate
data = d.to_dict()once per document, validatingisinstance(data, dict)before inspecting link IDs or appending withid=d.id. - Strict Type Hints: Add full typing annotations (
uid: str, *, firestore_client: Optional[Any] = None) -> list[dict[str, Any]]). - Unit Tests: Add 8 comprehensive unit tests in
backend/tests/unit/test_channel_visibility.pycovering normal flow, cohort filtering, whitespace stripping, missing/malformed payloads, and exception handling.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
Hi @kodjima33 @josancamon19, is the complete repair in #21901 still being commissioned beyond open PR #21937 and closed, unmerged #21902?
Iām interested in the full result: whitespace/blank UID handling, safe fallbacks for a missing Firestore client and failures in both streams, one validated deserialization per document, full typing, and all 8 regressions, while preserving the existing cohort opt-in and channel-link visibility rules. Should a failure after a stream has yielded some documents discard partial results and return []?
If work remains, which target revision and acceptance checks should it meet, and who can confirm the assignment? The issue lists $50 proposed; what amount and currency are approved, and what payment method, contributor eligibility, fees and payment timing apply?
With those points clear, I can propose a delivery estimate for the complete repair.
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! š