What Is the “Approve-and-Pull” Race Condition Vulnerability and How Can It Be Mitigated?
This vulnerability occurs when a user wants to change an existing allowance. If a user has an allowance of 100 and wants to reduce it to 50, they submit a transaction to approve 50.
A malicious contract could watch for this and, in the short time before the new transaction is mined, submit a transaction to spend the original 100. Then, once the new approval is mined, they could spend the new 50 as well, for a total of 150.
Mitigation involves setting the allowance to 0 first, then setting the new amount.