Skip to content

Truly independent web browser

test-web: Load tests from an origin that is not potentially trustworthy

Luke Wilde485f5c8a8ced
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 3027e3062e7..e23d70556c6 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1089,6 +1089,11 @@ Text/input/wpt-import/css/cssom-view/scroll-behavior-scrollintoview-nested.html
; Expects an animation's 1ms delay to elapse within two frames
Text/input/wpt-import/css/css-animations/event-dispatch.tentative.html
+[LoadFromInsecureOrigin]
+Text/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html
+; Upstream serves it from a page that is not potentially trustworthy, where its data: frame's blob: worker is not mixed content.
+Text/input/wpt-import/webmessaging/broadcastchannel/opaque-origin.html
+
[Skipped]
; Needs vertical-rl inline geometry fidelity beyond the binary transpose
Ref/input/wpt-import/css/css-position/position-absolute-in-inline-006.html
diff --git a/Tests/LibWeb/Text/expected/HTML/page-from-an-insecure-origin-is-not-a-secure-context.txt b/Tests/LibWeb/Text/expected/HTML/page-from-an-insecure-origin-is-not-a-secure-context.txt
new file mode 100644
index 00000000000..e42b1725531
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/page-from-an-insecure-origin-is-not-a-secure-context.txt
@@ -0,0 +1,2 @@
+served from a .test name: true
+secure context: false
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index 1cd0c5da28e..7d145ffd4ff 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -653,7 +653,9 @@ scrollendEvent
spoofCurrentURL
test
timeout
+uniqueID
uniqueLocalhostHostname
+uniqueTestHostname
webkitURL
wheelTargetToString
withCollectedWrapper
diff --git a/Tests/LibWeb/Text/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html b/Tests/LibWeb/Text/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html
new file mode 100644
index 00000000000..63c05e0da73
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ println(`served from a .test name: ${location.protocol === "http:" && location.hostname.endsWith(".test")}`);
+ println(`secure context: ${isSecureContext}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/include.js b/Tests/LibWeb/Text/input/include.js
index 43c53bb009d..ec4d34459fb 100644
--- a/Tests/LibWeb/Text/input/include.js
+++ b/Tests/LibWeb/Text/input/include.js
@@ -257,7 +257,7 @@ class HTTPTestServer {
return `${this.baseURL}/static/${path}`;
}
#echoPath(path) {
- const echoScope = this.echoScope ?? (__pageEchoScope ??= crypto.randomUUID());
+ const echoScope = this.echoScope ?? (__pageEchoScope ??= uniqueID());
return `/echo/${echoScope}${path}`;
}
}
@@ -283,10 +283,20 @@ function httpTestServer() {
return __httpTestServer;
}
+// A random identifier that a page which is not a secure context can make too.
+function uniqueID() {
+ return Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, "0")).join("");
+}
+
// Per-call unique loopback host, so tests that mutate global per-host state
// (e.g. HSTS) don't collide under the parallel runner or --repeat clones.
function uniqueLocalhostHostname(prefix) {
- return `${prefix}-${crypto.randomUUID()}.localhost`;
+ return `${prefix}-${uniqueID()}.localhost`;
+}
+
+// Per-call unique loopback host whose origin is not potentially trustworthy.
+function uniqueTestHostname(prefix) {
+ return `${prefix}-${uniqueID()}.test`;
}
const remoteFrameCount = () => (internals.dumpSiteIsolationProcessTree().match(/remote/g) || []).length;
diff --git a/Tests/LibWeb/test-web/main.cpp b/Tests/LibWeb/test-web/main.cpp
index 2d3906ec5be..921ff66a022 100644
--- a/Tests/LibWeb/test-web/main.cpp
+++ b/Tests/LibWeb/test-web/main.cpp
@@ -61,6 +61,7 @@ static RefPtr<Core::Promise<Empty>> s_all_tests_complete;
static Vector<ByteString> s_skipped_tests;
static Vector<ByteString> s_loaded_from_http_server;
static Vector<ByteString> s_frame_rate_capped;
+static Vector<ByteString> s_loaded_from_insecure_origin;
static HashMap<WebView::ViewImplementation const*, size_t> s_current_test_index_by_view;
struct TestRunContext {
@@ -119,9 +120,9 @@ static ErrorOr<void> add_config_paths(StringView test_root_path, Vector<ByteStri
return {};
}
-static ByteString unique_localhost_hostname(StringView prefix)
+static ByteString unique_hostname_within(StringView domain, StringView prefix)
{
- return ByteString::formatted("{}-{}.localhost", prefix, generate_random_uuid().to_byte_string());
+ return ByteString::formatted("{}-{}.{}", prefix, generate_random_uuid().to_byte_string(), domain);
}
static ErrorOr<void> load_test_config(StringView test_root_path)
@@ -144,6 +145,8 @@ static ErrorOr<void> load_test_config(StringView test_root_path)
TRY(add_config_paths(test_root_path, config->keys(group), s_loaded_from_http_server));
} else if (group == "CapFrameRate"sv) {
TRY(add_config_paths(test_root_path, config->keys(group), s_frame_rate_capped));
+ } else if (group == "LoadFromInsecureOrigin"sv) {
+ TRY(add_config_paths(test_root_path, config->keys(group), s_loaded_from_insecure_origin));
} else {
warnln("Unknown group '{}' in config {}", group, config_path);
}
@@ -961,15 +964,17 @@ static void run_test(TestWebView& view, TestRunContext& context, size_t test_ind
auto headers_path = ByteString::formatted("{}.headers", real_path);
Optional<URL::URL> url;
- if (FileSystem::exists(headers_path) || s_loaded_from_http_server.contains_slow(test.input_path)) {
+ auto is_loaded_from_insecure_origin = s_loaded_from_insecure_origin.contains_slow(test.input_path);
+ if (FileSystem::exists(headers_path) || is_loaded_from_insecure_origin || s_loaded_from_http_server.contains_slow(test.input_path)) {
// Some tests need to be served via the echo server so, for example, HTTP headers from .headers
// files are sent, or so that the resulting HTML document has a HTTP based origin (e.g for testing
- // cookies).
+ // cookies), or one that is not potentially trustworthy.
auto echo_server_port = Application::web_content_options().echo_server_port;
VERIFY(echo_server_port.has_value());
auto relative_path = LexicalPath::relative_path(real_path, app.test_root_path);
VERIFY(relative_path.has_value());
- url = URL::Parser::basic_parse(ByteString::formatted("http://{}:{}/static/{}", unique_localhost_hostname("test-web"sv), echo_server_port.value(), relative_path.value())).release_value();
+ auto hostname = unique_hostname_within(is_loaded_from_insecure_origin ? "test"sv : "localhost"sv, "test-web"sv);
+ url = URL::Parser::basic_parse(ByteString::formatted("http://{}:{}/static/{}", hostname, echo_server_port.value(), relative_path.value())).release_value();
} else {
url = URL::create_with_file_scheme(real_path).release_value();
}