ladybird/Libraries/LibSandbox/Sandbox.h
Andreas Kling ddbc3e2006 LibSandbox: Add macOS service sandboxing
Add Seatbelt-based macOS sandboxing for the browser service processes.
The shared profile builder grants only the filesystem, network, Mach,
and process execution permissions each service needs, with fatal sandbox
violation reporting enabled so denials are visible during development.

Wire sandbox profiles into WebContent, WebWorker, RequestServer,
ImageDecoder, and Compositor. Keep Landlock and Seatbelt APIs visible
only on the platforms that use them. Allow RequestServer resource
substitution files explicitly, preserve read access for read-write cache
paths, and only grant renderer process execution for an existing
Cranelift helper.
2026-06-10 21:16:41 +02:00

64 lines
1.5 KiB
C++

/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/Platform.h>
#include <AK/Span.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
namespace Sandbox {
#if defined(AK_OS_LINUX)
struct LandlockPath {
enum class Access {
ReadOnly,
ReadAndExecute,
ReadWrite,
};
ByteString path;
Access access { Access::ReadOnly };
};
#endif
#if defined(AK_OS_MACOS)
struct SeatbeltPath {
enum class Access {
ReadOnly,
ReadAndExecute,
ReadWrite,
};
ByteString path;
Access access { Access::ReadOnly };
bool is_directory { false };
};
enum class NetworkAccess {
Denied,
Allowed,
};
#endif
[[nodiscard]] ErrorOr<void> install_no_new_privileges();
[[nodiscard]] ErrorOr<void> configure_runtime();
#if defined(AK_OS_LINUX)
[[nodiscard]] ErrorOr<void> add_landlock_path_if_exists(Vector<LandlockPath>& paths, StringView path, LandlockPath::Access);
[[nodiscard]] ErrorOr<void> restrict_filesystem_with_landlock(ReadonlySpan<LandlockPath>);
[[nodiscard]] ErrorOr<void> restrict_filesystem_with_landlock(ReadonlySpan<StringView> readable_paths = {});
#endif
#if defined(AK_OS_MACOS)
[[nodiscard]] ErrorOr<void> add_seatbelt_path_if_exists(Vector<SeatbeltPath>& paths, StringView path, SeatbeltPath::Access);
[[nodiscard]] ErrorOr<void> apply_macos_sandbox(ReadonlySpan<SeatbeltPath>, NetworkAccess, ReadonlySpan<ByteString> executable_paths = {});
#endif
}