Use after free in V8 (CVE-2026-17807)
A use-after-free exists in V8's inspector: when a page logs an object whose formatting runs page JavaScript, that JavaScript can destroy the inspector session, freeing the runtime agent while it is still being used. An attacker could then cause a virtual call through a pointer read from the freed object, potentially leading to code execution in the renderer, though only while DevTools is attached.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 2 months
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the Chrome Security team. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
(Note from awillia: Our system dupes this bug to bug 511255112, but it's a separate issue. Raising this manually to bypass the duping).
Title: V8 Inspector: V8RuntimeAgentImpl UAF via session destruction during console.log→reportToFrontend re-entrancy (KeepSessionAliveScope missing on addMessage path)
Component: Blink>JavaScript>Inspector (or V8>Inspector)
Severity: S2 (renderer C++-heap UAF → vtable call on attacker-groomable freed chunk; DevTools-attached gating)
Summary
V8RuntimeAgentImpl::reportMessage (v8-runtime-agent-impl.cc:1222-1226)
passes &m_frontend and m_session into reportToFrontend, which can run
page JS via wrapArguments (custom formatters / Error-prototype accessors /
@@hasInstance). If that JS destroys the session (not the storage), the
agent — owned by unique_ptr<V8RuntimeAgentImpl> m_runtimeAgent inside the
session — is freed mid-call. On return, frontend->consoleAPICalled(...)
(v8-console-message.cc) makes a virtual call through a FrontendChannel*
read from the freed agent, then reportMessage does m_frontend.flush() and
m_session->contextGroupId() on freed this.
The KeepSessionAliveScope (a shared_ptr lock on the session,
v8-inspector-session-impl.h:163-172) that prevents this is only applied at
dispatchProtocolMessage:368 (CDP entry). The console.log path enters via
V8ConsoleMessageStorage::addMessage → V8InspectorImpl::forEachSession →
session->runtimeAgent()->messageAdded(), which never constructs the scope.
forEachSession re-looks-up the session by ID between iterations but hands
the lambda a raw V8InspectorSessionImpl* with no pin during one.
Why the bug 511255112 fix does not cover this
1dba9760bf9 + the addMessage:591 follow-up replaced
hasConsoleMessageStorage(gid) with consoleMessageStorage(gid) != storage
identity checks. But ~V8InspectorSessionImpl
(v8-inspector-session-impl.cc:161-170) does not erase
m_consoleStorageMap[gid] — only resetContextGroup does. So when the
session is destroyed and the storage survives, the storage-identity check
at v8-console-message.cc:370 returns false (unchanged) and execution
continues into frontend->consoleAPICalled() on the freed agent.
Destruction path (Chrome)
- DevTools attached,
Runtime.enableissued (default DevTools UI state). - Page does
console.log(obj)whereobjmakeswrapArgumentsrun page JS:objis a NativeError subclass with a prototypename/message/stackgetter —getErrorPropertyfalls through toobject->Get(value-mirror.cc:281); orRuntime.setCustomObjectFormatterEnabled(true)→devtoolsFormatters[i].header()(custom-preview.cc:312); ordoesAttributeHaveObservableSideEffectOnGet@@hasInstancecallout (value-mirror.cc:1473-1508).
- The re-entrant JS enters a nested message loop (
alert()/print()). During it, thehost_remote_Mojo disconnect handler fires (devtools_session.cc:188-190) — user closes DevTools, or a colluding extension callschrome.debugger.detach.Detach()doesv8_session_.reset()(devtools_session.cc:258) → shared_ptr refcount 0 →~V8InspectorSessionImpl→m_runtimeAgentdestroyed. wrapArgumentsreturns. Storage-identity check at:370passes (storage not erased).frontend->consoleAPICalled(...)readsfrontend->frontend_channel_from the freedV8RuntimeAgentImpland makes a virtualSendProtocolNotificationcall.- Back in
reportMessage:m_frontend.flush()andm_inspector->hasConsoleMessageStorage(m_session->contextGroupId())deref freedthis.
(Same-process iframe.remove() does not trigger this in Chrome — only
local-root frames own a WebDevToolsAgentImpl. Non-Chrome embedders using
V8Inspector::connect() (unique_ptr, no m_weakThis) have no keep-alive at
all; any synchronous embedder teardown from the JS callout suffices.)
Additional sinks (same root cause)
v8-console-message.cc:302— secondwrapArguments-loop iteration callssession->wrapObject(...)on freedsession(loop only re-checksinspectedContext).v8-console-message.cc:360—kExceptionbranchfrontend->exceptionThrown(...)afterwrapExceptionran page JS, with no post-JS check at all.
Suggested fix
Pin the session across messageAdded. Either in forEachSession's callback
wrapper, or in addMessage:
// v8-console-message.cc, V8ConsoleMessageStorage::addMessage:
inspector->forEachSession(contextGroupId, [&message](V8InspectorSessionImpl* session) {
V8InspectorSessionImpl::KeepSessionAliveScope keepAlive(*session);
if (message->origin() == V8MessageOrigin::kConsole)
session->consoleAgent()->messageAdded(message.get());
session->runtimeAgent()->messageAdded(message.get());
});
(or hoist into V8InspectorImpl::forEachSession so every callback gets it).
Assumptions
- Unconfirmed:
host_remote_disconnect handler dispatch inside analert()nested loop (standard renderer nested-message-loop pattern; not traced to the exactSequencedTaskRunner). - Confirmed in source:
KeepSessionAliveScopeonly at:368;~V8InspectorSessionImpldoes not erase console storage;forEachSessionpasses raw ptr without pin; Blink usesconnectSharedandDetach()doesv8_session_.reset().
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
Likely the session keep-alive lock (KeepSessionAliveScope) is only applied on the protocol-message entry path, not on the console message path, so re-entrant page JavaScript can destroy the session and free the agent mid-call.
Impact
A renderer C++-heap use-after-free leading to a virtual call on an attacker-groomable freed chunk, which could allow code execution, but only when DevTools is attached.
What the attacker needed
DevTools attached to the page; Runtime domain enabled; Page runs attacker-influenced JavaScript; Session destroyed during the JS callout
The fix
The session should be pinned across messageAdded, either in the forEachSession callback wrapper or in addMessage, using the keep-alive scope.
How it was found
- Attach DevTools and enable the Runtime domain (the default DevTools UI state).
- Have the page log an object whose formatting runs page JavaScript, for example via a prototype getter, a custom formatter, or a hasInstance callout.
- The re-entrant JavaScript enters a nested message loop, during which the DevTools connection is torn down and the session is destroyed.
- When formatting returns, the storage-identity check passes and a virtual call is made through the freed agent.
- Control returns to reportMessage, which dereferences the freed object again.
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 you open the browser's developer tools, the page and the tools talk to each other. Here, the page could run its own code in the middle of that conversation and pull the rug out from under the tools, so the browser then uses memory that has already been freed. Using freed memory can crash the browser or, in the worst case, let an attacker run their own code.
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.