From 3ccb7540c0103a72db7cadc6aa7737ae60239705 Mon Sep 17 00:00:00 2001 From: Narfinger Date: Sat, 27 Sep 2025 23:46:17 +0200 Subject: [PATCH] net: Do not send `data` scheme requests to DevTools (#39318) Simple check to not send data urls to devtools. Testing: Looked at reddit.com which sends data url and tested it with this fix. Fixes: Should fix https://github.com/servo/servo/issues/39127. --------- Signed-off-by: Narfinger Co-authored-by: Martin Robinson --- components/net/fetch/methods.rs | 1 - components/net/http_loader.rs | 8 ++++++++ components/shared/devtools/lib.rs | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index b77960fc772..84fdf79cb2f 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -260,7 +260,6 @@ pub async fn main_fetch( ) -> Response { // Step 1: Let request be fetchParam's request. let request = &mut fetch_params.request; - // send early HTTP request to DevTools send_early_httprequest_to_devtools(request, context); // Step 2: Let response be null. let mut response = None; diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index a3b0ccfa3a4..56c22dcedb8 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -430,6 +430,10 @@ pub fn send_request_to_devtools( msg: ChromeToDevtoolsControlMsg, devtools_chan: &Sender, ) { + if matches!(msg, ChromeToDevtoolsControlMsg::NetworkEvent(_, ref network_event) if !network_event.forward_to_devtools()) + { + return; + } if let Err(e) = devtools_chan.send(DevtoolsControlMsg::FromChrome(msg)) { error!("DevTools send failed: {e}"); } @@ -493,6 +497,10 @@ pub fn send_response_values_to_devtools( } pub fn send_early_httprequest_to_devtools(request: &Request, context: &FetchContext) { + // Do not forward data requests to devtools + if request.url().scheme() == "data" { + return; + } if let (Some(devtools_chan), Some(browsing_context_id), Some(pipeline_id)) = ( context.devtools_chan.as_ref(), request.target_webview_id.map(|id| id.into()), diff --git a/components/shared/devtools/lib.rs b/components/shared/devtools/lib.rs index 879dc3c6010..6483c7038a4 100644 --- a/components/shared/devtools/lib.rs +++ b/components/shared/devtools/lib.rs @@ -473,6 +473,17 @@ pub enum NetworkEvent { HttpResponse(HttpResponse), } +impl NetworkEvent { + pub fn forward_to_devtools(&self) -> bool { + !matches!(self, NetworkEvent::HttpRequest(http_request) if http_request.url.scheme() == "data") || + match self { + NetworkEvent::HttpRequest(http_request) => http_request.url.scheme() != "data", + NetworkEvent::HttpRequestUpdate(..) => true, + NetworkEvent::HttpResponse(..) => true, + } + } +} + impl TimelineMarker { pub fn start(name: String) -> StartedTimelineMarker { StartedTimelineMarker {