Open howlbot-integration[bot] opened 2 months ago
Regarding the issue with ref_ (referrer address): As you pointed out, the manipulation of referrer addresses is a phenomenon seen on other platforms as well, and may not be considered a significant problem.
Incorrect assertion about artId_: The report's claim that "Art 2 can be claimed with only approval for Art 1" misunderstands the actual operation of the code. This assertion is not accurate for the following reasons:
PhiArt storage art = arts[artId_];
bytes32 credMerkleRootHash = credMerkleRoot[art.credChainId][art.credId];
if (minter_ == address(0) || !art.verificationType.eq("MERKLE") || credMerkleRootHash == bytes32(0)) {
revert InvalidMerkleProof();
}
if (
!MerkleProofLib.verifyCalldata(
proof_, credMerkleRootHash, keccak256(bytes.concat(keccak256(abi.encode(minter_, leafPart_))))
)
) {
revert InvalidMerkleProof();
}
This code checks the verification type and credMerkleRootHash corresponding to the specified artId_. In other words, even if a different art ID is used, the correct verification information for that art is required. Therefore, it is not possible to claim Art 2 with only the approval for Art 1.
Issue with imageURI: The lack of verification for the imageURI parameter remains a potential problem. This could allow unapproved image URLs to be set.
Main issue after correction:
Lack of verification for imageURI:
Attackers may be able to specify unapproved image URLs. This could result in inappropriate images or unintended content being associated with the NFT.
fatherGoose1 changed the severity to 2 (Med Risk)
fatherGoose1 marked the issue as satisfactory
Valid medium. The user has the ability to provide any imageURI, potentially to the detriment of the protocol and its users.
fatherGoose1 marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L352-L375 https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L336-L337
Vulnerability details
Vulnerability Summary
In the file
PhiFactory.sol
,The lack of checks in
merkleClaim
allows malicious users to bypass the hash check to pass in their own parameter of choice. The 3 variables that could possibly be manipulated (referral, artId and imageURI) and their impact will be each discussed below.Missing
ref_
andartId_
in validation.As we can see in
merkleClaim
:address ref_
anduint256 artId_
is decoded fromencodeData_
which is simbly a bytes data type passed into the function parameter by the user.Observing the line where the merkle hash is cross-checked:
It becomes clear that only
minter_
fromencodeData_
is checked, leavingref_
andartId_
to whatever values passed by the user.By the way, both
ref_
andartId_
are explicitly checked in thesignatureClaim
function:Hence, to forge
ref_
andartId_
, malicious users will have to usemerkleClaim
instead ofsignatureClaim
.Impact of forging ref_
ref_
, successfully stealing the referral fee from the realref_
or the artist(who will receive the referal fee ifref_
is set to null).merkleClaim
to claim onaccount 1
, she can pass inaccount 2
as theref_
to illegally steal the referral fees to offset the cost of minting.account 2
instead ofaccount 1
as theref_
is because inPhiRewards.sol
'sdepositRewards
, referral has to be different from minter address in order for Alice to receive the referral fees.Impact of forging artId_
signatureClaim
which checksartId_
explicitly,merkleClaim
only verifiesminter_
andleafPart_
to the credId's merkle root hash.Cred A
hasArt 1
andArt 2
.Art 1
.signatureClaim
, Alice would only be able to claimArt 1
with that approval signature.merkleClaim
, she will be able to claimArt 2
with only approval forArt 1
by passing theartId_
ofArt 2
.Missing
imageURI
in validation.We can see in both
signatureClaim
Line 330 andmerkleClaim
Line 355,imageURI
is passed into the function parameter rather than extracted from the signature and is not involved in the merkle hash check as well.Since
imageURI
contains important information about the art details(such as location/directory). This could have a severe impact. When the malicious user is trying to claim an art that he has permission to, he could pass in animageURI
with the location directory of the picture image file pointing to another art which he does not have permission for.The line
advancedTokenURI[tokenId_][to_] = imageURI_;
inPhiNFT1155.sol
will also be set to an unapproved value.This will lead to undefined/unsupported behaviours when interacting with the smart contract regarding trying to render an user's art URI.
Proof of concept
Add this function to
test/PhiFactory.t.sol:TestPhiFactory
Run
forge test --match-test test_claimHack -vv
Comments:
Alice
managed to set the referral address to her second account(Alice_2
), and received the referral reward of0.00005 ether
. (Which will be a significant sum if Alice was minting high quantity of art, since rewards are calculated byquantity_ * referralReward
)IMAGE_URL2
instead ofIMAGE_URL
into the function parameter. (bothIMAGE_URL2
andIMAGE_URL
are different variables which are already declared in the original foundry test file)Recommended Mitigation Steps
In function
merkleClaim
:In function
signatureClaim
:Tools Used
Manual Review, Foundry, VSCode
Assessed type
Other