Skip to content
Memory corruption Advisory Advanced CVE-2025-1916

Use after free in Profiles (CVE-2025-1916)

A use-after-free vulnerability in Google Chrome's profile picker allows a remote attacker who convinces a user to install a malicious extension to potentially exploit heap corruption via a crafted HTML page. The flaw arises because a callback holds a raw pointer to a handler object that may be freed before the callback runs.

parkminchan Follow

Originally disclosed on Chrome VRP

Bounty$3,000 Medium View original
  • Fix shipped in 4 months

Summary

Use after free in Profiles in Google Chrome allows a remote attacker who convinced a user to install a malicious extension to potentially exploit heap corruption via a crafted HTML page.


Reproduction Case

  1. For ease of reproduction, Apply patch.diff.
  2. Press the UI button to open the Chromium Profile Management window.
  3. Open a new tab, move to chrome://profile-picker, type chrome.send("continueWithoutAccount", [0]); into the DevTools's console, and close the tab.

Root Cause Analysis

chrome/browser/ui/webui/signin/profile_picker_handler.cc

C++
void ProfilePickerHandler::HandleContinueWithoutAccount(
    const base::Value::List& args) {
  CHECK_EQ(1U, args.size());

  // profileColor is undefined for the default theme.
  std::optional<SkColor> profile_color;
  if (args[0].is_int())
    profile_color = args[0].GetInt();

  RecordProfilePickerAction(ProfilePickerAction::kLaunchNewProfile);
  ProfileMetrics::LogProfileAddNewUser(
      ProfileMetrics::ADD_NEW_PROFILE_PICKER_LOCAL);
  ProfilePicker::SwitchToSignedOutPostIdentityFlow(
      profile_color, profile_picked_time_on_startup_,
      base::BindOnce(
          &ProfilePickerHandler::OnProfileCreationFinished,
          // `OnProfileCreationFinished` is called when we want to close the
          // profile picker. `ProfilePickerHandler` will always be initialized
          // when we get to that call because the picker will still be open.
          base::Unretained(this))); // [0]
}
  • [0],HandleContinueWithoutAccount function transfers the ProfilePickerHandler::OnProfileCreationFinished function bound by the this pointer to the ProfilePicker::SwitchToSignedOutPostIdentityFlow function as a callback param.

chrome/browser/ui/views/profiles/profile_picker_view.cc

C++
void ProfilePicker::SwitchToSignedOutPostIdentityFlow(
    std::optional<SkColor> profile_color,
    base::TimeTicks profile_picked_time_on_startup,
    base::OnceCallback<void(bool)> switch_finished_callback) {
  if (g_profile_picker_view) {
    g_profile_picker_view->SwitchToSignedOutPostIdentityFlow(
        profile_color, profile_picked_time_on_startup,
        std::move(switch_finished_callback)); // [1]
  }
}
  • [1], In order to execute the g_profile_picker_view->SwitchToSignedOutPostIdentityFlow functions, the value of the g_profile_picker_view pointer must be set in a normal flow.

  • It is possible to create a complete chain that does not require user gestures by utilizing a chrome extension, but for simple proof, it is replaced by pressing a button directly to open the Chromium Profile Management window.

chrome/browser/profiles/profile_manager.cc

C++
void ProfileManager::CreateMultiProfileAsync(
    const std::u16string& name,
    size_t icon_index,
    bool is_hidden,
    base::OnceCallback<void(Profile*)> initialized_callback,
    base::OnceCallback<void(Profile*)> created_callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  DCHECK(!name.empty());
  DCHECK(profiles::IsDefaultAvatarIconIndex(icon_index));

  ProfileManager* profile_manager = g_browser_process->profile_manager();

  ProfileAttributesStorage& storage =
      profile_manager->GetProfileAttributesStorage();
  base::FilePath new_path;
  ProfileAttributesEntry* entry = nullptr;

  do {
    new_path = profile_manager->GenerateNextProfileDirectoryPath();
    // The generated path should be unused and free to use.
    DCHECK_EQ(profile_manager->GetProfileByPath(new_path), nullptr);
    DCHECK(profile_manager->CanCreateProfileAtPath(new_path));

    entry = storage.GetProfileAttributesWithPath(new_path);
  } while (entry != nullptr);

  ProfileAttributesInitParams init_params;
  init_params.profile_path = new_path;
  init_params.profile_name = name;
  init_params.icon_index = icon_index;
  init_params.is_ephemeral = is_hidden;
  init_params.is_omitted = is_hidden;
  storage.AddProfile(std::move(init_params));

  base::ThreadPool::PostTask(
      FROM_HERE,
      {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
       base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
      base::BindOnce(&NukeProfileFromDisk, new_path,
                     base::BindOnce(&ProfileManager::CreateProfileAsync,
                                    profile_manager->weak_factory_.GetWeakPtr(),
                                    new_path, std::move(initialized_callback),
                                    std::move(created_callback)))); // [2]
}
  • [2], The callback function delivered in [0] was executed within the initialized_callback function, and it was posted to the thread pool to asynchronously process tasks.

content/browser/webui/web_ui_message_handler.cc

C++
bool WebUIMessageHandler::IsJavascriptAllowed() {
  return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); // [3]
}
  • [3], the ProfilePickerHandler::OnProfileCreationFinished function posted in the thread pool is called back, and UAF occurs by referring to the javascript_allowed_ variable of WebUIMessageHandler that has already been freed within the function.

