omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(backend): validate identifiers, clamp boundaries, and add transaction retry in calendar_meetings ($50 proposed)

Open shitobu opened this issue 2 months ago • 0 comments

Following the contribution guide's invitation to propose paid work — @kodjima33, @Git-on-my-level, would a US$50 bounty be appropriate for this? Proposed amount, not an existing award.

Problem & Vulnerabilities in backend/database/calendar_meetings.py

  1. Transaction Contention Risk: create_meeting executed _upsert_meeting_transaction via db.transaction() directly without bounded retry logic. Concurrent calendar sync operations for the same user can trigger Firestore transaction contention (Aborted / Conflict), causing meeting creation to fail.
  2. Missing Input Validation & KeyError Risk: create_meeting indexed meeting_data['calendar_source'] and meeting_data['calendar_event_id'] directly without validation. Missing or malformed keys caused unhandled KeyError crashes.
  3. Identifier Sanitization: Missing path traversal and empty string validation on uid and meeting_id across create_meeting, get_meeting, update_meeting, delete_meeting, and list_meetings.
  4. Unbounded Pagination Limits: list_meetings passed unvalidated limit directly to Firestore queries without clamping, allowing invalid/negative arguments to fail.
  5. Unhandled NotFound on Concurrency: update_meeting and delete_meeting could raise uncaught NotFound exceptions when operating on concurrently removed documents.

Remediation

  1. Wrapped meeting upsert transactions in run_with_transaction_contention_retry to guarantee resilience against concurrent synchronization collisions.
  2. Sanitized identifiers (uid, meeting_id, calendar_source, calendar_event_id) with _clean_id and _clean_str to prevent invalid characters and path traversal.
  3. Added safe fallback defaults for calendar_source and calendar_event_id in create_meeting.
  4. Clamped pagination limits in list_meetings to [1, 500] and validated date ranges in get_meetings_in_time_range.
  5. Guarded NotFound exceptions during update and delete operations.
  6. Added 10 hermetic unit tests in backend/tests/unit/test_calendar_meetings_resilience.py (100% pass, zero stub leaks). Registered in .github/checks-manifest.yaml.

shitobu avatar Sep 29 '26 09:09 shitobu