Commit graph

22 commits

Author SHA1 Message Date
3186e524ab
feat: grant an app only the capabilities the user approved
Every capability a package declared was granted at launch, so a signed
package received all the permissions it asked for. Blueprint 5.2 rules
that out.

A package now gets only the capabilities the user approved. weft-pack
install --approve approves those the installed package declares, and
weft-pack approve <id> approves those of the installed app later.
Without approval, install lists what still needs it. The approval is
recorded in $XDG_DATA_HOME/weft/approvals/<id>. weft-appd refuses to
launch an app declaring a capability the record does not hold, with
403 and the capabilities named, after refusing unknown or unsupported
ones as before.

An update that declares a new capability needs approval again, and
uninstalling forgets the approval. Private app data is a minimal
execution resource and needs no approval, so Notes and the existing
fixtures are unchanged.

Unit tests cover the approval record, install and approve, an update
adding a capability, uninstall, and appd refusing and then launching.
tests/frame/check_update.py launches a real app declaring notifications:
it is refused until weft-pack approve, then runs.
2026-10-09 19:11:53 +00:00
9206088d10
test(frame): check package updates against running sessions
check_update.py installs a test app with weft-pack, runs it with the
real runtime and app shell, and checks the following:
- an update leaves a running session on the bytes and the revision it
  started from;
- a failed update keeps the active revision;
- a later launch gets the update;
- the old revision is collected only after its session ends;
- rollback reactivates the kept revision;
- uninstall refuses new launches without disturbing a running session,
  and a later uninstall removes the revisions.
2026-10-09 17:38:10 +00:00
d3adced897
fix(appd): require a usable HOME for ownership decisions and keep records for earlier-layout data
Without an absolute HOME the earlier data layout could not be checked,
so a first-launch or install owner record was written anyway and that
data was migrated to the new owner later. Both now refuse instead.
Uninstall keeps an owner record while data exists in either layout, or
while it cannot tell. Launch tests use a private HOME, and the test
data-home cleanup never removes the running process's own.
2026-10-09 14:46:21 +00:00
95db80a86d
fix(appd): count app data in the earlier layout as existing before recording an owner
App data in the earlier layout, <home>/.local/share/weft/apps/<id>/data,
is migrated to the app data directory after the owner check, so a
trusted package from another store could be recorded as owner on its
first launch and then receive that data. Both layouts now count as
existing data, in weft-appd and in weft-pack install, so unowned data
is only given away with --claim-data. The refusal says how to claim
it. Stale test data homes are removed only when their process has
exited, and the app-data check records the owner of the data it seeds.
2026-10-09 14:41:23 +00:00
39aacac822
fix(appd): bind the launched manifest to the signature and record first owners
The manifest is now read once, and its bytes must match the verified
inventory, so a manifest swapped in around the check cannot grant
capabilities or entries the owner did not sign. A trusted package with
no owner record is recorded as its signer's on its first launch, and
app data without a recorded owner is refused rather than handed to the
first publisher, matching weft-pack's --claim-data rule. A damaged
trust store or owner record is a host error (500), and the trust store
is not consulted for development content.

Supervisor tests use a private data home and an empty trust store; the
counter check runs with a private home, and the notes check records
the owner of the data it seeds.
2026-10-09 14:36:06 +00:00
11cea5e7e3
fix(appd): verify package owner and signature before a session starts
weft-appd trusted an installed directory as installed, so content
changed after installation, or signed by a key since removed from the
trust store, still ran with the owner's app data. Before anything
starts, a package recorded as a publisher's must carry that
publisher's valid signature over its current content, with the key
still trusted; a package with no record must be signed by a trusted
key; development content, recorded by weft-pack install --dev, runs
unverified. Failures are refused with code 403.

