[Bounty proposal] Harden backend/database/dream_canary.py against malformed snapshots, invalid UIDs, and non-numeric failure counts ($50 proposed)
Summary
backend/database/dream_canary.py guards the synthetic Dream canary account (ensure_synthetic_owner) and tracks consecutive canary health failures (failure_count, record_result, reset_failures), but currently has several snapshot and input resilience bugs:
- Unsafe document IDs in
ensure_synthetic_owner:if not uid or uid != canary_uid():does not verify thatuidandcanary_uid()are safe Firestore document IDs (free of leading/trailing whitespace,/,\,.., control characters, or lengths> 128chars) before passinguidtodatabase.collection('users').document(uid).
- Uncaught
AttributeError,TypeError, andValueErroron malformed snapshots andcanary_failuresfields:- In
ensure_synthetic_owner,existing = owner.get(transaction=tx).to_dict()raisesAttributeErrorwhenexisting.get('dream_canary')is called on a non-dict snapshot payload instead of raisingValueError('dream_canary_existing_owner'). - In
failure_countandrecord_result,int(row.get('canary_failures', 0))raisesTypeErrorwhencanary_failuresis explicitlyNone({'canary_failures': None}),ValueErroron non-numeric strings orNaN/inf, and returns negative counts whencanary_failures < 0. failure_countdoes not catch transient Firestore.get()errors, andrecord_resultdoes not validate thatpassedis a boolean.
- In
- Raw
.transaction()invocation withoutrun_transactional:ensure_synthetic_owner,reset_failures, andrecord_resultinvokedatabase.transaction()directly instead of routing throughrun_transactional(database, ...).
Proposed Fix
- Add
_is_safe_doc_idto validate bothuidandcanary_uid()inensure_synthetic_owner. - Guard
snapshot.to_dict()withisinstance(..., dict)acrossensure_synthetic_owner,failure_count, andrecord_result, and normalizecanary_failuresinto[0, 100]via_coerce_failure_count. - Validate
isinstance(passed, bool)inrecord_result, add a read error boundary infailure_count, and route transactions throughrun_transactional. - Add 35 hermetic unit tests in
backend/tests/unit/test_dream_canary_resilience.py.
Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
Implemented in PR #23256 with document ID validation, snapshot payload guards, failure count normalization, transactional routing, and 35 hermetic unit tests:
- Pull Request: https://github.com/BasedHardware/omi/pull/23256
- Unit Tests: 35/35 passing hermetically in
test_dream_canary_resilience.py - Full suite health: 279/279 passing (0 failures)
- Payout Address:
0xC345C07229307d4f1c7935aD2cAe48e390215808(USDC Polygon/Base/Arbitrum)
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! 🙏