Skip to content
Access control Audit finding Intermediate

Insecure calls to `safeTransferFrom` leads to users tokens steal by attacker

The protocol's order creation and modification functions use the order recipient as the owner for token transfers, allowing an attacker to create an order that pulls tokens from a victim who has a residual allowance. The attacker can then fill the order and profit while the victim loses tokens.

0x37 Follow with 0xaxaxa, 0xc0ffEE and 34 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-oku-judging/issues/789

Found by

0x37, 0xaxaxa, 0xc0ffEE, Bigsam, Boy2000, BugPull, ChinmayF, John44, KungFuPanda, Laksmana, LonWof-Demon, PoeAudits, Ragnarok, Tri-pathi, Xcrypt, Z3R0, bughuntoor, c-n-o-t-e, covey0x07, future2_22, gajiknownnothing, hals, iamandreiski, joshuajee, lanrebayode77, nikhil840096, phoenixv110, rahim7x, silver_eth, t.aksoy, tobi0x18, vinica_boy, whitehair0330, xiaoming90, y51r, zhoo, zxriptor

Summary

The function safeTransferFrom() is used to transfer tokens from user to the protocol contract. This function is used in modifyOrder and createOrder with the recipent address as the owner form who the tokens will be transfered from. An attacker can abuse this functionnality to create unfaire orders for a protocol user that approve more tokens than needed to the protocol contract the fill the order immediatly and gain instant profit while the victim lost his tokens.

Root Cause

In OracleLess.sol::procureTokens():280 https://github.com/sherlock-audit/2024-11-oku/blob/main/oku-custom-order-types/contracts/automatedTrigger/OracleLess.sol#L280 procureTokens() implement tokens transfer from an owner address to the protocol contract

In StopLimit.sol::createOrder():171 https://github.com/sherlock-audit/2024-11-oku/blob/main/oku-custom-order-types/contracts/automatedTrigger/StopLimit.sol#L171

In StopLimit.sol::modifyOrder():226-230 https://github.com/sherlock-audit/2024-11-oku/blob/main/oku-custom-order-types/contracts/automatedTrigger/StopLimit.sol#L226-L230

In Bracket.sol::modifyOrder():250-254 https://github.com/sherlock-audit/2024-11-oku/blob/main/oku-custom-order-types/contracts/automatedTrigger/Bracket.sol#L250-L254

Internal pre-conditions

No response

External pre-conditions

  1. A user should have approve more tokens than needed for a trade that whould result in some residual allowance to the protocole contract

Attack Path

  1. The attacker create/modify an unfaire order with the victim as recipent with an amounIn <= residual allowance
  2. The prococol then transfer the tokens from the user to create the order
  3. The attacker fill the order an gain instant profit

Impact

No response

PoC

No response

Mitigation

It would be better to use msg.sender to ensure that the recipient/owner of the order is the order creator or juste use msg.sender as parameter to the safeTransferFrom() function call instead of order recipient

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/gfx-labs/oku-custom-order-types/pull/1

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 order creation and modification functions use the order recipient as the owner in safeTransferFrom, instead of the caller (msg.sender), allowing anyone to specify a victim as recipient and pull tokens from them.

Impact

An attacker could steal tokens from a user who has a residual allowance, causing the victim to lose tokens while the attacker profits.

What the attacker needed

Victim has approved more tokens than needed; residual allowance remains

The fix

The protocol team fixed this issue by using msg.sender instead of the order recipient as the owner in safeTransferFrom.

How it was found

  1. The attacker creates or modifies an order with the victim as recipient and an amountIn within the victim's residual allowance.
  2. The protocol transfers tokens from the victim to create the order.
  3. The attacker fills the order and gains instant profit.

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 you approve a smart contract to spend your tokens, you often approve more than needed, leaving a leftover allowance. This report shows that an attacker could use that leftover to create an order that takes your tokens, then immediately fill it to profit, without your consent.

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 0x37

View all

79 more disclosed reports, best first.

More from Oku's New Order Types Contract 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.