Closed code423n4 closed 1 year ago
We dispute validity. From the known issues, assumptions and clarification section of the README:
(...) for example, (...) Governance whitelisting a malicious/erroneous module on purpose. This is part of the risk model assumptions and its management will become more decentralized over time.
donosonaumczuk marked the issue as sponsor disputed
Picodes marked the issue as unsatisfactory: Out of scope
Hi @Picodes, could you take a second look at this issue?
A module doesn't have to be malicious/erroneous to contain a fallback function or a function with a clashing selector; the scenario demonstrated here could very well occur after adding a completely normal module. As such, I don't think this issue should be considered out of scope due to the line pointed out by the sponsor.
Thanks!
@MiloTruck don't you agree that for the module to contain a fallback function or a function with a clashing selector that wouldn't revert when called with this payload it'd have to be malicious? Like it's not just a matter of bad luck and selector clash, you also need it to not revert so here to have no arguments or to work with the provided ones. You also need it to consume very little gas otherwise it'd be hard to make the first call revert using the 63/64 rule (if that's what you were referring to here "Note that an attacker can manipulate the amount of gas when calling mirror() to force this to occur").
Lines of code
https://github.com/code-423n4/2023-07-lens/blob/main/contracts/libraries/PublicationLib.sol#L428-L462
Vulnerability details
Bug Description
When
comment()
,mirror
orquote()
is called on a publication with a reference module, the reference module will be called.For example, when a user mirrors another publication with a reference module, the
processMirror()
function of that reference module is called in_processMirrorIfNeeded()
:PublicationLib.sol#L428-L462
As some publications are initialized with legacy reference modules, the function uses a
try-catch
to differentiate between V1 and V2 modules.However, this makes it possible for an attacker to completely skip the call to
processMirror()
if:IReferenceModule.processMirror()
reverts without an error message. Note that an attacker can manipulate the amount of gas when callingmirror()
to force this to occur.mirrorParams.referrerProfileIds.length
is 0.ILegacyReferenceModule.processMirror()
.If all three requirements are met, an attacker will be able to create a mirror publication without calling the reference module's
processMirror()
function.This becomes an issue if the publication's owner uses
processMirror()
to perform some sensitive logic, such as restricting publications to followers only.Note that this also applies to
_processCommentIfNeeded()
and_processQuoteIfNeeded()
as they are similar.Impact
Under certain circumstances, attackers will be able to comment/mirror/quote a publication while skipping the call to its reference module, which can be abused to bypass sensitive logic.
Given that Lens Protocol will add more reference modules over time, the chance that a reference module fulfils the requirements listed above is not low.
Proof of Concept
The following Foundry test demonstrates how an attacker can manipulate the gas amount passed to
mirror()
to skip the call toprocessMirror()
, which bypasses the whitelist validation logic in the reference module:It can be run with:
Recommended Mitigation
Ensure that future reference modules do not contain a fallback function or a function with the selector
0x57ba5584
.Assessed type
Other