Level 2 · First stepsThe village#092

Browser wallets like MetaMask explained: the website asks, you sign

A browser wallet is an extension that keeps your keys inside your web browser and lets websites ask it to sign. A website can only ask. The danger is what you agree to: one token approval can let a contract take your tokens later, without asking again.

Anna has a stall in the market and a stamp with her seal on it. Any trader can bring her a slip of paper. She reads it, and if she agrees, she stamps it. Nobody can stamp for her. They can only ask.

One morning a trader brings a slip that reads: "Anna allows the miller to take flour money from her account whenever he likes." She's in a hurry. It looks routine. She stamps it.

A browser wallet is Anna's stamp, sitting in your web browser. Every website you visit can slide a slip across the counter. The wallet will only stamp what you approve, and some slips go on working long after you've left the market.

What it is

A browser wallet is a wallet that runs as an extension in your web browser. It creates and stores your keys, encrypted with a password, and lets websites talk to it. MetaMask, used on Ethereum and similar networks, is one example. It calls itself a "self-custodial (non-custodial) crypto wallet": you hold the keys (MetaMask Help Center).

The conversation follows a public standard. EIP-1193, created in June 2018, describes how "key management software ('wallets')" exposes itself to web pages through a JavaScript object, usually available as window.ethereum. It recommends "not exposing any accounts by default": a site has to ask for access first, with a request such as eth_requestAccounts (EIP-1193). That's the pop-up you see when a site says "connect wallet".

Connecting shows the site your address. It doesn't let it move anything. Moving needs a signature, every time, unless you've already signed away the need to ask.

How it works: the slip that says "whenever he likes"

Tokens on Ethereum mostly follow ERC-20, a standard written in November 2015. It includes a function called approve, which "allows _spender to withdraw from your account multiple times, up to the _value amount" (ERC-20). Exchanges and apps built on smart contracts use it so they can move your tokens when you trade.

Here is what an approval looks like in numbers.

  1. You want to swap 100 tokens on a trading website. The site asks your browser wallet to approve its contract to spend your tokens.
  2. The amount it asks for can be far more than 100. Some sites ask for the largest number the contract can store, 2 to the power of 256 minus 1. Written out, that's 115792089237316195423570985008687907853269984665640564039457584007913129639935 tokens, a 78-digit number. In practice, unlimited.
  3. You approve once. From then on, that contract can move your tokens of that type at any time, up to the limit, without asking you again.
  4. Nothing happens for months. Then the contract is exploited, or it was malicious from the start, and your balance leaves in a transaction you never saw.

MetaMask's own help pages put it bluntly: with an approval in place, "the dapp already has your permission to take the necessary quantity of tokens straight out of your account", and "having an unlimited token allowance in place may put you at risk of theft." Its advice: "Never grant unlimited (astronomically high) allowances" (MetaMask Help Center).

When the website itself is the stranger

Sometimes the slip comes from a site you trust. On 14 December 2023, an attacker phished a former employee of Ledger, the hardware wallet maker, and used that person's access to publish poisoned versions of Ledger Connect Kit, a code library many crypto websites load to talk to wallets. The malicious versions went up between 09:49 and 11:37 CET. Websites that loaded them showed visitors requests that drained their wallets when signed. Ledger said assets were actively drained for "less than two hours in total", and that a "low volume of users" signed (Ledger, 2023).

The browser wallets worked exactly as designed. They asked. People signed.

Where people get it wrong

  • "Connecting my wallet is harmless." Connecting only shares your address. Signing is what costs money, so read every request after you connect.
  • "I only approved a small swap." You may have approved an unlimited amount. Check the figure before you confirm.
  • "Once the trade is done, the permission ends." Approvals stay until you change them.
  • "A familiar website is safe." Sites load code from many places. If one of them is poisoned, so is the request.
  • "It's in my browser, so it's like online banking." A bank can reverse a fraudulent payment. The blockchain doesn't.

Check your approvals

Go through the token approvals your browser wallet has given. Many wallets show them, and MetaMask's help pages link to a guide on revoking. Remove the ones you don't need, and next time set the spending cap to the amount you're actually using, not the 78-digit number.

The stamp only works when you press it. The trick is the slip that never needs you again.

Frequently asked questions

What is a browser wallet?

A browser wallet is a crypto wallet that runs as an extension in your web browser. It stores your keys, encrypted with a password, and lets websites request signatures for transactions, which you approve or reject in a pop-up.

Is MetaMask a custodial wallet?

No. MetaMask describes itself as a "self-custodial (non-custodial) crypto wallet": the keys are created and stored on your device and recreated from your Secret Recovery Phrase. The company says it cannot access that phrase and cannot recover your funds if you lose it.

What is a token approval?

A token approval is permission, given with the ERC-20 approve function, for a smart contract to move a certain amount of one of your tokens without asking you again. Unlimited approvals are common and can be abused if the contract is malicious or exploited.

Is it safe to connect my wallet to a website?

Connecting shares your wallet address with the site but doesn't let it move funds. The risk comes when you sign requests, so read every approval and transaction carefully, especially on sites you reached through a link or an advert.

How do I revoke a token approval?

Most browser wallets, or tools linked from their help pages, show the approvals your address has given and let you set them to zero with a new transaction. Revoking costs a small network fee, and it stops a contract from moving more of that token in future.

Sources

  1. Fabian Vogelsteller and others, EIP-1193: Ethereum Provider JavaScript API
  2. Fabian Vogelsteller and Vitalik Buterin, ERC-20: Token standard
  3. MetaMask Help Center, How to customize token approvals with a spending cap
  4. MetaMask Help Center, MetaMask is a self-custodial wallet
  5. Ledger, Security incident report (20 December 2023)

Read next.