Skip to content
Memory corruption Advisory Advanced CVE-2026-3918

Use after free in WebMCP (CVE-2026-3918)

A declarative WebMCP tool pointer stored in the browser engine's tool map was not traced by the garbage collector, and a shutdown edge case skipped unregistering it, leaving a stale entry. Calling the testing API to list tools then dereferenced the freed object, causing a use-after-free crash in the renderer.

Syn4pse Follow

Originally disclosed on Chrome VRP

Bounty$10,000 High View original
  • Fix shipped in 27 days

Summary

navigator.modelContextTesting.listTools() reaches ModelContext::ForEachScriptTool, which unconditionally calls ComputeInputSchema() on each declarative tool pointer stored in tool_map_. Declarative tool registration stores a raw pointer in ModelContext::ToolData::declarative_tool, and the pointer is not traced in GC. After iframe/document shutdown, a lifecycle gap in form-side unregister logic can leave a stale map entry; once the underlying HTMLFormMcpTool is reclaimed, ForEachScriptTool dereferences a dangling pointer and triggers renderer UAF/use-after-poison.

Note that the root cause of this issue is different with the recent reported issue 483569512. And the fix in the issue 483569512 does not mitigate this issue as well.

Details

The current implementation path for DeclarativeWebMCPTool is: declarative form registration -> raw pointer retained in ModelContext::tool_map_ -> unregister skipped in a shutdown edge case -> later schema refresh dereferences stale pointer.

In ModelContext::RegisterDeclarativeTool, declarative registration stores DeclarativeWebMCPTool* into ToolData:

C++
void ModelContext::RegisterDeclarativeTool(String name,
                                           String description,
                                           DeclarativeWebMCPTool* tool) {
  auto script_tool = mojom::blink::ScriptTool::New();
  auto* tool_data = MakeGarbageCollected<ToolData>();
  script_tool->name = name;
  script_tool->description = description;
  script_tool->input_schema = "{}";  // For now
  tool_data->script_tool = std::move(script_tool);
  tool_data->declarative_tool = tool;

  tool_map_.insert(name, std::move(tool_data));
  OnToolsChanged();
}

In ModelContext::ToolData::Trace, only the V8 tool function is traced; the declarative pointer is not:

C++
void ModelContext::ToolData::Trace(Visitor* visitor) const {
  visitor->Trace(v8_tool_function);
}

In HTMLFormElement::UpdateMcpDefinitionsIfNeeded, the function returns early when ModelContext is unavailable (e.g., detached document with no domWindow()/navigator()), so the unregister path is skipped in that state:

C++
ModelContext* model_context = nullptr;
if (auto* window = GetDocument().domWindow(); window && window->navigator()) {
  model_context = ModelContextSupplement::modelContext(*window->navigator());
}
if (!model_context) {
  return;
}

if (IsValidWebMCPForm()) {
  ...
  model_context->unregisterTool(active_webmcp_tool_->ToolName(),
                                ASSERT_NO_EXCEPTION);
  active_webmcp_tool_ = nullptr;
}

Later, ModelContext::ForEachScriptTool updates declarative schemas on iteration and dereferences the stale pointer:

C++
void ModelContext::ForEachScriptTool(
    base::FunctionRef<void(const mojom::blink::ScriptTool&)> func) const {
  for (const auto& tool : tool_map_) {
    auto tool_data = tool.value;
    // Always update the input schema, since the DOM might have changed.
    if (auto* declarative_tool = tool_data->declarative_tool) {
      tool_data->script_tool->input_schema =
          declarative_tool->ComputeInputSchema();
    }
    func(*tool_data->script_tool);
  }
}

Therefore, we can leverage the following chain to achieve UAF: implementation stores an untraced raw pointer -> lifecycle edge skips unregister -> GC reclaims the declarative tool object -> listTools() reaches ForEachScriptTool and dereferences freed memory.

REPRODUCTION

Build args on commit 349bddcf54ebcd90e7d4d6b00433982956d3b33e in Linux:

is_asan=true
is_component_build=true
dcheck_always_on=false
is_debug=false

Run command:

Bash
./chrome --user-data-dir=/tmp/xx --enable-features=WebMCPTesting --enable-experimental-web-platform-features --no-first-run --no-sandbox --js-flags=--expose-gc poc.html

