adapter-stellar: the xdr-json WASM is fetched from unpkg and run with no integrity check

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript, wasm

Research direction

Start in packages/adapter-stellar/src/sac/xdr.ts, especially the CDN URL and init(CDN_WASM_URL) calls, and read the comment at the top of the file. Compare the options in the issue against the package version range and existing SAC load error handling. Done means the chosen approach prevents unverified WASM from running and reports failures through the SAC load error with the reason on cause.

Written by the indexing model from the issue text.

Description

What happens

To load a Stellar Asset Contract, the adapter encodes the SAC spec with @stellar/stellar-xdr-json, whose WASM is not bundled. It is fetched at run time from https://unpkg.com/@stellar/stellar-xdr-json@<installed version>/stellar_xdr_json_bg.wasm and instantiated as served: sac/xdr.ts L28-L30 (the URL) and L53 (init(CDN_WASM_URL)).

Nothing checks that the bytes are the ones published for that version. The version in the URL follows the installed package, but the content is not verified.

Why it matters

  • The app runs code from a third-party CDN in the user's browser, in the same page that builds and signs transactions. If unpkg, or anything on the path to it, serves different bytes, the adapter runs them.
  • The WASM produces the SAC interface the app shows and encodes against, so a wrong module can change which functions and argument types a user sees for a token contract.
  • Availability is a separate, smaller point: if unpkg is down or blocked by a Content Security Policy, SACs do not load. That already fails with a clear error and is not what this issue is about.

Suggested fix

Options, to be weighed by whoever picks this up:

  1. Verify before instantiating: fetch the bytes, compare their SHA-256 with a hash the adapter ships for that package version, and refuse on mismatch. The adapter depends on a version range, so it needs either a hash per known version (and a decision on what an unknown version does) or an exact pin.
  2. Let the consumer supply the WASM (a URL or the bytes), so an app can host it under its own policy. This also helps strict-CSP apps.
  3. Bundle the WASM. Ruled out so far for bundle size and bundler compatibility (see the comment at the top of xdr.ts); listed for completeness.

Whichever is chosen, a failed check should surface as the existing SAC load error, with the reason on cause.

Dominant language
TypeScript
Stars
2
Forks
2
Avg merge
6h 33m
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenZeppelin/openzeppelin-adapters

All issues in OpenZeppelin/openzeppelin-adapters

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.