The desktop checks trust the demo key, and the confinement check,
whose package deliberately holds a link, records it as development
content.
2026-10-09 14:29:14 +00:00
e2f9746fb5
Merge remote-tracking branch 'origin/fix/confine-app-renderer' into fix/resolve-verified-package
# Conflicts:
#	docs/architecture.md
2026-10-09 10:18:47 +00:00
687439a2a3
test(frame): make the worker and srcdoc confinement probes observable
Servo refuses worker scripts for file: pages, blob: ones included, so
the worker probe now requires only that no worker fetch succeeds, and
the worker is built from the page itself. The srcdoc frame reports to a
listener installed before the frame exists. Band failures and requests
that reached the servers are reported together, so a run without the
policy shows every leak.
2026-10-09 10:16:22 +00:00
2148ffc8ae
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.

weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.

The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
16a184ad9e
fix(app-shell): close the remaining paths out of the application page
Review of the renderer policy found loads it did not see or judged
wrongly:

- Loads Servo does not attribute to the webview, such as
  navigator.sendBeacon(), reached the network. They are all refused.
- On a redirect Servo reports the first URL again, so every redirect
  is refused.
- A symbolic link inside the UI directory led anywhere on disk; file
  loads are checked again after resolving links.
- Only about:blank is allowed among about: URLs.

The Servo pin moves to 5d90f51, which keeps compiled classic scripts
rooted until they run (a parser-blocking script waiting for a failed
stylesheet import crashed the content process) and withholds
navigator.servo from about:blank and about:srcdoc documents.

The confinement check gains probes for links, workers, beacons,
imports, fonts and srcdoc frames, and its WebSocket server completes
the handshake. The slow stylesheet's delay now starts when the host
first tries to open it.
2026-10-09 10:03:30 +00:00
d60152f443
fix(app-shell): confine application pages to their UI files and bridge
An application page could load any local file through file: URLs and
reach any network destination with images, fetch, XHR or WebSockets,
bypassing the component's fetch grants. The shell now checks every
resource load: files inside the UI directory, inline data:, blob: and
about: resources and the session bridge are allowed; anything else
fails with a network error before a request leaves the renderer.

tests/frame/check_confinement.py probes each path on the nested desktop
and requires that no HTTP request or TCP connection reaches the host.
The frame check's slow stylesheet becomes a file next to the page held
back with a file lease, so it stays inside the confined scope.
2026-10-09 09:39:37 +00:00
481495d929
fix(notes): show loading status and check the editor after a failed load
The first load showed an empty status while the editor was read-only;
it now says loading. check_notes.py also types and saves after a failed
load and requires the stored file to stay unchanged.
2026-10-09 09:07:27 +00:00
c1ea57fbef
fix(notes): keep Discard usable after a failed load
Discard waited for a stored revision, so after a load failed (stored
notes not valid UTF-8, a read error, a lost reply) the editor stayed
read-only with no way to reload. The page now tracks the outstanding
load itself: Discard is refused only while a load or save is in flight,
a load error or a ten-second timeout ends the load, and Discard retries.

A save acknowledgement arriving after its timeout and after Discard had
started a reload replaced the saved state while the editor still showed
older text, so the next save would silently revert it. Acknowledgements
are ignored while a load is outstanding, and a reload forgets the last
save.

The component removes a lock whose token could not be written and
cleans up renamed stale locks with the abandoned staging files.
check_notes.py adds a failed load followed by a repaired file and
Discard; the previous package stays read-only there and fails.
2026-10-09 09:05:25 +00:00
f39a330027
fix(notes): serialise saves and keep unseen notes from being replaced
The editor accepted typing before the stored notes had loaded, and a
load reply then adopted the stored revision for text edited from
nothing, so a save replaced notes the user never saw; the same happened
when typing during a Discard reload. The editor is now read-only until
it holds the stored text.

Two Notes windows saving at once shared one staging file and could each
pass the revision check, storing a mix of both texts. Each save now
holds a lock file while it checks the revision and replaces the notes,
writes its own staging file, syncs it before the rename, and removes
only that file on failure; a lock left by an ended session expires
after ten seconds.

