omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize identifiers, harden etag matching, and add client injection to action items cache ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Statement

backend/database/action_items_cache.py implements the per-uid write-invalidated response cache for GET /v1/action-items. This cache is mission-critical for system health, eliminating repeated Firestore reads across large-backlog accounts.

However, several architectural resilience and security gaps exist:

  1. Unsanitized UIDs and Redis Key Injection: _version_key() and list_cache_key() construct Redis keys (ail:ver:{uid}) without validating or sanitizing uid. Whitespace, embedded newlines (\r\n), or control characters can lead to Redis command injection or malformed key topologies.
  2. Missing Client Dependency Injection: _redis() is cached with @lru_cache(maxsize=1) and returns the shared Redis client without accepting an optional redis_client: Any = None parameter across module functions (bump_action_items_list_version, get_action_items_list_version, read_cached_list, write_cached_list). This prevents hermetic unit testing without global state mutation.
  3. Rigid RFC 9110 ETag Matching: if_none_match_matches() strips the weak W/ prefix but does not strip wrapping quotes on raw hash strings, causing mismatches when clients omit wrapping quotes or use unquoted weak validators.
  4. Fragile Lever Dependency: If config.firestore_read_levers is missing in certain environment tiers, importing action_items_cache.py fails with an unhandled ImportError.
  5. Zero Dedicated Unit Tests: backend/database/action_items_cache.py previously had zero dedicated hermetic unit tests.

Proposed Solution

  1. Add _sanitize_uid() rejecting empty strings, non-string values, and characters that could cause Redis injection or malformed keys (\r, \n, ' ').
  2. Add *, redis_client: Any = None across all public cache functions for 100% hermetic dependency injection.
  3. Harden if_none_match_matches() to strip both W/ weak prefixes and wrapping double quotes ("), ensuring robust RFC 9110 compliance.
  4. Add safe fallback for lever_enabled to prevent import failures.
  5. Add 33 dedicated hermetic unit tests in backend/tests/unit/test_action_items_cache_resilience.py running in 0.47s.

Proposed Bounty

$50

Claimant PayPal: https://paypal.me/Dragonire9 Email: [email protected]

Dragonire9 avatar Oct 18 '26 14:10 Dragonire9

Claiming this bounty. PR opened: https://github.com/BasedHardware/omi/pull/22210

Implements all five items from the proposal:

  1. _sanitize_uid() rejects non-strings, empty/whitespace, and any uid containing \r, \n, space or tab
  2. redis_client injection on every public cache function
  3. _normalize_validator() strips W/ weak prefix and wrapping quotes for RFC 9110 compliance
  4. lever_enabled fallback so a missing config.firestore_read_levers no longer raises ImportError
  5. 49 hermetic unit tests in backend/tests/unit/test_action_items_cache_resilience.py (0.19s, no Redis/Firestore)

Verification: 49 passed via pytest against the real redis package (6.4.0).

PayPal for payout: https://paypal.me/redman1309

Reggiebro avatar Oct 18 '26 18:10 Reggiebro

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