Skip to content
Access control Audit finding Intermediate

Unlinked address can link immediately again

The unlinkAddress function deletes the linked address record but does not clear the pending link request, so the unlinked address can immediately call linkAddress again and become linked without the master's permission. An attacker who controls a previously unlinked address could re-link to the master without approval.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon

Impact

After a master calls unlinkAddress() to unlink an address, the address that has just been unlinked can directly link again without permission. The address that is just unlinked can call linkAddress(masterAddress) which will execute because pendingLinkAddresses is still set. Assuming the master has unlinked for a good reason it is unwanted to be able to be linked again without any permission from the master.

Note: a master can prevent this by calling cancelAddressLinkingRequest(), but this doesn’t seem logical to do

Proof of Concept

https://github.com/code-423n4/2021-12-sublime/blob/e688bd6cd3df7fefa3be092529b4e2d013219625/contracts/Verification/Verification.sol#L129-L154

    function unlinkAddress(address _linkedAddress) external {
        address _linkedTo = linkedAddresses[_linkedAddress].masterAddress;
        require(_linkedTo != address(0), 'V:UA-Address not linked');
        require(_linkedTo == msg.sender, 'V:UA-Not linked to sender');
        delete linkedAddresses[_linkedAddress];
       ...
}
    function linkAddress(address _masterAddress) external {
        require(linkedAddresses[msg.sender].masterAddress == address(0), 'V:LA-Address already linked');   // == true (after unlinkAddress)
        require(pendingLinkAddresses[msg.sender][_masterAddress], 'V:LA-No pending request');                 // == true (after unlinkAddress)
        _linkAddress(msg.sender, _masterAddress);                                                                                           // // pendingLinkAddresses not reset
    }

function cancelAddressLinkingRequest(address _linkedAddress) external {
        ...
        delete pendingLinkAddresses[_linkedAddress][msg.sender]; // only location where pendingLinkAddresses is reset

Recommended Mitigation Steps

Add something like to following at the end of linkAddress:

delete pendingLinkAddresses[msg.sender][_masterAddress];

ritik99 (Sublime) confirmed

The original report as published on Code4rena, by gpersoon. 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.

How it worked

Root cause

Likely the unlinkAddress function does not delete the pendingLinkAddresses entry, so the pending request remains valid after unlinking.

Impact

An address that was unlinked can re-link itself without the master's permission, unless the master also calls cancelAddressLinkingRequest.

What the attacker needed

Victim has previously linked an address; victim calls unlinkAddress; attacker controls the unlinked address

The fix

The linkAddress function should delete the pending link request after a successful link, or unlinkAddress should clear it.

How it was found

  1. A master calls unlinkAddress to remove an address.
  2. The unlinked address calls linkAddress with the master's address.
  3. The call succeeds because the pending link request was not cleared.

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.

When a master removes an address from their list, the system forgets the link but still remembers that the address had asked to be linked. That leftover request lets the removed address link itself back immediately, without the master saying yes again.

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.

More by gpersoon

View all

47 more disclosed reports, best first.

More from Sublime contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.