We should observe the Use-after-Poison crash shown in the asan.txt.

This has been reachable in the M145, and will be shipped in the M146 dev trial.

Bisection

This issue is introduced by the commit 3df80580897d24fbb730c0ee411f25ffe04e766b.

SUGGESTED FIX

Make declarative tool lifetime GC-safe at the ToolData boundary and enforce stale-entry pruning during iteration.

We may:

  1. Change ToolData::declarative_tool from raw DeclarativeWebMCPTool* to a GC-traceable handle.
  2. Update ToolData::Trace() to trace declarative tool references.
  3. Add a defensive guard in ForEachScriptTool to skip and remove entries whose declarative tool is no longer valid before calling ComputeInputSchema().

This keeps tool_map_ entries from holding dangling declarative pointers and prevents listTools() from dereferencing reclaimed objects.

The original report as published on the Chromium issue tracker, by Syn4pse. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

WebMCP is the part of Blink that lets a page expose tools to a model context. A page can register a tool declaratively, by marking up a form, and the browser then advertises that tool through navigator.modelContextTesting.listTools(). Each registered tool carries a name, a description and an input schema, and the schema is recomputed from the live DOM whenever the tool list is enumerated, because the form may have changed since registration.

The advisory covers a use after free in that machinery, tracked as CVE-2026-3918, rated high severity, with a bounty of 10,000 USD. It was disclosed on 10 March 2026 through the Chrome VRP by the researcher Syn4pse. The weakness class is use after free, and the affected asset is WebMCP.

Setup

The bug was reproduced on a Linux build from commit [redacted], with these build arguments:

Text
is_asan=true
is_component_build=true

dcheck_always_on=false
is_debug=false

ASan is what turns the dangling access into a visible Use-after-Poison report. The browser was started with these flags and the proof of concept page as the startup URL:

Bash
./chrome --user-data-dir=/tmp/xx --enable-features=WebMCPTesting --enable-experimental-web-platform-features --no-first-run --no-sandbox --js-flags=--expose-gc poc.html

The report notes that the bug was reachable in M145 and would ship in the M146 dev trial. Bisection pinned the introduction to commit [redacted].

Finding it

The researcher traced the path taken by a declarative tool from registration to enumeration. The entry point is navigator.modelContextTesting.listTools(), which reaches ModelContext::ForEachScriptTool. That function unconditionally calls ComputeInputSchema() on every declarative tool pointer stored in tool_map_.

The problem is how those pointers get into the map. Declarative registration stores a raw pointer in ModelContext::ToolData::declarative_tool, and that pointer is not traced by the garbage collector. Separately, the form-side unregister logic has a lifecycle gap: after an iframe or document shutdown, the unregister can be skipped, leaving a stale entry in the map. Once the underlying HTMLFormMcpTool is reclaimed, ForEachScriptTool dereferences a dangling pointer and the renderer hits a use after free, reported under ASan as use-after-poison.

The report is explicit that this is not the same root cause as the recently reported issue 483569512, and that the fix for that issue does not mitigate this one.

Exploitation

Step 1: register a declarative tool

A form marked up as a WebMCP tool is registered through ModelContext::RegisterDeclarativeTool, which stores the DeclarativeWebMCPTool* inside a ToolData object:

C++
void ModelContext::RegisterDeclarativeTool(String name,
                                           String description,
                                           DeclarativeWebMCPTool* tool) {
  auto script_tool = mojom::blink::ScriptTool::New();
  auto* tool_data = MakeGarbageCollected<ToolData>();
  script_tool->name = name;
  script_tool->description = description;
  script_tool->input_schema = "{}";  // For now
  tool_data->script_tool = std::move(script_tool);
  tool_data->declarative_tool = tool;

  tool_map_.insert(name, std::move(tool_data));
  OnToolsChanged();
}

The ToolData itself is garbage collected, but the declarative_tool member is a plain pointer with no GC relationship to the object it points at.

Step 2: confirm the pointer is untraced

The tracing method for ToolData only visits the V8 tool function:

C++
void ModelContext::ToolData::Trace(Visitor* visitor) const {
  visitor->Trace(v8_tool_function);
}

