[Bounty proposal] fix(database): sanitize uid and period, add error boundary to budget choice ($50 proposed)
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:
- Unsanitized UID & Path Skew:
_reference(client, uid)interpolatesuiddirectly intoclient.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. - Missing Input Validation on Period: In
set_choice,periodis never validated or stripped. Blank or malformed strings can be accepted and committed to Firestore. - Unprotected Firestore Read in get_choice:
get_choicedirectly 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 returningNone. - Boolean Type Safety:
dont_ask_againshould strictly enforce boolean type (type(...) is bool) to prevent falsy/truthy non-bool injections. - Zero Dedicated Unit Tests:
backend/database/budget_choice.pycurrently has zero unit test coverage inbackend/tests/unit/test_budget_choice.py.
Proposed Solution
- UID & Period Sanitization: Strip
uidandperiodacross_reference,get_choice, andset_choice. Validate and raiseValueError('invalid_uid')orValueError('invalid_budget_period')appropriately on writes, and returnNoneon reads. - Read Error Boundary: Wrap Firestore retrieval in
get_choicein atry/except Exceptionboundary returningNoneon any error or missing doc. - Strict Validation: Enforce
choice in CHOICESandtype(dont_ask_again) is boolinset_choice. - Safe Dict Extraction: Safeguard
doc.to_dict()extraction in_store. - Unit Tests: Author 26 test assertions across 13 dedicated unit test cases in
backend/tests/unit/test_budget_choice.pyverifying path construction, sanitization, read fallbacks, input validation, transaction creation, idempotency, and conflict states.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
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.
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! š