Submitted by IllIllI
Since the Lens platform is a blockchain-based social media platform, its important that information relevant to users be emitted so that light clients need not continually refer to the blockchain, which can be expensive. From the docs:
Events are emitted at every state-changing function call, in addition to standard ERC721 events. Events often include the timestamp as a specific parameter, which allows for direct consumption using a bloom filter without needing to fetch block context on every event.
As such, it is important that the content of emitted events matches what direct lookups of publication data shows.
Due to the reentrancy bug outlined below, an attacker is able to emit a comment containing some information that does not match the actual information of a post, allowing him/her to trick light clients into responding to a post that they otherwise would have avoided. The attacker can use this to propagate scams, serve malware, or otherwise poison other users profiles with unwanted content. Because there is no way to disable publications after the fact, these commenters profiles now link to this bad content forever.
According to the developers in the contest discord, the intention is for the whitelisting of modules to eventually be disabled altogether, or moved to be controlled by a DAO. The main purpose of the whitelist is to make sure that the modules written and used by everyone are built and scoped appropriately, not to limit calls to outside contracts (i.e. the module does what it does in the most efficient manner, using the method requiring the fewest outside contract calls). As such its reasonable to assume that at some point in the future, an attacker will be able to find or write a ReferenceModule that enables him/her to trigger a function in a contract he/she owns (e.g. transfer an NFT, triggering an ERC721 pre-transfer approval check callback). Below is a version of this where, for simplicitys sake, the malicious code is directly in the module rather than being called by a callback somehow.
As for triggering the actual attack, the attacker first acquires a profile with a lot of followers either by organically growing a following, stealing a profiles NFT, or buying access to one. Next, the attacker publishes interesting content with the malicious ReferenceModule, and finally, the attacker publishes an extremely engaging/viral comment to that publication, which will cause lots of other people to respond to it. The comment will emit an event that contains the original comment information, but the module will be able to overwrite the actual published comment on the blockchain with the attackers alternate content due to a reentrancy bug where the pubCount can be overwritten:
LensHub.sol#L878-L888
The following test uses this altered module and shows that the attacker can emit a different comment than is actually stored by/used for subsequent comments:
After applying the above changes, running npm test test/hub/interactions/publishing-comments.spec.ts yields:
Anyone that has commented on the engaging comment now has unwittingly commented on a malicious URI, potentially encouraging others to visit the URI.
Code inspection
Hardhat
Store the new pubCount in a variable before the comment is created and use it during the creation rather than choosing it afterwards.
Zer0dot (Aave Lens) commented:
Zer0dot (Aave Lens) acknowledged and commented:
0xleastwood (judge) commented:
Zer0dot (Aave Lens) commented:
0xleastwood (judge) decreased severity to Medium and commented:
For this contest, 14 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by WatchPug received the top score from the judge.
The following wardens also submitted reports: Dravee, pauliax, defsec, csanuragjain, hubble, gzeon, cccz, hyh, sikorico, 0xwags, 0x0x0x, 0x1f8b, and kenta.
