Open code423n4 opened 1 year ago
Yeah the line break generally happened approx. after 40 bytes, which results in somewhat weird results for these huge emojis. Should be fixed when the tokenURI is refactored, see #87
OpenCoreCH marked the issue as sponsor confirmed
0xleastwood marked the issue as primary issue
0xleastwood marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-bio-protocol/src/Bio.sol#L43
Vulnerability details
Impact
Bio NFT incorrectly breaks SVG lines and doesn't support more than 120 characters effectively.
Proof of Concept
According to the docs
Let's take two strings and pass them to create an NFT. The first one is 200 characters long, and the second one is 120 characters long.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaW
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaW
This is how they will look like. As you can see they look identical.
Next, lets take this text for which we create nft. I took it from a test and double.
012345678901234567890123456789012345678๐จโ๐ฉโ๐งโ๐ง012345678901234567890123456789012345678๐จโ๐ฉโ๐งโ๐ง
Here is on the left how it looks now vs how it suppose to be. As you can you line breaking doesn't work. I did enlarge viewBox so you can see the difference.
The problem is in this part of the code, where
(i > 0 && (i + 1) % 40 == 0)
doesn't handle properly because you want to include emojis, so length will be more than 40 (40 + length(emoji)
)canto-bio-protocol/src/Bio.sol#L56 Lastly, the NFT doesn't center-align text, but I believe it should. I took text from a test and on the left is how it currently appears, while on the right is how I think it should be.
Here is the code. dy doesn't apply correctly; it should be 0 for the first line.
canto-bio-protocol/src/Bio.sol#L104
Tools Used
Manual review
Recommended Mitigation Steps
Enlarge viewBox so it will support 200 length or restrict to 120 characters. Here is a complete code with correct line breaking and center text. I'm sorry that I didn't add
differ
to code because there will be too many lines. It does pass tests and fix current issues