{"id":"GHSA-8mj7-wxmc-f424","aliases":["GHSA-8mj7-wxmc-f424","RUSTSEC-2022-0028"],"related":[],"kind":"vulnerability","state":"published","title":"Use after free in Neon external buffers","summary":"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`.\n\nThe following example demonstrates use after free. It compiles on versions `<0.10.1` and fails to compile afterward.\n\n```rust\npub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {\n    let mut data = vec![0u8, 1, 2, 3];\n    \n    // Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl\n    // of `AsMut<T> for &mut T`\n    let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());\n\n    // `buf` is still holding a reference to `data`!\n    drop(data);\n\n    Ok(buf)\n}\n```","summaryFormat":"markdown","summarySource":"ghsa","descriptions":[{"lang":"en","text":"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`.\n\nThe following example demonstrates use after free. It compiles on versions `<0.10.1` and fails to compile afterward.\n\n```rust\npub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {\n    let mut data = vec![0u8, 1, 2, 3];\n    \n    // Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl\n    // of `AsMut<T> for &mut T`\n    let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());\n\n    // `buf` is still holding a reference to `data`!\n    drop(data);\n\n    Ok(buf)\n}\n```","format":"markdown","source":"ghsa"}],"published":"2022-05-22T12:00:00.000Z","modified":"2023-11-08T04:17:25.410Z","severity":{"scorer":"GitHub","scheme":"rating","rating":"HIGH"},"severities":[{"scorer":"GitHub","scheme":"rating","rating":"HIGH"}],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0.8.0","status":"affected","fixed":"0.10.1"}],"ecosystem":"crates.io","package":"neon","purl":"pkg:cargo/neon","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.8.0","status":"affected","fixed":"0.10.1"}],"ecosystem":"crates.io","package":"neon","purl":"pkg:cargo/neon","source":"rustsec"}],"references":[{"url":"https://github.com/neon-bindings/neon/issues/896","tags":["report","web"],"sources":["ghsa","rustsec"]},{"url":"https://github.com/neon-bindings/neon","tags":["package"],"sources":["ghsa"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2022-0028.html","tags":["advisory","web"],"sources":["ghsa","rustsec"]},{"url":"https://crates.io/crates/neon","tags":["package"],"sources":["rustsec"]}],"credits":[],"sources":[{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-8mj7-wxmc-f424","url":"https://github.com/advisories/GHSA-8mj7-wxmc-f424","licence":"CC-BY-4.0","modified":"2023-11-08T04:17:25.410Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2022-0028","url":"https://rustsec.org/advisories/RUSTSEC-2022-0028.html","licence":"CC0-1.0","modified":"2023-11-08T04:17:25.410Z"}],"updatedAt":"2026-11-25T22:56:43.099Z"}