Can impersonate another high value rental because token_uri is arbitrary and supplied by user
The token_uri field in the mint function is arbitrary and user-supplied, allowing a malicious user to set it to a fake URL or JSON that impersonates a higher-value rental property. This could phish users into renting or buying the wrong property if the frontend displays the metadata without sanitisation.
Because token_uri value is not sanitized and is arbitrary/provided by a user, a malicious user can provide a token uri which may have " or , or simply a fake url which points to a different higher value rental property in order to phish unsuspecting users.
Proof Of Concept
pub fn mint(
&self,
deps: DepsMut,
info: MessageInfo,
token_id: String,
owner: String,
token_uri: Option<String>,
extension: T,
) -> Result<Response<C>, ContractError> {
//@audit no money collected to mint a token? do they mint for free?
// cw_ownable::assert_owner(deps.storage, &info.sender)?;
let longterm_rental = LongTermRental {
islisted: None,
price_per_month: 0u64,
available_period:vec![],
deposit_amount: Uint128::from(0u64),
withdrawn_amount: Uint128::from(0u64),
denom:"ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349".to_string(),
auto_approve:false,
cancellation:vec![],
minimum_stay:0u64,
};
let shortterm_rental = ShortTermRental {
islisted: None,
price_per_day: 0u64,
available_period: vec![],
deposit_amount: Uint128::from(0u64),
withdrawn_amount: Uint128::from(0u64),
denom: "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349".to_string(),
auto_approve: false,
cancellation:vec![],
minimum_stay:0u64,
};
let sell = Sell {
islisted:None,
auto_approve:false,
price:0u64,
denom:"ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349".to_string(),
};
// create the token
let token = TokenInfo {
owner: info.sender.clone(),
approvals: vec![],
rentals:vec![],
bids:vec![],
longterm_rental,
shortterm_rental,
sell,
token_uri,
extension,
};
self.tokens
.update(deps.storage, &token_id, |old| match old {
Some(_) => Err(ContractError::Claimed {}),
None => Ok(token),
})?;
self.increment_tokens(deps.storage)?;
Ok(Response::new()
.add_attribute("action", "mint")
.add_attribute("minter", info.sender)
.add_attribute("owner", owner) //@audit here owner arg is used but in the token object owner is set to info.sender. owner may not be info.sender
.add_attribute("token_id", token_id))
}
Let’s say a malicious user wants to make a rental that impersonates another high value rental, the attacker can set his own token’s uri to be an exact copy of the high value rental and display attributes/json metadata which is the same. Unsuspecting users might then be tricked into renting from the wrong landlord or buying the wrong rental, because the frontend will display same rental property image and same attributes. All this is possible because token_uri is arbitrary.
To prevent your project from becoming a hotbed for phishing, the token_uri should not be arbitrary, it can be generated by the code. There are a few similar implementations like this here. The token uri is constructed into a json string and its then modified into a base64 json.
Recommended Mitigation
Don’t make token uri arbitrary, generate it in code. Ensure your generation logic rejects strings that contain " and , as these can also be exploited by attackers to do json injection of false fields.
Requires some assumptions about the off-chain usage, but similar issues have historically been judged as Medium, as seen here and here and there is a valid attack pattern.
@Lambda - I disagree with the Medium severity of this issue. It should be classified as a QA-level finding at most.
There are 2 claimed impacts here:
Impersonation of another high-value property (rental).
JSON injection.
Let’s explore the validity of these claims.
Impersonation
To generalize the problem, NFTs are typically distinguished by several identifiers such as tokenId, tokenURI, and specific token attributes. For example, a token with tokenId=1 and tokenURI=A is a different asset from one with tokenId=2 and tokenURI=B.
In this particular protocol, the key identifiers of the tokens (representing properties) are:
TokenID: Each token’s tokenId is unique and user-specified, ensuring that no two tokens can have the same tokenId.
TokenURI: This field is arbitrary, meaning that its content (whether in JSON format, URL, or any other structure) does not follow a strict convention. However, the format or content of the tokenURI is irrelevant to the impersonation risk, as it merely serves as metadata.
In traditional NFT protocols, tokenURI plays a significant role in defining a token’s value, as it may contain important unique metadata. If an attacker could replicate the tokenURI, it might be possible to create a token that looks identical and that eliminates the value of the unique NFT. However, in this protocol, the value is instead linked to the real-world property and, therefore, to the ownership of that property.
Real-World Analogy: Consider a rental platform like Airbnb. If two properties look identical, a user will check the legitimacy of the owner to verify the booking. Similarly, in this protocol, the core identifier is the property’s owner, not just the tokenURI. The protocol must ensure that the owner’s identity, along with other token identifiers, is clearly presented on the front-end to avoid confusion.
Thus, while the tokenURI is arbitrary, impersonation in this protocol relies primarily on the ownership of the property, making it a front-end issue, not a smart contract level concern.
To simply put it, one should distinguish each token using not just one of its identifiers but all of its identifiers.
JSON Injection
Regarding JSON injection, the concern here appears to stem from the assumption that tokenURI might be used in a structured format such as JSON. However, this is speculative. The tokenURI field is arbitrary, and without explicit evidence, like in the cited findings, we can’t assume that it’s gonna be constructed at a smart contract level in JSON format.
Besides, the risk of impersonation related to the tokenURI, regardless of format, was already addressed in the previous section.
Conclusion
In conclusion, while the claim regarding the arbitrary tokenURI is valid, the claimed impact is not. This issue should be regarded as a front-end concern rather than a smart contract vulnerability, as there is no effective mitigation at the smart contract level to address it directly.
That is, the front-end should:
Must ensure that the owner’s identity, along with other token identifiers, is clearly presented on the front-end to avoid confusion.
Must sanitize and validate the input from tokenURI (I don’t think you can do that effectively on the smart contract level, given the computational limit by nature of transaction execution on blockchain).
Although there is precedent for classifying similar issues as Medium severity, I believe it is more appropriate to tailor the severity to the specific context of this protocol, rather than generalizing the issue based on previous cases.
This issue should be regarded as a front-end concern rather than a smart contract vulnerability, as there is no effective mitigation at the smart contract level to address it directly.
@nnez - But there is a good mitigation for this, which is preventing arbitrary strings to be used as token URI. And I put a snippet of a better token Uri generation implementation in my original submission. high value protocols that use nft; i.e., uniswap never allows arbitrary uri generation.
Also, how is it a front end concern and not a contract vuln if the issue stems from a misuse of the smart contract? this protocol is very well dependent on the token Uri for their use case As token Uri contains all attributes and possibly images of the rental.
Here, the name, the description, the image and other metadata on the token is still an arbitrary params. How would you effectively prevent a malicious actor from using the same name, same description, and the same image of the legitimate rental property?
Even if you hash all the inputs and prevent the same inputs from being used twice, a malicious actor can just change the url, add another character or words to the name and description.
My whole point here is that one cannot rely solely on tokenURI for uniqueness of the token. One will know for sure that they’re making a reservation on a legitimate token (property) if one knows all three information: owner, tokenId and tokenURI. One can never know for sure if they only know one of the three.
owner and tokenId are both unique and cannot be forged.
You must have a private key of the owner to impersonate as owner
The logic of the contract prevents the token with same tokenId from being created
So, it does make sense to allow an arbitrary information in tokenURI so that token owner can put their property’s information there. How other protocols uses their tokenURI is irrelevant here as I have pointed out that the context for this protocol is different.
It is the front-end responsbility to display all required information (owner, tokenId and tokenURI) to users to enable them to distinguish between genuine and fake properties.
@nnez - I agree with the points raised about impersonation. You cannot solely rely on these attributes, which is a problem that all NFTs face to a certain point (there is for instance nothing stopping anyone from creating a fake BAYC contract that points to the same image) and is very hard to solve (especially without introducing some centralized instance that would e.g., verify the attributes).
For the second point:
Regarding JSON injection, the concern here appears to stem from the assumption that tokenURI might be used in a structured format such as JSON. However, this is speculative.
This is indeed somewhat speculative (it relies on external requirements, which is generally fine for a Medium), but seems like a reasonable assumption. The ERC721 standard even requires this with its metadata assumption. The implementation is based on CW721 with similar requirements/recommendations (see here). Of course, it is also not clear what external systems are doing with this information. But a reasonable assumption here is that it is parsed and/or downloaded and displayed in a frontend.
These things are valid concerns and have happened in the past (see here or here, for e.g.). Of course, they should also be addressed in a frontend by taking respective measures. But I see the valid attack path with external requirements here (although I would have liked a few more details in the issue description).
Of course, it is also not clear what external systems are doing with this information. But a reasonable assumption here is that it is parsed and or downloaded and displayed in a frontend.
Isn’t this an indication that the issue resides on the front-end side?
I believe the criteria for external requirement is the other way around where it requires a specific situation for the bug to occur on smart contract not that it would happen on the external system.
The issue would be valid if the tokenURI were intended to be immutable like traditional NFTs. However, in this case, it’s designed to allow arbitrary information because users need to input their rental information.
Would your perspective on the issue change if the field name were changed to description and allowed arbitrary string? Would it be the front-end’s responsibility to filter and sanitize the string data retrieved before using it?
It is definitely debatable whose responsibility it is and I’d recommend everyone writing a frontend to sanitize any tokenURI return value before using it in the frontend. Nevertheless, this is unfortunately not always done (see above, this was even a major NFT platform) and in such cases, users might actually blame you/your contract because your contracts ultimately caused the malicious payload.
Would your perspective on the issue change if the field name were changed to description and allowed arbitrary string?
Depends, if the string were sanitized, definitely. Otherwise I’d still see the valid attack path.
The original report as published on Code4rena, by adeolu. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the mint function accepts an arbitrary token_uri string without validation or generation by the contract, allowing users to supply any metadata they choose.
Impact
A malicious user could impersonate a high-value rental property, potentially tricking users into renting or buying the wrong property if the frontend relies on token_uri for display; the judge noted this requires assumptions about off-chain usage and is partly a frontend concern.
What the attacker needed
Attacker can mint a token; frontend displays token_uri without sanitisation
The fix
The token_uri should not be arbitrary; it should be generated by the contract code, and the generation logic should reject strings containing quotes or commas to prevent JSON injection.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In this smart contract, each rental property is represented by a token, and the token_uri is like a link to a picture and description of the property. The problem is that anyone can set this link to whatever they want, so a bad actor could copy the link of an expensive property and make their cheap property look identical. If the website showing these tokens does not check carefully, users might be tricked into renting the wrong place.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.