Skip to content

bug: getMetadata casts untrusted IPFS gateway JSON to TokenMetadata without validation #849

Description

@Ejirowebfi

Summary

IPFSService.getMetadata casts an arbitrary gateway JSON response straight to TokenMetadata with no runtime shape validation.

Evidence

frontend/src/services/ipfs.ts:97-101

try {
  return (await response.json()) as TokenMetadata
} catch {
  throw new IPFSUploadError('Metadata response is not valid JSON.')
}

The content behind an ipfs:// URI is user/third-party controlled. The returned name/description/image are then consumed by UI components. A missing/malformed image field (or unexpected types) flows downstream untyped, and the as cast gives a false sense of safety.

Suggested fix

Validate the parsed object against the TokenMetadata shape (e.g. a small guard or zod schema) before returning; reject or sanitize unexpected fields. Ensure consumers treat image defensively.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions