Skip to content

fix: prevent nonce poisoning (WAPI-1121)#69

Open
chakra-guy wants to merge 2 commits intomainfrom
cyfrin/wapi-1121
Open

fix: prevent nonce poisoning (WAPI-1121)#69
chakra-guy wants to merge 2 commits intomainfrom
cyfrin/wapi-1121

Conversation

@chakra-guy
Copy link
Collaborator

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

Summary

Prevents nonce poisoning attacks by deferring nonce persistence until after successful decryption. Previously, nonces were saved immediately on message receipt, allowing an attacker to send high-nonce messages that fail decryption but permanently block legitimate messages.

  • Nonce is now confirmed via callback only after successful decryption in BaseClient
  • Added MAX_NONCE_JUMP (100) to reject suspiciously large nonce jumps from known senders
  • Added NaN recovery in nonce storage
  • Added mutex around confirmNonce to prevent concurrent race conditions

Jira

Test plan

  • Unit tests for confirmNonce, NaN recovery, nonce regression prevention
  • All existing unit tests pass (63/63)
  • Lint passes

Note

Medium Risk
Touches transport-level deduplication and message acceptance rules; incorrect confirmation usage or overly strict nonce-jump thresholds could cause dropped or stuck messages in edge cases.

Overview
Prevents nonce poisoning by changing WebSocket incoming-message handling to defer nonce persistence until after a message is successfully decrypted: WebSocketTransport now emits message events with an optional confirmNonce() callback, and BaseClient calls it only on successful decrypt.

Adds additional nonce safety: rejects suspiciously large nonce jumps from known senders (MAX_NONCE_JUMP), tracks in-memory pendingNonces to avoid double-processing before confirmation (e.g., live + history), clears pending state on clear(), and hardens outbound nonce storage against NaN. Includes new WebSocketTransportStorage.confirmNonce() (mutex-protected) plus updated/added unit + integration tests and a new async-mutex dependency.

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

@socket-security
Copy link

socket-security bot commented Feb 25, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedasync-mutex@​0.5.010010010080100

View full report

…ryption (WAPI-1121)

Nonces are no longer persisted immediately on message receipt. Instead,
a confirmNonce callback is emitted with each message and called by
BaseClient only after successful decryption. This prevents attackers
from poisoning the nonce tracker with high-nonce messages that fail
decryption, which would permanently block legitimate messages.

Also adds MAX_NONCE_JUMP (100) to reject suspiciously large nonce jumps,
NaN recovery in nonce storage, and a mutex around confirmNonce to prevent
race conditions.
Tests now call confirmNonce() after receiving messages so nonces are
persisted to storage, matching the new two-phase nonce confirmation
flow introduced by the nonce poisoning fix.
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.

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.

1 participant