omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize identifiers, add store failure boundaries, and add client injection to import_jobs ($50 proposed)

Open huynhnhatquandongnai-source opened this issue 1 month ago • 2 comments

What's wrong

  1. Unsanitized and unvalidated identifiers: Functions in backend/database/import_jobs.py (create_import_job, update_import_job, update_import_job_unless_cancelled, cancel_import_job_if_active, update_import_job_progress, get_import_job, get_import_jobs, delete_import_job) pass job_id and uid directly to Firestore .document(job_id) / .where('uid', '==', uid) without whitespace normalization or path-safety validation. Empty strings, whitespace-only values, or path delimiters (/, \, ..) cause invalid Firestore document paths or unguarded KeyError / client argument exceptions.
  2. Race-condition NotFound crashes on updates and deletes: When an import job is deleted concurrently by a user while a background worker calls update_import_job(job_id, updates) or when delete_import_job(job_id) runs on an already-deleted job, .update() / .delete() raises an uncaught google.api_core.exceptions.NotFound exception. Empty updates dicts also raise Firestore client errors.
  3. Uncaught store failures, missing limit clamping, and missing ID hydration on reads: get_import_job and get_import_jobs lack error boundaries around Firestore reads and streams, causing transient store outages or corrupted document snapshots to fail the caller instead of returning safe fallbacks (None / []). Additionally, get_import_jobs(uid, limit=50) does not clamp limit at the database boundary (1..1000), and legacy documents missing an internal 'id' key are not hydrated from doc.id.
  4. Incomplete client dependency injection: Only cancel_import_job_if_active accepted *, firestore_client: Any = None, while all other 7 functions hardcoded module-global db, preventing hermetic unit testing without global state mutation.

Proposed Fix

  1. Add _sanitize_id() and _clean_optional_id() to trim whitespace and reject empty, non-string, or path-traversal identifiers (ValueError on writes, safe None / [] fallbacks on reads).
  2. Guard update_import_job and delete_import_job against NotFound and empty update payloads, returning a boolean outcome.
  3. Wrap get_import_job and get_import_jobs in store failure boundaries, clamp limit to [1, 1000], skip unreadable stream documents, and backfill data['id'] = str(doc.id) when absent.
  4. Add *, firestore_client: Optional[Any] = None across all functions in backend/database/import_jobs.py.
  5. Add 21 hermetic unit tests in backend/tests/unit/test_import_jobs_resilience.py.

Proposed Bounty

$50

Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94

Implemented in PR #23257 with identifier sanitization, NotFound guards, store failure boundaries, client injection, and 22 hermetic unit tests:

  • Pull Request: https://github.com/BasedHardware/omi/pull/23257
  • Unit Tests: 22/22 passing hermetically in test_import_jobs_resilience.py
  • Full suite health: 301/301 passing (0 failures)
  • Payout Address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)

Dimank92 avatar Oct 22 '26 07:10 Dimank92

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 12:10 undivisible