A save larger than the 64 KiB app message limit after JSON encoding was
dropped on its way and left the page waiting forever with Save
disabled. The page now refuses such saves before sending, gives up on a
save after ten seconds without a reply, and the component answers every
request, including malformed ones, so no request goes unanswered.

check_notes.py now pauses weft-runtime with SIGSTOP to make text typed
during a save and keys typed during a Discard reload deterministic; the
previous package fails it by saving text typed before the reload. The
building guide lists the application checks, the pinned toolchain for
reproducing the demo binaries and the demo key path.
2026-10-09 08:55:50 +00:00
a508f1ebe4
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.

The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.

The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
4b27d7f16c
fix(notes): store notes exactly and never overwrite newer text
The Notes demo exchanged hand-escaped strings: the page turned every
literal backslash-n into a line break on load and save, the component
escaped only some control characters, so other text produced invalid
replies, and every reply replaced the editor contents, discarding text
typed while a save was in flight. Saves wrote the file in place and
replaced whatever another Notes window had stored.

Requests and replies are now JSON objects. The component reports a
revision (a hash of the stored bytes) with each load; a save names the
revision it was edited from and is refused when the stored notes have
changed since, so a second window's text is never replaced silently. The
file is written beside notes.txt and renamed over it. A save
acknowledgement updates only the saved state, never the editor, and
Discard reloads the stored notes.

tests/frame/check_notes.py edits Notes with real keyboard input on the
nested desktop: text with a literal backslash sequence, quotes, a tab and
non-ASCII characters is stored byte for byte, text typed during a save
survives, and a save after another window changed the file is refused.
It fails against the previous package, which turned the seeded "\n"
into a line break. app.wasm is rebuilt and the package re-signed with the
demo key.
2026-10-09 08:47:01 +00:00
cc69c048c0
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.

App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.

tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
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
c28a829624
fix(runtime): enforce effective capability grants per session
Every host import was registered and callable whatever the package
declared, read-only directory capabilities were preopened read-write,
and appd launched packages whose capabilities it could not satisfy. The
fetch import also could not be linked: the host returned a tuple where
the WIT declares the response record, so any component importing
weft:app/fetch failed to instantiate.

One capability vocabulary now lives in weft_ipc_types::capability and
is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a
session's grants once, before the session exists, and refuses the launch
with error 403 when a capability is unknown, unsupported (hw:gpu:*) or
unsatisfiable (documents without an XDG documents directory). The
documents directory now comes from user-dirs.dirs instead of a guessed
~/Documents.

