Skip to content

fix: reject inbound messages on expired sessions (WAPI-1130)#72

Open
chakra-guy wants to merge 1 commit intomainfrom
cyfrin/wapi-1130
Open

fix: reject inbound messages on expired sessions (WAPI-1130)#72
chakra-guy wants to merge 1 commit intomainfrom
cyfrin/wapi-1130

Conversation

@chakra-guy
Copy link
Collaborator

@chakra-guy chakra-guy commented Feb 25, 2026

Summary

  • Adds session expiry check to the inbound message handler in BaseClient, closing a gap where only outbound messages were checked for expiry
  • Expired inbound messages are silently discarded with an error event emitted and disconnect triggered

Background

The Cyfrin audit identified that while sendMessage() checks for session expiry before sending, the transport.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: Unified checkSessionExpiry() method (returns boolean, handles disconnect + error emission). Used in both the inbound message handler (early return) and sendMessage (throws after check).
  • packages/core/src/base-client.integration.test.ts: New test case for expired session message rejection
  • apps/integration-tests/src/end-to-end.integration.test.ts: New E2E test verifying messages sent to an expired receiver are dropped and trigger SESSION_EXPIRED

Test plan

  • yarn build passes
  • yarn test:unit passes (63/63 tests)
  • yarn lint passes (no new warnings)
  • Integration tests pass (8/8 tests, including new expired session test)

Note

Medium Risk
Touches core message-handling and session lifecycle behavior; an incorrect expiry check or disconnect side effect could drop legitimate traffic or cause unexpected disconnects.

Overview
Expired sessions now block inbound traffic. BaseClient adds a session-expiry gate in the transport message handler so messages arriving after expiresAt are rejected, a SESSION_EXPIRED error is emitted, and cleanup/disconnect is triggered.

checkSessionExpiry() is refactored to return a boolean and is reused by both inbound and outbound paths, with new integration/E2E tests asserting that post-expiry messages are not delivered. Dependency housekeeping pins eciesjs to 0.4.17 across apps/core (and updates yarn.lock) and records the fix in the core changelog.

Written by Cursor Bugbot for commit 9827ff0. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

adonesky1
adonesky1 previously approved these changes Feb 25, 2026
Copy link

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chakra-guy chakra-guy force-pushed the cyfrin/wapi-1121 branch 2 times, most recently from a117dc7 to fd3a662 Compare February 27, 2026 14:07
@jiexi
Copy link
Member

jiexi commented Mar 2, 2026

is the confirmNonce logic meant to be in this PR?

@chakra-guy chakra-guy changed the base branch from cyfrin/wapi-1121 to main March 6, 2026 13:19
@chakra-guy chakra-guy dismissed adonesky1’s stale review March 6, 2026 13:19

The base branch was changed.

@chakra-guy
Copy link
Collaborator Author

is the confirmNonce logic meant to be in this PR?

nope, it was just originally based in top of another pr that got mixed it after a merge conflict

@chakra-guy chakra-guy requested a review from adonesky1 March 6, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants