mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb+LibWebView+WebContent: Begin implementing simple site islotation
Site isolation is a common technique to reduce the chance that malicious sites can access data from other sites. When the user navigates, we now check if the target site is the same as the current site. If not, we instruct the UI to perform the navigation in a new WebContent process. The phrase "site" here is defined as the public suffix of the URL plus one level. This means that navigating from "www.example.com" to "sub.example.com" remains in the same process. There's plenty of room for optimization around this. For example, we can create a spare WebContent process ahead of time to hot-swap the target site. We can also create a policy to keep the navigated-from process around, in case the user quickly navigates back.
This commit is contained in:
parent
a34f7a5bd1
commit
5810c8073e
Notes:
github-actions[bot]
2025-03-11 11:11:49 +00:00
Author: https://github.com/trflynn89
Commit: 5810c8073e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3882
Reviewed-by: https://github.com/gmta ✅
12 changed files with 94 additions and 0 deletions
31
Libraries/LibWebView/SiteIsolation.cpp
Normal file
31
Libraries/LibWebView/SiteIsolation.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/URL.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWebView/SiteIsolation.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
bool is_url_suitable_for_same_process_navigation(URL::URL const& current_url, URL::URL const& target_url)
|
||||
{
|
||||
// Allow navigating from about:blank to any site.
|
||||
if (Web::HTML::url_matches_about_blank(current_url))
|
||||
return true;
|
||||
|
||||
// Allow cross-scheme non-HTTP(S) navigation. Disallow cross-scheme HTTP(s) navigation.
|
||||
auto current_url_is_http = Web::Fetch::Infrastructure::is_http_or_https_scheme(current_url.scheme());
|
||||
auto target_url_is_http = Web::Fetch::Infrastructure::is_http_or_https_scheme(target_url.scheme());
|
||||
|
||||
if (!current_url_is_http || !target_url_is_http)
|
||||
return !current_url_is_http && !target_url_is_http;
|
||||
|
||||
// Disallow cross-site HTTP(S) navigation.
|
||||
return current_url.origin().is_same_site(target_url.origin());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue