Submitted by sin1st3r__, and also juancito
Original Issue: A malicious borrower can hijack any NFT with permit() function he rents.
https://github.com/re-nft/smart-contracts/blob/97e5753e5398da65d3d26735e9d6439c757720f5/src/policies/Fallback.sol#L116
Partially mitigated
In summary, the previous version of the codebase allowed the hijacking of any rented NFT with the permit() functionality. What allowed the vulnerability to occur is that there were no checks or validation during the signature validation step (where the ERC721Permit reached out to the owner of the rented NFT (borrower rental safe), and asked it if the supplied signature is indeed a signature made by an owner of the rental safe (EIP-1271)). The execution flow of the exploit was as follows:
Execution flow:
Sponsors introduced a new Policy contract named Fallback.sol, set this contract to be the default fallback handler of the rental gnosis safe and prevented the rental safe owner from setting a fallback handler.
Additionally, in the Fallback.sol policy contract, they introduced a modified version of the EIP1271 function isValidSignature() (which was present in previous fallback handlers). 
In the modified isValidSignature function, it checks if the token that is trying to request signature verification (in this case, the permitNFT), is whitelisted or not. If its whitelisted, then the function will revert, preventing the hijacking of the permit NFT since the hijacking relies on the signature validation phase passing. If its blacklisted, itll normally allow the signature validation. This check does not differentiate between rented and non-rented tokens (as the sponsor noted in the README and mentioned that its expected behavior). As long as the NFT is whitelisted, no signature verifications will be allowed for it.
Looking closely at the check introduced in the new isValidSignature() function, there appears to be no check if a permit NFT token is blacklisted and is rented at the same time, which allows rented permit NFT tokens to be hijacked at any moment if the admins decide to blacklist the token.
Imagine the following scenario:
To run the PoC, youll need to do the following:
The file:
Replace each of the following files with the modified ones listed below: Stop.sol, Create.sol, Storage.sol, Fallback.sol.
What this mitigation does is that it simply prevents any signature verification of a blacklisted token as long as there rentals active involving this blacklisted token. The implementation is as follows: A newly-introduced state mapping variable mapping(address erc721Token => uint256 count) public rentedERC721s; in the storage is updated during both, the creation and the termination of a rental. Additionally, in isValidSignature::Fallback.sol, its checked if the originalSender is a blacklisted NFT, if thats the case, then check if rentedERC721s[originalSender] returns more than zero, if thats the case, then that means that there are permit nft rentals still in the storage -> revert.
After adding the files, dont forget to modify the unit tests for them to work properly. Rest of the tests are fine. Re-running the exploit after making the suggested modifications will fail.
The files
Access Control
gzeon (judge) commented:
