omi
omi copied to clipboard
[Bounty proposal] fix(backend): validate inputs and add resilience guards in database wrapped ($50 proposed)
Following the contribution guide's invitation to propose paid work — @kodjima33, @aryanorastar, @Git-on-my-level, would a US$50 bounty be appropriate for this? Proposed amount, not an existing award.
This addresses input validation, year boundaries, and state transition resilience in backend/database/wrapped.py to prevent crashes and invalid document references during yearly recap generation and querying.
Problem & Vulnerability
- Unvalidated User Identifiers & Path Traversal:
get_wrapped,create_wrapped,update_wrapped_status,update_wrapped_progress, andreset_wrapped_for_regenerationconstructed document paths directly without validatinguid. Passing empty strings, whitespace, or strings with/causes invalid document paths or traversal.
- Unbounded Year References:
yearwas accepted as any integer without range bounds, allowing negative years or arbitrary numbers that break expected time window queries and partition semantics.
- Missing Document & Invalid Status Guards in State Transitions:
update_wrapped_statusandupdate_wrapped_progressdid not guard against invalid status values or non-dict progress payloads, which could corrupt schema contract expectations.
- AttributeError in Stuck Detection:
is_wrapped_stuckfailed withAttributeErrorwhen providedNoneor non-dict payloads, and did not defensively handle non-positivestale_minutes.
Remediation
- Identifier & Year Validation:
- Added
_validate_identifierto sanitizeuidagainst empty strings, whitespace, and path traversal (/). - Added
_validate_yearto enforce integer types within[2000, 2100]. get_wrappedsafely fails and returnsNoneon invalid identifiers without issuing wasteful Firestore calls.
- Added
- Defensive State Transitions:
- Enforced
VALID_WRAPPED_STATUSESallowlist inupdate_wrapped_status. - Guaranteed non-dict progress payloads fail safely.
- Enforced
- Resilient Stuck Detection:
- Safely guarded
is_wrapped_stuckagainstNoneand non-dict inputs, with a fallback for invalid stale intervals.
- Safely guarded
- Hermetic Unit Test Suite:
- Added
backend/tests/unit/test_database_wrapped_resilience.pywith 8 comprehensive unit tests covering bounds checking, identifier sanitation, status validation, and edge cases (8/8 passing). Existing tests intest_wrapped_error_sanitization.py(3/3) passing (total 11/11 passing).
- Added
Bounty Payout Destination (EVM - Base): 0x5892E49d30b3BDa6f97DaBC5B657d64cb9c02D80
Hey you won't get paid here give up