omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] Harden backend/database/dream_dirty.py against omitted default arguments, blank IDs, and unsafe refs ($50 proposed)

Open huynhnhatquandongnai-source opened this issue 1 month ago • 2 comments

Summary

backend/database/dream_dirty.py provides the @after_write(collection) post-write decorator and notify(uid, refs) signal helper for Dream queue enqueueing, but currently has several argument-binding and identifier-validation bugs:

  1. Uncaught KeyError / IndexError in after_write when default arguments are omitted or signature has < 2 parameters:
    • bound = signature.bind(*args, **kwargs).arguments does not call apply_defaults() before indexing bound[parameters[0]] and bound[parameters[1]]. When a decorated function has a default value for its second parameter that is omitted by the caller (or has < 2 parameters), bound[parameters[1]] raises an uncaught KeyError / IndexError after the primary database write has already succeeded.
  2. Unfiltered None, boolean, blank, and path-traversal IDs in after_write:
    • When collection == 'action_items' and result is a list containing None, booleans, empty/whitespace strings, or unsafe path segments, ids = result forwards those raw entries directly into notify(uid, [(collection, value) for value in ids]).
  3. Unvalidated uid and refs in notify(uid, refs):
    • notify does not validate uid (empty/whitespace-only, /, \, .., control characters, or IDs > 128 chars) or sanitize/filter refs (non-2-tuple items, blank collection/document IDs, or unsafe characters) before calling mark_dirty(uid, refs).

Proposed Fix

  • Call bound_args.apply_defaults() in after_write and safely access bound.get(parameters[0]) and bound.get(parameters[1]) when present.
  • Add _clean_token and _clean_ids to strip and validate uid, collection, and document IDs in both after_write and notify, dropping blank, non-string, or path-traversal tokens before calling mark_dirty.
  • Add 24 hermetic unit tests in backend/tests/unit/test_dream_dirty_resilience.py.

Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94

Implemented in #22893: default-argument binding, id filtering, uid/ref validation, hermetic tests.

Bounty settlement address (Base Mainnet USDC): 0x93c0d4e7100bc6b59e28e074f30a1ac37244b6af

Andu1223 avatar Oct 20 '26 16:10 Andu1223

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