Skip to content

fix: validate parsed.method in ws-handler before use#569

Merged
realfishsam merged 1 commit into
mainfrom
fix/559-ws-handler-cast
May 24, 2026
Merged

fix: validate parsed.method in ws-handler before use#569
realfishsam merged 1 commit into
mainfrom
fix/559-ws-handler-cast

Conversation

@realfishsam

Copy link
Copy Markdown
Contributor

Fixes #559

@realfishsam

Copy link
Copy Markdown
Contributor Author

PR Review: VERIFIED

What This Does

Validates parsed.method from WebSocket messages before use, promoting it from an unvalidated parsed.method as string cast to a guarded extraction with an early-return error. Previously a client could omit method and the value undefined would be silently cast to string, propagating through subscribe/unsubscribe handlers.

Blast Radius

  • Core server only (core/src/server/ws-handler.ts)
  • Affects all WebSocket subscribe/unsubscribe message handling
  • No exchange/SDK/OpenAPI impact

Findings

  1. The method field is already required in both SubscribeMessage and UnsubscribeMessage interfaces (lines 12-27), so validating it at the parsing boundary is correct and consistent with the type contract.
  2. The guard !method correctly catches both undefined (missing field) and "" (empty string). The error message is updated to list all four required fields.
  3. After the guard, method is a narrowed string, so the downstream assignments (method: method) no longer need as string casts. Clean.
  4. The extraction pattern (const method = parsed.method as string | undefined) is consistent with how id, action, and exchange are extracted on lines 254-256.

PMXT Pipeline Check

  • Field propagation: N/A
  • OpenAPI sync: N/A
  • Type safety: OK -- eliminates unsafe cast, adds runtime validation

Semver Impact

patch -- adds input validation to WebSocket handler. Clients that were omitting method were already getting undefined behavior; now they get a clear error.

Risk

None. The only behavioral change is that malformed messages missing method now get an explicit error instead of silently failing downstream.

@realfishsam realfishsam merged commit 941abfb into main May 24, 2026
10 of 11 checks passed
@realfishsam realfishsam deleted the fix/559-ws-handler-cast branch May 24, 2026 17:04
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.

[non-null] server/ws-handler.ts: parsed.method cast to string without validation

1 participant