Because declarative_tool is not traced, the collector has no reason to keep the declarative tool alive for as long as the map entry exists.

Step 3: skip the unregister during shutdown

HTMLFormElement::UpdateMcpDefinitionsIfNeeded returns early when no ModelContext can be found, for example in a detached document with no domWindow() or navigator(). In that state the unregister path never runs:

C++
ModelContext* model_context = nullptr;
if (auto* window = GetDocument().domWindow(); window && window->navigator()) {
  model_context = ModelContextSupplement::modelContext(*window->navigator());
}
if (!model_context) {
  return;
}

if (IsValidWebMCPForm()) {
  ...
  model_context->unregisterTool(active_webmcp_tool_->ToolName(),
                                ASSERT_NO_EXCEPTION);
  active_webmcp_tool_ = nullptr;
}

The map entry survives the shutdown while the object it points at does not.

Step 4: force collection and enumerate tools

With the entry left behind, garbage collection reclaims the declarative tool object. The next call to listTools() reaches ForEachScriptTool, which refreshes the schema of every entry and dereferences the stale pointer:

C++
void ModelContext::ForEachScriptTool(
    base::FunctionRef<void(const mojom::blink::ScriptTool&)> func) const {
  for (const auto& tool : tool_map_) {
    auto tool_data = tool.value;
    // Always update the input schema, since the DOM might have changed.
    if (auto* declarative_tool = tool_data->declarative_tool) {
      tool_data->script_tool->input_schema =
          declarative_tool->ComputeInputSchema();
    }
    func(*tool_data->script_tool);
  }
}

Running the command from the setup section against the proof of concept page produces the Use-after-Poison crash recorded in the researcher's asan.txt.

The full chain is: an untraced raw pointer is stored at registration, a lifecycle edge skips the unregister, the collector reclaims the declarative tool, and listTools() reaches ForEachScriptTool and reads freed memory.

Root cause

The design keeps a raw, untraced pointer to a garbage-collected object inside a garbage-collected container. ToolData::Trace does not visit declarative_tool, so the collector is free to reclaim the tool while the map still references it. The unregister logic in HTMLFormElement::UpdateMcpDefinitionsIfNeeded assumes it will always be able to reach a ModelContext, and the early return when the document is detached breaks that assumption, leaving the stale entry in place. ForEachScriptTool then trusts every non-null declarative_tool pointer and calls ComputeInputSchema() on it without any validity check.

Existing defences did not help. The earlier fix for issue 483569512 addresses a different root cause and, per the report, does not mitigate this issue.

Impact

After an iframe or document shutdown in the state described above, a dangling pointer can be left in the tool map. The next enumeration of tools dereferences freed memory in the renderer, producing a use after free. The report demonstrates the crash under ASan; it does not describe a path to code execution or any other outcome beyond the memory-safety violation. The report notes the bug was reachable in M145 and would ship in the M146 dev trial.

Fix

The suggested fix makes declarative tool lifetime GC-safe at the ToolData boundary and prunes stale entries during iteration:

  1. Change ToolData::declarative_tool from a raw DeclarativeWebMCPTool* to a GC-traceable handle.
  2. Update ToolData::Trace() to trace declarative tool references.
  3. Add a defensive guard in ForEachScriptTool to skip and remove entries whose declarative tool is no longer valid before calling ComputeInputSchema().

Together these stop tool_map_ entries from holding dangling declarative pointers and stop listTools() from dereferencing reclaimed objects.

Variants to test

  • Look for other garbage-collected containers that hold raw pointers to garbage-collected objects without tracing them. A positive result is a Trace method that omits a member which is later dereferenced during iteration or refresh.
  • Audit early returns in lifecycle and unregister code paths, especially those guarded on domWindow() or navigator(). A positive result is a state in which registration has happened but the corresponding unregister is skipped.
  • Exercise iframe and document shutdown while tools or similar registrations are active, then force collection and enumerate. A positive result is a crash under ASan or a stale entry visible in the enumeration output.
  • Check iteration paths that recompute state from the DOM, such as schema refresh, for missing validity checks on cached pointers. A positive result is a dereference of an object that has already been reclaimed.
  • Compare fixes for related advisories against the code they touch. A positive result is a fix that closes one lifecycle gap while leaving a different one, as the report states happened with issue 483569512.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 18 min read.

