Logic flaw in check_can_edit_short
allows editing short-term rental before finalization enabling theft of users' deposited funds
#4
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-07
primary issue
Highest quality submission among a set of duplicates
🤖_04_group
AI based duplicate group recommendation
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L1953-L1972
Vulnerability details
Impact
Malicious actor can exploit this vulnerability to steal other users' deposited token from the contract.
Description
The landlord (property owner) invokes
finalizeshorttermrental
on a specific rental to settle the payment. If the rental is canceled after approval or has concluded (reached check-out time), the contract sends the payment to the token owner's address.The bug stems from an oversight in the function that checks whether a property can be re-listed for short-term rental.
The
finalizeshorttermrental
function uses thedenom
(token type) stored in theshortterm_rental
struct to determine which token to use for payment:The
setlistforshorttermrental
function, which can change thisdenom
, is supposed to be callable only when there are no active rentals. This is checked by thecheck_can_edit_short
function:However, this function only checks if the current time exceeds the last rental's check-out time. It doesn't verify whether all rentals have been finalized or if there are any pending payments.
This oversight allows a malicious landlord to change the
denom
after a rental period has ended but before finalization, potentially getting payment in a more valuable token than originally configured.The attack scenario could unfold as follows:
Attacker starts with two accounts, one as landlord and one as renter.
denom
.setlistforshorttermrental
to change thedenom
to a high-value token (e.g., USDC worth $1).finalizeshorttermrental
to settle the payment.This exploit allows the attacker to artificially inflate the value of their rental payment, draining funds from the contract that were deposited by other users.
Proof-of-Concept
The following test demonstrate the described scenario.
Boilerplate for PoC: https://gist.github.com/nnez/c76b1a867dd8dc441dbe552e048b796e
Steps
contracts/codedestate/src/multi_tests.rs
with boilerplate from above secret gist.cargo test h2_drain_funds_by_updating_listing_denoms_before_finalize -- --nocapture
Recommended Mitigations
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: