Skip to content
Access control Audit finding Intermediate

Missing revoke instruction leads to Old delegate accounts have unlimited number of token allowance

The restaking and vault programs approve an unlimited token allowance to a delegate account but never revoke it when the delegate is changed. A previous delegate could therefore still spend the owner's tokens after being replaced.

shanb1605 Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#36675 [SC-Insight] Missing revoke instruction leads to Old delegate accounts have unlimited number

Submitted on Nov 10th 2024 at 19:00:49 UTC by @shanb1605 for Audit Comp | Jito Restaking

Description

Exact Affected Files:

https://github.com/jito-foundation/restaking/blob/master/restaking\\_program/src/ncn\\_delegate\\_token\\_account.rs

https://github.com/jito-foundation/restaking/blob/master/restaking\\_program/src/operator\\_delegate\\_token\\_account.rs

https://github.com/jito-foundation/restaking/blob/master/vault\\_program/src/delegate\\_token\\_account.rs

Brief/Intro

The Restaking program has delegating token process for both NCN and Operator. Also, Vault program has a process for token delegation. These three process delegates the token to delegate account, which is authorized by the delegate admin.

When the approve instruction from SPL token 2022 program is called inside these process, it approves unlimited token allowance to delegate account. This allowance stays, even delegate admin changes the delegate account.

Since, there is no specific instruction or inbuilt instruction to revoke the old approvals, the past delegates have still some allowance left and has a chance to steal the tokens from the owner by past malicious delegates.

Vulnerability Details

Unlimited token approval take place in the three process. ncn_delegate_token_account.rs https://github.com/jito-foundation/restaking/blob/master/restaking\\_program/src/ncn\\_delegate\\_token\\_account.rs#L62-L69

Operator_delegate_token_account.rs https://github.com/jito-foundation/restaking/blob/master/restaking\\_program/src/operator\\_delegate\\_token\\_account.rs#L62-L69

delegate_token_account.rs (Vault program) https://github.com/jito-foundation/restaking/blob/master/vault\\_program/src/delegate\\_token\\_account.rs#L65-L72

The issue is not unlimited approvals, rather than missing instruction for revoking approvals inside those files or separate process function to revoke the approval from Old delegate account.

To describe the vulnerability, here is the necessary assumption:

  1. The NCN/Operator/Vault delegate admin has approved Alice as token delegate account for some time.
  2. On some occurrence, the delegate admin wishes to change the delegate account.
  3. Now, the NCN/Operator/Vault delegate admin has approved Bob as token delegate account.
  4. Alice notices, the initial call for allowance is set to U64 Max allowance, and there is still allowance amount is left.
  5. Alice, the Old delegate turns out be malicious and spends all remaining token allowance.

Impact Details

The impact labelled as direct theft of user funds, as the report clearly states that past delegates have still some allowance amount left, and they are able to spend/steal the amount.

I searched for any revoke instruction written as separate process, it is not viable on in-scope repo. Since, there is missing revoke instruction, the allowance for old delegates stays forever on-chain leading to possible unauthorized spend.

References

The Solana staking documentation mentions deactivating the stake delegations must be one of the operations by the authority. https://solana.com/docs/economics/staking/stake-accounts#understanding-account-authorities

Recommendation(s)

Consider adding revoke functionality from SPL token 2022 program: https://docs.rs/spl-token-2022/latest/spl\\_token\\_2022/instruction/fn.revoke.html

It could be added in affected files or kept as separate process function.

Link to Proof of Concept

https://gist.github.com/shanb1605/f11146e17f72880e0a5e30b53549b4ec

Proof of Concept

Proof of Concept

POC demonstrates the assumptions stated in Vulnerability Description

Make sure everything is set up through cloning the repo: https://github.com/jito-foundation/restaking/tree/master

There is no specific instruction for viewing allowance, so the code logs the allowance amount from state variable after executing each process for Alice and Bob.

Add this snippet to /integration_tests/tests/restaking/ncn_delegate_token_account.rs https://gist.github.com/shanb1605/f11146e17f72880e0a5e30b53549b4ec#file-ncn\\_delegate\\_token\\_account-rs

Add this snippet to /integration_tests/tests/restaking/Operator_delegate_token_account.rs https://gist.github.com/shanb1605/f11146e17f72880e0a5e30b53549b4ec#file-operator\\_delegate\\_token\\_account-rs

Add this snippet to /integration_tests/tests/vault/delegate_token_account.rs https://gist.github.com/shanb1605/f11146e17f72880e0a5e30b53549b4ec#file-delegate\\_token\\_account-rs

Each step possess different commands to run, follow the snippet's comment on Line no: 1 to run the POC

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

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 delegate-change flow calls approve for the new delegate but never calls revoke for the old delegate, leaving the old allowance active on-chain.

Impact

A previous delegate could spend the owner's remaining token allowance, which the report labels as direct theft of user funds.

What the attacker needed

Delegate admin changes the delegate account; old delegate acts maliciously

The fix

The program should add a revoke call from the SPL token 2022 program, either in the affected files or as a separate process function, when changing the delegate.

How it was found

  1. The delegate admin approves Alice as the token delegate account.
  2. The delegate admin later changes the delegate account to Bob.
  3. Alice notices the old allowance is still present.
  4. Alice, now malicious, spends the remaining token allowance.

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.

A token owner can let another account spend their tokens by giving it an allowance. This report says the program gives an unlimited allowance but never takes it back when the delegate is swapped, so the old delegate can still move the tokens.

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 shanb1605

View all

3 more disclosed reports, best first.

More from Jito Restaking

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.