Lack of data validation when users are claiming their art allows malicious user to bypass signature/merkle hash to provide unapproved ref_ , artId_ and imageURI
The merkleClaim function in PhiFactory.sol only verifies the minter address against the merkle root, leaving the referral address, art ID, and image URI unchecked. An attacker could set their own referral address to steal referral fees, claim a different art ID than approved, or set an arbitrary image URI for the NFT.
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_ and artId_ in validation.
As we can see in merkleClaim, address ref_ and uint256 artId_ is decoded from encodeData_ which is simply a bytes data type passed into the function parameter by the user.
Hence, to forge ref_ and artId_, malicious users will have to use merkleClaim instead of signatureClaim.
Impact of forging ref_
Malicious users can pass in their own other account address as ref_, successfully stealing the referral fee from the real ref_ or the artist(who will receive the referral fee if ref_ is set to null).
Suppose Alice has 2 accounts, when she calls merkleClaim to claim on account 1, she can pass in account 2 as the ref_ to illegally steal the referral fees to offset the cost of minting.
The reason why Alice has to pass in account 2 instead of account 1 as the ref_ is because in PhiRewards.sol’s depositRewards, referral has to be different from minter address in order for Alice to receive the referral fees.
Impact of forging artId_
Unlike signatureClaim which checks artId_ explicitly, merkleClaim only verifies minter_ and leafPart_ to the credId’s merkle root hash.
Since a Cred can have multiple art linked to it, this becomes a problem.
Suppose Cred A has Art 1 and Art 2.
Now, Alice got approval to claim Art 1.
If the art’s verification type was set to “SIGNATURE” and Alice had to call signatureClaim, Alice would only be able to claim Art 1 with that approval signature.
However if the art’s verification type was “MERKLE” instead, when she calls merkleClaim, she will be able to claim Art 2 with only approval for Art 1 by passing the artId_ of Art 2.
Missing imageURI in validation
We can see in both signatureClaimLine 330 and merkleClaimLine 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 an imageURI 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_; in PhiNFT1155.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:
function test_claimHack() public {
bytes32 expectedRoot = 0xe70e719557c28ce2f2f3545d64c633728d70fbcfe6ae3db5fa01420573e0f34b;
bytes memory credData = abi.encode(1, owner, "MERKLE", 31_337, expectedRoot);
bytes memory signCreateData = abi.encode(expiresIn, ART_ID_URL_STRING, credData);
bytes32 createMsgHash = keccak256(signCreateData);
bytes32 createDigest = ECDSA.toEthSignedMessageHash(createMsgHash);
(uint8 cv, bytes32 cr, bytes32 cs) = vm.sign(claimSignerPrivateKey, createDigest);
if (cv != 27) cs = cs | bytes32(uint256(1) << 255);
phiFactory.createArt{ value: NFT_ART_CREATE_FEE }(
signCreateData,
abi.encodePacked(cr, cs),
IPhiFactory.CreateConfig(participant, receiver, END_TIME, START_TIME, MAX_SUPPLY, MINT_FEE, false)
);
address Alice = participant; //Original file setup already deals `participant` enough ether to pay for mint fees
address Alice_2 = address(0x123456); //Alice's account 2
vm.startPrank(Alice);
bytes32[] memory proof = new bytes32[](2);
proof[0] = 0x0927f012522ebd33191e00fe62c11db25288016345e12e6b63709bb618d777d4;
proof[1] = 0xdd05ddd79adc5569806124d3c5d8151b75bc81032a0ea21d4cd74fd964947bf5;
address to = 0x1111111111111111111111111111111111111111;
bytes32 value = 0x0000000000000000000000000000000003c2f7086aed236c807a1b5000000000;
uint256 artId = 1;
bytes memory data = abi.encode(artId, to, proof, Alice_2, uint256(1), value, IMAGE_URL2); // Within this line we have the freedom to decide artId, address of referral and the image URL
bytes memory dataCompressed = LibZip.cdCompress(data);
uint256 totalMintFee = phiFactory.getArtMintFee(artId, 1);
phiFactory.claim{ value: totalMintFee }(dataCompressed);
(, bytes memory response) = phiFactory.phiRewardsAddress().call(abi.encodeWithSignature("balanceOf(address)", Alice_2));
uint256 balance = abi.decode(response, (uint256));
console2.log("Alice_2: ", balance); //Alice successfully illegally receives referral fee through her second account
vm.stopPrank();
}
Run forge test --match-test test_claimHack -vv:
Ran 1 test for test/PhiFactory.t.sol:TestPhiFactory
[PASS] test_claimHack() (gas: 1356967)
Logs:
Alice_2: 50000000000000
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 14.83ms (4.52ms CPU time)
As you can see from the Code and the output, Alice managed to set the referral address to her second account (Alice_2), and received the referral reward of 0.00005 ether; which will be a significant sum if Alice was minting high quantity of art, since rewards are calculated by quantity_ * referralReward
Alice also managed to manipulate image_uri, encoding IMAGE_URL2 instead of IMAGE_URL into the function parameter. Both IMAGE_URL2 and IMAGE_URL are different variables which are already declared in the original foundry test file.
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:
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.
Valid medium. The user has the ability to provide any imageURI, potentially to the detriment of the protocol and its users.
The original report as published on Code4rena, by rscodes. 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
The merkle proof verification only includes the minter address and leaf part, omitting the referral address, art ID, and image URI from the hashed data.
Impact
An attacker could steal referral fees by setting their own referral address, claim a different art ID than approved (though the project disputes this), and set an arbitrary image URI, potentially leading to inappropriate content.
What the attacker needed
A valid merkle proof for the minter; a second account for referral
The fix
Include ref_, artId_, and imageURI in the merkle proof verification and validate them in signatureClaim.
How it was found
Create an art with MERKLE verification type.
Prepare a claim with a valid merkle proof but set the referral address to a second account.
Call merkleClaim with the crafted data.
Observe the referral fee credited to the second account.
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
When you claim an NFT, the system checks a proof to ensure you are allowed. But it only checks your address, not other details like who referred you or which art you are claiming. So you can change those details to get extra rewards or claim the wrong art.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.