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 <Narfinger@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Narfinger 2025-09-27 23:46:17 +02:00 committed by GitHub
parent 601ad7e5c6
commit 3ccb7540c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -260,7 +260,6 @@ pub async fn main_fetch(
) -> Response { ) -> Response {
// Step 1: Let request be fetchParam's request. // Step 1: Let request be fetchParam's request.
let request = &mut fetch_params.request; let request = &mut fetch_params.request;
// send early HTTP request to DevTools
send_early_httprequest_to_devtools(request, context); send_early_httprequest_to_devtools(request, context);
// Step 2: Let response be null. // Step 2: Let response be null.
let mut response = None; let mut response = None;

View file

@ -430,6 +430,10 @@ pub fn send_request_to_devtools(
msg: ChromeToDevtoolsControlMsg, msg: ChromeToDevtoolsControlMsg,
devtools_chan: &Sender<DevtoolsControlMsg>, devtools_chan: &Sender<DevtoolsControlMsg>,
) { ) {
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)) { if let Err(e) = devtools_chan.send(DevtoolsControlMsg::FromChrome(msg)) {
error!("DevTools send failed: {e}"); 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) { 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)) = ( if let (Some(devtools_chan), Some(browsing_context_id), Some(pipeline_id)) = (
context.devtools_chan.as_ref(), context.devtools_chan.as_ref(),
request.target_webview_id.map(|id| id.into()), request.target_webview_id.map(|id| id.into()),

View file

@ -473,6 +473,17 @@ pub enum NetworkEvent {
HttpResponse(HttpResponse), 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 { impl TimelineMarker {
pub fn start(name: String) -> StartedTimelineMarker { pub fn start(name: String) -> StartedTimelineMarker {
StartedTimelineMarker { StartedTimelineMarker {