fix(backend): validate inputs and add resilience guards in database capture wedge state ($50 proposed)
Proposed Bounty: $50 USD
Associated PR: #19831 (https://github.com/BasedHardware/omi/pull/19831)
Motivation & Context
backend/database/capture_wedge_state.py manages operational state for the capture-wedge self-heal detector, determining when user devices are wedged and controlling the 24h push notification rate limit. Currently, uid and day are passed directly without path traversal sanitization, and atomic Firestore transactions lack error boundaries, which risks crashing background self-healing jobs or escaping the collection during network drops.
Solution Overview
- Implemented
_clean_idand_clean_daysanitization defending against path traversal (..,/,\\), null bytes, and length overruns. - Wrapped atomic transactions in defensive try-except boundaries with structured logging.
- Added
get_wedge_stateandreset_wedge_statehelpers and client fallback. - Added 12 hermetic unit tests in
backend/tests/unit/test_capture_wedge_state_resilience.pypassing in <0.35s.
EVM Wallet Address: 0x3dB8636F9C32DeF9D96079A9eCF272E174093A11
(Compatible with Base, Ethereum Mainnet, Arbitrum, Optimism, Polygon, BSC)
Submitted fix in PR #23628 (https://github.com/BasedHardware/omi/pull/23628):
- Defensive coordinate normalization for
uidandday(bounds checking, whitespace trimming, rejection of traversal characters and null bytes). - Robust UTC datetime normalization for both incoming parameters and stored Firestore timestamps, preventing unhandled
TypeErrorduring offset-naive and offset-aware subtractions. - Fail-safe error boundaries surrounding client resolution and transaction execution to keep self-healing background jobs running without unhandled crash.
- Added
get_wedge_stateandreset_wedge_stateinspection and recovery helpers. - Added 11 hermetic unit tests in
backend/tests/unit/test_capture_wedge_state_resilience.py(40/40 tests passing across the capture wedge suite in 2.90s, 0 CRLF).
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! 🙏