omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize uid and period, add error boundary to budget choice ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Description

The budget choice data access module (backend/database/budget_choice.py) stores and retrieves per-account bounded budget choices (on_device vs upgrade). However, it has several input sanitization, error resilience, and testability shortcomings:

  1. Unsanitized UID & Path Skew: _reference(client, uid) interpolates uid directly into client.collection('users').document(uid)... without whitespace stripping or validation. Any leading/trailing whitespace causes path skew (/users/ user123 /budget_choice/current), while empty/None uids can trigger unhandled exceptions or malformed references.
  2. Missing Input Validation on Period: In set_choice, period is never validated or stripped. Blank or malformed strings can be accepted and committed to Firestore.
  3. Unprotected Firestore Read in get_choice: get_choice directly executes _reference(client, uid).get().to_dict() outside of any error boundary. If Firestore suffers a transient network timeout or service degradation, the endpoint raises an unhandled exception instead of gracefully returning None.
  4. Boolean Type Safety: dont_ask_again should strictly enforce boolean type (type(...) is bool) to prevent falsy/truthy non-bool injections.
  5. Zero Dedicated Unit Tests: backend/database/budget_choice.py currently has zero unit test coverage in backend/tests/unit/test_budget_choice.py.

Proposed Solution

  1. UID & Period Sanitization: Strip uid and period across _reference, get_choice, and set_choice. Validate and raise ValueError('invalid_uid') or ValueError('invalid_budget_period') appropriately on writes, and return None on reads.
  2. Read Error Boundary: Wrap Firestore retrieval in get_choice in a try/except Exception boundary returning None on any error or missing doc.
  3. Strict Validation: Enforce choice in CHOICES and type(dont_ask_again) is bool in set_choice.
  4. Safe Dict Extraction: Safeguard doc.to_dict() extraction in _store.
  5. Unit Tests: Author 26 test assertions across 13 dedicated unit test cases in backend/tests/unit/test_budget_choice.py verifying path construction, sanitization, read fallbacks, input validation, transaction creation, idempotency, and conflict states.

Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])

Dragonire9 avatar Oct 16 '26 17:10 Dragonire9

Hi @josancamon19 @kodjima33 — is the complete budget_choice.py repair in #21907 still something the team wants to commission beyond the implementation already mentioned here?

I’m looking at the full result: UID/period normalization, safe read/dict fallbacks, strict choice/boolean validation, and the transaction, idempotency and conflict regression cases (13 tests/26 assertions). If work remains, which revision and acceptance checks should I use, and should I coordinate with the existing contributor?

The issue proposes $50 but has no Paid Bounty label. Is a cash bounty approved for this complete result, in which currency and amount? Can you pay a mainland-China individual in the same legal name, and through which permitted method, with what fees and timing?

Once scope and payment are confirmed, I can check the complete implementation and give a delivery estimate.

ayqy avatar Oct 17 '26 04:10 ayqy

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 12:10 undivisible