Bisect

https://source.chromium.org/chromium/chromium/src/+/4dd469427e8a336a1ca52f9a523b78785bbdb897

  • In the process of reorganizing the function ProfilePickerHandler::HandleCreateProfileAndOpenCustomizationDialog to HandleContinueWithoutAccount, consideration of the lifetime of the object was omitted.

Recommended Patch

chrome/browser/ui/webui/signin/profile_picker_handler.h

C++
class ProfilePickerHandler : public content::WebUIMessageHandler,
                             public content::WebContentsObserver,
#if BUILDFLAG(IS_CHROMEOS_LACROS)
                             public AccountProfileMapper::Observer,
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
                             public ProfileAttributesStorage::Observer {
...

  base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this};
};
  • weak_factory_ has already been declared within the ProfilePickerHandler class.

fix.diff

Diff
--- a/chrome/browser/ui/webui/signin/profile_picker_handler.cc	
+++ b/chrome/browser/ui/webui/signin/profile_picker_handler.cc	
@@ -617,7 +617,7 @@
           // `OnProfileCreationFinished` is called when we want to close the
           // profile picker. `ProfilePickerHandler` will always be initialized
           // when we get to that call because the picker will still be open.
-          base::Unretained(this)));
+          weak_factory_.GetWeakPtr()));
 }

 void ProfilePickerHandler::HandleGetSwitchProfile(
  • UAF can be prevented by modifying the existing base::Unretained(this) to weak_factory_.GetWeakPtr() to verify that the object of the callback function is valid.

It is dangerous because an attacker can use Extension to create PoCs that do not require separate user gestures.


Version

131.0.6776.0

Credit

parkminchan, working for SSD Labs Korea.

The original report as published on the Chromium issue tracker, by parkminchan, SSD Labs Korea. 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. 5 min read.

Context

Google Chrome's profile management UI includes a profile picker, a WebUI page served at chrome://profile-picker. The picker lets a user create a new profile, including the option to continue without signing in to a Google account. The front end of that page talks to browser-side code through a content::WebUIMessageHandler subclass, ProfilePickerHandler, which receives messages such as continueWithoutAccount and drives the profile creation flow.

This report describes a use after free in that flow, tracked as CVE-2025-1916, rated medium severity and disclosed on 4 March 2025. The researcher is parkminchan of SSD Labs Korea, and the Chrome VRP awarded a bounty of 3000 USD. The version listed in the report is 131.0.6776.0.

Setup

No accounts or special roles are needed. The reproduction uses a local Chrome build and DevTools. The researcher notes that a full chain can be built with a Chrome extension so that no user gesture is required, but for a simple proof the profile management window is opened by pressing a UI button directly.

The report also asks the reader to apply patch.diff first, for ease of reproduction. The contents of that patch are not included in the report.

Finding it

The handler passes a callback bound with base::Unretained(this) into an asynchronous flow. Because the callback can outlive the handler, the bound raw pointer can be dereferenced after the handler has been freed. The bisect points to the commit where ProfilePickerHandler::HandleCreateProfileAndOpenCustomizationDialog was reorganised into HandleContinueWithoutAccount, a change that omitted consideration of the object's lifetime.

Exploitation

Step 1: open the profile management window

Press the UI button that opens the Chromium Profile Management window. This sets the g_profile_picker_view pointer that the later call chain depends on.

Step 2: trigger the message from the picker page

Open a new tab, navigate to chrome://profile-picker, and run the following in the DevTools console:

JavaScript
chrome.send("continueWithoutAccount", [0]);

Then close the tab. The message invokes ProfilePickerHandler::HandleContinueWithoutAccount with a single integer argument, which is used as the profile colour. Then close the tab.

Step 3: the callback fires on a freed handler

The profile creation work is posted to the thread pool. When it completes, the callback that was bound with base::Unretained(this) runs and reaches WebUIMessageHandler::IsJavascriptAllowed, which reads javascript_allowed_ on the already freed handler. That read is the use after free.

Root cause

The chain starts in chrome/browser/ui/webui/signin/profile_picker_handler.cc:

C++
void ProfilePickerHandler::HandleContinueWithoutAccount(
    const base::Value::List& args) {
  CHECK_EQ(1U, args.size());

  // profileColor is undefined for the default theme.
  std::optional<SkColor> profile_color;
  if (args[0].is_int())
    profile_color = args[0].GetInt();

  RecordProfilePickerAction(ProfilePickerAction::kLaunchNewProfile);
  ProfileMetrics::LogProfileAddNewUser(
      ProfileMetrics::ADD_NEW_PROFILE_PICKER_LOCAL);
  ProfilePicker::SwitchToSignedOutPostIdentityFlow(
      profile_color, profile_picked_time_on_startup_,
      base::BindOnce(
          &ProfilePickerHandler::OnProfileCreationFinished,
          // `OnProfileCreationFinished` is called when we want to close the
          // profile picker. `ProfilePickerHandler` will always be initialized
          // when we get to that call because the picker will still be open.
          base::Unretained(this))); // [0]
}

HandleContinueWithoutAccount transfers ProfilePickerHandler::OnProfileCreationFinished, bound with the this pointer, to ProfilePicker::SwitchToSignedOutPostIdentityFlow as a callback parameter. The comment in the code assumes the picker will still be open when the callback runs.

The call is forwarded in chrome/browser/ui/views/profiles/profile_picker_view.cc:

C++
void ProfilePicker::SwitchToSignedOutPostIdentityFlow(
    std::optional<SkColor> profile_color,
    base::TimeTicks profile_picked_time_on_startup,
    base::OnceCallback<void(bool)> switch_finished_callback) {
  if (g_profile_picker_view) {
    g_profile_picker_view->SwitchToSignedOutPostIdentityFlow(
        profile_color, profile_picked_time_on_startup,
        std::move(switch_finished_callback)); // [1]
  }
}

For this to run, the value of the g_profile_picker_view pointer must be set in a normal flow, which is why the profile management window is opened first.

The asynchronous part is in chrome/browser/profiles/profile_manager.cc:

C++
void ProfileManager::CreateMultiProfileAsync(
    const std::u16string& name,
    size_t icon_index,
    bool is_hidden,
    base::OnceCallback<void(Profile*)> initialized_callback,
    base::OnceCallback<void(Profile*)> created_callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  DCHECK(!name.empty());
  DCHECK(profiles::IsDefaultAvatarIconIndex(icon_index));

  ProfileManager* profile_manager = g_browser_process->profile_manager();

  ProfileAttributesStorage& storage =
      profile_manager->GetProfileAttributesStorage();
  base::FilePath new_path;
  ProfileAttributesEntry* entry = nullptr;

  do {
    new_path = profile_manager->GenerateNextProfileDirectoryPath();
    // The generated path should be unused and free to use.
    DCHECK_EQ(profile_manager->GetProfileByPath(new_path), nullptr);
    DCHECK(profile_manager->CanCreateProfileAtPath(new_path));

    entry = storage.GetProfileAttributesWithPath(new_path);
  } while (entry != nullptr);

  ProfileAttributesInitParams init_params;
  init_params.profile_path = new_path;
  init_params.profile_name = name;
  init_params.icon_index = icon_index;
  init_params.is_ephemeral = is_hidden;
  init_params.is_omitted = is_hidden;
  storage.AddProfile(std::move(init_params));

  base::ThreadPool::PostTask(
      FROM_HERE,
      {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
       base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
      base::BindOnce(&NukeProfileFromDisk, new_path,
                     base::BindOnce(&ProfileManager::CreateProfileAsync,
                                    profile_manager->weak_factory_.GetWeakPtr(),
                                    new_path, std::move(initialized_callback),
                                    std::move(created_callback)))); // [2]
}

The callback delivered in [0] is executed within the initialized_callback, and the work is posted to the thread pool for asynchronous processing. When it runs, ProfilePickerHandler::OnProfileCreationFinished is called back and reaches content/browser/webui/web_ui_message_handler.cc:

C++
bool WebUIMessageHandler::IsJavascriptAllowed() {
  return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); // [3]
}

At that point the handler has already been freed, so reading javascript_allowed_ is a use after free.

Impact

The report states that the bug allows a remote attacker who has convinced a user to install a malicious extension to potentially exploit heap corruption via a crafted HTML page. The researcher stresses that an attacker can use an extension to build proofs of concept that do not require separate user gestures, which makes the bug dangerous. The platform rates the issue medium severity.

Fix

The recommended patch replaces the raw pointer binding with a weak pointer. weak_factory_ is already declared within the ProfilePickerHandler class:

C++
class ProfilePickerHandler : public content::WebUIMessageHandler,
                             public content::WebContentsObserver,
#if BUILDFLAG(IS_CHROMEOS_LACROS)
                             public AccountProfileMapper::Observer,
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
                             public ProfileAttributesStorage::Observer {
...

  base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this};
};

