Use after free in Autofill (CVE-2026-17685)
A use-after-free vulnerability exists in the password generation agent because synchronous JavaScript execution during iteration over a heap-allocated vector can destroy the underlying GenerationItemInfo structure. An attacker could potentially trigger this by manipulating focus and input events to free the vector while it is still being iterated, leading to memory corruption.
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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential Use-After-Free (UAF) vulnerability exists in PasswordGenerationAgent due to synchronous JavaScript execution during iteration over a heap-allocated vector of elements. By triggering a re-entrant focus/text change during password generation, the underlying GenerationItemInfo structure can be destroyed and freed. Resuming the iteration or accessing the elements afterwards results in a use-after-free scenario.
Affected files:
components/autofill/content/renderer/password_generation_agent.cc
Estimated timestamp from git blame: 2018-11-06
Root Cause Analysis
In components/autofill/content/renderer/password_generation_agent.cc, the method PasswordGenerationAgent::GeneratedPasswordAccepted performs an iteration over current_generation_item_->password_elements_ (which is a heap-allocated std::vector<blink::WebInputElement> owned by current_generation_item_):
for (blink::WebInputElement& password_element :
current_generation_item_->password_elements_) {
ScopedUpdatingOtherPasswordFields auto_reset_update_confirmation_password(
this);
password_element.SetAutofillValue(blink::WebString::FromUtf16(password));
// ...
When password_element.SetAutofillValue is called, it can dispatch synchronous events (e.g., keydown/keyup and subsequent DOM events) into the document, allowing untrusted attacker-controlled JavaScript to execute synchronously mid-iteration.
During this synchronous execution window, the attacker can:
- Clear the password element's value, reducing its length below
kMinimumLengthForEditedPassword(4). - Shift focus back to the element, triggering focus/suggestion state updates. This invokes
PasswordNoLongerGenerated(), resettingcurrent_generation_item_->password_is_generated_tofalse. - Shift focus to another password generation-eligible field. This triggers
ShowPasswordGenerationSuggestions()for the new field, invokingMaybeCreateCurrentGenerationItem().
Since current_generation_item_->password_is_generated_ is now false, the re-entrancy guard in MaybeCreateCurrentGenerationItem() is bypassed:
if (current_generation_item_ &&
(current_generation_item_->generation_element_ == generation_element ||
current_generation_item_->password_is_generated_))
return;
This causes the agent to reassign the current_generation_item_ unique pointer:
current_generation_item_ = std::make_unique<GenerationItemInfo>(...);
Reassigning the unique pointer immediately destroys the old GenerationItemInfo, deallocating the underlying std::vector<blink::WebInputElement>. When control returns from JavaScript to the C++ loop in GeneratedPasswordAccepted, the range-for loop's internal iterators/references point to deallocated memory, resulting in a Use-After-Free.
A secondary, identical instance also potentially occurs in CopyElementValueToOtherInputElements() via text-change mirroring, where elements is passed as a reference to current_generation_item_->password_elements_.
Potential Trigger Steps
Note: Since our testing environment is purely static and we cannot run code, the following sequence represents a potential proof-of-concept flow:
- Create a page with two password fields
pwA(Form 1) andpwB(Form 2), both eligible for password generation. - Bind an
inputevent listener topwAin JavaScript. - Accept the generated password suggestion on
pwA, triggeringGeneratedPasswordAccepted(). - In the first loop iteration,
SetAutofillValue()is called onpwA. This triggers the synchronousinputevent listener. - Inside the event listener, the script sets
pwA.value = ''and focuses a helper element, then refocusespwA. - This synchronously dispatches a focus change.
AutofillAgenthandles the focus and callsShowPasswordGenerationSuggestions(pwA). - Seeing the value is empty, the agent calls
PasswordNoLongerGenerated(), settingpassword_is_generated_tofalse. - The script now shifts focus to
pwB. - This triggers
ShowPasswordGenerationSuggestions(pwB). Since the re-entrancy guard checks are bypassed,current_generation_item_is reassigned and the old allocation is freed. - The JavaScript execution completes, and the native stack resumes iteration over the now-deallocated
password_elements_vector.
MiraclePtr / Mitigation Discussion
The dangling iterators and elements are stored within a standard std::vector heap allocation on PartitionAlloc. Because the Use-After-Free occurs on the container's backing buffer itself (and raw iterators used in the range-for loop expansion), this is not mitigated by MiraclePtr.
Suggested Fix
The safest and most robust fix is to use a base::WeakPtr to track the lifetime of GenerationItemInfo and return early if the item is destroyed or replaced during synchronous event dispatch.
In components/autofill/content/renderer/password_generation_agent.cc:
void PasswordGenerationAgent::GeneratedPasswordAccepted(
const std::u16string& password) {
if (!current_generation_item_) {
return;
}
// ...
base::WeakPtr<GenerationItemInfo> generation_item =
current_generation_item_->weak_ptr_factory_.GetWeakPtr();
for (size_t i = 0; i < generation_item->password_elements_.size(); ++i) {
ScopedUpdatingOtherPasswordFields auto_reset_update_confirmation_password(
this);
// We copy the element to a local variable to be safe
blink::WebInputElement password_element = generation_item->password_elements_[i];
password_element.SetAutofillValue(blink::WebString::FromUtf16(password));
// Check if the generation item was replaced or destroyed during synchronous JS
if (!generation_item) {
return;
}
if (!render_frame()) {
return;
}
if (password_element.Value().IsEmpty()) {
return;
}
password_agent_->TrackAutofilledElement(password_element);
}
// ...
This pattern should also be applied to other loops in password_generation_agent.cc that invoke SetAutofillValue or dispatch synchronous events, including CopyElementValueToOtherInputElements and the subsequent UpdateStateForTextChange loop.
Evaluated with Chrome root at commit: b1520ef4a76878853a31f0943b565e42060edec8
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
Data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
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 code iterates over a heap-allocated vector owned by a unique pointer, and synchronous JavaScript execution during the loop can reassign that pointer, freeing the vector while iterators still reference it.
Impact
This could lead to memory corruption, potentially allowing an attacker to execute arbitrary code or cause a denial of service, though the report does not demonstrate a full exploit.
What the attacker needed
Victim visits a malicious page; page has two password fields; user accepts password suggestion
The fix
The fix should use a base::WeakPtr to track the lifetime of GenerationItemInfo and return early if it is destroyed during synchronous event dispatch, and apply this pattern to other similar loops.
How it was found
- Create a page with two password fields, both eligible for password generation.
- Bind an input event listener to the first password field.
- Accept the generated password suggestion on the first field, triggering GeneratedPasswordAccepted().
- In the event listener, clear the first field's value and shift focus to a helper element, then back to the first field.
- Shift focus to the second password field, causing the current generation item to be replaced and the old one freed.
- The native loop resumes iterating over the freed vector.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program frees memory but keeps using it, that's a use-after-free. Here, the browser's password generator loops over a list of password fields, and during that loop, a malicious webpage can run JavaScript that causes the list to be deleted. The loop then continues using the deleted list, which can crash the browser or potentially be exploited.
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.