Skip to content

fix: Raise a Seam error for a success response that is malformed - #1005

Merged
razor-x merged 1 commit into
mainfrom
claude/js-sdk-audit-6x115l-m3-invalid-response
Aug 24, 2026
Merged

fix: Raise a Seam error for a success response that is malformed#1005
razor-x merged 1 commit into
mainfrom
claude/js-sdk-audit-6x115l-m3-invalid-response

Conversation

@razor-x

@razor-x razor-x commented Aug 24, 2026

Copy link
Copy Markdown
Member

Problem

SDK audit finding M3 (medium): a 200 with an unexpected envelope (proxy rewrite, gateway maintenance page with a JSON content type, response-key rename) bypassed all typed errors. execute() read response[responseKey] unguarded, returning undefined or feeding it into the action-attempt poller, which crashed with a bare TypeError: Cannot read properties of undefined (reading 'status'). The paginator threw plain Error objects for the same class of failure, and a missing pagination object silently truncated iteration to one page.

Fix

Mirrors seamapi/php#475. Centralize the response unwrap in an exported readResponseData helper and raise a new SeamHttpInvalidResponseError (with path and responseKey properties, plus an isSeamHttpInvalidResponseError guard) whose message names the endpoint and the missing key:

Seam returned an invalid response for /devices/get: expected "device", which the response does not contain

The paginator uses the same guard for the list value (got string instead of a list), for a missing pagination object, and for a non-object pagination value — no more silent one-page truncation.

Tests

7 new nock-driven tests pin the exact messages: missing key, non-object body, null body, malformed action-attempt response, non-list data, missing pagination, non-object pagination. Per the audit-notes recipe, with the guards reverted all 7 fail with the audit's exact symptoms (bare TypeErrors, including the poller's reading 'status'). Full suite (132 tests), lint, typecheck green.

Part of applying the rev-3 SDK audit (one PR per finding). Related: #1002, #1003, #1004.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2


Generated by Claude Code

A 200 response with an unexpected envelope, such as a proxy rewrite or
a gateway page with a JSON content type, escaped the SDK error
hierarchy entirely: reading a missing response key produced undefined,
which surfaced as a bare TypeError from the action attempt poller or as
undefined response data. The paginator threw plain Error objects for
the same class of failure.

Centralize the response unwrap in readResponseData and raise the new
SeamHttpInvalidResponseError, which names the endpoint path and the
expected response key. The paginator uses the same guard for the list
data and the pagination object.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
@razor-x
razor-x requested a review from a team as a code owner August 24, 2026 19:23
@razor-x
razor-x merged commit 532012a into main Aug 24, 2026
16 checks passed
@razor-x
razor-x deleted the claude/js-sdk-audit-6x115l-m3-invalid-response branch August 24, 2026 19:32
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.

2 participants