What happened, in plain words

A web browser is a program that runs code from websites. Chrome, made by Google, is one of them. Inside Chrome there is a piece of code called Blink that decides how web pages are displayed and how they behave. One part of Blink is called WebMCP. WebMCP lets a web page offer small helpers, called tools, to an AI model that is running alongside the browser. Think of it like a restaurant menu: the page writes down what it can do, and the model reads the menu to decide what to order.

A page can put a tool on that menu in a simple way: by marking up an ordinary web form. A form is the box with text fields and a submit button that you fill in on many websites. When a form is marked as a tool, the browser remembers it. Later, when something asks for the list of tools, the browser walks through its list and, for each tool, recalculates a description of what input the tool expects. That description is called an input schema. It is recalculated every time because the form may have changed since it was first registered.

The bug is in how the browser remembers those forms. It keeps a note that says, in effect, "the tool is over there", pointing at a spot in the computer's memory. But it never tells the part of the browser that cleans up unused memory, called the garbage collector, that this note exists. The garbage collector is like a cleaner who throws away objects nobody is using any more. Because it does not know about the note, it can throw the form away while the note still points at it. The note is then called a dangling pointer: it points at memory that has been freed and may be reused for something else.

There is a second problem. When a page or a frame inside a page shuts down, the browser is supposed to remove the tool from its list. But in one particular shutdown situation, that removal step is skipped. So the list keeps an entry for a tool that no longer exists.

Put the two together and you get a use after free. That is the name of a whole family of bugs: a program keeps using a piece of memory after it has given it back. Imagine borrowing a friend's flat, handing the keys back, and then walking in anyway; you might find the furniture rearranged, or a stranger living there. In software, reading or writing memory that has been freed can crash the program, and in the worst cases an attacker can arrange for the freed memory to be filled with their own data and take control. This particular report only demonstrates a crash, not an attack that takes over the machine.

The bug is tracked as CVE-2026-3918. A CVE is a public catalogue number given to a known security flaw so that people can talk about it unambiguously. It is rated high severity, and a bounty of 10,000 USD was paid. A bounty is money a company offers to people who find and report bugs responsibly. It was disclosed on 10 March 2026 through the Chrome VRP, Google's Vulnerability Reward Program, by a researcher going by the name Syn4pse. The weakness class is use after free, and the affected asset is WebMCP.

Setup

The researcher reproduced the bug on a Linux build of Chrome made from a specific point in the source code history, commit [redacted]. A commit is a saved snapshot of a code project, identified by a long string of letters and digits. Building Chrome from source means compiling the whole browser yourself, which is why the build settings matter.

These were the build arguments:

Text
is_asan=true
is_component_build=true

dcheck_always_on=false
is_debug=false

Line by line:

  • is_asan=true switches on AddressSanitizer, usually shortened to ASan. ASan is a tool that watches every memory access a program makes and shouts loudly when the program touches memory it should not. Without it, a use after free might silently read garbage and carry on; with it, the program stops and prints a detailed report. The report calls the specific message a Use-after-Poison report, because ASan marks freed memory with a special pattern, a poison, so that any later access is caught.
  • is_component_build=true builds the browser as many separate pieces rather than one giant program. This is a common choice for development builds and makes rebuilding faster.
  • dcheck_always_on=false turns off debug assertions, which are extra internal checks that slow the browser down. Turning them off makes the build behave more like a normal release build.
  • is_debug=false builds an optimised, non-debug version, again closer to what real users run.

The browser was started with special switches, called flags: The proof of concept page, a small HTML file named poc.html that triggers the bug, is passed as the page to open at startup:

Bash
./chrome --user-data-dir=/tmp/xx --enable-features=WebMCPTesting --enable-experimental-web-platform-features --no-first-run --no-sandbox --js-flags=--expose-gc poc.html

