Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

s_password is publicly accessible, therefore allowing anyone to retrieve it

Summary

The s_password string variable is publicly accessible, therefore allowing anyone to retrieve the stored password.

Vulnerability Details

The protocol's goal is to allow only s_owner to call getPassword() and retrieve the stored password in s_password. However, the s_password variable is publicly accessible, since all data stored on EVM compatible blockchains is publicly accessible. The variable's visibility being set to private is irrelevant in this context.

@> string private s_password;

Impact

Anyone can retrieve the stored password in s_password, therefore rendering the entire protocol's goal useless.

The following Foundry commands show how to retrieve the s_password from a deployed instance of PasswordStore:

// 1) start a local anvil node
make anvil
// 2) deploy contract (in a new terminal)
make deploy
// 3) retrieve hex data from storage slot 0x1 using the contract address from 2)
cast storage `contract address` 0x1
// 4) cast hex data from 3) to ascii
cast to-ascii 0x6d7950617373776f726400000000000000000000000000000000000000000014
// myPassword

Tools Used

  • Foundry

Recommendations

Don't use this protocol at all, since it's generally a bad idea to store private data on EVM compatible blockchains.

If you insist on using this protocol, you can encrypt the password off-chain before storing it. However, in this case you need to store the encryption key off-chain, which renders the protocol redundant as you could use the encryption key or part of it as your password.

Updates

Lead Judging Commences

inallhonesty Lead Judge
about 2 years ago
inallhonesty Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-anyone-can-read-storage

Private functions and state variables are only visible for the contract they are defined in and not in derived contracts. In this case private doesn't mean secret/confidential

Support

FAQs

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