DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: low
Invalid

Unescaped ERC20 Symbol in SVG Generation Can Lead to Invalid XML

Summary

MetadataImage contract generates SVG images that include ERC20 token symbols. Albeit, these symbols are not properly escaped before being inserted into the SVG XML. This can bring about generation of invalid XML when token symbols contain special characters, potentially causing rendering issues or broken NFT images as the case may be.

Vulnerability Details

Firstly, let's look at tokenName and getTokenName functions:

tokenName function:

function tokenName(address token) internal view returns (string memory) {
return
string(
abi.encodePacked(
'<text x="10" y="14.5" font-size="12" fill="White" text-anchor="start" font-family="futura">',
getTokenName(token),
"</text>"
)
);
}

getTokenName function:

function getTokenName(address token) internal view returns (string memory tokenString) {
if (token == C.UNRIPE_LP) {
tokenString = "urBEANLP";
} else {
tokenString = ERC20(token).symbol();
}
}

The getTokenName function directly returns the ERC20 token's symbol without any escaping or sanitization. This raw symbol is then inserted into the SVG XML in the tokenName function.

If an ERC20 token's symbol contains special XML characters such as '<', '>', '&', '"', or ''', it will result in malformed XML. For instance:

  • A token with symbol "A&B" would produce: <text>A&B</text>, which is invalid XML.

  • A token with symbol "C<D" would produce: <text>C<D</text>, which is also invalid XML.

This issue affects not only the tokenName function but also the movingTokenAddress function, which uses the token address directly in the SVG without escaping.

Impact

For tokens with symbols containing special XML characters, the generated SVG will be invalid XML. This can lead to broken or improperly rendered NFT images. In cases where the SVG is invalid, some renderers might fail to display the token symbol entirely, leading to a loss of critical information in the NFT metadata.

Tools Used

Manual review

Recommendations

To fix this, we could implement an XML escaping function and then modify the getTokenName function to use this escaping function. Also consider implementing some sort of sanitization/input validation for token symbols and addresses to reject or handle tokens with excessively long or complex symbols that might cause issues even after escaping.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational/Gas

Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity

Appeal created

rhaydden Submitter
about 1 year ago
inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational/Gas

Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.