Skip to content

fix: validate Horizon and Soroban RPC responses - #177

Open
jeremytsng wants to merge 1 commit into
mainfrom
fix/horizon-api-response-validation
Open

fix: validate Horizon and Soroban RPC responses#177
jeremytsng wants to merge 1 commit into
mainfrom
fix/horizon-api-response-validation

Conversation

@jeremytsng

Copy link
Copy Markdown
Contributor

Adds superstruct validation for the fields the snap consumes from Horizon and Soroban RPC responses, so malformed payloads fail fast with a NetworkServiceException instead of propagating undefined values into account, fee, transaction and asset mapping.

Explanation

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens packages/snap network integrations by validating the specific Horizon and Soroban RPC response fields the Snap consumes, so malformed payloads fail early with NetworkServiceException instead of leaking undefined deeper into mapping logic.

Changes:

  • Added a reusable assertNetworkResponse helper that wraps Superstruct validation errors as NetworkServiceException.
  • Introduced Superstruct schemas for the consumed Horizon/RPC response shapes and enforced them across NetworkService read paths.
  • Expanded NetworkService test coverage to ensure malformed responses surface the new validation errors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/snap/src/services/network/utils.ts Adds a shared response-validation helper used by network calls.
packages/snap/src/services/network/NetworkService.ts Applies response validation to Horizon/RPC calls before mapping/consuming fields.
packages/snap/src/services/network/NetworkService.test.ts Adds tests ensuring malformed responses throw the intended validation errors.
packages/snap/src/services/network/api.ts Defines Superstruct schemas for Horizon and Soroban RPC response subsets used by the Snap.
packages/snap/snap.manifest.json Updates Snap bundle shasum for the new build output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

response: unknown,
struct: Struct<Validated>,
message: string,
): void {
num_sponsoring: optional(number()),
num_sponsored: optional(number()),
data_attr: optional(record(string(), string())),
balances: optional(array(HorizonBalanceLineStruct)),
Adds superstruct validation for the fields the snap consumes from Horizon
and Soroban RPC responses, so malformed payloads fail fast with a
NetworkServiceException instead of propagating undefined values into
account, fee, transaction and asset mapping.
@jeremytsng
jeremytsng force-pushed the fix/horizon-api-response-validation branch from cc9bf3f to 40558fe Compare August 11, 2026 08:33
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