Use-after-free in RTCEncodedFrameBase ArrayBuffer
The RTCEncodedFrameBase constructor exposes the underlying WebRTC frame buffer to JavaScript as an ArrayBuffer, but the destructor never detaches that buffer, so the JS object keeps pointing at freed native memory. An attacker could read stale heap contents and write into reused allocations, causing crashes and potentially code execution.
Originally disclosed on Mozilla
- Fixed in 44 days
- Paid in 51 days
- Disclosed after 44 days
Created attachment 9518404 poc-minimal.html
Hello team,
there is a potential use-after-free in RTCEncodedFrameBase where a JS ArrayBuffer aliases freed native memory, allowing read/write on dangling storage from web content.
Root cause
RTCEncodedFrameBase constructor wraps the libwebrtc frame buffer with JS::NewArrayBufferWithUserOwnedContents, but the destructor does not detach:
// dom/media/webrtc/jsapi/RTCEncodedFrameBase.cpp:38
mData = JS::NewArrayBufferWithUserOwnedContents(
jsapi.cx(), mFrame->GetData().size(),
(void*)mFrame->GetData().data());
// Line 42
RTCEncodedFrameBase::~RTCEncodedFrameBase() = default; // no DetachArrayBuffer
Impact
JS retains access to freed memory. Reads leak stale heap contents; writes corrupt reused allocations, enabling process crashes and potential RCE.
Reproduction
Attached PoC (poc-minimal.html, poc-minimal-worker.js):
- Creates two
RTCPeerConnections with canvas video track (no permissions). - Worker collects up to 200
frame.dataArrayBuffers, drops frame wrappers to trigger destructor. - Overwrites all leaked buffers with
0x41on each subsequent frame. - Monitors for changes: logs
[leak N] CHANGEDwhen bytes differ from0x41, proving memory reuse.
Minidump stack
Operating system: Linux
6.12.32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.32-1 (2025-06-07)
CPU: amd64
family 25 model 97 stepping 2
32 CPUs
Linux debian 13 - trixie (Debian GNU/Linux 13 (trixie))
Crash reason: SIGSEGV / SI_KERNEL
Crash address: 0x0000000000000000 **
** Non-canonical address detected: 0x4141414141414159
Crashing instruction: `call qword [rax + 0x18]`
Memory accessed by instruction:
0. Address: 0x4141414141414159
Size: 8
Access type: Read
1. Address: 0x00007f1ef06ff6e8
Size: 8
Access type: Write
Thread 34 WebrtcC~read #1 (crashed) - tid: 958997
0 libxul.so!mozilla::DelayedRunnable::Notify(nsITimer*) [DelayedRunnable.cpp : 92]
Found by: inlining
1 libxul.so!{virtual override thunk({offset(-16)}, mozilla::DelayedRunnable::Notify(nsITimer*))} [DelayedRunnable.cpp : 0 + 0x3b]
rax = 0x4141414141414141 rdx = 0x0000000000000003
rcx = 0x0000000000000000 rbx = 0x00007f1ef0093ee8
rsi = 0x0000000000000000 rdi = 0x00007f1ef0093e40
rbp = 0x0000000000000001 rsp = 0x00007f1ef06ff6f0
r8 = 0x0000000000000011 r9 = 0x00000000ffffffff
r10 = 0x0000000000000000 r11 = 0x0000000000000246
r12 = 0x0000000000000012 r13 = 0x0000000000000000
r14 = 0x00007f1ef0093ec0 r15 = 0x00007f1ef0093e40
rip = 0x00007f1efb969b87
Best regards,
Igor Morgenstern
Aisle Research
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The destructor of RTCEncodedFrameBase does not detach the ArrayBuffer created with JS::NewArrayBufferWithUserOwnedContents, leaving JS holding a pointer to memory freed with the frame.
Impact
Reads could leak stale heap contents and writes could corrupt reused allocations, causing process crashes and potentially remote code execution, as shown by a crash where a corrupted pointer was dereferenced.
What the attacker needed
No permissions needed; victim loads attacker page; browser with WebRTC support
How it was found
- Create two RTCPeerConnections with a canvas video track, needing no permissions.
- In a worker, collect up to 200 frame.data ArrayBuffers and drop the frame wrappers to trigger the destructor.
- Overwrite all leaked buffers with a repeated byte value on each subsequent frame.
- Watch for bytes that differ from the written value, which proves the memory has been reused.
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 report has not been written yet. The Original tab links to the source.
When a program frees a piece of memory, anything still pointing at it becomes dangerous. Here a JavaScript buffer was handed a pointer to memory owned by a WebRTC frame, and when the frame was destroyed the buffer was not cut loose, so scripts could still read and write that freed memory. That is called a use-after-free, and it can crash the browser or let an attacker take control.
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.