diff --git a/content/browser/devtools/devtools_session.cc b/content/browser/devtools/devtools_session.cc index 22c21058b4b23..5815a733fd4a4 100644 --- a/content/browser/devtools/devtools_session.cc +++ b/content/browser/devtools/devtools_session.cc @@ -556,7 +556,14 @@ void DevToolsSession::DispatchProtocolResponseOrNotification( blink::mojom::DevToolsMessagePtr message, const std::string& session_id, const bool& is_notification) { - base::span message_span = message->data; + // SECURITY: |message->data| is a mojo_base::BigBuffer and may be backed by + // shared memory that the (potentially compromised) renderer can still write + // to. Copy it into browser-owned memory before validating, and forward the + // *copy*, so the bytes ValidateMessage() inspects are exactly the bytes the + // DevTools client receives (no TOCTOU window). + const std::vector message_copy(message->data.begin(), + message->data.end()); + const base::span message_span(message_copy); if (!ValidateMessage(session_id, /*expected_has_id=*/!is_notification, message_span)) { if (RenderProcessHost* process_host = agent_host->GetProcessHost()) { @@ -565,7 +572,7 @@ void DevToolsSession::DispatchProtocolResponseOrNotification( } return; } - client->DispatchProtocolMessage(agent_host, message->data); + client->DispatchProtocolMessage(agent_host, message_span); } void DevToolsSession::DispatchProtocolResponse(