fix(backend): validate inputs and handle serialization in database webhook health
Closed
BR
8h ago+314+314+012345678901234567890123456789-47-47-01234567890123456789
Closes #19332
Summary
Hardens backend/database/webhook_health.py against serialization failures, unhandled exceptions, and in-memory cache poisoning:
- DLQ Non-JSON Payload Serialization: Added
default=strtojson.dumpsinenqueue_dev_webhook_dlqso payloads containingdatetime,UUID, or other non-primitive types serialize gracefully instead of failing silently and dropping the event from the DLQ. - Subscript Crash Guard: Guarded
(webhook_url or '')[:500]to preventTypeError: 'NoneType' object is not subscriptablewhenwebhook_urlisNone. - Firestore Auto-Disable Resilience: Handled
google.api_core.exceptions.NotFoundgracefully indisable_app_in_firestore. Cache state is now updated only on successful Firestore update, preventing cache poisoning if Firestore write fails. - Resilient Cache Eviction: Protected
_evict_oldestagainst empty dictionary input (StopIterationrisk) and added safe type casting for mixed cache entries. - 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, andrecord_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