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

s_password can be read by anyone leaking sensitive data

Summary

The variable s_password is stored as a string private, and is intended to hold sensitive information only accessible to the owner of the contract. However, variable contents are publicly readable on the blockchain and this variable can easily be obtained by non-owners.

Vulnerability Details

Knowing the smart contract address, anyone can use tools like web3.eth.getStorageAt() or cast storage <address> 1 to obtain the value of the s_password variable, leaking the sensitive password to unauthorized users.

Obtain the contract address and use the below Foundry command to read the raw storage value in slot 1.

$ cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 1
0x6d7950617373776f726400000000000000000000000000000000000000000014

The returned value can be sent to cast --to-ascii to convert this to the string:

$ cast --to-ascii "0x6d7950617373776f726400000000000000000000000000000000000000000014"
myPassword

As you can see, this has revealed the password that was initially set on contract deploy.

Impact

The sensitive password can be revealed to anyone who knows the smart contract address.

Tools Used

  • foundry

  • cast

Recommendations

Do not store sensitive data on the blockchain as the entire smart contract and variable data are publicly viewable on the blockchain as demonstrated above.

This application should be designed so that the data stored on the blockchain is encrypted. For example, setPassword() could only accept and store within s_password the encrypted value handed to it. It would then be up to the owner to encrypt and decrypt the contents off chain.

Updates

Lead Judging Commences

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.