WEFT_OS/crates/weft-runtime/wit/weft-app.wit
Marco Allegretti 51ca194acb
fix(runtime): close fetch and preopen gaps in grant enforcement
A component with a host-specific fetch grant could reach another origin
by setting its own Host header, and could inject request lines through
the method string, which ureq writes unvalidated. Fetch now accepts only
standard methods and refuses Host, framing and hop-by-hop headers. Fetch
grants accept canonical DNS names and dotted IPv4 addresses only, so a
grant can never be written in a form that silently never matches.

--preopen split host and guest at the first `::`, so a host path
containing `::` widened the preopened directory; it now splits from the
right, and appd refuses host paths that are not UTF-8 or contain `::`.

appd validated capabilities one at a time, creating the data directory
before a later capability was refused, and required HOME even for
packages without filesystem capabilities. It now checks every capability
first, resolves host directories only when needed, validates the app ID
with the rule weft-pack uses (now shared in weft_ipc_types::package), and
reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is
read as a shell would: the last assignment wins, $HOME must be followed
by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is
not used.

The grants probe now also overwrites, renames, removes and creates
directories in read-only data, and sends a forged Host header, an
injected method and a file: URL; it fails when directory permissions of
a read-only preopen are widened or the header check is removed. A new
CI job builds the runtime with its engine and fetch support and runs the
check. The mount test that sets WEFT_APP_STORE now holds the env lock.

Package images are still located separately from directory installs;
deriving grants from the verified image is part of resolving one package
descriptor.
2026-10-09 08:25:40 +00:00

62 lines
2.2 KiB
Text

package weft:app@0.1.0;
/// Host interface that a WEFT app component imports to signal lifecycle events.
interface notify {
/// Signal to the runtime that the application has finished initialising
/// and is ready to serve requests. The runtime forwards this signal to
/// the session supervisor (appd), which transitions the session to the
/// Running state.
ready: func();
}
/// Host interface for bidirectional IPC between the Wasm component and the
/// HTML front-end served by weft-app-shell. Messages are JSON strings.
interface ipc {
/// Send a payload to the HTML front-end. Returns an error string if the
/// channel is not connected or the write fails.
send: func(payload: string) -> result<_, string>;
/// Return the next pending payload from the HTML front-end, or none if
/// no message is currently available. Non-blocking.
recv: func() -> option<string>;
}
/// Host interface for outbound HTTP requests. Requires a net:fetch:<host>
/// or net:fetch:* capability in wapp.toml covering the request's host.
interface fetch {
record response {
status: u16,
content-type: string,
body: list<u8>,
}
/// Perform a synchronous HTTP request. method is GET, POST, etc.
/// headers is a list of (name, value) pairs. body is the request body.
fetch: func(
url: string,
method: string,
headers: list<tuple<string, string>>,
body: option<list<u8>>,
) -> result<response, string>;
}
/// Host interface for sending desktop notifications. Requires the
/// sys:notifications capability to be declared in wapp.toml.
interface notifications {
/// Send a desktop notification. icon is an optional XDG icon name.
notify: func(
title: string,
body: string,
icon: option<string>,
) -> result<_, string>;
}
/// Host interface for reading and writing the Wayland clipboard.
/// Requires sys:clipboard:read and/or sys:clipboard:write capabilities.
interface clipboard {
/// Return the current clipboard text contents.
read: func() -> result<string, string>;
/// Replace the clipboard contents with the given text.
write: func(text: string) -> result<_, string>;
}