omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(notifications): typed request models, bounds validation, and empty admin key guard (0 proposed)

Open shitobu opened this issue 1 month ago • 1 comments

Bounty Proposal: Notification Request Models Resilience & Bounds Validation ($50 USD)

Pull Request: https://github.com/BasedHardware/omi/pull/23111

Problem & Impact

  1. Unhandled KeyError Crashes (HTTP 500): In POST /v1/notification, the endpoint accepted untyped Dict[str, Any] and used direct subscripts (data['title'], data['body']). Calling the endpoint with missing required fields raised an unhandled KeyError resulting in an HTTP 500 server crash.
  2. Missing String Sanitization & Bounds: uid, title, and body had no character bounds or whitespace stripping, permitting blank or oversized payloads to flow downstream into notification delivery services.
  3. Unvalidated App Integration Notifications: POST /v1/integrations/notification took raw Dict[str, Any] rather than adopting the existing SendAppNotificationRequest model.
  4. Unset ADMIN_KEY Guard: If ADMIN_KEY was unset or empty in the environment, the check secret_key != os.getenv('ADMIN_KEY') could behave unpredictably with empty header values. It now explicitly verifies that ADMIN_KEY is configured.

Key Improvements in PR #23111

  1. Typed Request Models:
    • Hardened SendNotificationRequest with field bounds (uid: 1-128, title: 1-500, body: 1-2000) and whitespace stripping validators rejecting empty strings.
    • Hardened SendAppNotificationRequest with field bounds and whitespace validation.
  2. Endpoint Hardening:
    • Replaced raw dictionary subscripts in send_notification_to_user and send_app_notification_to_user with typed model attributes.
    • Added explicit guard ensuring ADMIN_KEY is configured and non-empty.
  3. Hermetic Test Suite:
    • Added comprehensive tests in backend/tests/unit/test_integration_notification_validation.py covering unauthorized access, unset admin key rejection, successful dispatch, whitespace message rejection, and model validation (6/6 passing hermetically in 4.4s, clean ruff).

Designated Payout Channel

shitobu avatar Oct 21 '26 20:10 shitobu

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