omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(backend): validate inputs and add resilience guards in database wrapped ($50 proposed)

Open foxck016077 opened this issue 2 months ago • 1 comments

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

  1. Unvalidated User Identifiers & Path Traversal:
    • get_wrapped, create_wrapped, update_wrapped_status, update_wrapped_progress, and reset_wrapped_for_regeneration constructed document paths directly without validating uid. Passing empty strings, whitespace, or strings with / causes invalid document paths or traversal.
  2. Unbounded Year References:
    • year was accepted as any integer without range bounds, allowing negative years or arbitrary numbers that break expected time window queries and partition semantics.
  3. Missing Document & Invalid Status Guards in State Transitions:
    • update_wrapped_status and update_wrapped_progress did not guard against invalid status values or non-dict progress payloads, which could corrupt schema contract expectations.
  4. AttributeError in Stuck Detection:
    • is_wrapped_stuck failed with AttributeError when provided None or non-dict payloads, and did not defensively handle non-positive stale_minutes.

Remediation

  1. Identifier & Year Validation:
    • Added _validate_identifier to sanitize uid against empty strings, whitespace, and path traversal (/).
    • Added _validate_year to enforce integer types within [2000, 2100].
    • get_wrapped safely fails and returns None on invalid identifiers without issuing wasteful Firestore calls.
  2. Defensive State Transitions:
    • Enforced VALID_WRAPPED_STATUSES allowlist in update_wrapped_status.
    • Guaranteed non-dict progress payloads fail safely.
  3. Resilient Stuck Detection:
    • Safely guarded is_wrapped_stuck against None and non-dict inputs, with a fallback for invalid stale intervals.
  4. Hermetic Unit Test Suite:
    • Added backend/tests/unit/test_database_wrapped_resilience.py with 8 comprehensive unit tests covering bounds checking, identifier sanitation, status validation, and edge cases (8/8 passing). Existing tests in test_wrapped_error_sanitization.py (3/3) passing (total 11/11 passing).

Bounty Payout Destination (EVM - Base): 0x5892E49d30b3BDa6f97DaBC5B657d64cb9c02D80

foxck016077 avatar Sep 30 '26 08:09 foxck016077

Hey you won't get paid here give up

hugoaap-code avatar Sep 30 '26 08:09 hugoaap-code