MetaMask / MetaMask/metamask-extension

Improve multibase parsing for IPFS urls

Open
#21,519 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

INVALID-ISSUE-TEMPLATE team-assets team-extension-platform
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

Assets Controllers uses the multiformats library to parse IPFS urls in getIpfsCIDv1AndPath in assetUtils.ts.

This type of string is detected in parseCIDtoBytes in node_modules/multiformats/src/cid.js.

One of the accepted CIDv1 is an RFC 4648 base32 string when it has a b prefix. However, if a character of this number is a 1, 8, 9, or an uppercase letter, the string is not a valid base32 string and a Non-base32 character error is thrown.

This matches what Dan Miller had already observed to be the case for base58btc strings, too (see issue and PR).

There is a third case, in which the prefix is none of the known prefixes, in which case the function throws a different error To parse non base32 or base58btc encoded CID multibase decoder must be provided (see bug report).

Dan’s solution in the PR linked above solves this temporarily by silencing the error and preventing it from bubbling up. The current solution seems to silence the error everywhere because multiformats is only used in getIpfsCIDv1AndPath that is used in the extension in getFormattedIpfsUrl.

A long-term solution should be to replace the CID.parse function with a multibase parser that can interpret all types of strings and don't try to decode the strings that don't adhere to the conventions.

Contributor guide

Open the contributing guide

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.

Research direction

Start in assetUtils.ts at getIpfsCIDv1AndPath, then trace its use from getFormattedIpfsUrl. Reproduce the base32, base58btc, and unknown-prefix cases described in the issue, and compare them with CID.parse in multiformats. Done means IPFS URL parsing can distinguish unsupported encodings without silencing unrelated errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.