Line by line:

  • ./chrome runs the browser program that was just built, from the current folder.
  • --user-data-dir=/tmp/xx tells Chrome to keep its profile data, such as history and settings, in a throwaway folder called /tmp/xx instead of your normal profile. This keeps the test isolated and repeatable.
  • --enable-features=WebMCPTesting enables the WebMCP testing feature.
  • --enable-experimental-web-platform-features turns on experimental web platform features.
  • --no-first-run skips the welcome screens Chrome normally shows the first time it starts.
  • --no-sandbox disables the sandbox, a security layer that restricts what each part of the browser is allowed to do.
  • --js-flags=--expose-gc passes a flag to the JavaScript engine, V8, that lets page scripts ask for garbage collection on demand.
  • poc.html is the page to open, the proof of concept that triggers the flaw.

The report notes that the bug was reachable in M145, a Chrome milestone version, and would ship in the M146 dev trial. A milestone is Chrome's numbering for major releases; a dev trial is an early testing channel where a feature is rolled out to a limited audience. Bisection pinned the introduction of the bug to commit [redacted]. Bisection is a technique for finding the exact change that introduced a problem: you test the middle of a range of commits, learn whether the bug is present, and keep halving the range until only one change is left.

Finding it

The researcher traced the path a declarative tool takes from registration to enumeration. Enumeration means asking the browser for the full list of tools. The entry point is navigator.modelContextTesting.listTools(). In a browser, navigator is a built-in object that represents the browser itself, and it carries various capabilities. modelContextTesting is the testing interface for the model context, and listTools() is the function that returns the list of registered tools. An API, short for application programming interface, is simply a defined set of functions a program offers so that other code can use it; listTools() is one such function.

That call reaches ModelContext::ForEachScriptTool. The :: notation means "the function named ForEachScriptTool that belongs to the ModelContext class". A class is a blueprint for an object in code, and a function is a named block of instructions. ForEachScriptTool walks through every tool in the map and does something with it. A map is a data structure that stores values under names, like a dictionary where each word has a definition. The map here is called tool_map_.

For each tool, ForEachScriptTool unconditionally calls ComputeInputSchema() on the stored declarative tool pointer. Unconditionally means it does not check first whether the pointer is still valid; it just assumes it is. ComputeInputSchema() recalculates the description of the tool's expected input from the current page.

The problem is how those pointers get into the map. Declarative registration stores a raw pointer in ModelContext::ToolData::declarative_tool. A raw pointer is just a memory address, a number saying where an object lives, with no extra bookkeeping attached. The garbage collector does not trace it, meaning it is not told that this address is in use, so it may free the object anyway.

Separately, the form-side unregister logic has a lifecycle gap. Lifecycle here means the stages an object goes through: created, used, and destroyed. After an iframe or document shutdown, the unregister can be skipped, leaving a stale entry in the map. An iframe is a web page embedded inside another web page, like a picture-in-picture window. A stale entry is a record that refers to something that no longer exists.

Once the underlying HTMLFormMcpTool is reclaimed, meaning the garbage collector has freed it, ForEachScriptTool dereferences a dangling pointer. Dereferencing means following the address to read or use the object it points at. The renderer, the part of Chrome that draws pages and runs their code, then hits a use after free, reported under ASan as use-after-poison.

The report is explicit that this is not the same root cause as the recently reported issue 483569512, and that the fix for that issue does not mitigate this one. Root cause means the underlying reason the bug exists, as opposed to a symptom. Mitigate means reduce the impact or prevent the problem.

Exploitation

Step 1: register a declarative tool

A form marked up as a WebMCP tool is registered through ModelContext::RegisterDeclarativeTool, which stores the DeclarativeWebMCPTool* inside a ToolData object:

C++
void ModelContext::RegisterDeclarativeTool(String name,
                                           String description,
                                           DeclarativeWebMCPTool* tool) {
  auto script_tool = mojom::blink::ScriptTool::New();
  auto* tool_data = MakeGarbageCollected<ToolData>();
  script_tool->name = name;
  script_tool->description = description;
  script_tool->input_schema = "{}";  // For now
  tool_data->script_tool = std::move(script_tool);
  tool_data->declarative_tool = tool;

  tool_map_.insert(name, std::move(tool_data));
  OnToolsChanged();
}

