Secret Vault on Aptos

First Flight #46
Beginner FriendlyWallet
100 EXP
View results
Submission Details
Impact: high
Likelihood: high
Invalid

No Access Control in set_secret

Root + Impact

Description

  • The contract is designed to allow only the designated owner to store secrets.

  • However, the set_secret function allows any user to create a Vault resource under their own account and store a secret.

@>public entry fun set_secret(caller:&signer,secret:vector<u8>){
let secret_vault = Vault{secret: string::utf8(secret)};
move_to(caller,secret_vault);
event::emit(SetNewSecret {});
}

Risk

Likelihood:

  • Any user can call this function and create their own vault, as there are no authorization checks

Impact:

  • Complete bypass of intended ownership model; anyone can store secret.

Proof of Concept

In this test we can see an unrelated user set a secret.

#[test(owner = @owner, user = @0x1234)]
fun test_set_secret(owner: &signer, user: &signer) acquires Vault {
use aptos_framework::account;
// Set up test environment
account::create_account_for_test(signer::address_of(owner));
account::create_account_for_test(signer::address_of(user));
// Not the owner, but can store secret
let secret = b"i'm a secret";
set_secret(user, secret);
let vault = borrow_global<Vault>(signer::address_of(user));
assert!(vault.secret == string::utf8(secret), 1);
}

Recommended Mitigation

Add a check, that the caller corresponds to the owner.

public entry fun set_secret(caller:&signer,secret:vector<u8>){
+ assert! (signer::address_of(caller) == @owner, NOT_OWNER);
let secret_vault = Vault{secret: string::utf8(secret)};
Updates

Lead Judging Commences

bube Lead Judge 17 days ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Anyone can call `set_secret` function

In Move for Aptos, the term "owner" refers to a signer, which is a verified account that owns a given resource, has permission to add resources and the ability to grant access or modify digital assets. Following this logic in this contest, the owner is the account that owns `Vault`. This means that anyone has right to call `set_secret` and then to own the `Vault` and to retrieve the secret from the `Vault` in `get_secret` function. Therefore, this group is invalid, because the expected behavior is anyone to call the `set_secret` function.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.