Skip to content

Truly independent web browser

RequestServer: Confine the sandbox to the disk cache directory

Andreas Kling0f1fe2a5066b
diff --git a/Services/RequestServer/Sandbox.h b/Services/RequestServer/Sandbox.h
index 1284a1bb851..2da72be8e82 100644
--- a/Services/RequestServer/Sandbox.h
+++ b/Services/RequestServer/Sandbox.h
@@ -8,10 +8,13 @@
#include <AK/ByteString.h>
#include <AK/Error.h>
+#include <AK/Optional.h>
+#include <AK/StringView.h>
#include <AK/Vector.h>
namespace RequestServer {
-[[nodiscard]] ErrorOr<void> apply_sandbox(StringView mach_server_name, Vector<ByteString> const& certificates, StringView cache_path);
+// The disk cache directory is the only place on disk this process may write to, and it has none without a disk cache.
+[[nodiscard]] ErrorOr<void> apply_sandbox(StringView mach_server_name, Vector<ByteString> const& certificates, Optional<StringView> disk_cache_directory);
}
diff --git a/Services/RequestServer/SandboxLinux.cpp b/Services/RequestServer/SandboxLinux.cpp
index 348bb66a334..861f6765e7c 100644
--- a/Services/RequestServer/SandboxLinux.cpp
+++ b/Services/RequestServer/SandboxLinux.cpp
@@ -6,7 +6,6 @@
#include <AK/CharacterTypes.h>
#include <AK/String.h>
-#include <LibCore/Directory.h>
#include <LibCore/Environment.h>
#include <LibCore/File.h>
#include <LibSandbox/Sandbox.h>
@@ -88,7 +87,7 @@ static void preload_nss_host_modules()
}
}
-ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const& certificates, StringView cache_path)
+ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const& certificates, Optional<StringView> disk_cache_directory)
{
TRY(Sandbox::install_no_new_privileges());
TRY(Sandbox::configure_runtime());
@@ -96,7 +95,6 @@ ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const& certificates,
preload_nss_host_modules();
Vector<Sandbox::LandlockPath> paths;
- TRY(Core::Directory::create(cache_path, Core::Directory::CreateDirectories::Yes));
TRY(add_certificate_store_paths(paths));
TRY(Sandbox::add_landlock_path_if_exists(paths, "/etc/host.conf"sv, Sandbox::LandlockPath::Access::ReadOnly));
@@ -117,7 +115,8 @@ ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const& certificates,
}));
}
- TRY(Sandbox::add_landlock_path_if_exists(paths, cache_path, Sandbox::LandlockPath::Access::ReadWrite));
+ if (disk_cache_directory.has_value())
+ TRY(Sandbox::add_landlock_path_if_exists(paths, *disk_cache_directory, Sandbox::LandlockPath::Access::ReadWrite));
TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
diff --git a/Services/RequestServer/SandboxMacOS.cpp b/Services/RequestServer/SandboxMacOS.cpp
index b7c4e7507e0..cb6866f2ce7 100644
--- a/Services/RequestServer/SandboxMacOS.cpp
+++ b/Services/RequestServer/SandboxMacOS.cpp
@@ -5,7 +5,6 @@
*/
#include <AK/String.h>
-#include <LibCore/Directory.h>
#include <LibCore/System.h>
#include <LibSandbox/Sandbox.h>
#include <RequestServer/ResourceSubstitutionMap.h>
@@ -13,12 +12,11 @@
namespace RequestServer {
-ErrorOr<void> apply_sandbox(StringView mach_server_name, Vector<ByteString> const& certificates, StringView cache_path)
+ErrorOr<void> apply_sandbox(StringView mach_server_name, Vector<ByteString> const& certificates, Optional<StringView> disk_cache_directory)
{
TRY(Sandbox::configure_runtime());
Vector<Sandbox::SeatbeltPath> paths;
- TRY(Core::Directory::create(cache_path, Core::Directory::CreateDirectories::Yes));
auto executable_path = TRY(Core::System::current_executable_path());
@@ -45,7 +43,8 @@ ErrorOr<void> apply_sandbox(StringView mach_server_name, Vector<ByteString> cons
}));
}
- TRY(Sandbox::add_seatbelt_path_if_exists(paths, cache_path, Sandbox::SeatbeltPath::Access::ReadWrite));
+ if (disk_cache_directory.has_value())
+ TRY(Sandbox::add_seatbelt_path_if_exists(paths, *disk_cache_directory, Sandbox::SeatbeltPath::Access::ReadWrite));
return Sandbox::apply_macos_sandbox({
.paths = paths.span(),
diff --git a/Services/RequestServer/SandboxUnimplemented.cpp b/Services/RequestServer/SandboxUnimplemented.cpp
index 3b0b15b8d12..96865014172 100644
--- a/Services/RequestServer/SandboxUnimplemented.cpp
+++ b/Services/RequestServer/SandboxUnimplemented.cpp
@@ -8,7 +8,7 @@
namespace RequestServer {
-ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const&, StringView)
+ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const&, Optional<StringView>)
{
return {};
}
diff --git a/Services/RequestServer/main.cpp b/Services/RequestServer/main.cpp
index 9ff9a60fc29..8126c3ab147 100644
--- a/Services/RequestServer/main.cpp
+++ b/Services/RequestServer/main.cpp
@@ -143,8 +143,12 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
TRY(RequestServer::initialize_libcurl());
- if (!disable_sandbox)
- TRY(RequestServer::apply_sandbox(mach_server_name, certificates, cache_path));
+ if (!disable_sandbox) {
+ Optional<StringView> disk_cache_directory;
+ if (disk_cache.has_value())
+ disk_cache_directory = disk_cache->cache_directory().string();
+ TRY(RequestServer::apply_sandbox(mach_server_name, certificates, disk_cache_directory));
+ }
// Connections are stored on the stack to ensure they are destroyed before static destruction begins. This prevents
// crashes from notifiers trying to unregister from already-destroyed thread data during process exit.