Skip to content

[non-null] baozi/websocket.ts: unsafe Map.get()! assertion on orderBookResolvers #261

@realfishsam

Description

@realfishsam

Risk Level

HIGH

File

core/src/exchanges/baozi/websocket.ts

Findings

  • Line 88: this.orderBookResolvers.get(marketPubkey)!.push({ resolve, reject }); — assumes marketPubkey is already registered in orderBookResolvers. If the key is absent (race condition, re-subscription after cleanup, or unexpected call order), .push() is called on undefined.

What Happens When It's Wrong

TypeError: Cannot read properties of undefined (reading 'push') — the pending watchOrderBook promise leaks; the caller hangs until the watch timeout fires with no indication of what went wrong.

Suggested Fix

if (!this.orderBookResolvers.has(marketPubkey)) this.orderBookResolvers.set(marketPubkey, []);
this.orderBookResolvers.get(marketPubkey)!.push({ resolve, reject });

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