User supplied owner address which is meant to be token owner is never the token owner
The mint function accepts an owner parameter but sets the token's owner to the caller's address instead. This means a user cannot mint a token for another address, as the caller always becomes the owner.
Submitted by adeolu
In the function mint(), owner is a parameter which is accepted by the function and is meant to be set into the TokenInfo struct’s owner field during the mint. But the issue is that the TokenInfo struct sets the owner to be the info.sender. This is wrong because info.sender, which is the function caller is not always the owner arg. This means the mint logic is defective, the user supplied value for owner will never be the owner of the newly minted token.
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> {
From above, we can see the mint function’s name and parameters, the owner parameter is a required parameter meant to be provided by the caller of the function. But this owner parameter is not used in the token:TokenInfo struct. Instead, owner is set to be the function caller instead of the user supplied owner value.
let token = TokenInfo {
owner: info.sender.clone(), //@audit owner is provided as arg, function caller is set as owner instead.
approvals: vec![],
rentals:vec![],
bids:vec![],
longterm_rental,
shortterm_rental,
sell,
token_uri,
extension,
};
This will mean that a case where user A wants to mint token1 for user B will not work because even though user A is the function caller and has specified that user B should be the owner of token1, user A will still be set as the token owner.
Recommended Mitigation
Set user supplied owner value as owner in the token struct.
let token = TokenInfo {
owner: owner,
approvals: vec![],
rentals:vec![],
bids:vec![],
longterm_rental,
shortterm_rental,
sell,
token_uri,
extension,
};
Assessed type
Context
blockchainstar12 (Coded Estate) acknowledged and commented:
It does not make any issues actually.
It does not make any issues actually.
The function accepts user specified Param address to be owner; the function doesn’t set the user specified param address as owner in token struct and then returns a response that it has set owner to be the user specified “owner” param value. The owner param value is not always same as
info.sender.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The mint function uses the caller's address (info.sender) as the token owner instead of the provided owner parameter.
Impact
A user cannot mint a token for another address; the caller always becomes the owner, which may break intended use cases.
What the attacker needed
None
The fix
The mint function should set the token owner to the provided owner parameter instead of the caller's address.
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.
When you mint a token, you can say who should own it. But the code ignores that and makes you the owner instead. So you can't give a token to someone else when you create it.
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.