[Bounty proposal] Harden backend/database/dream_dirty.py against omitted default arguments, blank IDs, and unsafe refs ($50 proposed)
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:
- Uncaught
KeyError/IndexErrorinafter_writewhen default arguments are omitted or signature has< 2parameters:bound = signature.bind(*args, **kwargs).argumentsdoes not callapply_defaults()before indexingbound[parameters[0]]andbound[parameters[1]]. When a decorated function has a default value for its second parameter that is omitted by the caller (or has< 2parameters),bound[parameters[1]]raises an uncaughtKeyError/IndexErrorafter the primary database write has already succeeded.
- Unfiltered
None, boolean, blank, and path-traversal IDs inafter_write:- When
collection == 'action_items'andresultis a list containingNone, booleans, empty/whitespace strings, or unsafe path segments,ids = resultforwards those raw entries directly intonotify(uid, [(collection, value) for value in ids]).
- When
- Unvalidated
uidandrefsinnotify(uid, refs):notifydoes not validateuid(empty/whitespace-only,/,\,.., control characters, or IDs> 128chars) or sanitize/filterrefs(non-2-tuple items, blank collection/document IDs, or unsafe characters) before callingmark_dirty(uid, refs).
Proposed Fix
- Call
bound_args.apply_defaults()inafter_writeand safely accessbound.get(parameters[0])andbound.get(parameters[1])when present. - Add
_clean_tokenand_clean_idsto strip and validateuid,collection, and document IDs in bothafter_writeandnotify, dropping blank, non-string, or path-traversal tokens before callingmark_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
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! 🙏