# GHSA-8mj7-wxmc-f424: Use after free in Neon external buffers

> A use-after-free vulnerability in the Neon Rust library allows attackers to execute arbitrary code or cause crashes via improperly managed external buffers.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 22 May 2022
- **Also known as:** RUSTSEC-2022-0028

## What is GHSA-8mj7-wxmc-f424?

GHSA-8mj7-wxmc-f424 is an use after free vulnerability in neon, published on 22 May 2022. 

### Official description

Neon provides functionality for creating JavaScript `ArrayBuffer` (and the `Buffer` subtype) instances backed by bytes allocated outside of V8/Node. The [`JsArrayBuffer::external`](https://docs.rs/neon/0.10.0/neon/types/struct.JsArrayBuffer.html#method.external) and [`JsBuffer::external`](https://docs.rs/neon/0.10.0/neon/types/struct.JsBuffer.html#method.external) did not require `T: 'static` prior to Neon `0.10.1`. This allowed creating an externally backed buffer from types that may be freed while they are still referenced by a JavaScript `ArrayBuffer`.

The following example demonstrates use after free. It compiles on versions `<0.10.1` and fails to compile afterward.

```rust
pub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
    let mut data = vec![0u8, 1, 2, 3];
    
    // Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl
    // of `AsMut<T> for &mut T`
    let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());

    // `buf` is still holding a reference to `data`!
    drop(data);

    Ok(buf)
}
```

## Which versions are affected by GHSA-8mj7-wxmc-f424?

3 open source packages ship an affected version, including neon.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `neon` | crates.io | From 0.8.0 | 0.10.1 |
| `neon` | crates.io | From 0.8.0 | 0.10.1 |
| `neon` | crates.io | From 0.8.0 | 0.10.1 |

## How do I fix GHSA-8mj7-wxmc-f424?

Upgrade neon to 0.10.1 or later.

## Is GHSA-8mj7-wxmc-f424 being exploited?

There is no known exploitation of GHSA-8mj7-wxmc-f424 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-8mj7-wxmc-f424 and fix it if it is affected.

What it is: GHSA-8mj7-wxmc-f424 is an use after free vulnerability in neon, published on 22 May 2022. 
Exploitation: There is no known exploitation of GHSA-8mj7-wxmc-f424 in the wild and no public exploit code.

Affected packages and fixed versions:
- neon (crates.io): affected from 0.8.0; fixed in 0.10.1
- neon (crates.io): affected from 0.8.0; fixed in 0.10.1
- neon (crates.io): affected from 0.8.0; fixed in 0.10.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-8mj7-wxmc-f424/ (Markdown: https://insights.sbomify.com/GHSA-8mj7-wxmc-f424/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-8mj7-wxmc-f424

---
From sbomify Insights: https://insights.sbomify.com/GHSA-8mj7-wxmc-f424/
Summaries are generated and may contain mistakes; the official description above is the record.
