omi icon indicating copy to clipboard operation
omi copied to clipboard

fix(backend): validate inputs and add resilience guards in database capture wedge state ($50 proposed)

Open ajin558 opened this issue 2 months ago • 2 comments

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_id and _clean_day sanitization defending against path traversal (.., /, \\), null bytes, and length overruns.
  • Wrapped atomic transactions in defensive try-except boundaries with structured logging.
  • Added get_wedge_state and reset_wedge_state helpers and client fallback.
  • Added 12 hermetic unit tests in backend/tests/unit/test_capture_wedge_state_resilience.py passing in <0.35s.

EVM Wallet Address: 0x3dB8636F9C32DeF9D96079A9eCF272E174093A11 (Compatible with Base, Ethereum Mainnet, Arbitrum, Optimism, Polygon, BSC)

ajin558 avatar Sep 29 '26 18:09 ajin558

Submitted fix in PR #23628 (https://github.com/BasedHardware/omi/pull/23628):

  • Defensive coordinate normalization for uid and day (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 TypeError during 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_state and reset_wedge_state inspection 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).

Dragonire9 avatar Oct 25 '26 20:10 Dragonire9

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! 🙏

aryanorastar avatar Oct 31 '26 06:10 aryanorastar