Skip to content
Memory corruption Write-up Advanced

CVE-2021-38297 – Analysis of a Go Web Assembly vulnerability

A buffer overflow in Go's WebAssembly runtime allows an attacker who controls a command-line argument or environment variable to overwrite the entire Wasm module with malicious code. This can lead to arbitrary code execution, with higher impact when the module runs in Node.js.

Uriya Yavnieli Follow

Published on jfrog.com

The JFrog Security Research team continuously monitors reported vulnerabilities in open-source software (OSS) to help our customers and the wider community be aware of potential software supply chain security threats and their impact. In doing so, we often notice important trends and key learnings worth highlighting.

Uriya Yavnieli (@uriya_yavniely), on jfrog.com

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

The wasm_exec.js runtime copies command-line arguments and environment variables into memory without checking total length, allowing a long input to overwrite the Wasm module's bytecode.

Impact

In a browser, the impact is medium (similar to XSS, limited by the sandbox); in Node.js, the impact is high, allowing remote code execution.

What the attacker needed

Go version before 1.16.9 or 1.17.2; Wasm module compiled by Go; Attacker controls a command-line argument or environment…

How it was found

  1. Compile a Go program to WebAssembly using the appropriate environment variables.
  2. Load the Wasm module in a JavaScript environment (browser or Node.js) that passes external input as command-line arguments or environment variables.
  3. Provide a very long string (over 4096 characters) as an argument or environment variable.
  4. The overflow overwrites the Wasm module's code with attacker-controlled data, leading to code execution.

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.

When a Go program is compiled to WebAssembly (a format for running code in browsers or Node.js), it receives command-line arguments and environment variables. If an attacker can make one of these very long, it can overflow a buffer and overwrite the program's code. This lets the attacker run their own code, which is especially dangerous on a server because it can lead to full system compromise.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.