Skip to content
low Best Practice No SWC entry CWE-20

Unbounded / Unsanitised tokenURI Metadata

SAFE-0215 Best Practice Checked automatically by the scanner
1

What goes wrong

tokenURI concatenates unbounded or user-influenced strings (baseURI set by anyone, or on-chain user data) without sanitisation, enabling metadata spoofing or oversized returns for integrators.

2

The vulnerable pattern

proof of concept — how it is exploited
// if setBaseURI is unprotected, anyone points metadata at a phishing
// host; marketplaces render the attacker's image/name for your NFT.
3

How to fix it

the pattern that is safe
// restrict baseURI to owner; validate/escape any on-chain string data
function setBaseURI(string calldata u) external onlyOwner { baseURI = u; }
Gate baseURI and sanitise on-chain metadata inputs.
4

Where this has happened

Largest recorded losses in the same failure class — related, not the same bug:

Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0215 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs