Commit graph

42 commits

Author SHA1 Message Date
e28897d987
Merge remote-tracking branch 'origin/main' into fix/runtime-resource-limits
# Conflicts:
#	tests/runtime/check_grants.py
2026-10-10 07:26:31 +00:00
656c3df8fd
Merge fix/confine-file-portal: confine file portal operations beneath the granted directory (#28) 2026-10-10 09:25:46 +02:00
373cec1bab
Merge remote-tracking branch 'origin/main' into fix/keyboard-system-navigation
# Conflicts:
#	docs/building.md
2026-10-10 07:25:25 +00:00
4b9e7b7773
Merge remote-tracking branch 'origin/main' into fix/reserve-panel-work-area
# Conflicts:
#	docs/building.md
2026-10-10 07:24:23 +00:00
bc2c155d24
Merge remote-tracking branch 'origin/main' into fix/activate-app-windows
# Conflicts:
#	docs/building.md
2026-10-10 07:23:50 +00:00
ff6ecacbb6
Merge fix/bind-app-surfaces-to-sessions: bind each app session's Wayland client to its session through appd (#18) 2026-10-10 09:23:18 +02:00
72dda72432
fix(compositor): show the shell on a Super key tap
From an application window there was no keyboard path to the system
shell: only a pointer click on the taskbar strip raised the panel.

The Super keys now belong to the compositor and are never delivered to
an application. A tap, Super pressed and released without another key,
activates the shell's panel, raising it with keyboard focus, and then
delivers the tap to it so the shell can open its launcher; a key or a
pointer button pressed meanwhile makes it no tap. Keys pressed while
Super is held reach the focused window with the Super modifier: a client
is sent the modifiers whenever a key the compositor takes changes them,
so none stays held there. With several panels, the first registered one
is the shell's.
2026-10-09 20:21:26 +00:00
e482fec07c
fix(pack): add approvals by name only for installed, declared capabilities
Pruning compared a list of the declared capabilities with the set of
approved ones by length. A manifest repeating a capability could
therefore keep an approval it no longer declared. The two are now
compared as sets.

weft-pack approve <id> <capability>... replaced the app's approval
instead of adding to it. It also accepted any app ID and any
capability, which let an approval cover a capability declared later. It
now adds to the approval, requires the app to be installed, and for a
package weft-pack can read, requires each listed capability to be
declared. The docs state the remaining limits for verified images.
2026-10-09 19:20:52 +00:00
9b83625778
fix(pack): approve the package weft-appd launches, and drop approvals no longer declared
weft-pack approve read only the user store, so an app in the system
store, or installed as a verified image, could not be approved. The
remedy the launch refusal named also did not work.

approve now resolves the package in weft-appd's store order. It also
accepts the capabilities by name, which is how an image is approved,
since weft-pack cannot read its manifest.

An install or rollback without --approve now drops approvals for
capabilities the package no longer declares. A capability declared
again later therefore asks again. Both commands report what still needs
approval. weft-appd validates capabilities without side effects first,
then refuses unapproved ones, then derives grants, so an unsupported
capability is reported as such and not as one needing approval. The
docs state that approvals are per user.
2026-10-09 19:18:22 +00:00
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
ff1388c6d9
test(portal): make the link-swap race test exercise both states, and fix limits
The race test could finish before its swapping thread first ran, so in
some runs nothing was exercised and the test failed. The link now
exists from the start. The test runs until it has seen both reads that
stay inside and reads refused for leading out, and it also swaps in a
relative link that climbs out.

Other fixes:
- A request line ending in CRLF is measured without the CRLF.
- Responses that the client stops reading time out like requests do.
- Temporary file names include the portal's start time, so a file left
  by an earlier instance cannot collide with a new one.

The test binary passed 30 runs in a row.
2026-10-09 18:59:01 +00:00
36ae676d83
fix(runtime): close the IPC socket when the connection ends, and do not count refused growth
When the runtime ended an IPC connection, it only marked it closed.
weft-appd therefore kept a session whose messages went nowhere. The
socket is now shut down, so weft-appd ends the session as it does when a
component closes the connection.

A growth past a memory's or table's own maximum is refused without
being counted against the store's limit, since Wasmtime would reject it
anyway.
2026-10-09 18:42:18 +00:00
cbc984eef6
fix(runtime): limit a component's memory in total and end IPC on failed sends
The memory limit applied to each linear memory separately, so a
component made of several core modules could multiply it. A limiter now
accounts all memories together, and bounds table elements, memories,
tables and core instances.

IPC fixes:
- A failed or timed-out send (10 seconds) ends the connection, since
  part of the line may already have been written.
- A line over the limit ends the connection, also when its newline
  arrives in the same read.
- A line that is not UTF-8 is dropped and logged.

TasksMax is raised to 512, since the runtime runs a few threads per CPU.

Counter and Notes still run under the limits (check_counter.py and
check_notes.py), and check_grants.py passes.
2026-10-09 18:39:05 +00:00
044634692f
fix(runtime): bound component memory and app messages
The runtime set no limits of its own:
- A component could grow its linear memory until the host ran out, with
  no ceiling at all where systemd is unavailable.
- An app message could contain line breaks and split into several
  messages.
- An overlong message from weft-appd was buffered without bound.
- A closed connection looked the same as an empty one.

The Wasmtime store now has a limiter: linear memory is capped at 256 MiB
by default (--max-memory-mib changes it), and tables and instances are
bounded too. A memory that would grow past the limit does not grow, and
the component sees an allocation failure.

App messages are single lines of at most 64 KiB, the limit weft-appd
applies. A longer message, or one containing a line break, is refused.
A longer line from weft-appd ends the connection, and sending afterwards
reports that it is closed. The systemd scope also gets TasksMax=64.

The grants probe component now also tries a 300 MiB allocation and the
two refused messages. tests/runtime/check_grants.py checks that the
allocation fails at the default limit and succeeds with a 512 MiB
limit.
2026-10-09 18:23:07 +00:00
50418d4c0b
fix(portal): refuse indirect paths as given and harden connection handling
Path parsing drops '.' components, empty components and a trailing '/'.
A request like dir/. was therefore accepted, and a write renamed over
the directory itself instead of failing. The path text is now checked as
given.

Other fixes:
- A replaced file keeps its permission bits.
- A connection's slot is released even when its handler panics.
- Connections close after 60 seconds without a request.
- Temporary files get unique names and are not listed.
- A request of exactly the line limit is accepted.

A new test swaps a link between a directory inside the granted root and
one outside while reads and writes run, and checks that nothing outside
is read or written.

weft-appd no longer sets WEFT_FILE_PORTAL_SOCKET for the runtime, which
no longer reads it.
2026-10-09 18:15:28 +00:00
f519832af1
fix(portal): confine file operations beneath the granted directory
The portal normalised a request path to check it against the granted
directories, but then operated on the raw path. A link inside a granted
directory, followed by '..', therefore reached files outside it. Links
pointing outside were followed too.

Each granted directory is now opened once. Every request is resolved
beneath that descriptor with openat2(RESOLVE_BENEATH | NO_MAGICLINKS),
so the kernel keeps the operation inside the directory even when links
are replaced while it runs. Paths with '.' or '..' components are
refused.

Other changes:
- Writes replace the file atomically and no longer create directories.
- Files are limited to 16 MiB, listings to 10,000 entries, request
  lines to the size of a full write, and the portal to 4 concurrent
  connections.
- The runtime no longer passes the portal's socket path to components,
  which cannot reach it.
2026-10-09 18:06:25 +00:00
8399914dfa
fix(compositor): show the shell's home on a panel click and release a dead panel's strip
With applications filling the work area, the system UI's launcher, drawn
in the panel beneath them, could not be seen while any application was
open. Clicking the panel now brings it to the front as the shell's home
until an application is activated again.

A panel that is destroyed, or whose client goes away, releases its
reserved strip and the applications are laid out again; dead panels no
longer count toward the work area, so a restarted shell does not reserve
the strip twice. A work area is never configured with a zero size. The
zweft_shell configure for an application window, at creation and in
reply to set_geometry, reports the work area the layout gives it, and a
panel's reports the output.

check_activation.py now clicks the taskbar strip, requires the panel to
cover both applications, and activates one back.
2026-10-09 16:06:19 +00:00
5253eaf251
fix(compositor): reserve the taskbar strip and lay app windows out in the work area
Application windows opened at the client's default size at the origin,
so one as large as the output hid the taskbar with no way back.

zweft_shell_window_v1 version 3 adds set_exclusive_zone: a panel
reserves a strip along an output edge, and other windows get the new
invalid_exclusive_zone error. weft-servo-shell reserves its 48-pixel
taskbar at the bottom (TASKBAR_HEIGHT, matching --taskbar-height in the
system UI). The compositor computes the work area as the output less the
reserved strips and configures every application window to fill it,
again when the output or a reservation changes.

The desktop harness now uses a 1400x900 X screen so the nested
compositor's whole 1280x800 output is captured. check_activation.py
requires both applications to fill the work area and end at the
reserved strip; check_notes.py finds the Discard button from the window's
right edge and check_confinement.py samples its probes from the measured
page instead of a fixed 800x600 window.
2026-10-09 16:00:38 +00:00
16af8d2a8c
fix(compositor): give a session focus on map only once in its lifetime
Unmapping a closed window made a session with no mapped window count
as new again, so destroying and recreating its only window took
keyboard focus from the application the user had activated. The
compositor now remembers which sessions already received focus on map
until the session ends.
2026-10-09 15:45:52 +00:00
65c02231a0
fix(compositor): restore focus when a window closes and keep later windows from taking it
When the focused window closed, keys went to a dead surface until the
next click; the topmost remaining application window, or the panel,
now gets focus. Only a session's first window takes focus when it
maps, so a client cannot take keystrokes meant for another application
by creating windows. A panel is fitted and kept beneath however the
shell orders its requests, and focusing the panel clears the
applications' activated state. ACTIVATE_APP is refused while the
compositor is not connected rather than queued.

check_activation.py now also ends the focused application and checks
that keys reach the remaining one.
2026-10-09 15:42:42 +00:00
aa67e7f190
fix(compositor): own stacking and focus, and activate app windows on request
The system shell's panel was an ordinary toplevel at winit's default
size, stacked by map order with the applications, and clicking or the
taskbar could never bring an application back to the front.

The compositor now sizes the panel to the output and keeps it beneath
every application window. A newly mapped, clicked or activated
application window is raised, marked activated and given keyboard
focus. weft-appd accepts ACTIVATE_APP for a running session and asks
the compositor to activate that session's window (AppFocusRequest),
and the system UI's taskbar entries send it when chosen.

check_activation.py runs the system shell with a solid panel page and
two test applications: the panel fills the output beneath them, each
launch comes to the front with keyboard focus, ACTIVATE_APP switches
between the sessions with focus, and activating a session that is not
running is refused.
2026-10-09 15:36:55 +00:00
db042fcb5c
fix(appd): keep the previous session when shutdown interrupts its restore
The session file is read and removed at startup, and restoring now runs
in its own task, so a shutdown during the restore would have saved only
the apps launched so far. Until the restore finishes, a shutdown stops
it and saves the restored list unchanged.
2026-10-09 15:25:57 +00:00
2e27adc4f6
fix(compositor): retry queued appd frames until sent and restore sessions in the background
Frames queued for a slow appd were sent only on later traffic, so the
end of a burst could wait indefinitely. A timer now retries the flush
every 20 ms, armed only while frames are queued. weft-appd restores the
previous session in its own task, so waiting for the compositor no
longer delays clients or shutdown, and the security docs describe the
launch refusal and the backlog limit exactly.
2026-10-09 15:23:41 +00:00
d6a2f94a1d
fix(compositor): buffer appd-bound frames and ignore stale session disconnects
A full socket buffer toward a stalled appd closed the connection and
with it every app. Frames for appd are now queued whole and flushed on
each send and read, and only a backlog beyond the frame limit or a
write error ends the connection. A disconnect report is applied only
when it comes from the session's current client, so a client closed
with an earlier appd cannot remove the mapping of a new session that
reused its ID. A failure to watch a new appd connection no longer
leaves the compositor refusing every later one.

weft-appd refuses a launch with 503 before anything starts while the
compositor is not connected, and waits up to 10 s for the connection
before restoring the previous session.
2026-10-09 15:20:29 +00:00
4c778330a3
fix(compositor): keep shell-level interfaces from sessions and harden the appd connection
Session clients could still create layer-shell surfaces, including
full-screen overlays with exclusive keyboard input, and bind the input
method, which bypassed the refusal of shell roles. Both globals are now
hidden from clients bound to a session.

The compositor IPC connection is tracked by its read source, so a write
error can no longer let a second peer feed the same buffers; a failed
write shuts the connection down. An undecodable or oversized frame ends
the connection, since descriptors could otherwise pair with the wrong
messages, and the descriptor limit counts only descriptors no message
claims, so a burst of launches is not taken for abuse. When appd's
connection ends, the compositor closes the clients of the sessions it
attached.

weft-appd notices when the compositor closes the connection, resends a
message whose write failed after reconnecting, and refuses a launch
while the compositor is not connected instead of starting an app shell
that can never connect.
2026-10-09 15:15:01 +00:00
7cf8639ae3
fix(compositor): bind each app session's Wayland client to its session through appd
The compositor stored appd's (pid, session) announcements and never used
them, so no surface could be attributed to a session and any client
could claim any app ID or the panel role.

weft-appd now creates a connected socket pair for each session, gives
the app shell one end as standard input with WAYLAND_SOCKET=0 and no
WAYLAND_DISPLAY, and sends the other end to the compositor with the
session and app ID over the compositor IPC socket (SCM_RIGHTS). The
compositor inserts it as a client bound to that session: holding the
connection is the session's identity. A session's zweft_shell windows
carry its app ID, the panel and overlay roles are refused to sessions
with a new role_not_permitted error, the session's first toplevel is
reported to appd, an ended session's client is closed, and a client's
disconnection is reported. The compositor accepts one appd connection
at a time.

The counter desktop check now requires the compositor to bind the app's
client to its session and to close it when the session is terminated.
2026-10-09 15:07:33 +00:00
af6f716823
fix(pack): let --claim-data install without HOME and test HOME refusals
Claiming data does not depend on finding earlier-layout data, so an
install that claims it no longer needs HOME. Tests cover a first launch
and a first install with an unusable HOME refusing and recording no
owner, and the security docs state the HOME requirement.
2026-10-09 14:56:42 +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
025388f84e
fix(pack): create relative stores and set new store modes through a no-follow descriptor
A relative store none of whose components existed failed, because the
empty ancestor was treated as a directory to create. New store
directories are now created private and set to 0755 through a
descriptor opened without following links, so a swapped path cannot
redirect the mode change. The security docs state the hard-link
protection as the kernel enforces it.
2026-10-09 14:25:09 +00:00
d67ea24004
fix(pack): create a missing store at 0755 regardless of umask
A first root install under a restrictive umask created the store and its
parents unreadable to other users even though the package inside was
0755/0644. Missing store directories are now created and set to 0755.
The copy comment and the hard-link note in the security docs describe
exactly what is checked and what the kernel enforces.
2026-10-09 14:22:37 +00:00
8221e6fc3d
fix(pack): set installed modes regardless of umask and hold one descriptor per level
Modes requested at creation were masked by the umask, so a root install
under umask 077 produced system packages other users could not read.
They are now set explicitly after creation. The copy reads each
directory's names and closes the listing before recursing, so deep
trees hold one descriptor per level. The owner-lock test now uses an
ID that would otherwise open, and the docs describe the copy check and
its device-node residual precisely.
2026-10-09 14:20:35 +00:00
181aa0fefa
fix(pack): copy packages by directory descriptor so swapped links cannot redirect the copy
Checking each file's device and inode against a path-based listing still
followed a directory replaced by a link after it was listed. The copy now
holds each source directory open and opens its entries relative to it
with O_NOFOLLOW, checking type, device and inode against the listing.
Only real packages in other stores keep an owner record, the store list
is deduplicated, archive names must be valid app IDs, and the help text
is wrapped.
2026-10-09 14:17:09 +00:00
c64ee531ee
fix(pack): take the app ID from the staged copy and check copied file identity
The app ID now comes from the staged copy, so a source changed after
validation cannot steer paths outside the store or the owners directory,
and lock_owner refuses invalid IDs. Copied files must keep the device and
inode they were listed with, and are opened without following links or
blocking on FIFOs, which no longer depends on /proc. Uninstall keeps an
owner record while another known store holds the package, and a failure
to inspect app data refuses rather than counting as no data.
2026-10-09 14:13:18 +00:00
39f7ca2a3f
fix(pack): close inventory forgery, serialize ownership changes and refuse to follow links
Names with control characters have no content digest, so a crafted name
can no longer reproduce other inventory lines and drop signed files.
Installs and uninstalls of an ID hold a per-ID lock, so a failed
concurrent install cannot remove the record of the one that won. App
data without a recorded owner goes to a new owner only with
--claim-data. Uninstall releases a record left by an interrupted
install once no data remains. Files are opened without following links
and, on Linux, must be the file that was listed.
2026-10-09 14:04:53 +00:00
d175bf012e
fix(pack): normalize installed modes and never leave a partial or orphaned owner record
Installed files take fixed modes (0644, or 0755 when executable) and
directories 0755, so a world-writable source cannot install as such.
An owner record created by an installation whose package then fails to
be placed is removed, and records are written under a temporary name
and linked into place, so they are never partial. Archives unpack into
a random private directory that is always removed. Uninstall frees an
ID only when the app data is truly absent, signatures are checked with
verify_strict, and list marks development installs.
2026-10-09 13:59:54 +00:00
88c2e9f6a5
fix(pack): install only trusted packages and bind each app ID to its owner
weft-pack install copied any package into the store: signatures were
never checked, no key was trusted for anything, any publisher could
install over another's app ID and reach its retained data, and the
signing inventory followed symbolic links, so a package could sign and
install files from outside itself.

Installation now requires a signature by a key in the trust store
($XDG_CONFIG_HOME/weft/trusted-keys and /etc/weft/trusted-keys, or
$WEFT_TRUSTED_KEYS alone). Unsigned or untrusted content installs only
with --dev, recorded as development content. The package is copied
into the store, checked and verified on that copy, and renamed into
place, so the verified bytes are the installed bytes.

The first installation of an app ID records its owner beside the app
data; later installations must have the same owner, so neither another
publisher nor a development build can take the ID over. The record
outlives uninstall while app data remains.

The content digest moves to weft_ipc_types::trust and refuses links,
special files and non-UTF-8 paths; it keeps the existing inventory
format, and both committed demo signatures still verify. Catalogs list
only directories named after their package ID. The security guide
described a signature over wapp.toml and app.wasm only; it now
describes the full inventory and the trust and ownership rules.
2026-10-09 13:49:49 +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
0b26c2e548 docs: remove internal tracking labels from all public documentation
- README.md: remove internal tracking labels; replace with plain
  English descriptions
- docs/security.md: rename section heading, remove tracking reference
- crates/weft-servo-shell/SERVO_PIN.md: replace tracking labels with
  descriptive headings; rename section to Known limitations
2026-03-12 20:45:56 +01:00
e3504c324b feat(infra): NixOS VM config, CI type-check job, documentation
- flake.nix, infra/nixos/: NixOS VM with Mesa, virtio-gpu, Wayland,
  systemd user services for compositor and session supervisor
- infra/vm/: QEMU build and run scripts
- .github/workflows/ci.yml: add Linux job to type-check weft-servo-shell
  and weft-app-shell with --features servo-embed
- docs/architecture.md, docs/security.md, docs/building.md: replace
  stale pre-implementation design documents
- README.md: rewrite to reflect current codebase
- crates/weft-servo-shell/SERVO_PIN.md: update implementation status and add
  SpiderMonkey process boundary statement
2026-03-12 20:03:25 +01:00