omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize uid and protect session streams in channel visibility ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

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:

  1. Unsanitized UID Path Skew: If caller uid contains 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.
  2. Missing Client & Stream Exception Safety: visible_sessions performs Firestore operations without error handling. If the Firestore client is None or if .stream() experiences network interruptions or timeouts, calls crash with unhandled exceptions instead of failing safely with [].
  3. Double Deserialization & None Vulnerability: In chat_sessions iteration, 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 is None or non-dict, calling dict(None, id=d.id) raises TypeError: 'NoneType' object is not iterable.
  4. Missing Type Annotations: visible_sessions lacks type annotations for parameters and return values (list[dict[str, Any]]).
  5. Zero Unit Test Coverage: backend/database/channel_visibility.py currently has zero dedicated unit tests.

Proposed Solution

  1. Sanitize UID: Strip whitespace from uid and return [] immediately if uid is empty or blank.
  2. Resilient Firestore Error Handling: Guard against None clients and wrap streams in a try/except boundary returning [] on error.
  3. Single Deserialization & Payload Validation: Evaluate data = d.to_dict() once per document, validating isinstance(data, dict) before inspecting link IDs or appending with id=d.id.
  4. Strict Type Hints: Add full typing annotations (uid: str, *, firestore_client: Optional[Any] = None) -> list[dict[str, Any]]).
  5. Unit Tests: Add 8 comprehensive unit tests in backend/tests/unit/test_channel_visibility.py covering normal flow, cohort filtering, whitespace stripping, missing/malformed payloads, and exception handling.

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

Dragonire9 avatar Oct 16 '26 17:10 Dragonire9

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.

ayqy avatar Oct 17 '26 10:10 ayqy

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