Line by line:

  • void ModelContext::RegisterDeclarativeTool(String name, String description, DeclarativeWebMCPTool* tool) { declares a function that takes a tool's name, its description, and a pointer to the declarative tool object. void means it returns nothing. String is a piece of text. The * in DeclarativeWebMCPTool* means "pointer to", so this parameter is a raw address, not the object itself.
  • auto script_tool = mojom::blink::ScriptTool::New(); creates a new ScriptTool object. mojom is the system Chrome uses to describe messages passed between its internal processes, and blink is the part of Chrome that handles web content. auto lets the compiler work out the type for you.
  • auto* tool_data = MakeGarbageCollected<ToolData>(); creates a ToolData object that is managed by the garbage collector. MakeGarbageCollected is the helper that allocates such objects.
  • script_tool->name = name; copies the name into the script tool. The -> means "the member of the object pointed at".
  • script_tool->description = description; copies the description in the same way.
  • script_tool->input_schema = "{}"; // For now sets the input schema to an empty JSON object, {}. JSON is a text format for structured data. The comment // For now says this is a placeholder that will be filled in later.
  • tool_data->script_tool = std::move(script_tool); hands the script tool over to the tool data. std::move transfers ownership rather than copying, which is more efficient.
  • tool_data->declarative_tool = tool; stores the raw pointer to the declarative tool. This is the line at the heart of the bug: a plain address is saved, with no registration with the garbage collector.
  • tool_map_.insert(name, std::move(tool_data)); puts the tool data into the map, filed under its name.
  • OnToolsChanged(); notifies anything listening that the list of tools has changed.

The ToolData itself is garbage collected, but the declarative_tool member is a plain pointer with no GC relationship to the object it points at. In other words, the container is looked after by the cleaner, but the note inside it is invisible to the cleaner.

Step 2: confirm the pointer is untraced

The tracing method for ToolData only visits the V8 tool function:

C++
void ModelContext::ToolData::Trace(Visitor* visitor) const {
  visitor->Trace(v8_tool_function);
}

Line by line:

  • void ModelContext::ToolData::Trace(Visitor* visitor) const { declares the tracing function. const means it does not modify the object. Visitor* is a pointer to a helper object that walks through references.
  • visitor->Trace(v8_tool_function); tells the visitor to mark the V8 tool function as in use. V8 is the JavaScript engine, the part of Chrome that runs JavaScript, the language of web page scripts. Marking it means the collector will not free it.
  • } closes the function.

Because declarative_tool is not traced, the collector has no reason to keep the declarative tool alive for as long as the map entry exists. The cleaner simply does not know the note exists.

Step 3: skip the unregister during shutdown

HTMLFormElement::UpdateMcpDefinitionsIfNeeded returns early when no ModelContext can be found, for example in a detached document with no domWindow() or navigator(). A detached document is a page that is no longer attached to a visible window, for instance because its frame was removed. domWindow() is the function that returns the window object for a document, and navigator() returns the navigator. In that state the unregister path never runs:

C++
ModelContext* model_context = nullptr;
if (auto* window = GetDocument().domWindow(); window && window->navigator()) {
  model_context = ModelContextSupplement::modelContext(*window->navigator());
}
if (!model_context) {
  return;
}

if (IsValidWebMCPForm()) {
  ...
  model_context->unregisterTool(active_webmcp_tool_->ToolName(),
                                ASSERT_NO_EXCEPTION);
  active_webmcp_tool_ = nullptr;
}

Line by line:

  • ModelContext* model_context = nullptr; starts with an empty pointer. nullptr means "points at nothing".
  • if (auto* window = GetDocument().domWindow(); window && window->navigator()) { asks the document for its window, and checks that the window exists and has a navigator. && means "and".
  • model_context = ModelContextSupplement::modelContext(*window->navigator()); fetches the model context attached to the navigator. The * before window->navigator() means "the object the pointer points at".
  • } closes the if block.
  • if (!model_context) { checks whether no model context was found. ! means "not".
  • return; leaves the function immediately. This is the early return: if there is no model context, the rest of the function, including the unregister, is skipped.
  • } closes that check.
  • if (IsValidWebMCPForm()) { checks whether the form is a valid WebMCP form.
  • ... stands for code omitted from the excerpt.
  • model_context->unregisterTool(active_webmcp_tool_->ToolName(), ASSERT_NO_EXCEPTION); removes the tool from the model context, using its name. ASSERT_NO_EXCEPTION says no error should be raised if something goes wrong.
  • active_webmcp_tool_ = nullptr; clears the stored pointer to the active tool.
  • } closes the block.

The map entry survives the shutdown while the object it points at does not. The cleaner frees the form, but the menu still lists it.

Step 4: force collection and enumerate tools

With the entry left behind, garbage collection reclaims the declarative tool object. The next call to listTools() reaches ForEachScriptTool, which refreshes the schema of every entry and dereferences the stale pointer:

C++
void ModelContext::ForEachScriptTool(
    base::FunctionRef<void(const mojom::blink::ScriptTool&)> func) const {
  for (const auto& tool : tool_map_) {
    auto tool_data = tool.value;
    // Always update the input schema, since the DOM might have changed.
    if (auto* declarative_tool = tool_data->declarative_tool) {
      tool_data->script_tool->input_schema =
          declarative_tool->ComputeInputSchema();
    }
    func(*tool_data->script_tool);
  }
}

Line by line:

  • void ModelContext::ForEachScriptTool( begins the function declaration.
  • base::FunctionRef<void(const mojom::blink::ScriptTool&)> func) const { takes a function to call for each tool. FunctionRef is a reference to a function, void says it returns nothing, and const mojom::blink::ScriptTool& is a read-only reference to a script tool. const at the end means the method does not modify the model context.
  • for (const auto& tool : tool_map_) { loops over every entry in the map. const auto& means "a read-only reference to each item, with the type worked out automatically".
  • auto tool_data = tool.value; takes the value stored under the current key.
  • // Always update the input schema, since the DOM might have changed. is a comment explaining why the schema is recalculated. The DOM, short for Document Object Model, is the browser's live model of the page's structure; if the page changed, the schema may be out of date.
  • if (auto* declarative_tool = tool_data->declarative_tool) { fetches the stored pointer and checks it is not null. This is the only check: it confirms the pointer is not empty, but not that it still points at a live object.
  • tool_data->script_tool->input_schema = declarative_tool->ComputeInputSchema(); calls ComputeInputSchema() on the pointer and stores the result. If the object has been freed, this is the use after free.
  • } closes the check.
  • func(*tool_data->script_tool); passes the script tool to the caller's function.
  • } closes the loop.
  • } closes the function.

Running the command from the setup section against the proof of concept page produces the Use-after-Poison crash recorded in the researcher's asan.txt. That file is the text output ASan writes when it catches the bad access.

The full chain is: an untraced raw pointer is stored at registration, a lifecycle edge skips the unregister, the collector reclaims the declarative tool, and listTools() reaches ForEachScriptTool and reads freed memory.

Root cause

The design keeps a raw, untraced pointer to a garbage-collected object inside a garbage-collected container. ToolData::Trace does not visit declarative_tool, so the collector is free to reclaim the tool while the map still references it. The unregister logic in HTMLFormElement::UpdateMcpDefinitionsIfNeeded assumes it will always be able to reach a ModelContext, and the early return when the document is detached breaks that assumption, leaving the stale entry in place. ForEachScriptTool then trusts every non-null declarative_tool pointer and calls ComputeInputSchema() on it without any validity check.

Existing defences did not help. The earlier fix for issue 483569512 addresses a different root cause and, per the report, does not mitigate this issue.

Impact

After an iframe or document shutdown in the state described above, a dangling pointer can be left in the tool map. The next enumeration of tools dereferences freed memory in the renderer, producing a use after free. The report demonstrates the crash under ASan; it does not describe a path to code execution or any other outcome beyond the memory-safety violation. The report notes the bug was reachable in M145 and would ship in the M146 dev trial.

Fix

The suggested fix makes declarative tool lifetime GC-safe at the ToolData boundary and prunes stale entries during iteration. GC-safe means the garbage collector can see and respect the reference, so it will not free the object while it is still needed. Pruning means removing entries that are no longer valid.

  1. Change ToolData::declarative_tool from a raw DeclarativeWebMCPTool* to a GC-traceable handle. A handle is a reference the collector understands, rather than a bare address.
  2. Update ToolData::Trace() to trace declarative tool references, so the collector knows to keep them alive.
  3. Add a defensive guard in ForEachScriptTool to skip and remove entries whose declarative tool is no longer valid before calling ComputeInputSchema(). A guard is a check that stops unsafe work from happening.

Together these stop tool_map_ entries from holding dangling declarative pointers and stop listTools() from dereferencing reclaimed objects.

Variants to test

  • Look for other garbage-collected containers that hold raw pointers to garbage-collected objects without tracing them. A positive result is a Trace method that omits a member which is later dereferenced during iteration or refresh.
  • Audit early returns in lifecycle and unregister code paths, especially those guarded on domWindow() or navigator(). A positive result is a state in which registration has happened but the corresponding unregister is skipped.
  • Exercise iframe and document shutdown while tools or similar registrations are active, then force collection and enumerate. A positive result is a crash under ASan or a stale entry visible in the enumeration output.
  • Check iteration paths that recompute state from the DOM, such as schema refresh, for missing validity checks on cached pointers. A positive result is a dereference of an object that has already been reclaimed.
  • Compare fixes for related advisories against the code they touch. A positive result is a fix that closes one lifecycle gap while leaving a different one, as the report states happened with issue 483569512.

Glossary

  • API: a defined set of functions a program offers so other code can use it.
  • ASan (AddressSanitizer): a tool that watches memory accesses and reports when a program touches memory it should not.
  • Bisection: a technique for finding the change that introduced a bug by repeatedly halving a range of commits.
  • Blink: the part of Chrome that handles web content, such as pages and forms.
  • Bounty: money a company pays to someone who reports a security bug responsibly.
  • Build arguments: settings that control how a program is compiled from source.
  • Class: a blueprint in code for creating objects.
  • Commit: a saved snapshot of a code project, identified by a long string.
  • Const: a keyword meaning a value or function does not modify something.
  • CVE: a public catalogue number for a known security flaw.
  • Dangling pointer: a pointer to memory that has already been freed.
  • Declarative tool: a tool registered by marking up a form, rather than by writing script.
  • Dereference: to follow a pointer and read or use the object it points at.
  • Detached document: a page no longer attached to a visible window.
  • DOM (Document Object Model): the browser's live model of a page's structure.
  • domWindow(): a function that returns the window object for a document.
  • Early return: leaving a function before its remaining steps run.
  • Enumeration: asking for the full list of items, here the registered tools.
  • Flag: a startup switch that changes how a program behaves.
  • Function: a named block of instructions in code.
  • Garbage collector: the part of a program that frees memory nobody is using any more.
  • GC-safe: a reference the garbage collector can see and respect.
  • Guard: a check that stops unsafe work from happening.
  • Handle: a reference the collector understands, rather than a bare address.
  • HTMLFormMcpTool: the object representing a form registered as a WebMCP tool.
  • Iframe: a web page embedded inside another web page.
  • Input schema: a description of what input a tool expects.
  • JSON: a text format for structured data.
  • Lifecycle: the stages an object goes through: created, used, destroyed.
  • Map: a data structure storing values under names, like a dictionary.
  • Milestone: Chrome's numbering for major releases.
  • Mitigate: reduce the impact of or prevent a problem.
  • Model context: the environment through which a page offers tools to an AI model.
  • navigator: a built-in browser object representing the browser itself.
  • Nullptr: a pointer that points at nothing.
  • Pointer: a memory address saying where an object lives.
  • Pruning: removing entries that are no longer valid.
  • Raw pointer: a bare memory address with no extra bookkeeping.
  • Renderer: the part of Chrome that draws pages and runs their code.
  • Root cause: the underlying reason a bug exists, as opposed to a symptom.
  • Sandbox: a security layer restricting what each part of the browser may do.
  • Stale entry: a record referring to something that no longer exists.
  • Trace: to tell the garbage collector that a reference is in use.
  • Unconditional: done without checking first.
  • Use after free: a bug where a program uses memory after giving it back.
  • Use-after-Poison: ASan's report name for touching memory it has marked as freed.
  • V8: the JavaScript engine inside Chrome.
  • VRP (Vulnerability Reward Program): Google's programme paying for responsibly reported bugs.
  • WebMCP: the part of Blink that lets pages offer tools to a model context.

More by Syn4pse

View all

13 more disclosed reports, best first.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.