fix(backend): validate inputs and handle serialization in database webhook health

Closed
BR
8h ago
+314-47

Closes #19332

Summary

Hardens backend/database/webhook_health.py against serialization failures, unhandled exceptions, and in-memory cache poisoning:

  1. DLQ Non-JSON Payload Serialization: Added default=str to json.dumps in enqueue_dev_webhook_dlq so payloads containing datetime, UUID, or other non-primitive types serialize gracefully instead of failing silently and dropping the event from the DLQ.
  2. Subscript Crash Guard: Guarded (webhook_url or '')[:500] to prevent TypeError: 'NoneType' object is not subscriptable when webhook_url is None.
  3. Firestore Auto-Disable Resilience: Handled google.api_core.exceptions.NotFound gracefully in disable_app_in_firestore. Cache state is now updated only on successful Firestore update, preventing cache poisoning if Firestore write fails.
  4. Resilient Cache Eviction: Protected _evict_oldest against empty dictionary input (StopIteration risk) and added safe type casting for mixed cache entries.
  5. Input Validation: Normalized and stripped string identifiers across record_app_webhook_failure, record_app_webhook_success, clear_app_webhook_health, is_app_webhook_disabled, get_app_webhook_health, record_dev_webhook_failure, and record_dev_webhook_success.

Testing & Verification

  • Authored hermetic unit tests in backend/tests/unit/test_database_webhook_health_resilience.py (10 passing tests).
  • Verified existing suite backend/tests/unit/test_webhook_health_cache_cap.py (2 passing tests).
  • Formatted with Black 26.5.1 (--line-length 120 --skip-string-normalization) with 0 formatting deviations.

Designated Payout Rails

  • Primary: Base USDC: 0xbB9686b9684421A8e326AC0F8B3eCf88Df975120
  • Backup: PayPal: brandonworkforce@tutamail.com