omi
omi copied to clipboard
[Bounty proposal] Harden backend/database/import_quotas.py against unsafe Redis hash tags, invalid amounts, and malformed env limits ($50 proposed)
Summary
backend/database/import_quotas.py enforces rolling 30-day upload and byte quotas for transcript imports using Redis Lua scripts, but currently lacks input validation and environment parsing resilience:
- Unvalidated Redis Cluster hash-tag
uidandkindin_quota_keys:_quota_keys(uid, kind)formatsf'import:monthly:{kind}:{{{uid}}}'directly without validatinguidorkind. An empty/whitespace-onlyuidor one containing{,},:,/,\,.., or control characters breaks Redis Cluster hash-tag slot routing ({uid}) or collapses users into the empty{}slot.import_quota_limit(kind)raises an uncaughtKeyErroron unknownkindvalues and crashes withValueErrorifIMPORT_MONTHLY_<KIND>_LIMITis set to a malformed non-integer string.
- Boolean and non-positive
amountbypasses inreserve_import_quota:reserve_import_quota(uid, kind, amount)acceptsamount=True(sinceisinstance(True, int)isTrue),amount <= 0(which can decrementtotalor insert zero-cost entries into the sorted set/hash), or non-integer amounts.
- Unvalidated
reservationinrelease_import_quotaand missingredis_clientinjection:release_import_quotaexecutes a Redis Lua round-trip even whenreservationisNone, empty/whitespace-only, or contains control characters, and neitherreserve_import_quotanorrelease_import_quotaaccepts an optionalredis_clientparameter for hermetic testing.
Proposed Fix
- Add
_sanitize_uid,_sanitize_kind, and_sanitize_amountto validateuid,kind, and positive integeramountvalues. - Guard
import_quota_limitagainst malformed environment variable values by logging a warning and falling back to the default limit. - Skip Redis Lua execution in
release_import_quotawhenreservationis blank/invalid, and add optionalredis_clientinjection toreserve_import_quotaandrelease_import_quota. - Add 34 hermetic unit tests in
backend/tests/unit/test_import_quotas_resilience.py.
Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
Implemented in #22897: hash-tag/kind/amount validation, safe env parsing, and hermetic tests
Bounty settlement address (Base Mainnet USDC): 0x93c0d4e7100bc6b59e28e074f30a1ac37244b6af
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! 🙏