MetaMask is a crypto wallet and a gateway to blockchain apps for 30 million users. With MetaMask Snaps it’s also turning into a highly customizable wallet with community-built features. Built by independent developers, these Snaps offer scalability and functionality, including interoperability, transaction insights, and notifications, directly within MetaMask.
As community-created solutions, it’s necessary to ensure Snaps are not only functional but secure. MetaMask Snaps have already undergone over 40 audits with various security firms, exposing high-risk vulnerabilities and logic errors. In this guide, Hacken auditors will share best practices for secure MetaMask Snaps development to safeguard users’ assets and privacy.
Announced in late 2023, MetaMask Snaps are customizable community-built JavaScript programs that enhance MetaMask wallet experience. Today, MetaMask has over 50 allowed Snaps offering a variety of applications tailored to different needs (see the full list here). The most popular Snaps are Solana Wallet, Leap Cosmos Wallet, and Wallet Guard. These programs allow users to manage various blockchain assets, interact with decentralized applications, secure their transactions, and explore a broader Web3 world.
Out of the 40 MetaMask Snaps audits, 18 revealed numerous vulnerabilities, including flaws in sandbox security, insecure endowment handling, authentication issues, logic errors, and inadequate network security protocols. Addressing these issues is crucial to safeguarding user security and maintaining trust in MetaMask Snaps.
Insecure Endowment Handling refers to a flaw in managing funds or assets within a secure environment like a sandbox, such as in MetaMask Snaps. These endowments are resources allocated for specific purposes, like supporting decentralized applications. In MetaMask, there were instances where endowment management was not secure, leading to unauthorized access and manipulation.
Best Practices For Endowment Handling:
The foundation of a secure system rests on rigorous user authentication and authorization. Authentication confirms a user’s identity, while authorization dictates their permitted actions. Vulnerabilities in these areas expose flaws in how a system verifies and manages user access to resources.
A critical discovery unveiled that certain actions, particularly those involving the exportation of private keys, did not consistently demand user authorization. This loophole implies that individuals could execute these actions without the explicit consent of the user. This presents a major security threat, as it enables unauthorized access and manipulation of vital private keys essential for protecting cryptocurrency wallets and sensitive data. Compromised private keys allow attackers to steal funds, impersonate users, or seize control of user accounts.
Several audit findings indicate a deficiency in the proper enforcement of the system’s authorization protocols. This lapse could stem from various factors, including coding errors that permit users to circumvent authorization checks or improper system configuration, where authorization may not be appropriately mandated for all sensitive actions.
Best Practices For Authorization and Authentication:
A checksum breach allows for the manipulation of cryptographic checksums, used to validate data integrity. A discovered method in the Wallet Guard audit allowed bypassing checksums, enabling the insertion of malicious code without detection. When a checksum is bypassed, attackers can compromise system security by injecting malicious code. This emphasizes the importance of checksums in maintaining code integrity and highlights the risks posed by vulnerabilities in this cryptographic safeguard.
Best Practices For Checksum Integrity:
The timeout refers to the maximum duration permitted for a Snap to execute before termination, serving as a safeguard against indefinite execution and excessive utilization of system resources.
The MetaMask Snap audit for Filsnap reveals a vulnerability in the MetaMask Snap execution mechanism, enabling Snaps to elude the predetermined timeouts. This implies that a malicious or inadequately designed Snap could persist indefinitely, monopolizing system resources and potentially destabilizing the network.
The ability of Snaps to bypass timeouts presents a significant security threat. Exploiting this vulnerability, an attacker could launch Denial of Service (DoS) attacks, rendering the MetaMask network inaccessible to other users. Furthermore, a poorly constructed Snap might unintentionally consume disproportionate resources, causing performance issues for other users.
Best Practices For Snap Execution Timeout:
Data validation is the critical process of verifying that the information entered into a system aligns with specific criteria, ensuring its accuracy, consistency, and relevance. This serves as a pivotal security measure, preventing the inclusion of invalid, corrupted, or malicious data that could compromise the system’s integrity or functionality.
Error handling, on the other hand, refers to how a system adeptly manages and responds to errors occurring during its operation. This encompasses gracefully addressing errors, furnishing informative error messages, and taking appropriate actions to recover from errors seamlessly, all without disrupting the user experience.
A MetaMask Snaps Audit uncovered a deficiency in robust data validation and error handling practices. This exposes the system to potential infiltration of invalid or malicious data, introducing risks of security breaches or unforeseen system behavior.
Best Practices For Data Validation And Error Handling:
The provider interfaces in MetaMask Snaps connect users to the blockchain and facilitate interactions with decentralized applications and services. These interfaces serve as bridges, enabling seamless engagement with the blockchain ecosystem, including transactions and actions. However, several audits discovered vulnerabilities within these interfaces, risking unauthorized transactions and compromising user funds and blockchain integrity.
Best Practices For Safeguarding Provider Interface:
Vulnerabilities in the user interface that could be exploited for phishing attacks or unauthorized data access pose a significant risk. Insecure UI elements may compromise user interactions, leading to unintended actions or exposure of sensitive information. The UI security issue was identified in Identify MetaMask Snaps audit.
Best Practices For Safeguarding UI:
Logic Errors and Inefficiencies encompass flaws in a system’s logic, potentially resulting in unexpected behavior, operational disruptions, and diminished performance. Although these errors may not directly jeopardize the system’s security, they can substantially impact its usability and reliability.
MetaMask Snaps Audit of Forta revealed several low-severity logical errors that can cause operational disruptions and degrade performance. A specific instance of a logic error involved the mishandling of network names. Incorrect handling could trigger crashes, communication failures, or other unpredictable outcomes, rendering the system unreliable and frustrating for users.
Logical errors are still a problem as they could undermine user confidence in the system. Users might be reluctant to use a system known for being buggy and unreliable. Furthermore, the unpredictability introduced by these errors could expand the system’s attack surface, providing opportunities for attackers to exploit unexpected behavior.
Best Practices For Safeguarding Against Logic Errors And Inefficiencies:
Misconfigurations in the system setup can lead to potential security loopholes. Incorrect configurations may expose sensitive data, weaken access controls, or create opportunities for unauthorized access. Consensus has identified some such instances in Push MetaMask Snap Audit.
Best Practices For Configuration Management:
Dependencies are external libraries or modules used by the program. Using outdated or vulnerable dependencies within the MetaMask Snap environment-–as was uncovered in this audit—poses a significant risk, potentially leading to security breaches.
Best Practices For Secure Dependencies:
MetaMask Snaps operate within a secure sandbox environment. To enforce the safety of its execution environment, MetaMask employs a three-layered approach: Iframe, LavaMoat, and SES Containers.
However, if some features ever get broken, a minor permission bypass can mislead the allowed permissions of the Snap. This is how a vulnerability called property spoofing was found. The bypass could mislead the allowed permission of the Snap, potentially retrieving key pairs or proposing malicious transactions. This breach undermined the isolated environment and risks user assets, emphasizing the need for continuous vigilance in maintaining secure execution environments.
Best Practices For Sandbox Security:
MetaMask has fixed the permission bypass issue by sanitizing JSON before checking for blocked methods. Nevertheless, developers building Snaps should implement vigorous permission checks to create an isolated and safe execution environment for their programs:
External Code Review and Audit:
Code Cleanliness and Permission Management:
Comprehensive Testing Suite Development:
Balanced Logging for Production Environments:
Network Security Protocols:
Audit Trail Implementation:
Adherence to MetaMask Docs:
In 2023, Web3 businesses lost $1.9 billion to hacks and scams. The majority of lost funds were due to access control compromises and leaked private keys. Being one of the most popular crypto wallets, MetaMask must extend its rigid security to community-built Snaps.
As one of the very few MetaMask-approved Snap auditors, Hacken is committed to making sure Snaps are not only functional but safe to use for the final user. We offer tailored audits for Snaps builders.
MetaMask serves as a gateway to blockchain apps for millions of users, now enhanced with community-built features called Snaps. Security is paramount, especially considering over 40 audits have unveiled vulnerabilities, including logic errors and insecure practices.
This guide outlines best practices to ensure the secure development of MetaMask Snaps, emphasizing continuous vigilance, regular audits, and user education. It’s evident that maintaining security in the Snap ecosystem requires a collaborative effort between developers, auditors, and users to safeguard assets and privacy. Addressing identified vulnerabilities is vital to uphold user trust and ensure the integrity of MetaMask Snaps.
Be the first to receive our latest company updates, Web3 security insights, and exclusive content curated for the blockchain enthusiasts.
Table of contents
Tell us about your project
6 min read
Discover
8 min read
Discover
8 min read
Discover