The change in fix.diff is a single line:

Diff
--- a/chrome/browser/ui/webui/signin/profile_picker_handler.cc
+++ b/chrome/browser/ui/webui/signin/profile_picker_handler.cc
@@ -617,7 +617,7 @@
           // `OnProfileCreationFinished` is called when we want to close the
           // profile picker. `ProfilePickerHandler` will always be initialized
           // when we get to that call because the picker will still be open.
-          base::Unretained(this)));
+          weak_factory_.GetWeakPtr()));
 }

 void ProfilePickerHandler::HandleGetSwitchProfile(

Replacing base::Unretained(this) with weak_factory_.GetWeakPtr() lets the callback verify that the object is still valid, which prevents the use after free.

Variants to test

  1. Audit other WebUIMessageHandler subclasses for callbacks bound with base::Unretained(this) that are passed into asynchronous work, such as thread pool tasks or profile creation. A positive result is a path where the WebUI can be closed, for example by closing the tab, before the callback runs.
  2. Look at refactors that rename or reorganise a handler method, as happened with HandleCreateProfileAndOpenCustomizationDialog becoming HandleContinueWithoutAccount. A positive result is a new asynchronous callback whose lifetime assumptions were carried over from the old synchronous flow without rechecking.
  3. Exercise WebUI messages that take arguments from the page, such as the integer colour in continueWithoutAccount, and close the page immediately after sending them. A positive result is a crash or sanitizer report in IsJavascriptAllowed or another member read on the freed handler.
  4. Check whether the same flow can be reached from an extension without a user gesture, as the report suggests. A positive result is a proof of concept that triggers the callback after the handler is gone without any click.

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. 16 min read.

What happened, in plain words

Google Chrome lets you keep several separate profiles, each with its own bookmarks, history and settings. When you open the profile management screen, Chrome shows a small web page called the profile picker. That page is not on the internet: it is built into the browser and lives at the address chrome://profile-picker. It offers, among other things, a button to create a new profile without signing in to a Google account.

A web page inside the browser cannot change browser settings by itself. It sends short messages to browser-side code, and that code does the real work. In this case the receiving code is a class called ProfilePickerHandler. One of the messages it understands is continueWithoutAccount.

This report describes a bug in that message flow, tracked as CVE-2025-1916. It is a use after free, which means the program keeps using a piece of memory after it has already given that memory back. The bug was rated medium severity and disclosed on 4 March 2025. The researcher is parkminchan of SSD Labs Korea, and the Chrome VRP (Chrome's bug bounty programme) paid a bounty of 3000 USD. The version listed in the report is 131.0.6776.0.

Context

Chrome's profile management screen is a WebUI page. WebUI is Chrome's name for its own built-in pages, such as settings or the profile picker, which are written with web technology (HTML, JavaScript) but run inside the browser with special powers. The page at chrome://profile-picker lets a user create a new profile, including the option to continue without signing in to a Google account.

The front end of that page talks to browser-side code through a content::WebUIMessageHandler subclass. A subclass is a class built on top of another class, inheriting its behaviour and adding its own. WebUIMessageHandler is the base class Chrome provides for "the code on the browser side that receives messages from a WebUI page". The subclass here is ProfilePickerHandler, and it receives messages such as continueWithoutAccount and drives the profile creation flow.

Think of the WebUI page as a customer at a counter and the message handler as the clerk behind it. The customer cannot walk into the back room; they hand a written request to the clerk, and the clerk does the work. If the clerk leaves the counter while a request is still being processed, anything that later tries to hand results back to that clerk is talking to nobody.

Setup

No accounts or special roles are needed. The reproduction uses a local Chrome build and DevTools. DevTools is the set of developer tools built into Chrome, opened with F12 or Ctrl+Shift+I, which includes a console where you can type JavaScript and run it on the current page.

The researcher notes that a full chain can be built with a Chrome extension so that no user gesture is required. A Chrome extension is a small add-on installed into the browser; once installed, its code can act on its own, without the user clicking anything. A user gesture is a deliberate action by the user, such as a click or a key press. For a simple proof, though, the profile management window is opened by pressing a UI button directly.

The report also asks the reader to apply patch.diff first, for ease of reproduction. The contents of that patch are not included in the report.

Finding it

The researcher traced the continueWithoutAccount message from the WebUI handler into the profile creation code. Tracing means following the path a request takes through the code, function by function, to see where it ends up.

Along that path the researcher noticed that the handler passes a callback bound with base::Unretained(this) into an asynchronous flow. Two ideas need unpacking here.

  • A callback is a function you hand to someone else, to be run later when some work finishes. Like leaving your phone number at a repair shop: you are not waiting at the counter, but they will call you when the job is done.
  • Asynchronous means the work does not finish immediately. The program starts it, moves on, and comes back to it later. Creating a profile involves writing files to disk, which takes time, so it is done in the background.
  • base::Unretained(this) is Chrome's way of saying "when you call this callback later, use this object, and do not check whether it still exists". this means "the current object", here the ProfilePickerHandler. "Unretained" means nothing keeps the object alive on the callback's behalf.

Because the callback can outlive the handler, the bound raw pointer can be dereferenced after the handler has been freed. A raw pointer is just a memory address with no safety net; dereferencing it means reading or writing the memory it points at. If that memory has been freed and possibly reused, the result is unpredictable, which is why this class of bug can lead to heap corruption. The heap is the region of memory a program uses for objects it creates while running.

The bisect points to the commit where ProfilePickerHandler::HandleCreateProfileAndOpenCustomizationDialog was reorganised into HandleContinueWithoutAccount. A bisect is a search through the project's history, halving the range each time, to find the exact change that introduced a bug. A commit is one recorded change to the code. The reorganisation omitted consideration of the object's lifetime.

Exploitation

Step 1: open the profile management window

Press the UI button that opens the Chromium Profile Management window. This sets the g_profile_picker_view pointer that the later call chain depends on. A pointer is a variable that holds the address of an object; g_profile_picker_view is a global variable (the g_ prefix is a naming convention for globals) that points at the profile picker window. If that window was never opened, the pointer is empty and the later code does nothing.

Step 2: trigger the message from the picker page

Open a new tab, navigate to chrome://profile-picker, and run the following in the DevTools console:

JavaScript
chrome.send("continueWithoutAccount", [0]);

Line by line:

  • chrome.send is the function a WebUI page uses to send a message to its browser-side handler. It takes the message name and a list of arguments.
  • "continueWithoutAccount" is the name of the message. It matches the handler function HandleContinueWithoutAccount on the browser side.
  • [0] is the argument list, containing a single number, zero. That number is used as the profile colour.

Then close the tab. The message invokes ProfilePickerHandler::HandleContinueWithoutAccount with a single integer argument, which is used as the profile colour. Then close the tab. This is the key move: the clerk leaves the counter before the job is finished.

Step 3: the callback fires on a freed handler

The profile creation work is posted to the thread pool. A thread pool is a set of background workers the program can hand tasks to, so that slow work does not block the rest of the browser. When the work completes, the callback that was bound with base::Unretained(this) runs and reaches WebUIMessageHandler::IsJavascriptAllowed, which reads javascript_allowed_ on the already freed handler. That read is the use after free.

javascript_allowed_ is a member variable, a piece of data stored inside the handler object, recording whether the page is currently allowed to receive JavaScript calls. Reading it after the object was freed means reading memory that no longer belongs to this object.

Root cause

The chain starts in chrome/browser/ui/webui/signin/profile_picker_handler.cc:

C++
void ProfilePickerHandler::HandleContinueWithoutAccount(
    const base::Value::List& args) {
  CHECK_EQ(1U, args.size());

  // profileColor is undefined for the default theme.
  std::optional<SkColor> profile_color;
  if (args[0].is_int())
    profile_color = args[0].GetInt();

  RecordProfilePickerAction(ProfilePickerAction::kLaunchNewProfile);
  ProfileMetrics::LogProfileAddNewUser(
      ProfileMetrics::ADD_NEW_PROFILE_PICKER_LOCAL);
  ProfilePicker::SwitchToSignedOutPostIdentityFlow(
      profile_color, profile_picked_time_on_startup_,
      base::BindOnce(
          &ProfilePickerHandler::OnProfileCreationFinished,
          // `OnProfileCreationFinished` is called when we want to close the
          // profile picker. `ProfilePickerHandler` will always be initialized
          // when we get to that call because the picker will still be open.
          base::Unretained(this))); // [0]
}

Line by line:

  • void ProfilePickerHandler::HandleContinueWithoutAccount( starts the function that handles the message. const base::Value::List& args is the list of arguments sent from the page.
  • CHECK_EQ(1U, args.size()); stops the program if the list does not contain exactly one argument. 1U means the number one as an unsigned integer.
  • std::optional<SkColor> profile_color; declares a variable that may or may not hold a colour. SkColor is a colour type. std::optional is a wrapper meaning "a value, or nothing".
  • if (args[0].is_int()) checks whether the first argument is an integer.
  • profile_color = args[0].GetInt(); stores that integer as the colour.
  • RecordProfilePickerAction(...) and ProfileMetrics::LogProfileAddNewUser(...) record usage statistics for the action of launching a new profile.
  • ProfilePicker::SwitchToSignedOutPostIdentityFlow( calls the function that starts the profile creation flow, passing the colour, the time the picker was opened, and a callback.
  • base::BindOnce( prepares a callback to be run exactly once.
  • &ProfilePickerHandler::OnProfileCreationFinished, is the function to run when the work finishes.
  • base::Unretained(this))); // [0] attaches the current handler object to the callback without any lifetime protection. The marker [0] is the report's label for this line.

The comment in the code assumes the picker will still be open when the callback runs. HandleContinueWithoutAccount transfers ProfilePickerHandler::OnProfileCreationFinished, bound with the this pointer, to ProfilePicker::SwitchToSignedOutPostIdentityFlow as a callback parameter.

The call is forwarded in chrome/browser/ui/views/profiles/profile_picker_view.cc:

C++
void ProfilePicker::SwitchToSignedOutPostIdentityFlow(
    std::optional<SkColor> profile_color,
    base::TimeTicks profile_picked_time_on_startup,
    base::OnceCallback<void(bool)> switch_finished_callback) {
  if (g_profile_picker_view) {
    g_profile_picker_view->SwitchToSignedOutPostIdentityFlow(
        profile_color, profile_picked_time_on_startup,
        std::move(switch_finished_callback)); // [1]
  }
}

Line by line:

  • The function takes the colour, a timestamp (base::TimeTicks is a point in time measured by the system clock), and switch_finished_callback, which is the callback to run when the switch finishes. base::OnceCallback<void(bool)> means a callback that can be run once and takes a true/false argument.
  • if (g_profile_picker_view) { checks that the profile picker window exists.
  • g_profile_picker_view->SwitchToSignedOutPostIdentityFlow( forwards the same call to the window object.
  • std::move(switch_finished_callback) hands the callback over to the next function. std::move is a C++ way of saying "I am done with this; pass it on".

For this to run, the value of the g_profile_picker_view pointer must be set in a normal flow, which is why the profile management window is opened first.

The asynchronous part is in chrome/browser/profiles/profile_manager.cc:

C++
void ProfileManager::CreateMultiProfileAsync(
    const std::u16string& name,
    size_t icon_index,
    bool is_hidden,
    base::OnceCallback<void(Profile*)> initialized_callback,
    base::OnceCallback<void(Profile*)> created_callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  DCHECK(!name.empty());
  DCHECK(profiles::IsDefaultAvatarIconIndex(icon_index));

  ProfileManager* profile_manager = g_browser_process->profile_manager();

  ProfileAttributesStorage& storage =
      profile_manager->GetProfileAttributesStorage();
  base::FilePath new_path;
  ProfileAttributesEntry* entry = nullptr;

  do {
    new_path = profile_manager->GenerateNextProfileDirectoryPath();
    // The generated path should be unused and free to use.
    DCHECK_EQ(profile_manager->GetProfileByPath(new_path), nullptr);
    DCHECK(profile_manager->CanCreateProfileAtPath(new_path));

    entry = storage.GetProfileAttributesWithPath(new_path);
  } while (entry != nullptr);

  ProfileAttributesInitParams init_params;
  init_params.profile_path = new_path;
  init_params.profile_name = name;
  init_params.icon_index = icon_index;
  init_params.is_ephemeral = is_hidden;
  init_params.is_omitted = is_hidden;
  storage.AddProfile(std::move(init_params));

  base::ThreadPool::PostTask(
      FROM_HERE,
      {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
       base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
      base::BindOnce(&NukeProfileFromDisk, new_path,
                     base::BindOnce(&ProfileManager::CreateProfileAsync,
                                    profile_manager->weak_factory_.GetWeakPtr(),
                                    new_path, std::move(initialized_callback),
                                    std::move(created_callback)))); // [2]
}

Line by line:

  • void ProfileManager::CreateMultiProfileAsync( starts the function that creates a new profile in the background. Async in the name signals that it does not finish before returning.
  • const std::u16string& name, is the profile name as a UTF-16 string (a string type that can hold characters beyond plain ASCII).
  • size_t icon_index, is which avatar icon to use, as a number.
  • bool is_hidden, says whether the profile is hidden from the picker.
  • base::OnceCallback<void(Profile*)> initialized_callback, and created_callback are two callbacks to run at two stages of creation, each receiving a pointer to the new profile.
  • DCHECK_CURRENTLY_ON(BrowserThread::UI); is a debug-only check that this runs on the browser's main UI thread. A thread is one line of execution inside a program; the UI thread is the one that handles the interface.
  • DCHECK(!name.empty()); checks the name is not empty.
  • DCHECK(profiles::IsDefaultAvatarIconIndex(icon_index)); checks the icon number is a valid default avatar.
  • ProfileManager* profile_manager = g_browser_process->profile_manager(); fetches the global profile manager object.
  • ProfileAttributesStorage& storage = profile_manager->GetProfileAttributesStorage(); gets the storage that holds profile metadata (name, icon, and so on).
  • base::FilePath new_path; declares a variable for the new profile's folder path.
  • ProfileAttributesEntry* entry = nullptr; declares a pointer to a profile entry, initially empty (nullptr).
  • The do { ... } while (entry != nullptr); loop generates a new folder path and repeats until it finds one that is not already in use. DCHECK_EQ(profile_manager->GetProfileByPath(new_path), nullptr); checks no profile exists at that path, and DCHECK(profile_manager->CanCreateProfileAtPath(new_path)); checks a profile can be created there.
  • ProfileAttributesInitParams init_params; builds the settings for the new profile: path, name, icon, and whether it is ephemeral and omitted (both set from is_hidden).
  • storage.AddProfile(std::move(init_params)); saves those settings.
  • base::ThreadPool::PostTask( hands a task to the thread pool.
  • FROM_HERE, records where the task was posted from, for debugging.
  • {base::MayBlock(), base::TaskPriority::USER_BLOCKING, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, are task options: the task may block (wait on disk), it has user-blocking priority (it matters to the user), and it may be skipped if the browser is shutting down.
  • base::BindOnce(&NukeProfileFromDisk, new_path, prepares a task that first removes any leftover profile data at the new path.
  • base::BindOnce(&ProfileManager::CreateProfileAsync, then prepares the actual profile creation.
  • profile_manager->weak_factory_.GetWeakPtr(), passes a weak pointer to the profile manager. A weak pointer does not keep an object alive; it becomes empty if the object is destroyed, so the callback can check whether the object still exists. This is the safe pattern, and it is used here for the profile manager.
  • new_path, std::move(initialized_callback), std::move(created_callback)))); // [2] passes the path and the two callbacks along. The marker [2] labels this line.

The callback delivered in [0] is executed within the initialized_callback, and the work is posted to the thread pool for asynchronous processing. When it runs, ProfilePickerHandler::OnProfileCreationFinished is called back and reaches content/browser/webui/web_ui_message_handler.cc:

C++
bool WebUIMessageHandler::IsJavascriptAllowed() {
  return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); // [3]
}

Line by line:

  • bool WebUIMessageHandler::IsJavascriptAllowed() { starts a function that answers the question "may the page receive JavaScript calls right now?".
  • return javascript_allowed_ && web_ui() && web_ui()->CanCallJavascript(); checks three things in order: the flag javascript_allowed_ is true, the handler still has a web_ui() object, and that object says JavaScript can be called. && means "and", and it stops at the first false value.
  • The marker [3] labels this line.

At that point the handler has already been freed, so reading javascript_allowed_ is a use after free.

Impact

The report states that the bug allows a remote attacker who has convinced a user to install a malicious extension to potentially exploit heap corruption via a crafted HTML page. In plain terms: the attacker is not sitting at the machine, but can reach the user through a web page and an add-on the user installs. Heap corruption means memory used for objects gets damaged.

The researcher stresses that an attacker can use an extension to build proofs of concept that do not require separate user gestures, which makes the bug dangerous. A proof of concept is a minimal demonstration that a bug is real. The platform rates the issue medium severity.

Fix

The recommended patch replaces the raw pointer binding with a weak pointer. weak_factory_ is already declared within the ProfilePickerHandler class:

C++
class ProfilePickerHandler : public content::WebUIMessageHandler,
                             public content::WebContentsObserver,
#if BUILDFLAG(IS_CHROMEOS_LACROS)
                             public AccountProfileMapper::Observer,
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
                             public ProfileAttributesStorage::Observer {
...

  base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this};
};

Line by line:

  • class ProfilePickerHandler : public content::WebUIMessageHandler, declares the class and says it inherits from WebUIMessageHandler.
  • public content::WebContentsObserver, means it also inherits from WebContentsObserver, a class that lets code watch a tab's contents.
  • The #if BUILDFLAG(IS_CHROMEOS_LACROS) block adds another base class, AccountProfileMapper::Observer, only on ChromeOS Lacros builds. #if is a preprocessor directive: the code inside is included only when the condition holds.
  • public ProfileAttributesStorage::Observer { adds a final base class that lets the handler watch profile metadata changes.
  • ... stands for code omitted from the snippet.
  • base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this}; is the member that produces weak pointers to this handler. It already existed, so the fix can use it.

The change in fix.diff is a single line:

Diff
--- a/chrome/browser/ui/webui/signin/profile_picker_handler.cc
+++ b/chrome/browser/ui/webui/signin/profile_picker_handler.cc
@@ -617,7 +617,7 @@
           // `OnProfileCreationFinished` is called when we want to close the
           // profile picker. `ProfilePickerHandler` will always be initialized
           // when we get to that call because the picker will still be open.
-          base::Unretained(this)));
+          weak_factory_.GetWeakPtr()));
 }

 void ProfilePickerHandler::HandleGetSwitchProfile(

Line by line:

  • The --- and +++ lines name the file before and after the change.
  • @@ -617,7 +617,7 @@ says the change is around line 617, with seven lines of context on each side.
  • The three lines starting with a space are unchanged context: the comment explaining the old assumption.
  • The line starting with - is removed: base::Unretained(this)));.
  • The line starting with + is added: weak_factory_.GetWeakPtr()));.
  • The remaining lines are more unchanged context, showing the next function.

