[Bounty proposal] fix(database): sanitize identifiers, harden etag matching, and add client injection to action items cache ($50 proposed)
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:
- Unsanitized UIDs and Redis Key Injection:
_version_key()andlist_cache_key()construct Redis keys (ail:ver:{uid}) without validating or sanitizinguid. Whitespace, embedded newlines (\r\n), or control characters can lead to Redis command injection or malformed key topologies. - Missing Client Dependency Injection:
_redis()is cached with@lru_cache(maxsize=1)and returns the shared Redis client without accepting an optionalredis_client: Any = Noneparameter 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. - Rigid RFC 9110 ETag Matching:
if_none_match_matches()strips the weakW/prefix but does not strip wrapping quotes on raw hash strings, causing mismatches when clients omit wrapping quotes or use unquoted weak validators. - Fragile Lever Dependency: If
config.firestore_read_leversis missing in certain environment tiers, importingaction_items_cache.pyfails with an unhandledImportError. - Zero Dedicated Unit Tests:
backend/database/action_items_cache.pypreviously had zero dedicated hermetic unit tests.
Proposed Solution
- Add
_sanitize_uid()rejecting empty strings, non-string values, and characters that could cause Redis injection or malformed keys (\r,\n,' '). - Add
*, redis_client: Any = Noneacross all public cache functions for 100% hermetic dependency injection. - Harden
if_none_match_matches()to strip bothW/weak prefixes and wrapping double quotes ("), ensuring robust RFC 9110 compliance. - Add safe fallback for
lever_enabledto prevent import failures. - Add 33 dedicated hermetic unit tests in
backend/tests/unit/test_action_items_cache_resilience.pyrunning in 0.47s.
Proposed Bounty
$50
Claimant PayPal: https://paypal.me/Dragonire9 Email: [email protected]
Claiming this bounty. PR opened: https://github.com/BasedHardware/omi/pull/22210
Implements all five items from the proposal:
_sanitize_uid()rejects non-strings, empty/whitespace, and any uid containing\r,\n, space or tabredis_clientinjection on every public cache function_normalize_validator()stripsW/weak prefix and wrapping quotes for RFC 9110 compliancelever_enabledfallback so a missingconfig.firestore_read_leversno longer raises ImportError- 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
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! 🙏