Skip to content

LibWeb: Pass a null sourceDocument to Browser UI initiated navigations #4515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 97 additions & 55 deletions Libraries/LibWeb/HTML/Navigable.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Libraries/LibWeb/HTML/Navigable.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Navigable : public JS::Cell

struct NavigateParams {
URL::URL url;
GC::Ref<DOM::Document> source_document;
GC::Ptr<DOM::Document> source_document = nullptr;
Variant<Empty, String, POSTResource> document_resource = Empty {};
GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
bool exceptions_enabled = false;
Expand Down
14 changes: 13 additions & 1 deletion Libraries/LibWeb/MixedContent/AbstractOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace Web::MixedContent {
// https://w3c.github.io/webappsec-mixed-content/#upgrade-algorithm
void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropriate(Fetch::Infrastructure::Request& request)
{
// AD-HOC: Browser-UI initiated navigations should not be upgraded.
if (!request.client())
return;

// 1. If one or more of the following conditions is met, return without modifying request:
if (
// 1. request’s URL is a potentially trustworthy URL.
Expand All @@ -22,7 +26,7 @@ void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropr
// 2. request’s URL’s host is an IP address.
|| (request.url().host().has_value() && (request.url().host()->has<URL::IPv4Address>() || request.url().host()->has<URL::IPv6Address>()))

// 3. §4.3 Does settings prohibit mixed security contexts? returns "Does Not Restrict Mixed Security Contents" when applied to request’s client.
// 3. § 4.3 Does settings prohibit mixed security contexts? returns "Does Not Restrict Mixed Security Contents" when applied to request’s client.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this spec has some non-breaking spaces in it when you copy from it, caught my eye in the IDE.

|| does_settings_prohibit_mixed_security_contexts(request.client()) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts

// 4. request’s destination is not "image", "audio", or "video".
Expand Down Expand Up @@ -68,6 +72,10 @@ ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(GC
// https://w3c.github.io/webappsec-mixed-content/#should-block-fetch
Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request& request)
{
// AD-HOC: Browser-UI initiated navigations should not be blocked.
if (!request.client())
return Fetch::Infrastructure::RequestOrResponseBlocking::Allowed;

// 1. Return allowed if one or more of the following conditions are met:
if (
// 1. § 4.3 Does settings prohibit mixed security contexts? returns "Does Not Restrict Mixed Security Contexts" when applied to request’s client.
Expand All @@ -93,6 +101,10 @@ Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_bloc
// https://w3c.github.io/webappsec-mixed-content/#should-block-response
Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request& request, GC::Ref<Fetch::Infrastructure::Response>& response)
{
// AD-HOC: Browser-UI initiated navigations should not be blocked.
if (!request.client())
return Fetch::Infrastructure::RequestOrResponseBlocking::Allowed;

// 1. Return allowed if one or more of the following conditions are met:
if (
// 1. § 4.3 Does settings prohibit mixed security contexts? returns Does Not Restrict Mixed Content when applied to request’s client.
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibWeb/Page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void Page::navigable_document_destroyed(Badge<DOM::Document>, HTML::Navigable& n

void Page::load(URL::URL const& url)
{
(void)top_level_traversable()->navigate({ .url = url, .source_document = *top_level_traversable()->active_document(), .user_involvement = HTML::UserNavigationInvolvement::BrowserUI });
(void)top_level_traversable()->navigate({ .url = url, .source_document = nullptr, .user_involvement = HTML::UserNavigationInvolvement::BrowserUI });
}

void Page::load_html(StringView html)
Expand All @@ -80,7 +80,7 @@ void Page::load_html(StringView html)
heap().collect_garbage();

(void)top_level_traversable()->navigate({ .url = URL::about_srcdoc(),
.source_document = *top_level_traversable()->active_document(),
.source_document = nullptr,
.document_resource = String::from_utf8(html).release_value_but_fixme_should_propagate_errors(),
.user_involvement = HTML::UserNavigationInvolvement::BrowserUI });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
entries[length - 1] is current entry: true
currentEntry is a [object NavigationHistoryEntry]
transition is null: true
canGoBack: false
canGoForward: true
entries[length - 1] is current entry: false
currentEntry is a [object NavigationHistoryEntry]
transition is null: true
canGoBack: true
canGoForward: true
11 changes: 10 additions & 1 deletion Tests/LibWeb/Text/input/HTML/Navigation-object-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

println(`transition is null: ${n.transition == null}`);
println(`canGoBack: ${n.canGoBack}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why our test runner causes this to become false due to this change, but I can't say I think it should have been true to begin with.

println(`canGoForward: ${n.canGoForward}`);
println(`canGoForward: ${n.canGoForward}`);

history.pushState({}, "", "#foo");

println(`entries[length - 1] is current entry: ${n.entries()[len - 1] === n.currentEntry}`);
println(`currentEntry is a ${n.currentEntry}`);

println(`transition is null: ${n.transition == null}`);
println(`canGoBack: ${n.canGoBack}`);
println(`canGoForward: ${n.canGoForward}`);
});
</script>
Loading