Skip to content

[non-null] ws-client.ts: 2 unsafe this.ws! assertions before send #281

@realfishsam

Description

@realfishsam

Risk Level

MEDIUM

File

sdks/typescript/pmxt/ws-client.ts

Findings

  • Line 243: this.ws!.send(JSON.stringify(message));
  • Line 281: this.ws!.send(JSON.stringify(message));

this.ws is a class field that is assigned when the WebSocket connection is established. Both assertions assume the connection is live at the point of the send call. If a message is sent during reconnection, after an explicit disconnect, or before the first connection completes, this.ws is undefined and the assertion throws.

What Happens When It's Wrong

TypeError: Cannot read properties of undefined (reading 'send') — the outbound message is silently dropped and the SDK produces an unhandled exception rather than a connection error.

Suggested Fix

Guard the send, or queue the message for when the connection is re-established:

if (!this.ws) {
    throw new Error('[ws-client] Cannot send: WebSocket not connected');
}
this.ws.send(JSON.stringify(message));

Found by automated non-null assertion audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions