Skip to content

Harden JSON and SVG escaping for metadata rendering #119

Description

@starknetdev

Summary

Renderer utilities manually build JSON/SVG strings and only partially escape user-controlled values. Characters such as &, ', quotes, and control characters can produce malformed metadata or SVG output.

Affected Code

  • packages/utilities/src/renderer/svg.cairo:99
  • packages/utilities/src/renderer/svg.cairo:252
  • packages/utilities/src/renderer/svg.cairo:474
  • packages/utilities/src/utils/json.cairo:77

Risk

Malformed token metadata or SVG rendering issues in wallets, marketplaces, and indexers.

Suggested Fix

Introduce dedicated JSON string escaping and SVG/XML text/attribute escaping helpers, then use them consistently.

Suggested Tests

Add cases with the following characters in names, image URLs, context values, and JSON arrays:

  • &
  • '
  • "
  • <
  • >
  • %
  • commas
  • backslashes
  • control characters

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions