omi
omi copied to clipboard
[Bounty proposal] fix(notifications): typed request models, bounds validation, and empty admin key guard (0 proposed)
Bounty Proposal: Notification Request Models Resilience & Bounds Validation ($50 USD)
Pull Request: https://github.com/BasedHardware/omi/pull/23111
Problem & Impact
- Unhandled KeyError Crashes (HTTP 500):
In
POST /v1/notification, the endpoint accepted untypedDict[str, Any]and used direct subscripts (data['title'],data['body']). Calling the endpoint with missing required fields raised an unhandledKeyErrorresulting in an HTTP 500 server crash. - Missing String Sanitization & Bounds:
uid,title, andbodyhad no character bounds or whitespace stripping, permitting blank or oversized payloads to flow downstream into notification delivery services. - Unvalidated App Integration Notifications:
POST /v1/integrations/notificationtook rawDict[str, Any]rather than adopting the existingSendAppNotificationRequestmodel. - Unset ADMIN_KEY Guard:
If
ADMIN_KEYwas unset or empty in the environment, the checksecret_key != os.getenv('ADMIN_KEY')could behave unpredictably with empty header values. It now explicitly verifies thatADMIN_KEYis configured.
Key Improvements in PR #23111
- Typed Request Models:
- Hardened
SendNotificationRequestwith field bounds (uid: 1-128,title: 1-500,body: 1-2000) and whitespace stripping validators rejecting empty strings. - Hardened
SendAppNotificationRequestwith field bounds and whitespace validation.
- Hardened
- Endpoint Hardening:
- Replaced raw dictionary subscripts in
send_notification_to_userandsend_app_notification_to_userwith typed model attributes. - Added explicit guard ensuring
ADMIN_KEYis configured and non-empty.
- Replaced raw dictionary subscripts in
- Hermetic Test Suite:
- Added comprehensive tests in
backend/tests/unit/test_integration_notification_validation.pycovering unauthorized access, unset admin key rejection, successful dispatch, whitespace message rejection, and model validation (6/6 passing hermetically in 4.4s, clean ruff).
- Added comprehensive tests in
Designated Payout Channel
- PayPal:
[email protected] - GitHub:
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! 🙏