Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 2.17 KB

File metadata and controls

29 lines (18 loc) · 2.17 KB

Improper Access Control

Access control vulnerabilities in Solidity occur when a smart contract does not properly restrict access to sensitive functions or data. This can lead to unauthorized actions being performed by malicious users or other contracts, compromising the contract's security and integrity. Common access control issues include improper use of function visibility, missing access restrictions, and the reliance on the tx.origin value for authentication.

Impact

The impact of access control vulnerabilities includes:

  1. Unauthorized access to sensitive data or functions, potentially leading to theft of funds or manipulation of contract state.
  2. Loss of user confidence in the contract, which may lead to reduced adoption or usage.
  3. Damage to the reputation of the contract creator or associated organizations.

Example

Consider a simple contract that allows the owner to update a stored value:

image

In this example, the updateValue function is missing access control checks, allowing anyone to update the storedValue variable. This can lead to unauthorized manipulation of the contract's state.

Remediation

Use function modifiers: Implement custom function modifiers that check the caller's access rights before executing sensitive functions.

Properly set function visibility: Ensure that function visibility is set correctly (i.e., public, external, internal, or private) to restrict access as needed.

Avoid relying on tx.origin for authentication: Use msg.sender instead of tx.origin to check the caller's identity, as tx.origin can be manipulated by malicious contracts. (This is covered as well in the compendium as its own vulnerability).

The SimpleStorage contract can be improved as follows

image

In this improved version, we implement a custom function modifier onlyOwner to ensure that only the contract owner can call the updateValue function and nobody else. This mitigates the access control vulnerability and makes the contract more secure.