fix: reject inbound messages on expired sessions (WAPI-1130)#72
Open
chakra-guy wants to merge 2 commits intocyfrin/wapi-1121from
Open
fix: reject inbound messages on expired sessions (WAPI-1130)#72chakra-guy wants to merge 2 commits intocyfrin/wapi-1121from
chakra-guy wants to merge 2 commits intocyfrin/wapi-1121from
Conversation
Previously, only outbound messages checked for session expiry. Inbound messages arriving on an expired session were still decrypted and processed. Now, the inbound message handler checks session expiry before decryption and silently discards messages on expired sessions, emitting an error event and triggering a disconnect.
6e3660c to
65d0d35
Compare
Move the SESSION_EXPIRED error emit out of checkSessionExpiry() and into the inbound message handler, so the outbound path (sendMessage) only signals expiry via the thrown exception - not both emit and throw.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseClient, closing a gap where only outbound messages were checked for expiryisSessionExpired/checkSessionExpirymethods into a singlecheckSessionExpirythat returns a boolean, reused by both the inbound and outbound pathsBackground
The Cyfrin audit identified that while
sendMessage()checks for session expiry before sending, thetransport.on("message", ...)handler did not perform any expiry check. This meant a message arriving on an expired session would still be decrypted and processed.Changes
packages/core/src/base-client.ts: UnifiedcheckSessionExpiry()method (returnsboolean, handles disconnect + error emission). Used in both the inbound message handler (early return) andsendMessage(throws after check).packages/core/src/base-client.integration.test.ts: New test case for expired session message rejectionapps/integration-tests/src/end-to-end.integration.test.ts: New E2E test verifying messages sent to an expired receiver are dropped and trigger SESSION_EXPIREDTest plan
yarn buildpassesyarn test:unitpasses (63/63 tests)yarn lintpasses (no new warnings)Note
Medium Risk
Touches core session lifecycle behavior for all inbound messages; could introduce unexpected disconnects or error emissions if expiry timing/clock skew is mishandled, though changes are small and covered by new tests.
Overview
Inbound message handling now enforces session expiry.
BaseClientchecks expiry on every transportmessageevent and, if expired, triggers disconnect cleanup and emits aSESSION_EXPIREDerror instead of decrypting/processing the payload.checkSessionExpiry()is refactored to return a boolean (expired vs not) and is reused by both inbound handling andsendMessage()(which now throws when the check reports expiry). New integration and E2E tests cover dropping inbound messages to an expired receiver, and the core changelog is updated.Written by Cursor Bugbot for commit 5c38e3b. This will update automatically on new commits. Configure here.