Management Summary
AnChain contacted Sayfer Security in order to perform a complete security audit on their Snap in 08/2023.
Before assessing the above services, we held a kickoff meeting with the AnChain technical team and received an overview of the system and the goals for this research.
Over the research period of 2 weeks, we discovered 6 vulnerabilities in the system.
Several fixes should be implemented following the report, but the system’s security posture is competent.
Risk Methodology
At Sayfer, we are committed to delivering the highest quality penetration testing to our clients. That’s why we have implemented a comprehensive risk assessment model to evaluate the severity of our findings and provide our clients with the best possible recommendations for mitigation.
Our risk assessment model is based on two key factors: IMPACT and LIKELIHOOD. Impact refers to the potential harm that could result from an issue, such as financial loss, reputational damage, or a non-operational system. Likelihood refers to the probability that an issue will occur, taking into account factors such as the complexity of the attack and the number of potential attackers.
By combining these two factors, we can create a comprehensive understanding of the risk posed by a particular issue and provide our clients with a clear and actionable assessment of the severity of the issue. This approach allows us to prioritize our recommendations and ensure that our clients receive the best possible advice on how to protect their business.
Risk is defined as follows:

Vulnerabilities by Risk
High – Direct threat to key business processes.
Medium – Indirect threat to key business processes or partial threat to business processes.
Low – No direct threat exists. The vulnerability may be exploited using other vulnerabilities.
Informational – This finding does not indicate vulnerability, but states a comment that notifies about design flaws and improper implementation that might cause a problem in the long run.
| Severity | # of issues |
|---|---|
| High | 1 |
| Medium | 1 |
| Low | 2 |
| Informational | 2 |
Approach
Introduction
AnChain contacted Sayfer to perform complete white box penetration testing on the MetaMask Snap. This report documents the research carried out by Sayfer targeting the selected resources defined under the research scope. Particularly, this report displays the security posture review for the Snap application and its surrounding infrastructure and process implementations.
Scope Overview
During our first meeting and after understanding the company’s needs, we defined the application’s scope that resides at the following URLs as the scope of the project:
- AnChain Snap
Audit commit: 6d0314b5c9c42e3720039ebbd2bba9ee9c8a30f6
Fixes commit: d69cfe0cdb3f00778cba3efc996e1230d5046fef
Our tests were performed from 15/08/2023 to 30/08/2023.
Scope Validation
We began by ensuring that the scope defined to us by the client was technically logical. Deciding what scope is right for a given system is part of the initial discussion. Getting the scope right is key to deriving maximum business value from the research.
Threat Model
During our kickoff meetings with the client, we defined the most important assets the application possesses.
Security Evaluation Methodology
Sayfer uses OWASP WSTG as our technical standard when reviewing web applications. After gaining a thorough understanding of the system we decided which OWASP tests are required to evaluate the system.
Security Assessment
After understanding and defining the scope, performing threat modeling, and evaluating the correct tests required in order to fully check the application for security flaws, we performed our security assessment.
Tools Used
During the test, we used multiple automated tools in addition to our manual tests, including the following: Burp Suite Professional, Web browser, DevTools, Nmap, Metasploit, SQLmap, Nessus, Shodan, Hydra, John the Ripper and wafw00f.
Issue Table Description
Issue title
| ID | The OWASP ID of the issue. Additional tests that we conduct and are not included in the OWASP table will have Sayfer ID. Example ID: WSTG-INFO-002 WSTG – Web Security Test Guide. INFO – A shorthand for the topic to which the issue belongs. 002 – Issue number. |
| Risk | Represents the risk factor of the issue. For further description refer to the Vulnerabilities by Risk section. |
| Required Skill | Describes the skill level required to conduct successful exploitation. The lower the skill level the easier the exploitation process. |
| OWASP Reference |
A link to the relevant OWASP page for further knowledge. |
| Location | The URL in which this issue was detected. Issues with no location have no particular location and refer to the product as a whole. |
| Business Impact | The impact of the findings on the system |
Description
Here we provide a brief description of the issue and how it formed, the steps we made to find or exploit it, along with proof of concept (if present), and how this issue can affect the product or its users. .
Mitigation
Suggested resolving options for this issue and links to advised sites for further remediation.
Security Evaluation
The following tests were conducted while auditing the system
Information Gathering
| Information Gathering | Test Name |
| WSTG-INFO-01 | Conduct Search Engine Discovery Reconnaissance for Information Leakage |
| WSTG-INFO-02 | Fingerprint Web Server |
| WSTG-INFO-03 | Review Webserver Metafiles for Information Leakage |
| WSTG-INFO-04 | Enumerate Applications on Webserver |
| WSTG-INFO-05 | Review Webpage Content for Information Leakage |
| WSTG-INFO-06 | Identify application entry points |
| WSTG-INFO-07 | Map execution paths through application |
| WSTG-INFO-08 | Fingerprint Web Application Framework |
| WSTG-INFO-09 | Fingerprint Web Application |
| WSTG-INFO-10 | Map Application Architecture |
Configuration and Deploy Management Testing
| Configuration and Deploy Management Testing | Test Name |
| WSTG-CONF-01 | Test Network Infrastructure Configuration |
| WSTG-CONF-02 | Test Application Platform Configuration |
| WSTG-CONF-03 | Test File Extensions Handling for Sensitive Information |
| WSTG-CONF-04 | Review Old Backup and Unreferenced Files for Sensitive Information |
| WSTG-CONF-05 | Enumerate Infrastructure and Application Admin Interfaces |
| WSTG-CONF-06 | Test HTTP Methods |
| WSTG-CONF-07 | Test HTTP Strict Transport Security |
| WSTG-CONF-08 | Test RIA cross domain policy |
| WSTG-CONF-09 | Test File Permission |
| WSTG-CONF-10 | Test for Subdomain Takeover |
| WSTG-CONF-11 | Test Cloud Storage |
Identity Management Testing
| Identity Management Testing | Test Name |
| WSTG-IDNT-01 | Test Role Definitions |
| WSTG-IDNT-02 | Test User Registration Process |
| WSTG-IDNT-03 | Test Account Provisioning Process |
| WSTG-IDNT-04 | Testing for Account Enumeration and Guessable User Account |
| WSTG-IDNT-05 | Testing for Weak or unenforced username policy |
Authentication Testing
| Authentication Testing | Test Name |
| WSTG-ATHN-01 | Testing for Credentials Transported over an Encrypted Channel |
| WSTG-ATHN-02 | Testing for Default Credentials |
| WSTG-ATHN-03 | Testing for Weak Lock Out Mechanism |
| WSTG-ATHN-04 | Testing for Bypassing Authentication Schema |
| WSTG-ATHN-05 | Testing for Vulnerable Remember Password |
| WSTG-ATHN-06 | Testing for Browser Cache Weaknesses |
| WSTG-ATHN-07 | Testing for Weak Password Policy |
| WSTG-ATHN-08 | Testing for Weak Security Question Answer |
| WSTG-ATHN-09 | Testing for Weak Password Change or Reset Functionalities |
| WSTG-ATHN-10 | Testing for Weaker Authentication in Alternative Channel |
Authorization Testing
| Authorization Testing | Test Name |
| WSTG-ATHZ-01 | Testing Directory Traversal File Include |
| WSTG-ATHZ-02 | Testing for Bypassing Authorization Schema |
| WSTG-ATHZ-03 | Testing for Privilege Escalation |
| WSTG-ATHZ-04 | Testing for Insecure Direct Object References |
Session Management Testing
| Session Management Testing | Test Name |
| WSTG-SESS-01 | Testing for Session Management Schema |
| WSTG-SESS-02 | Testing for Cookies Attributes |
| WSTG-SESS-03 | Testing for Session Fixation |
| WSTG-SESS-04 | Testing for Exposed Session Variables |
| WSTG-SESS-05 | Testing for Cross Site Request Forgery |
| WSTG-SESS-06 | Testing for Logout Functionality |
| WSTG-SESS-07 | Testing Session Timeout |
| WSTG-SESS-08 | Testing for Session Puzzling |
| WSTG-SESS-09 | Testing for Session Hijacking |
Data Validation Testing
| Data Validation Testing | Test Name |
| WSTG-INPV-01 | Testing for Reflected Cross Site Scripting |
| WSTG-INPV-02 | Testing for Stored Cross Site Scripting |
| WSTG-INPV-03 | Testing for HTTP Verb Tampering |
| WSTG-INPV-04 | Testing for HTTP Parameter Pollution |
| WSTG-INPV-05 | Testing for SQL Injection |
| WSTG-INPV-06 | Testing for LDAP Injection |
| WSTG-INPV-07 | Testing for XML Injection |
| WSTG-INPV-08 | Testing for SSI Injection |
| WSTG-INPV-09 | Testing for XPath Injection |
| WSTG-INPV-10 | Testing for IMAP SMTP Injection |
| WSTG-INPV-11 | Testing for Code Injection |
| WSTG-INPV-12 | Testing for Command Injection |
| WSTG-INPV-13 | Testing for Format String Injection |
| WSTG-INPV-14 | Testing for Incubated Vulnerability |
| WSTG-INPV-15 | Testing for HTTP Splitting Smuggling |
| WSTG-INPV-16 | Testing for HTTP Incoming Requests |
| WSTG-INPV-17 | Testing for Host Header Injection |
| WSTG-INPV-18 | Testing for Server-side Template Injection |
| WSTG-INPV-19 | Testing for Server-Side Request Forgery |
Error Handling
| Error Handling | Test Name |
| WSTG-ERRH-01 | Testing for Improper Error Handling |
| WSTG-ERRH-02 | Testing for Stack Traces |
Cryptography
| Cryptography | Test Name |
| WSTG-CRYP-01 | Testing for Weak Transport Layer Security |
| WSTG-CRYP-02 | Testing for Padding Oracle |
| WSTG-CRYP-03 | Testing for Sensitive Information Sent via Unencrypted Channels |
| WSTG-CRYP-04 | Testing for Weak Encryption |
Business logic Testing
| Business logic Testing | Test Name |
| WSTG-BUSL-01 | Test Business Logic Data Validation |
| WSTG-BUSL-02 | Test Ability to Forge Requests |
| WSTG-BUSL-03 | Test Integrity Checks |
| WSTG-BUSL-04 | Test for Process Timing |
| WSTG-BUSL-05 | Test Number of Times a Function Can be Used Limits |
| WSTG-BUSL-06 | Testing for the Circumvention of Work Flows |
| WSTG-BUSL-07 | Test Defenses Against Application Mis-use |
| WSTG-BUSL-08 | Test Upload of Unexpected File Types |
| WSTG-BUSL-09 | Test Upload of Malicious Files |
Client Side Testing
| Client Side Testing | Test Name |
| WSTG-CLNT-01 | Testing for DOM-Based Cross Site Scripting |
| WSTG-CLNT-02 | Testing for JavaScript Execution |
| WSTG-CLNT-03 | Testing for HTML Injection |
| WSTG-CLNT-04 | Testing for Client Side URL Redirect |
| WSTG-CLNT-05 | Testing for CSS Injection |
| WSTG-CLNT-06 | Testing for Client Side Resource Manipulation |
| WSTG-CLNT-07 | Test Cross Origin Resource Sharing |
| WSTG-CLNT-08 | Testing for Cross Site Flashing |
| WSTG-CLNT-09 | Testing for Clickjacking |
| WSTG-CLNT-10 | Testing WebSockets |
| WSTG-CLNT-11 | Test Web Messaging |
| WSTG-CLNT-12 | Testing Browser Storage |
| WSTG-CLNT-13 | Testing for Cross Site Script Inclusion |
API Testing
| API Testing | Test Name |
| WSTG-APIT-01 | Testing GraphQL |
Security Assessment Findings
Snap Hosted Locally
| ID | SAY-01 |
| Status | Fixed |
| Risk | High |
| Location | snap/src/index.ts:5 |
| Business Impact | The solution in its current form does not work properly. |
Description
In its current form, Snap uses the endpoint variable with the hardcoded address of the local GraphQL server. However, when the solution is launched, such a server is not created – so no communication with GraphQL on the localhost can be carried out, and thus – the solution does not work.
Mitigation
We suggest changing the endpoint to an external server with a running GraphQL service or implementing a local server that supports three types of network communication.
Unexpected Success Message
| ID | SAY-02 |
| Status | Fixed |
| Risk | Medium |
| Location | snap/src/index.ts:94-99 |
| Business Impact | The user is incorrectly informed about success, even though an error occurred. |
Description
It has been noticed that when using the “store” method, the API key is stored in Snap’s storage. After validation using the validateApiKey function, setApiKey is called on success, followed by a success message.
Otherwise, an alert is returned to the user using the displayAlert function, and then there is no return to terminate the function call. Therefore, its execution goes further and, as in the case when the key is valid, a success message is returned to the user.
if (validKey) {
await setApiKey(request.params.apiKey)
} else {
await displayAlert(
'Invalid API Key',
'The API Key attempted to be stored is invalid. Please try
again.',
)
}
return snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
text(`API Key stored successfully`),
text(JSON.stringify(origin) + ' has successfully stored a valid api key in your local metamask storage'),
]),
},
})
Mitigation
We suggest that if the validation was unsuccessful – return an error message and abort the execution of the function, for example by “throw new Error(‘Error’)”
Lack of Documentation
| ID | SAY-03 |
| Status | Fixed |
| Risk | Low |
| Location | Whole solution |
| Business Impact | Lack of understanding of the solution, lack of clear installation instructions, the code has no explanations, which can be problematic for people reading it. |
Description
It was found that the code does not have any technical documentation explaining its operation and content. In addition, there are no comments in the code other than the default ones (Metamask template) referring to individual sections of the code and explaining their functioning. In addition, there is no clear instruction for installing Snap in the README file or in any other file, which may be problematic for users who are new to this technology.
Mitigation
We suggest creating appropriate technical documentation, and installation instructions, and adding comments explaining individual Snap functionalities.
Wrong Fuction Name
| ID | SAY-04 |
| Status | Fixed |
| Risk | Low |
| Location | snap/src/index.ts:129 |
| Business Impact | This reduces the readability of the code and can be confusing for someone trying to understand it. |
Description
The onRpcRequest handler accepts two methods – “store” and “fetchKey“. Based on its name, the fetchKey method is used to extract the API key from state and return it to the user.
Apparently, the function contains the right logic and is supposed to return a boolean. Then, the name is confusing and needs to be changed.
case 'fetchKey':
const persistedData = await snap.request({
method: 'snap_manageState',
params: { operation: 'get' },
})
if (
persistedData == null ||
!persistedData.hasOwnProperty('BEIKey') ||
persistedData.BEIKey == null
) {
return false
}
return true
Mitigation
We suggest modifying the function name to make it clear that it doesn’t return the key itself.
Unused Parameter
| ID | SAY-05 |
| Status | Fixed |
| Risk | Informational |
| Location | snap/src/index.ts:137 |
| Business Impact | Existence of unnecessary code, reducing the readability of Snap. |
Description
It was found that the on Transaction handler takes transactionOrigin as a parameter, even though it doesn’t use it anywhere afterwards. This is redundant and it is good practice to implement support for variables that are used wherever they are.
Mitigation
We suggest removing the transactionOrigin pass-through if Snap’s logic doesn’t use it anywhere.
Missing Unit Tests
| ID | SAY-06 |
| Status | Fixed |
| Risk | Informational |
| Location | Whole solution |
| Business Impact | No verification that Snap works properly and as expected. |
Description
Snap has been found to have no form of unit testing any of its functionalities. It is good practice for the core parts of the code (and preferably all) to have an appropriate test code validating their operation and comparing them with the expected results.
Mitigation
We suggest creating appropriate unit tests to determine whether Snap works as expected.
Appendix A: Security Evaluation Fixes
After a review by the Sayfer team, we certify that all the above-mentioned security issues have been addressed by the AnChain team.
Sayfer certifies that there are no longer any major vulnerabilities in the AnChain project that could cause security problems.
Fixes commit: d69cfe0cdb3f00778cba3efc996e1230d5046fef
