Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Unsafe use of Foundry's FFI capability in test scripts

Summary

The test script for MerkleAirdrop utilizes Foundry's Foreign Function Interface (FFI) capability to execute arbitrary code at the operating system level, which poses significant security risks. This feature, if misused or exploited in malicious or vulnerable scripts, can lead to severe implications including system compromise or data leakage.

Vulnerability Details

The function testPwned() in MerkleAirdrop.t.sol uses FFI to execute system-level commands. Specifically, it uses the touch command to create or update a file named "youve-been-pwned" on the host machine. This demonstrates the potential for test scripts to perform unauthorized actions beyond the Ethereum Virtual Machine (EVM) environment, affecting the host system directly.

function testPwned() public {
string[] memory cmds = new string[](2);
cmds[0] = "touch";
cmds[1] = "youve-been-pwned";
cheatCodes.ffi(cmds);
}

Importantly, the invocation of this function is triggered instantaneously as part of the automated processes defined in the Makefile's make command, significantly raising the potential for unintended consequences.

Impact

By enabling FFI in test environments, developers expose their systems to a range of attacks that could lead to unauthorized access or manipulation of the filesystem, execution of arbitrary and potentially harmful commands, and other unintended actions that could compromise both the integrity and confidentiality of the system.

Tools Used

Foundry, maual review.

Recommendations

  1. Disable the FFI capability in Foundry's configuration when not strictly necessary, particularly in shared or public codebases, to prevent the execution of arbitrary system commands.

  2. Review and audit any use of FFI in smart contract development environments to ensure that it is used securely and only where absolutely necessary.
    Implement strict access controls and review processes for any scripts that require FFI capabilities to mitigate potential security risks.

  3. To disable FFI, modify the foundry.toml configuration file:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
remappings = ['@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']
- ffi = true
+ ffi = false
solc_version = "0.8.24"
solc = "0.8.24"
...
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope
Assigned finding tags:

ffi

Support

FAQs

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