Supply Chain Attacks: A New Era
The Lavamoat sandboxing tool for JavaScript had two bypasses: one in Lavapack's source map comment removal allowed escaping the with() sandbox, and one in SnowJS allowed creating a non-sandboxed iframe via document.execCommand. An attacker who compromised an NPM dependency could execute arbitrary code and, in MetaMask, retrieve the encrypted keypair from extension storage.
Published on osec.io
Supply chain attacks are becoming increasingly popular in Web3. In response, Lavamoat has emerged as a robust defense mechanism against supply chain attacks, offering sophisticated isolation and access control features.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the root cause is that Lavapack's source map comment removal modified code after the syntax check, allowing invalid JavaScript to escape the with() sandbox, and SnowJS failed to hook document.execCommand, allowing creation of a non-sandboxed iframe.
Impact
By combining the exploits, an attacker who compromises an NPM dependency could completely bypass Lavamoat protections and, in MetaMask, retrieve the encrypted keypair from extension storage.
What the attacker needed
Compromised NPM dependency; for scuttling bypass: same-origin window; for scuttling bypass: window not scuttled
The fix
MetaMask mitigated the Lavapack issue by adding an independent assertValidJS() check, and is working on conceptual changes for SnowJS; the text does not say the SnowJS bypass was fully fixed.
How it was found
- Create a multiline source map comment containing invalid JavaScript.
- Bundle the code with Lavapack, which removes the comment and leaves the invalid JavaScript.
- The injected code executes when the bundle is imported, escaping the with() sandbox.
- For the scuttling bypass, insert a contenteditable element into the page.
- Use document.execCommand with insertHTML to add a non-sandboxed iframe.
- Execute code in the new iframe's realm to bypass scuttling.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Lavamoat is a tool that tries to stop malicious code in third-party packages from doing harm. The researchers found ways to get around its protections, so a bad package could still run harmful code. In a browser extension like MetaMask, this could let an attacker steal the encrypted wallet key.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.