Skip to content

Truly independent web browser

LibWebView: Rule capture and geolocation by hosted documents' policies

Zaggy1024c799494ce2f6
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index d6520b10ed0..2729b1ed4ec 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -1360,11 +1360,17 @@ void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& ent
// document, the page that hosted the displaced one holds the navigable remotely from now on.
if (document != previous_document) {
auto& traversable = top_level_traversable();
+ auto previous_host = previous_document->host();
traversable.remove_child_navigables_of(*this, *previous_document);
- if (auto previous_host = previous_document->host(); previous_host && previous_host != document->host() && previous_host->is_open())
- traversable.stop_hosting_in_page(*this, previous_host.release_nonnull());
+ if (previous_host && previous_host != document->host() && previous_host->is_open())
+ traversable.stop_hosting_in_page(*this, *previous_host);
// The Picture-in-Picture window of the displaced document, or of a document it embedded, closes with it.
PictureInPictureManager::the().active_documents_did_change();
+ // Whether a process may capture audio depends on the documents it hosts.
+ for (auto const& page : { previous_host, document->host() }) {
+ if (page && page->is_open())
+ page->client().update_audio_capture_permission();
+ }
}
// A navigation can commit while a newer navigation is already in flight. In that case update the replicated
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 905899783ec..a5fa2412ca4 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -528,11 +528,18 @@ void CanonicalTraversable::remove(CanonicalNavigable& navigable)
if (m_focused_navigable_id.has_value() && !find(*m_focused_navigable_id).has_value())
m_focused_navigable_id.clear();
+ auto reporting_page = navigable.reporting_page();
auto* parent = navigable.parent();
VERIFY(parent);
(void)parent->remove_child(navigable);
if (host)
- release_page_if_unused(host.release_nonnull());
+ release_page_if_unused(*host);
+
+ // Whether a process may capture audio depends on the documents it hosts.
+ for (auto const& page : { host, reporting_page }) {
+ if (page && page->is_open())
+ page->client().update_audio_capture_permission();
+ }
}
void CanonicalTraversable::remove_page(WebContentPage& page)
diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp
index b030a6cdd76..81beb174e43 100644
--- a/Libraries/LibWebView/WebContentClient.cpp
+++ b/Libraries/LibWebView/WebContentClient.cpp
@@ -858,9 +858,13 @@ void WebContentClient::update_audio_capture_permission()
bool WebContentClient::audio_capture_permitted() const
{
+ // A tab's grant reaches only the documents whose permissions policy allows them the microphone. The process may
+ // capture if it hosts one, as it can act for any document it hosts.
for (auto const& it : m_pages) {
auto const& page = it.value;
- if (page->is_open() && m_audio_capture_grants.contains(audio_capture_permission_key(page->view().url())))
+ if (!page->is_open() || !m_audio_capture_grants.contains(audio_capture_permission_key(page->view().url())))
+ continue;
+ if (page->hosts_a_document_allowed_to_use(Web::PermissionsPolicy::PolicyControlledFeature::Microphone))
return true;
}
return false;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 13d94f8c2c8..91189150184 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -12,6 +12,7 @@
#include <LibCore/StatsLog.h>
#include <LibDevTools/StorageHelpers.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
+#include <LibWebCommon/Geolocation/GeolocationPositionErrorCode.h>
#include <LibWebCommon/HTML/BrowsingContext.h>
#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/WebDriver/Error.h>
@@ -1493,8 +1494,26 @@ void WebContentPage::did_request_color_picker(Color current_color)
view().did_request_color_picker({}, *this, current_color);
}
+bool WebContentPage::hosts_a_document_allowed_to_use(Web::PermissionsPolicy::PolicyControlledFeature feature) const
+{
+ auto is_allowed = false;
+ traversable().for_each_in_inclusive_subtree([&](CanonicalNavigable const& navigable) {
+ auto const& document = navigable.active_document();
+ if (document.host() != this)
+ return IterationDecision::Continue;
+ auto value = Web::PermissionsPolicy::check_permissions_policy(document.permissions_policy(), feature, document.origin(), document.origin());
+ is_allowed = value == Web::PermissionsPolicy::FeatureValue::Enabled;
+ return is_allowed ? IterationDecision::Break : IterationDecision::Continue;
+ });
+ return is_allowed;
+}
+
void WebContentPage::did_request_geolocation_position(u64 request_id)
{
+ if (!hosts_a_document_allowed_to_use(Web::PermissionsPolicy::PolicyControlledFeature::Geolocation)) {
+ async_geolocation_position_response(request_id, {}, to_underlying(Web::Geolocation::GeolocationPositionErrorCode::PermissionDenied));
+ return;
+ }
if (view().on_request_geolocation_position)
view().on_request_geolocation_position(*this, request_id);
}
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 4e1b8da376b..af2e4722a69 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -21,6 +21,7 @@
#include <LibWebCommon/HTML/CrossProcessId.h>
#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/Page/PageId.h>
+#include <LibWebCommon/PermissionsPolicy/PermissionsPolicy.h>
#include <LibWebCommon/StorageAPI/StorageEndpoint.h>
#include <LibWebView/Export.h>
#include <LibWebView/Forward.h>
@@ -102,6 +103,9 @@ public:
// False once the page can no longer host work: the page is unregistered or the process is gone. A page
// awaiting a detached close remains open; it still coordinates its own close.
bool is_open() const { return m_is_open; }
+
+ // Whether a document this page hosts may use the feature. The process hosting the page can act for any of them.
+ bool hosts_a_document_allowed_to_use(Web::PermissionsPolicy::PolicyControlledFeature) const;
void close();
void owe_reply(OwedReply);