The runtime receives grants explicitly (--grant CAP, --preopen
HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks
the grant on every notifications, clipboard and fetch call. Fetch accepts
only http and https to granted hosts, returns redirects and HTTP error
statuses as responses instead of following or failing them, and bounds
connect time, total time and response size. The file portal takes
read-only directories with --allow-read and refuses writes there.

tests/runtime/check_grants.py runs the real runtime on a probe component
under each kind of grant and checks the outcome of every operation; it
fails when read-only data is writable or an import ignores its grant.
The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock
shared with the tests that set it.
2026-10-09 08:08:58 +00:00
db712e056e
fix(appd): authorize WebSocket clients by role and session
The browser-facing WebSocket accepted requests from any local page, so a
page could launch or terminate apps and inject messages into any session.

Every connection now completes the upgrade and sends HELLO within five
seconds. The system role authenticates with a token appd writes to
$XDG_RUNTIME_DIR/weft/appd.systoken (mode 0600) and may manage sessions,
but never sees or sends application messages. The app role authenticates
with a per-session bridge token passed to weft-app-shell in
WEFT_BRIDGE_TOKEN and exchanges APP_MESSAGE envelopes with its own
session only; it is disconnected when that session stops.

weft-servo-shell hands the system endpoint only to the system UI
document and denies navigation away from it. weft-app-shell installs the
bridge only in top-level documents inside the application's UI
directory and denies navigation outside it. The launcher renders package
names as text.

tests/frame/check_counter.py drives the Counter demo end to end through
the compositor, appd, the Wasm runtime and the app shell.
2026-10-09 07:45:49 +00:00
ae176aae93
test: verify native pointer and keyboard input through weft-compositor
Nothing checked that input reaches a page through the compositor; the
Servo hosts' input forwarding had only been compiled.

tests/frame/check_input.py runs weft-servo-shell with
tests/frame/input.html on the nested desktop and injects real X input
with xdotool into weft-compositor's window. The compositor's winit backend
routes it through its seat to the Wayland client, which has no X display.
The page must react in its presented pixels: clicks 6 px either side of
the boundary between its halves change only the half under the pointer,
and the a and Shift+a key presses arrive with the right key value and
modifier. The harness gives the compositor's X window input focus, as a
window manager would; the client's keyboard focus comes from the
compositor's click-to-focus.

The nested desktop setup shared with check_frame.py moves to
tests/frame/session.py. Xvfb now reports the display it picked through
-displayfd, so concurrent runs cannot share an X server, and a run clears
only the logs and capture it writes.

Validation:
- check_input.py: 3 of 3 runs pass; two concurrent runs pass
- negative pages fail: no script; left click handled by the right half;
  an element extending the left half 20 px across the boundary; a key
  handler ignoring Shift
- check_frame.py --host system, --host app, --host app --slow-style 3 pass
  after the refactor
- unverified: key release and repeat, pointer motion and button release
  events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes,
  weft-app-shell input
2026-10-09 01:18:53 +00:00
64f8cff6fd
fix(shells): paint and present Servo frames and report readiness truthfully
With servo-embed, weft-servo-shell and weft-app-shell did not compile
against the selected Servo revision: the keyboard event shape, key and
mouse action variants, frame readback, shutdown, URL type and window
handle APIs had changed. The frame path never called WebView::paint; the
software path rebuilt its softbuffer surface every frame and read pixels
without painting, and the EGL path presented nothing. weft-app-shell
printed READY right after creating its WebView, before any frame, and its
feature-disabled build printed READY and parked. Servo also disables CSS
Grid by default, which the system UI uses.

Both hosts now build against the selected API. Each frame is painted with
WebView::paint and presented: the software path reads the painted frame
back, presents the context and copies it into a persistent softbuffer
surface; the EGL path presents its window context. Nothing is presented
before Servo's first repaint request. Shutdown drops the WebView and
Servo, whose drop completes the shutdown, and exits the event loop. Both
hosts enable layout_grid_enabled.

weft-app-shell prints READY on the first frame presented after the
document has loaded and Servo reports its rendering settled: on load
completion it requests WebView::take_screenshot, which completes only once
every frame has fired load, render-blocking resources, images and web
fonts are done and the rendering is up to date. Feature-disabled builds of
both hosts exit with an error instead of reporting readiness. weft-appd
does not consume the app shell's READY yet.

tests/frame/check_frame.py runs weft-compositor nested on Xvfb with the
winit backend, starts a host showing tests/frame/reference.html and checks
the presented pixels (four colour quadrants and text). For the app host
the page must be on screen within two seconds of READY; --slow-style
delays a render-blocking stylesheet that reveals the page, so premature
readiness fails.

Validation (Ubuntu 24.04, Mesa 25.2.8 llvmpipe, software path):
- check_frame.py --host system, --host app and --host app --slow-style 3:
  5 of 5 runs pass each
- negative fixtures fail: page with red and green swapped; a fake host
  printing READY without rendering; a local build printing READY on its
  first presented frame (--slow-style 4, 3 of 3)
- cargo clippy -D warnings with and without servo-embed; cargo fmt --check
- unverified: EGL path, DRM, resize, output scale, idle wakeup, input
2026-10-09 01:02:26 +00:00