Replacing base::Unretained(this) with weak_factory_.GetWeakPtr() lets the callback verify that the object is still valid, which prevents the use after free. If the handler has been destroyed, the weak pointer is empty and the callback does nothing instead of touching freed memory.

Variants to test

  1. Audit other WebUIMessageHandler subclasses for callbacks bound with base::Unretained(this) that are passed into asynchronous work, such as thread pool tasks or profile creation. A positive result is a path where the WebUI can be closed, for example by closing the tab, before the callback runs.
  2. Look at refactors that rename or reorganise a handler method, as happened with HandleCreateProfileAndOpenCustomizationDialog becoming HandleContinueWithoutAccount. A positive result is a new asynchronous callback whose lifetime assumptions were carried over from the old synchronous flow without rechecking.
  3. Exercise WebUI messages that take arguments from the page, such as the integer colour in continueWithoutAccount, and close the page immediately after sending them. A positive result is a crash or sanitizer report in IsJavascriptAllowed or another member read on the freed handler.
  4. Check whether the same flow can be reached from an extension without a user gesture, as the report suggests. A positive result is a proof of concept that triggers the callback after the handler is gone without any click.

Glossary

  • Asynchronous: work that is started now but finishes later, while the program carries on with other things.
  • Bisect: a search through code history that halves the range each time to find the change that introduced a bug.
  • Callback: a function handed to other code to be run later, when some work finishes.
  • Chrome extension: a small add-on installed into Chrome that can run its own code inside the browser.
  • Commit: one recorded change to a codebase.
  • CVE: a public identifier for a known security vulnerability.
  • Dereference: read or write the memory that a pointer points at.
  • DevTools: the developer tools built into Chrome, including a console for running JavaScript on the current page.
  • Heap: the region of memory a program uses for objects created while it runs.
  • Heap corruption: damage to that memory, which can make a program misbehave or run attacker-controlled code.
  • Member variable: a piece of data stored inside an object.
  • Pointer: a variable holding the memory address of an object.
  • Proof of concept: a minimal demonstration that a bug is real and reachable.
  • Raw pointer: a pointer with no safety net; nothing checks whether the object it points at still exists.
  • Refactor: reorganising code without changing what it is meant to do.
  • Subclass: a class built on top of another class, inheriting its behaviour and adding its own.
  • Thread: one line of execution inside a program.
  • Thread pool: a set of background workers that tasks can be handed to, so slow work does not block the interface.
  • UI thread: the thread that handles the browser's interface.
  • Use after free: using memory after the program has already given it back, which can lead to crashes or worse.
  • User gesture: a deliberate action by the user, such as a click or key press.
  • Weak pointer: a pointer that does not keep an object alive and becomes empty if the object is destroyed, so code can check safely.
  • WebUI: Chrome's name for its own built-in pages, written with web technology but running inside the browser with special powers.

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.