1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LaunchServer+LibDesktop: Add unveil-like mechanism for LaunchServer

Clients of LaunchServer can now provide a list of allowed handlers,
optionally with a specific set of URLs. The list can be sealed to
prevent future additions to it.

If LaunchServer receives a request to open something not on the allowed
handlers list, it will disconnect the client immediately.

The main idea here is to allow otherwise restricted programs to launch
specific things, e.g "Help" to open their manual, or "Browser" to load
the SerenityOS home page. :^)
This commit is contained in:
Andreas Kling 2021-01-03 11:39:33 +01:00
parent 8b2e7628fa
commit 1f1763c37a
5 changed files with 123 additions and 6 deletions

View file

@ -72,10 +72,45 @@ private:
virtual void handle(const Messages::LaunchClient::Dummy&) override { }
};
static LaunchServerConnection& connection()
{
static auto connection = LaunchServerConnection::construct();
return connection;
}
bool Launcher::add_allowed_handler_with_any_url(const String& handler)
{
auto response = connection().send_sync<Messages::LaunchServer::AddAllowedHandlerWithAnyURL>(handler);
if (!response) {
dbgln("Launcher::add_allowed_handler_with_any_url: Failed");
return false;
}
return true;
}
bool Launcher::add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>& urls)
{
auto response = connection().send_sync<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs>(handler, urls);
if (!response) {
dbgln("Launcher::add_allowed_handler_with_only_specific_urls: Failed");
return false;
}
return true;
}
bool Launcher::seal_allowed_handler_list()
{
auto response = connection().send_sync<Messages::LaunchServer::SealAllowedHandlersList>();
if (!response) {
dbgln("Launcher::seal_allowed_handler_list: Failed");
return false;
}
return true;
}
bool Launcher::open(const URL& url, const String& handler_name)
{
auto connection = LaunchServerConnection::construct();
return connection->send_sync<Messages::LaunchServer::OpenURL>(url, handler_name)->response();
return connection().send_sync<Messages::LaunchServer::OpenURL>(url, handler_name)->response();
}
bool Launcher::open(const URL& url, const Details& details)
@ -86,14 +121,12 @@ bool Launcher::open(const URL& url, const Details& details)
Vector<String> Launcher::get_handlers_for_url(const URL& url)
{
auto connection = LaunchServerConnection::construct();
return connection->send_sync<Messages::LaunchServer::GetHandlersForURL>(url.to_string())->handlers();
return connection().send_sync<Messages::LaunchServer::GetHandlersForURL>(url.to_string())->handlers();
}
auto Launcher::get_handlers_with_details_for_url(const URL& url) -> NonnullRefPtrVector<Details>
{
auto connection = LaunchServerConnection::construct();
auto details = connection->send_sync<Messages::LaunchServer::GetHandlersWithDetailsForURL>(url.to_string())->handlers_details();
auto details = connection().send_sync<Messages::LaunchServer::GetHandlersWithDetailsForURL>(url.to_string())->handlers_details();
NonnullRefPtrVector<Details> handlers_with_details;
for (auto& value : details) {
handlers_with_details.append(Details::from_details_str(value));