Repository navigation
feat(worker): define validated worker message protocol - #233
lamborghini21 wants to merge 6 commits into
Conversation
Define shared request, success, error, retention-gap, and progress unions for worker ↔ main thread communication. Validate inbound messages before reading fields. Include request IDs and ignore stale responses. Add malformed and unknown-message tests. - Create src/lib/workerProtocol.ts with discriminated unions for all message types - Add runtime validation functions for inbound messages - Implement RequestTracker class for request ID tracking and stale response filtering - Update app-sw.ts to use validated message protocol - Update stellar-notification-sw.ts to use validated message protocol - Update useNotificationSW.ts to use validated message protocol - Add comprehensive test suite for malformed and unknown message handling This addresses Wave 10 carryover wraith-protocol#211 for Wave 9 PR wraith-protocol#205 incomplete malformed-message handling.
|
@lamborghini21 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@lamborghini21 is attempting to deploy a commit to the truthixify's projects Team on Vercel. A member of the Team first needs to authorize it. |
truthixify
left a comment
There was a problem hiding this comment.
Blocking: the branch fails its own worker protocol test. validateMainThreadMessage accepts a SKIP_WAITING object with arbitrary extra fields, while the added test requires strict rejection. Enforce the declared message shape or adjust the contract and test consistently before merge.
Okay, I will do that |
I will fix it up now, sorry for late response |
…fields Add field whitelist validation to all message types to reject messages with unexpected fields. Update tests to verify extra field rejection. - Add allowedFields checks to all validateMainThreadMessage cases - Add allowedFields checks to all validateWorkerMessage cases - Update test expectations from 'Unknown message type' to 'extra fields' - Add extra field rejection tests for all message types Addresses review feedback about SKIP_WAITING accepting arbitrary extra fields.
truthixify
left a comment
There was a problem hiding this comment.
The strict shape checks now reject extra fields, but the PR\047s own focused suite is red: 8 assertions expect the rejection reason to contain "extra fields", while the implementation returns "unexpected fields" (for REGISTER_VIEWING_KEY, UNREGISTER_VIEWING_KEY, TRIGGER_SCAN, both push-subscription messages, VIEWING_KEY_REGISTERED, WRAITH_NOTIFICATION, and NAVIGATE_TO_MATCH). Please make the implementation/tests agree and run src/lib/workerProtocol.test.ts; current result is 8 failed, 41 passed.
Okay, I will do that |
truthixify
left a comment
There was a problem hiding this comment.
The strict-shape follow-up resolves the blocker. Reviewed exact head 9da7be1: all 49 worker protocol tests pass, the changed files pass Prettier, and the production build succeeds. Approved. The branch is still conflicting with develop, so please rebase it and rerun the current checks before merge; the Vercel status is the existing external authorization failure.
Summary
Implements a validated message protocol for worker ↔ main thread communication to address incomplete malformed-message handling from Wave 9 PR #205. All messages are now validated at runtime before processing, preventing crashes and security issues from malformed or unknown messages.
Changes
New Files
src/lib/workerProtocol.ts(462 lines)RequestTrackerclass for filtering stale responsessrc/lib/workerProtocol.test.ts(526 lines)Modified Files
src/sw/app-sw.tsvalidateMainThreadMessage()for all inbound messagesWorkerMessageresponsessrc/sw/stellar-notification-sw.tsvalidateMainThreadMessage()for all inbound messagesWorkerMessageresponsessrc/hooks/useNotificationSW.tsvalidateWorkerMessage()for inbound worker messagesmainThreadRequestTrackerfor request ID managementProtocol Definition
Message Types
Main Thread → Worker (Requests):
SKIP_WAITING- Skip service worker waitingRECOVER_SCAN_CURSOR- Recover scan cursor after retention gapREGISTER_VIEWING_KEY- Register a viewing key for scanningUNREGISTER_VIEWING_KEY- Unregister a viewing keyTRIGGER_SCAN- Trigger manual scanREGISTER_PUSH_SUBSCRIPTION- Register Web Push subscriptionUNREGISTER_PUSH_SUBSCRIPTION- Unregister Web Push subscriptionWorker → Main Thread (Responses):
VIEWING_KEY_REGISTERED,VIEWING_KEY_UNREGISTERED,PUSH_SUBSCRIPTION_REGISTERED,PUSH_SUBSCRIPTION_UNREGISTERED,STELLAR_SCAN_RECOVERY_COMPLETE,OFFLINE_QUEUE_FLUSHVIEWING_KEY_ERROR,PUSH_SUBSCRIPTION_ERRORSTELLAR_SCAN_RETENTION_GAP,WRAITH_NOTIFICATION,NAVIGATE_TO_MATCHValidation
All inbound messages are validated before processing:
Request Tracking
req-{number})Testing
Related Issues
Checklist