feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
|
|
use anyhow::Context;
|
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
|
|
|
use weft_ipc_types::manifest::{Manifest, entry_path};
|
|
|
|
|
use weft_ipc_types::package::ImageFiles;
|
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
|
|
|
use weft_ipc_types::trust::{Owner, PublisherKey, TrustStore};
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
|
|
|
|
|
|
match args.get(1).map(String::as_str) {
|
|
|
|
|
Some("check") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack check <dir>")?;
|
|
|
|
|
let result = check_package(Path::new(dir))?;
|
|
|
|
|
println!("{result}");
|
|
|
|
|
}
|
|
|
|
|
Some("info") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack info <dir>")?;
|
|
|
|
|
let manifest = load_manifest(Path::new(dir))?;
|
|
|
|
|
print_info(&manifest);
|
|
|
|
|
}
|
2026-03-11 08:45:31 +00:00
|
|
|
Some("install") => {
|
2026-10-09 14:04:53 +00:00
|
|
|
let usage = "usage: weft-pack install <dir|archive> [--dev] [--claim-data]";
|
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
|
|
|
let dir = args.get(2).context(usage)?;
|
2026-10-09 14:04:53 +00:00
|
|
|
let mut mode = InstallMode::Verified;
|
|
|
|
|
let mut claim_data = false;
|
|
|
|
|
for arg in &args[3..] {
|
|
|
|
|
match arg.as_str() {
|
|
|
|
|
"--dev" => mode = InstallMode::Development,
|
|
|
|
|
"--claim-data" => claim_data = true,
|
|
|
|
|
other => anyhow::bail!("unexpected argument '{other}'; {usage}"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
install_package(Path::new(dir), mode, claim_data)?;
|
2026-03-11 08:45:31 +00:00
|
|
|
}
|
2026-03-11 08:54:39 +00:00
|
|
|
Some("uninstall") => {
|
|
|
|
|
let app_id = args.get(2).context("usage: weft-pack uninstall <app_id>")?;
|
|
|
|
|
uninstall_package(app_id)?;
|
|
|
|
|
}
|
2026-03-11 10:57:08 +00:00
|
|
|
Some("list") => {
|
|
|
|
|
list_installed();
|
|
|
|
|
}
|
2026-03-11 14:39:18 +00:00
|
|
|
Some("build-image") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack build-image <dir>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
build_image(Path::new(dir), out.map(Path::new))?;
|
|
|
|
|
}
|
|
|
|
|
Some("build-verity") => {
|
|
|
|
|
let img = args.get(2).context("usage: weft-pack build-verity <img>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
build_verity(Path::new(img), out.map(Path::new))?;
|
|
|
|
|
}
|
2026-03-11 14:37:53 +00:00
|
|
|
Some("bundle") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack bundle <dir>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
bundle_package(Path::new(dir), out.map(Path::new))?;
|
|
|
|
|
}
|
|
|
|
|
Some("unbundle") => {
|
|
|
|
|
let archive = args.get(2).context("usage: weft-pack unbundle <archive>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str())
|
|
|
|
|
.unwrap_or(".");
|
|
|
|
|
unbundle_package(Path::new(archive), Path::new(out))?;
|
|
|
|
|
}
|
2026-03-11 14:29:49 +00:00
|
|
|
Some("generate-key") => {
|
|
|
|
|
let out = args.get(2).map(String::as_str).unwrap_or(".");
|
|
|
|
|
generate_key(Path::new(out))?;
|
|
|
|
|
}
|
|
|
|
|
Some("sign") => {
|
|
|
|
|
let dir = args
|
|
|
|
|
.get(2)
|
|
|
|
|
.context("usage: weft-pack sign <dir> --key <keyfile>")?;
|
|
|
|
|
let key = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--key")
|
|
|
|
|
.map(|w| &w[1])
|
|
|
|
|
.context("missing --key <keyfile>")?;
|
|
|
|
|
sign_package(Path::new(dir), Path::new(key))?;
|
|
|
|
|
}
|
|
|
|
|
Some("verify") => {
|
|
|
|
|
let dir = args
|
|
|
|
|
.get(2)
|
|
|
|
|
.context("usage: weft-pack verify <dir> --key <pubkeyfile>")?;
|
|
|
|
|
let key = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--key")
|
|
|
|
|
.map(|w| &w[1])
|
|
|
|
|
.context("missing --key <pubkeyfile>")?;
|
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
|
|
|
let ok = verify_package(Path::new(dir), &PublisherKey::from_file(Path::new(key))?)?;
|
2026-03-11 14:29:49 +00:00
|
|
|
if ok {
|
|
|
|
|
println!("OK");
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("INVALID signature");
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
_ => {
|
|
|
|
|
eprintln!("usage:");
|
2026-03-11 14:29:49 +00:00
|
|
|
eprintln!(" weft-pack check <dir> validate a package directory");
|
|
|
|
|
eprintln!(" weft-pack info <dir> print package metadata");
|
2026-10-09 14:17:09 +00:00
|
|
|
eprintln!(" weft-pack install <dir> [--dev] [--claim-data]");
|
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
|
|
|
eprintln!(
|
2026-10-09 14:17:09 +00:00
|
|
|
" install a package signed by a trusted key"
|
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
|
|
|
);
|
|
|
|
|
eprintln!(
|
2026-10-09 14:17:09 +00:00
|
|
|
" --dev: as unsigned development content"
|
2026-10-09 14:04:53 +00:00
|
|
|
);
|
|
|
|
|
eprintln!(
|
2026-10-09 14:17:09 +00:00
|
|
|
" --claim-data: adopt app data with no owner"
|
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
|
|
|
);
|
2026-03-11 14:29:49 +00:00
|
|
|
eprintln!(" weft-pack uninstall <app_id> remove installed package");
|
|
|
|
|
eprintln!(" weft-pack list list installed packages");
|
2026-03-11 14:43:59 +00:00
|
|
|
eprintln!(
|
|
|
|
|
" weft-pack build-image <dir> [--out <img>] create EROFS image with mkfs.erofs"
|
|
|
|
|
);
|
2026-03-11 14:39:18 +00:00
|
|
|
eprintln!(" weft-pack build-verity <img> [--out <hash>] add dm-verity hash tree");
|
2026-03-11 14:37:53 +00:00
|
|
|
eprintln!(" weft-pack bundle <dir> [--out <dir>] create .app.tar.zst archive");
|
|
|
|
|
eprintln!(" weft-pack unbundle <archive> [--out <dir>] extract .app.tar.zst");
|
2026-03-11 14:29:49 +00:00
|
|
|
eprintln!(" weft-pack generate-key [<outdir>] generate Ed25519 keypair");
|
|
|
|
|
eprintln!(" weft-pack sign <dir> --key <key> sign package with private key");
|
|
|
|
|
eprintln!(" weft-pack verify <dir> --key <pub> verify package signature");
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn check_package(dir: &Path) -> anyhow::Result<String> {
|
|
|
|
|
let mut errors: Vec<String> = Vec::new();
|
|
|
|
|
|
|
|
|
|
let manifest = match load_manifest(dir) {
|
|
|
|
|
Ok(m) => Some(m),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
errors.push(format!("wapp.toml: {e}"));
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
// A package holds only directories and regular files: its signature
|
|
|
|
|
// covers exactly those, and installation copies exactly those.
|
|
|
|
|
if let Err(e) = weft_ipc_types::trust::content_digest(dir) {
|
|
|
|
|
errors.push(e.to_string());
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// Earlier versions kept app data in `<package>/data`; the name stays
|
|
|
|
|
// reserved so package content is never mistaken for user data.
|
|
|
|
|
if std::fs::symlink_metadata(dir.join("data")).is_ok() {
|
|
|
|
|
errors.push("a top-level 'data' entry is reserved and cannot be part of a package".into());
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
if let Some(ref m) = manifest {
|
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
|
|
|
if !weft_ipc_types::package::is_valid_app_id(&m.package.id) {
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
errors.push(format!(
|
|
|
|
|
"package.id '{}' does not match required pattern",
|
|
|
|
|
m.package.id
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
if m.package.name.is_empty() {
|
|
|
|
|
errors.push("package.name is empty".into());
|
|
|
|
|
}
|
|
|
|
|
if m.package.name.len() > 64 {
|
|
|
|
|
errors.push(format!(
|
|
|
|
|
"package.name exceeds 64 characters ({})",
|
|
|
|
|
m.package.name.len()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
match entry_path(dir, &m.runtime.module) {
|
|
|
|
|
Err(e) => errors.push(format!("runtime.module: {e}")),
|
|
|
|
|
Ok(wasm_path) if !is_wasm_module(&wasm_path) => errors.push(format!(
|
2026-03-11 09:21:43 +00:00
|
|
|
"runtime.module '{}' is not a valid Wasm module (bad magic bytes)",
|
|
|
|
|
wasm_path.display()
|
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
|
|
|
)),
|
|
|
|
|
Ok(_) => {}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if let Err(e) = entry_path(dir, &m.ui.entry) {
|
|
|
|
|
errors.push(format!("ui.entry: {e}"));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
2026-03-11 17:33:05 +00:00
|
|
|
|
|
|
|
|
for cap in m.package.capabilities.iter().flatten() {
|
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
|
|
|
if let Err(e) = cap.parse::<weft_ipc_types::capability::Capability>() {
|
|
|
|
|
errors.push(e.to_string());
|
2026-03-11 17:33:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if errors.is_empty() {
|
|
|
|
|
Ok("OK".into())
|
|
|
|
|
} else {
|
|
|
|
|
Err(anyhow::anyhow!("{}", errors.join("\n")))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_manifest(dir: &Path) -> anyhow::Result<Manifest> {
|
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
|
|
|
Ok(Manifest::read(dir)?)
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn print_info(m: &Manifest) {
|
|
|
|
|
println!("id: {}", m.package.id);
|
|
|
|
|
println!("name: {}", m.package.name);
|
|
|
|
|
println!("version: {}", m.package.version);
|
|
|
|
|
if let Some(ref d) = m.package.description {
|
|
|
|
|
println!("desc: {d}");
|
|
|
|
|
}
|
|
|
|
|
if let Some(ref a) = m.package.author {
|
|
|
|
|
println!("author: {a}");
|
|
|
|
|
}
|
|
|
|
|
println!("module: {}", m.runtime.module);
|
|
|
|
|
println!("ui: {}", m.ui.entry);
|
2026-03-11 14:20:51 +00:00
|
|
|
if let Some(ref caps) = m.package.capabilities {
|
|
|
|
|
for cap in caps {
|
|
|
|
|
println!("cap: {cap}");
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:21:43 +00:00
|
|
|
fn is_wasm_module(path: &Path) -> bool {
|
|
|
|
|
const MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6D];
|
|
|
|
|
let mut buf = [0u8; 4];
|
|
|
|
|
match std::fs::File::open(path) {
|
|
|
|
|
Ok(mut f) => {
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
f.read_exact(&mut buf)
|
|
|
|
|
.map(|_| buf == MAGIC)
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
|
}
|
|
|
|
|
Err(_) => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:45:31 +00:00
|
|
|
fn resolve_install_root() -> anyhow::Result<PathBuf> {
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
|
2026-03-11 08:45:31 +00:00
|
|
|
return Ok(PathBuf::from(explicit));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
2026-03-11 08:45:31 +00:00
|
|
|
return Ok(PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"));
|
|
|
|
|
}
|
|
|
|
|
anyhow::bail!("cannot determine install root: HOME and WEFT_APP_STORE are both unset")
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// How a package is admitted to the store.
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
enum InstallMode {
|
|
|
|
|
/// The package must be signed by a key in the trust store.
|
|
|
|
|
Verified,
|
|
|
|
|
/// Unsigned or untrusted content, chosen explicitly by a developer and
|
|
|
|
|
/// recorded as development content.
|
|
|
|
|
Development,
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
fn install_package(path: &Path, mode: InstallMode, claim_data: bool) -> anyhow::Result<()> {
|
2026-03-11 08:54:39 +00:00
|
|
|
let root = resolve_install_root()?;
|
2026-10-09 14:04:53 +00:00
|
|
|
install_into(path, &root, mode, claim_data)
|
2026-03-11 08:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
#[cfg(test)]
|
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
|
|
|
fn install_package_to(path: &Path, store_root: &Path, mode: InstallMode) -> anyhow::Result<()> {
|
2026-10-09 14:04:53 +00:00
|
|
|
install_into(path, store_root, mode, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Installs the package at `path` into `store_root`. App data that exists
|
|
|
|
|
/// for the ID without a recorded owner, as left by an installation that
|
|
|
|
|
/// predates owner records, goes to this package's owner only with
|
|
|
|
|
/// `claim_data`.
|
|
|
|
|
fn install_into(
|
|
|
|
|
path: &Path,
|
|
|
|
|
store_root: &Path,
|
|
|
|
|
mode: InstallMode,
|
|
|
|
|
claim_data: bool,
|
|
|
|
|
) -> anyhow::Result<()> {
|
2026-10-09 14:22:37 +00:00
|
|
|
create_store(store_root)?;
|
2026-10-09 13:59:54 +00:00
|
|
|
if !(path.extension().is_some_and(|e| e == "zst" || e == "tar")
|
|
|
|
|
|| path.to_string_lossy().ends_with(".app.tar.zst"))
|
2026-03-11 14:49:34 +00:00
|
|
|
{
|
2026-10-09 14:04:53 +00:00
|
|
|
return install_dir(path, store_root, mode, claim_data);
|
2026-10-09 13:59:54 +00:00
|
|
|
}
|
|
|
|
|
let name = path
|
|
|
|
|
.file_name()
|
|
|
|
|
.and_then(|n| n.to_str())
|
|
|
|
|
.and_then(|n| n.strip_suffix(".app.tar.zst"))
|
2026-10-09 14:17:09 +00:00
|
|
|
.filter(|n| weft_ipc_types::package::is_valid_app_id(n))
|
|
|
|
|
.context("the archive must be named <app_id>.app.tar.zst")?;
|
2026-10-09 13:59:54 +00:00
|
|
|
// A fresh private directory in the store, removed whatever happens, so
|
|
|
|
|
// nothing can be planted in it and nothing is left behind.
|
|
|
|
|
let unpacked = private_scratch_dir(store_root, ".unpack")?;
|
|
|
|
|
let result = unbundle_package(path, &unpacked)
|
2026-10-09 14:04:53 +00:00
|
|
|
.and_then(|()| install_dir(&unpacked.join(name), store_root, mode, claim_data));
|
2026-10-09 13:59:54 +00:00
|
|
|
let _ = std::fs::remove_dir_all(&unpacked);
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:22:37 +00:00
|
|
|
/// Creates the store and any missing parents at 0755 whatever the umask, so
|
2026-10-09 14:25:09 +00:00
|
|
|
/// a store created by a root install is readable by every user. Each new
|
|
|
|
|
/// directory is created private and its mode set through a descriptor that
|
|
|
|
|
/// does not follow links, so only the directory just created is changed.
|
2026-10-09 14:22:37 +00:00
|
|
|
fn create_store(store_root: &Path) -> anyhow::Result<()> {
|
|
|
|
|
let mut missing: Vec<&Path> = store_root
|
|
|
|
|
.ancestors()
|
2026-10-09 14:25:09 +00:00
|
|
|
.filter(|dir| !dir.as_os_str().is_empty())
|
2026-10-09 14:22:37 +00:00
|
|
|
.take_while(|dir| std::fs::symlink_metadata(dir).is_err())
|
|
|
|
|
.collect();
|
|
|
|
|
missing.reverse();
|
|
|
|
|
for dir in missing {
|
2026-10-09 14:25:09 +00:00
|
|
|
let mut builder = std::fs::DirBuilder::new();
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
std::os::unix::fs::DirBuilderExt::mode(&mut builder, 0o700);
|
|
|
|
|
match builder.create(dir) {
|
2026-10-09 14:22:37 +00:00
|
|
|
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
|
|
|
|
other => other.with_context(|| format!("create {}", dir.display()))?,
|
|
|
|
|
}
|
|
|
|
|
#[cfg(unix)]
|
2026-10-09 14:25:09 +00:00
|
|
|
{
|
|
|
|
|
use rustix::fs::{CWD, Mode, OFlags};
|
|
|
|
|
let created = rustix::fs::openat(
|
|
|
|
|
CWD,
|
|
|
|
|
dir,
|
|
|
|
|
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::NOFOLLOW | OFlags::CLOEXEC,
|
|
|
|
|
Mode::empty(),
|
|
|
|
|
)
|
|
|
|
|
.with_context(|| format!("open {}", dir.display()))?;
|
|
|
|
|
rustix::fs::fchmod(&created, Mode::from_raw_mode(0o755))
|
|
|
|
|
.with_context(|| format!("set the mode of {}", dir.display()))?;
|
|
|
|
|
}
|
2026-10-09 14:22:37 +00:00
|
|
|
}
|
|
|
|
|
anyhow::ensure!(
|
|
|
|
|
store_root.is_dir(),
|
|
|
|
|
"{} is not a directory",
|
|
|
|
|
store_root.display()
|
|
|
|
|
);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 13:59:54 +00:00
|
|
|
/// Creates a new directory with a random name in `parent`, accessible only to
|
|
|
|
|
/// the user.
|
|
|
|
|
fn private_scratch_dir(parent: &Path, prefix: &str) -> anyhow::Result<PathBuf> {
|
|
|
|
|
let dir = parent.join(format!(
|
|
|
|
|
"{prefix}-{}",
|
|
|
|
|
hex::encode(rand::random::<[u8; 8]>())
|
|
|
|
|
));
|
|
|
|
|
let mut builder = std::fs::DirBuilder::new();
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
std::os::unix::fs::DirBuilderExt::mode(&mut builder, 0o700);
|
|
|
|
|
builder
|
|
|
|
|
.create(&dir)
|
|
|
|
|
.with_context(|| format!("create {}", dir.display()))?;
|
|
|
|
|
Ok(dir)
|
|
|
|
|
}
|
2026-03-11 14:49:34 +00:00
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
fn install_dir(
|
|
|
|
|
dir: &Path,
|
|
|
|
|
store_root: &Path,
|
|
|
|
|
mode: InstallMode,
|
|
|
|
|
claim_data: bool,
|
|
|
|
|
) -> anyhow::Result<()> {
|
2026-03-11 08:45:31 +00:00
|
|
|
check_package(dir)?;
|
2026-10-09 14:13:18 +00:00
|
|
|
// The package is copied into the store first and every decision, the app
|
|
|
|
|
// ID included, is made on that copy, so the bytes that are checked and
|
|
|
|
|
// trusted are the bytes that become installed. Only then does one rename
|
|
|
|
|
// make it available.
|
|
|
|
|
let staging = store_root.join(format!(
|
|
|
|
|
".staging-{}",
|
|
|
|
|
hex::encode(rand::random::<[u8; 8]>())
|
|
|
|
|
));
|
|
|
|
|
let result = dir
|
|
|
|
|
.canonicalize()
|
|
|
|
|
.with_context(|| format!("resolve {}", dir.display()))
|
|
|
|
|
.and_then(|source| copy_dir(&source, &staging))
|
|
|
|
|
.with_context(|| format!("copy {} -> {}", dir.display(), staging.display()))
|
|
|
|
|
.and_then(|()| install_staged(&staging, store_root, mode, claim_data));
|
|
|
|
|
if result.is_err() {
|
|
|
|
|
let _ = std::fs::remove_dir_all(&staging);
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn install_staged(
|
|
|
|
|
staging: &Path,
|
|
|
|
|
store_root: &Path,
|
|
|
|
|
mode: InstallMode,
|
|
|
|
|
claim_data: bool,
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
check_package(staging)?;
|
|
|
|
|
let manifest = load_manifest(staging)?;
|
2026-03-11 08:45:31 +00:00
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let dest = store_root.join(app_id);
|
2026-10-09 14:04:53 +00:00
|
|
|
let data_home = weft_ipc_types::package::data_home()
|
|
|
|
|
.context("cannot locate the data home to record who owns the app ID")?;
|
|
|
|
|
// Installations and uninstallations of one ID run one at a time, so the
|
|
|
|
|
// owner record always describes the package that is placed.
|
|
|
|
|
let _lock = weft_ipc_types::trust::lock_owner(&data_home, app_id)?;
|
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
|
|
|
// An earlier weft-appd could leave only app data, or an empty directory,
|
|
|
|
|
// where the package now goes; move the data to its own location so it
|
|
|
|
|
// neither blocks nor joins the package.
|
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
|
|
|
if dest.is_dir() && only_holds_app_data(&dest)? {
|
2026-10-09 09:01:28 +00:00
|
|
|
if std::fs::symlink_metadata(dest.join("data")).is_ok() && is_user_store(store_root) {
|
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
|
|
|
move_app_data_out(app_id, &dest)?;
|
|
|
|
|
}
|
|
|
|
|
let _ = std::fs::remove_dir(&dest);
|
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
|
|
|
}
|
2026-03-11 08:45:31 +00:00
|
|
|
if dest.exists() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"package '{}' is already installed at {}; remove it first",
|
|
|
|
|
app_id,
|
|
|
|
|
dest.display()
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
2026-10-09 14:13:18 +00:00
|
|
|
let admission = admit(staging, app_id, mode, &data_home, claim_data)?;
|
2026-10-09 13:59:54 +00:00
|
|
|
let owner = admission.owner;
|
2026-10-09 14:13:18 +00:00
|
|
|
place(staging, &dest, admission)?;
|
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
|
|
|
println!("installed {} -> {} ({owner})", app_id, dest.display());
|
2026-03-11 08:45:31 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 13:59:54 +00:00
|
|
|
/// The owner a staged package was admitted under, and the owner record this
|
|
|
|
|
/// installation created, if any.
|
|
|
|
|
struct Admission {
|
|
|
|
|
owner: Owner,
|
|
|
|
|
created_record: Option<PathBuf>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Makes the staged package available at `dest`. If that fails, the staging
|
|
|
|
|
/// copy is removed, and so is an owner record this installation created, so
|
|
|
|
|
/// a failed first installation leaves no claim on the app ID.
|
|
|
|
|
fn place(staging: &Path, dest: &Path, admission: Admission) -> anyhow::Result<()> {
|
|
|
|
|
if let Err(e) = weft_ipc_types::package::rename_no_replace(staging, dest) {
|
|
|
|
|
let _ = std::fs::remove_dir_all(staging);
|
|
|
|
|
if let Some(record) = &admission.created_record {
|
|
|
|
|
let _ = std::fs::remove_file(record);
|
|
|
|
|
}
|
|
|
|
|
return Err(e).with_context(|| format!("move {} -> {}", staging.display(), dest.display()));
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:13:18 +00:00
|
|
|
/// Establishes who owns the app ID of a checked, staged package:
|
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
|
|
|
/// the trusted publisher that signed it, or, only when asked, development.
|
|
|
|
|
/// The first installation of an ID records its owner, and every later one
|
2026-10-09 13:59:54 +00:00
|
|
|
/// must have the same owner. The record is written before the package is
|
|
|
|
|
/// placed, so concurrent installations by different owners cannot both win.
|
2026-10-09 14:04:53 +00:00
|
|
|
fn admit(
|
|
|
|
|
staged: &Path,
|
|
|
|
|
app_id: &str,
|
|
|
|
|
mode: InstallMode,
|
|
|
|
|
data_home: &Path,
|
|
|
|
|
claim_data: bool,
|
|
|
|
|
) -> anyhow::Result<Admission> {
|
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
|
|
|
use weft_ipc_types::trust::{owner_record_path, read_owner, write_owner};
|
|
|
|
|
let owner = match mode {
|
|
|
|
|
InstallMode::Development => Owner::Development,
|
|
|
|
|
InstallMode::Verified => {
|
|
|
|
|
let dirs = TrustStore::directories();
|
|
|
|
|
let signer = TrustStore::load(&dirs)?.signer(staged)?;
|
|
|
|
|
Owner::Verified(signer.with_context(|| {
|
|
|
|
|
format!(
|
|
|
|
|
"{app_id} is not signed by a trusted key (trusted keys are read from {}); \
|
|
|
|
|
install it with --dev to use it as development content",
|
|
|
|
|
dirs.iter()
|
|
|
|
|
.map(|d| d.display().to_string())
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
.join(", ")
|
|
|
|
|
)
|
|
|
|
|
})?)
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-10-09 14:04:53 +00:00
|
|
|
let record = owner_record_path(data_home, app_id);
|
2026-10-09 13:59:54 +00:00
|
|
|
let created_record = match read_owner(&record)? {
|
|
|
|
|
Some(existing) if existing == owner => None,
|
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
|
|
|
Some(existing) => anyhow::bail!(
|
|
|
|
|
"{app_id} belongs to {existing}; this package is {owner}. Its app data stays with \
|
|
|
|
|
its owner, so another publisher or a development build cannot take the ID over"
|
|
|
|
|
),
|
2026-10-09 13:59:54 +00:00
|
|
|
None => {
|
2026-10-09 14:04:53 +00:00
|
|
|
let data = weft_ipc_types::package::app_data_dir(data_home, app_id);
|
2026-10-09 14:13:18 +00:00
|
|
|
let no_data = match std::fs::symlink_metadata(&data) {
|
|
|
|
|
Err(e) if e.kind() == std::io::ErrorKind::NotFound => true,
|
|
|
|
|
Err(e) => return Err(e).with_context(|| format!("inspect {}", data.display())),
|
|
|
|
|
Ok(_) => false,
|
|
|
|
|
};
|
|
|
|
|
if !no_data && !claim_data {
|
2026-10-09 14:04:53 +00:00
|
|
|
anyhow::bail!(
|
|
|
|
|
"{} holds app data for {app_id} with no recorded owner; install with \
|
|
|
|
|
--claim-data to give it to {owner}, or move it aside",
|
|
|
|
|
data.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-10-09 13:59:54 +00:00
|
|
|
write_owner(&record, owner)?;
|
|
|
|
|
Some(record)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Ok(Admission {
|
|
|
|
|
owner,
|
|
|
|
|
created_record,
|
|
|
|
|
})
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:54:39 +00:00
|
|
|
fn uninstall_package(app_id: &str) -> anyhow::Result<()> {
|
|
|
|
|
let root = resolve_install_root()?;
|
|
|
|
|
uninstall_package_from(app_id, &root)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn uninstall_package_from(app_id: &str, store_root: &Path) -> anyhow::Result<()> {
|
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
|
|
|
if !weft_ipc_types::package::is_valid_app_id(app_id) {
|
2026-03-11 08:54:39 +00:00
|
|
|
anyhow::bail!("'{}' is not a valid app ID", app_id);
|
|
|
|
|
}
|
2026-10-09 14:04:53 +00:00
|
|
|
let data_home = weft_ipc_types::package::data_home();
|
|
|
|
|
let _lock = match &data_home {
|
|
|
|
|
Some(home) => Some(weft_ipc_types::trust::lock_owner(home, app_id)?),
|
|
|
|
|
None => None,
|
|
|
|
|
};
|
2026-03-11 08:54:39 +00:00
|
|
|
let target = store_root.join(app_id);
|
|
|
|
|
if !target.exists() {
|
2026-10-09 14:04:53 +00:00
|
|
|
// An installation interrupted between recording its owner and placing
|
|
|
|
|
// the package leaves a record with nothing installed; with no data
|
|
|
|
|
// either, it holds the ID for nothing and is released.
|
|
|
|
|
if let Some(home) = &data_home
|
2026-10-09 14:13:18 +00:00
|
|
|
&& !installed_in_another_store(app_id, store_root)
|
2026-10-09 14:04:53 +00:00
|
|
|
&& release_owner_without_data(home, app_id)
|
|
|
|
|
{
|
|
|
|
|
println!("released {app_id}, which was not installed");
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
2026-03-11 08:54:39 +00:00
|
|
|
anyhow::bail!(
|
|
|
|
|
"package '{}' is not installed at {}",
|
|
|
|
|
app_id,
|
|
|
|
|
target.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-10-09 09:01:28 +00:00
|
|
|
// A `data` directory is never removed with the package: packages cannot
|
|
|
|
|
// ship one, so it holds app data from an earlier version. It is moved to
|
|
|
|
|
// the app data directory when this is the user store and the package
|
|
|
|
|
// declares app data (or its manifest cannot be read); otherwise uninstall
|
|
|
|
|
// stops and leaves everything in place.
|
|
|
|
|
if std::fs::symlink_metadata(target.join("data")).is_ok() {
|
|
|
|
|
let may_hold_app_data = load_manifest(&target).map_or(true, |m| declares_app_data(&m));
|
|
|
|
|
if !(may_hold_app_data && is_user_store(store_root)) {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"{} contains a 'data' directory that may hold app data; move it aside before \
|
|
|
|
|
uninstalling",
|
|
|
|
|
target.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
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
|
|
|
move_app_data_out(app_id, &target)?;
|
|
|
|
|
}
|
2026-10-09 09:01:28 +00:00
|
|
|
// Moving the data removes a package directory it leaves empty.
|
|
|
|
|
match std::fs::remove_dir_all(&target) {
|
|
|
|
|
Err(e) if e.kind() != std::io::ErrorKind::NotFound => {
|
|
|
|
|
return Err(e).with_context(|| format!("remove {}", target.display()));
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
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
|
|
|
// The owner record keeps the app ID, and the data with it, for its owner
|
|
|
|
|
// while the data remains; with no data left, the ID is free again.
|
2026-10-09 14:13:18 +00:00
|
|
|
if let Some(home) = &data_home
|
|
|
|
|
&& !installed_in_another_store(app_id, store_root)
|
|
|
|
|
{
|
2026-10-09 14:04:53 +00:00
|
|
|
release_owner_without_data(home, app_id);
|
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
|
|
|
}
|
2026-03-11 08:54:39 +00:00
|
|
|
println!("uninstalled {}", app_id);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:13:18 +00:00
|
|
|
/// Whether `app_id` is installed in a known store other than `store_root`.
|
|
|
|
|
/// Owner records belong to the data home, not to a store, so a record stays
|
|
|
|
|
/// while any store this host knows holds the package.
|
|
|
|
|
fn installed_in_another_store(app_id: &str, store_root: &Path) -> bool {
|
|
|
|
|
let mut roots = list_installed_roots();
|
2026-10-09 14:17:09 +00:00
|
|
|
roots.push(PathBuf::from("/usr/share/weft/apps"));
|
|
|
|
|
roots.extend(std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".local/share/weft/apps")));
|
|
|
|
|
roots.sort();
|
|
|
|
|
roots.dedup();
|
|
|
|
|
// Only a package counts, as in `list`: a leftover empty or data-only
|
|
|
|
|
// directory does not hold the ID.
|
2026-10-09 14:13:18 +00:00
|
|
|
roots
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|root| root.as_path() != store_root)
|
2026-10-09 14:17:09 +00:00
|
|
|
.any(|root| Manifest::read(&root.join(app_id)).is_ok_and(|m| m.package.id == app_id))
|
2026-10-09 14:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
/// Removes the owner record of `app_id` when the app has no data, and
|
|
|
|
|
/// reports whether a record was removed.
|
|
|
|
|
fn release_owner_without_data(data_home: &Path, app_id: &str) -> bool {
|
|
|
|
|
let no_data =
|
|
|
|
|
std::fs::symlink_metadata(weft_ipc_types::package::app_data_dir(data_home, app_id))
|
|
|
|
|
.is_err_and(|e| e.kind() == std::io::ErrorKind::NotFound);
|
|
|
|
|
no_data
|
|
|
|
|
&& std::fs::remove_file(weft_ipc_types::trust::owner_record_path(data_home, app_id)).is_ok()
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Whether a package directory is empty or contains nothing but `data`.
|
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
|
|
|
fn only_holds_app_data(package_dir: &Path) -> anyhow::Result<bool> {
|
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
|
|
|
let entries = std::fs::read_dir(package_dir)
|
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
|
|
|
.with_context(|| format!("read {}", package_dir.display()))?
|
|
|
|
|
.map(|entry| entry.map(|e| e.file_name()))
|
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
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
|
|
|
Ok(entries.is_empty() || entries == ["data"])
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Whether the manifest declares an app-data capability; only such apps
|
|
|
|
|
/// had data kept in the package directory.
|
|
|
|
|
fn declares_app_data(manifest: &Manifest) -> bool {
|
|
|
|
|
use weft_ipc_types::capability::Capability;
|
|
|
|
|
manifest
|
|
|
|
|
.package
|
|
|
|
|
.capabilities
|
|
|
|
|
.iter()
|
|
|
|
|
.flatten()
|
|
|
|
|
.any(|c| matches!(c.parse(), Ok(Capability::AppData(_))))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
/// Whether `store_root` is the user package store, where earlier versions of
|
|
|
|
|
/// weft-appd kept app data, however the path is spelled.
|
|
|
|
|
fn is_user_store(store_root: &Path) -> bool {
|
|
|
|
|
let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
let user_store = home.join(".local/share/weft/apps");
|
|
|
|
|
match (
|
|
|
|
|
std::fs::canonicalize(store_root),
|
|
|
|
|
std::fs::canonicalize(user_store),
|
|
|
|
|
) {
|
|
|
|
|
(Ok(a), Ok(b)) => a == b,
|
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Moves app data that an earlier weft-appd kept in `<package_dir>/data` in
|
|
|
|
|
/// the user store to the app's data directory, which package operations
|
|
|
|
|
/// never remove. Fails, changing nothing, if the data cannot be moved.
|
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
|
|
|
fn move_app_data_out(app_id: &str, package_dir: &Path) -> anyhow::Result<()> {
|
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
|
|
|
use weft_ipc_types::package::{
|
2026-10-09 09:01:28 +00:00
|
|
|
Migration, app_data_dir, data_home, make_private, migrate_app_data,
|
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
|
|
|
};
|
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
|
|
|
let legacy = package_dir.join("data");
|
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
|
|
|
let data_home = data_home().context("cannot locate the data home to keep app data")?;
|
|
|
|
|
let target = app_data_dir(&data_home, app_id);
|
|
|
|
|
if migrate_app_data(&legacy, &target).with_context(|| format!("keep app data of {app_id}"))?
|
|
|
|
|
== Migration::Moved
|
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
|
|
|
{
|
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
|
|
|
make_private(&target).with_context(|| format!("restrict {}", target.display()))?;
|
|
|
|
|
println!("app data kept at {}", target.display());
|
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
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:57:08 +00:00
|
|
|
fn list_installed_roots() -> Vec<PathBuf> {
|
|
|
|
|
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
|
|
|
|
|
return vec![PathBuf::from(explicit)];
|
|
|
|
|
}
|
|
|
|
|
let mut roots = Vec::new();
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
|
|
|
|
roots.push(
|
|
|
|
|
PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
roots.push(PathBuf::from("/usr/share/weft/apps"));
|
|
|
|
|
roots
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn list_installed() {
|
|
|
|
|
let mut seen = std::collections::HashSet::new();
|
|
|
|
|
let mut count = 0usize;
|
|
|
|
|
for root in list_installed_roots() {
|
|
|
|
|
let Ok(entries) = std::fs::read_dir(&root) else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
let mut pkgs: Vec<(String, String, String)> = Vec::new();
|
|
|
|
|
for entry in entries.flatten() {
|
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
|
|
|
let Ok(m) = Manifest::read(&entry.path()) else {
|
2026-03-11 10:57:08 +00:00
|
|
|
continue;
|
|
|
|
|
};
|
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
|
|
|
// Only a directory named after the ID its manifest declares is an
|
|
|
|
|
// installed package; staging copies and stray directories are not.
|
2026-10-09 14:13:18 +00:00
|
|
|
if entry.file_name().to_str() != Some(m.package.id.as_str())
|
|
|
|
|
|| !weft_ipc_types::package::is_valid_app_id(&m.package.id)
|
|
|
|
|
{
|
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
|
|
|
continue;
|
|
|
|
|
}
|
2026-03-11 10:57:08 +00:00
|
|
|
if seen.insert(m.package.id.clone()) {
|
2026-10-09 13:59:54 +00:00
|
|
|
let development = weft_ipc_types::package::data_home().is_some_and(|home| {
|
|
|
|
|
matches!(
|
|
|
|
|
weft_ipc_types::trust::read_owner(
|
|
|
|
|
&weft_ipc_types::trust::owner_record_path(&home, &m.package.id)
|
|
|
|
|
),
|
|
|
|
|
Ok(Some(Owner::Development))
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
let version = if development {
|
|
|
|
|
format!("{} (development)", m.package.version)
|
|
|
|
|
} else {
|
|
|
|
|
m.package.version
|
|
|
|
|
};
|
|
|
|
|
pkgs.push((m.package.id, m.package.name, version));
|
2026-03-11 10:57:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pkgs.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
|
for (id, name, version) in pkgs {
|
|
|
|
|
println!("{id} {name} {version}");
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if count == 0 {
|
|
|
|
|
println!("no packages installed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Copies a package directory. Packages hold only directories and regular
|
|
|
|
|
/// files, so a symbolic link or special file stops the copy rather than
|
2026-10-09 14:17:09 +00:00
|
|
|
/// being followed. The walk holds each directory open and opens its entries
|
|
|
|
|
/// relative to it without following links, checking that each opened entry
|
2026-10-09 14:22:37 +00:00
|
|
|
/// has the type, device and inode it had when examined just before the
|
|
|
|
|
/// open, so a link or another file swapped in anywhere in the source during
|
|
|
|
|
/// the copy cannot redirect it.
|
2026-10-09 14:17:09 +00:00
|
|
|
/// Modes are not copied: the signature does not cover them, so installed
|
|
|
|
|
/// directories are 0755 and files 0644, or 0755 when the source is
|
|
|
|
|
/// executable, and nothing installed is writable by other users.
|
|
|
|
|
#[cfg(unix)]
|
2026-03-11 08:45:31 +00:00
|
|
|
fn copy_dir(src: &Path, dst: &Path) -> anyhow::Result<()> {
|
2026-10-09 14:17:09 +00:00
|
|
|
use rustix::fs::{CWD, Mode, OFlags};
|
|
|
|
|
let root = rustix::fs::openat(
|
|
|
|
|
CWD,
|
|
|
|
|
src,
|
|
|
|
|
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::NOFOLLOW | OFlags::CLOEXEC,
|
|
|
|
|
Mode::empty(),
|
|
|
|
|
)
|
|
|
|
|
.with_context(|| format!("open {}", src.display()))?;
|
|
|
|
|
copy_tree(&root, src, dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(not(unix))]
|
|
|
|
|
fn copy_dir(_src: &Path, _dst: &Path) -> anyhow::Result<()> {
|
|
|
|
|
anyhow::bail!("installing packages requires a Unix host")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn copy_tree(dir: &rustix::fd::OwnedFd, shown: &Path, dst: &Path) -> anyhow::Result<()> {
|
|
|
|
|
use rustix::fs::{AtFlags, FileType, Mode, OFlags};
|
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
2026-10-09 14:20:35 +00:00
|
|
|
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};
|
2026-10-09 14:17:09 +00:00
|
|
|
|
2026-10-09 14:20:35 +00:00
|
|
|
// Modes are set explicitly rather than requested at creation, so the
|
|
|
|
|
// installer's umask cannot make an installed package unreadable.
|
|
|
|
|
let set_mode = |path: &Path, mode: u32| {
|
|
|
|
|
std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode))
|
|
|
|
|
.with_context(|| format!("set the mode of {}", path.display()))
|
|
|
|
|
};
|
2026-10-09 14:17:09 +00:00
|
|
|
std::fs::DirBuilder::new()
|
2026-10-09 14:20:35 +00:00
|
|
|
.mode(0o700)
|
2026-10-09 13:59:54 +00:00
|
|
|
.create(dst)
|
|
|
|
|
.with_context(|| format!("create {}", dst.display()))?;
|
2026-10-09 14:20:35 +00:00
|
|
|
set_mode(dst, 0o755)?;
|
|
|
|
|
// The names are read first and the listing closed, so the walk holds one
|
|
|
|
|
// descriptor per directory level.
|
|
|
|
|
let mut names = Vec::new();
|
2026-10-09 14:17:09 +00:00
|
|
|
let mut entries =
|
|
|
|
|
rustix::fs::Dir::read_from(dir).with_context(|| format!("read {}", shown.display()))?;
|
|
|
|
|
while let Some(entry) = entries.read() {
|
|
|
|
|
let entry = entry.with_context(|| format!("read {}", shown.display()))?;
|
2026-10-09 14:20:35 +00:00
|
|
|
if !matches!(entry.file_name().to_bytes(), b"." | b"..") {
|
|
|
|
|
names.push(entry.file_name().to_owned());
|
2026-10-09 14:17:09 +00:00
|
|
|
}
|
2026-10-09 14:20:35 +00:00
|
|
|
}
|
|
|
|
|
drop(entries);
|
|
|
|
|
for name in &names {
|
2026-10-09 14:17:09 +00:00
|
|
|
let src_path = shown.join(std::ffi::OsStr::from_bytes(name.to_bytes()));
|
|
|
|
|
let dst_path = dst.join(std::ffi::OsStr::from_bytes(name.to_bytes()));
|
|
|
|
|
let listed = rustix::fs::statat(dir, name, AtFlags::SYMLINK_NOFOLLOW)
|
|
|
|
|
.with_context(|| format!("inspect {}", src_path.display()))?;
|
|
|
|
|
let kind = FileType::from_raw_mode(listed.st_mode);
|
|
|
|
|
let flags = match kind {
|
|
|
|
|
FileType::Directory => OFlags::DIRECTORY,
|
|
|
|
|
FileType::RegularFile => OFlags::NONBLOCK | OFlags::NOCTTY,
|
|
|
|
|
_ => anyhow::bail!(
|
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
|
|
|
"{} is not a regular file or directory; packages cannot contain links",
|
|
|
|
|
src_path.display()
|
2026-10-09 14:17:09 +00:00
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
let opened = rustix::fs::openat(
|
|
|
|
|
dir,
|
|
|
|
|
name,
|
|
|
|
|
flags | OFlags::RDONLY | OFlags::NOFOLLOW | OFlags::CLOEXEC,
|
|
|
|
|
Mode::empty(),
|
|
|
|
|
)
|
|
|
|
|
.with_context(|| format!("open {}", src_path.display()))?;
|
|
|
|
|
let found = rustix::fs::fstat(&opened)?;
|
|
|
|
|
anyhow::ensure!(
|
|
|
|
|
FileType::from_raw_mode(found.st_mode) == kind
|
|
|
|
|
&& found.st_dev == listed.st_dev
|
|
|
|
|
&& found.st_ino == listed.st_ino,
|
|
|
|
|
"{} changed while it was copied",
|
|
|
|
|
src_path.display()
|
|
|
|
|
);
|
|
|
|
|
if kind == FileType::Directory {
|
|
|
|
|
copy_tree(&opened, &src_path, &dst_path)?;
|
|
|
|
|
} else {
|
|
|
|
|
let executable = found.st_mode & 0o111 != 0;
|
|
|
|
|
let mut target = std::fs::OpenOptions::new()
|
|
|
|
|
.write(true)
|
|
|
|
|
.create_new(true)
|
2026-10-09 14:20:35 +00:00
|
|
|
.mode(0o600)
|
2026-10-09 14:17:09 +00:00
|
|
|
.open(&dst_path)
|
|
|
|
|
.with_context(|| format!("create {}", dst_path.display()))?;
|
|
|
|
|
std::io::copy(&mut std::fs::File::from(opened), &mut target)
|
|
|
|
|
.with_context(|| format!("copy {}", src_path.display()))?;
|
2026-10-09 14:20:35 +00:00
|
|
|
target
|
|
|
|
|
.set_permissions(std::fs::Permissions::from_mode(if executable {
|
|
|
|
|
0o755
|
|
|
|
|
} else {
|
|
|
|
|
0o644
|
|
|
|
|
}))
|
|
|
|
|
.with_context(|| format!("set the mode of {}", dst_path.display()))?;
|
2026-03-11 08:45:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:39:18 +00:00
|
|
|
fn build_image(dir: &Path, out_path: Option<&Path>) -> anyhow::Result<()> {
|
|
|
|
|
let manifest = load_manifest(dir)?;
|
|
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let output = match out_path {
|
|
|
|
|
Some(p) => p.to_path_buf(),
|
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
|
|
|
None => ImageFiles::in_store(Path::new(""), app_id).image,
|
2026-03-11 14:39:18 +00:00
|
|
|
};
|
|
|
|
|
if output.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", output.display());
|
|
|
|
|
}
|
|
|
|
|
let status = std::process::Command::new("mkfs.erofs")
|
|
|
|
|
.arg(&output)
|
|
|
|
|
.arg(dir)
|
|
|
|
|
.status()
|
|
|
|
|
.context("spawn mkfs.erofs; ensure erofs-utils is installed")?;
|
|
|
|
|
if !status.success() {
|
|
|
|
|
anyhow::bail!("mkfs.erofs failed with status {status}");
|
|
|
|
|
}
|
|
|
|
|
println!("image: {}", output.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build_verity(img: &Path, hash_out: Option<&Path>) -> anyhow::Result<()> {
|
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
|
|
|
let companions = ImageFiles::for_image(img);
|
|
|
|
|
let hash_path = hash_out
|
|
|
|
|
.map(|p| p.to_path_buf())
|
|
|
|
|
.unwrap_or(companions.hash_tree);
|
2026-03-11 14:39:18 +00:00
|
|
|
if hash_path.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", hash_path.display());
|
|
|
|
|
}
|
|
|
|
|
let output = std::process::Command::new("veritysetup")
|
2026-03-11 14:43:59 +00:00
|
|
|
.args([
|
|
|
|
|
"format",
|
|
|
|
|
&img.to_string_lossy(),
|
|
|
|
|
&hash_path.to_string_lossy(),
|
|
|
|
|
])
|
2026-03-11 14:39:18 +00:00
|
|
|
.output()
|
|
|
|
|
.context("spawn veritysetup; ensure cryptsetup-bin is installed")?;
|
|
|
|
|
if !output.status.success() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"veritysetup failed: {}",
|
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let root_hash = stdout
|
|
|
|
|
.lines()
|
|
|
|
|
.find(|l| l.starts_with("Root hash:"))
|
|
|
|
|
.context("root hash not found in veritysetup output")?;
|
|
|
|
|
let hash_value = root_hash.trim_start_matches("Root hash:").trim();
|
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
|
|
|
let roothash_path = companions.root_hash;
|
2026-03-11 14:39:18 +00:00
|
|
|
std::fs::write(&roothash_path, hash_value)
|
|
|
|
|
.with_context(|| format!("write {}", roothash_path.display()))?;
|
|
|
|
|
println!("hash image: {}", hash_path.display());
|
|
|
|
|
println!("root hash: {hash_value}");
|
|
|
|
|
println!("roothash: {}", roothash_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:37:53 +00:00
|
|
|
fn bundle_package(dir: &Path, out_dir: Option<&Path>) -> anyhow::Result<()> {
|
|
|
|
|
let manifest = load_manifest(dir)?;
|
|
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let archive_name = format!("{app_id}.app.tar.zst");
|
|
|
|
|
let dest_dir = out_dir.unwrap_or_else(|| Path::new("."));
|
|
|
|
|
let archive_path = dest_dir.join(&archive_name);
|
|
|
|
|
if archive_path.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", archive_path.display());
|
|
|
|
|
}
|
|
|
|
|
let file = std::fs::File::create(&archive_path)
|
|
|
|
|
.with_context(|| format!("create {}", archive_path.display()))?;
|
|
|
|
|
let encoder = zstd::Encoder::new(file, 0)
|
|
|
|
|
.context("create zstd encoder")?
|
|
|
|
|
.auto_finish();
|
|
|
|
|
let mut tar = tar::Builder::new(encoder);
|
|
|
|
|
tar.follow_symlinks(false);
|
|
|
|
|
tar.append_dir_all(app_id, dir)
|
|
|
|
|
.with_context(|| format!("append {} to archive", dir.display()))?;
|
|
|
|
|
tar.finish().context("finish tar archive")?;
|
|
|
|
|
println!("bundled: {}", archive_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn unbundle_package(archive: &Path, out_dir: &Path) -> anyhow::Result<()> {
|
|
|
|
|
let file =
|
|
|
|
|
std::fs::File::open(archive).with_context(|| format!("open {}", archive.display()))?;
|
|
|
|
|
let decoder = zstd::Decoder::new(file).context("create zstd decoder")?;
|
|
|
|
|
let mut tar = tar::Archive::new(decoder);
|
|
|
|
|
tar.unpack(out_dir)
|
|
|
|
|
.with_context(|| format!("unpack to {}", out_dir.display()))?;
|
|
|
|
|
println!("unbundled: {} -> {}", archive.display(), out_dir.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:29:49 +00:00
|
|
|
fn generate_key(output_dir: &Path) -> anyhow::Result<()> {
|
|
|
|
|
use ed25519_dalek::SigningKey;
|
|
|
|
|
use rand::rngs::OsRng;
|
|
|
|
|
let key_path = output_dir.join("weft-sign.key");
|
|
|
|
|
let pub_path = output_dir.join("weft-sign.pub");
|
|
|
|
|
if key_path.exists() || pub_path.exists() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"key files already exist in {}; remove them first",
|
|
|
|
|
output_dir.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let signing_key = SigningKey::generate(&mut OsRng);
|
|
|
|
|
let verifying_key = signing_key.verifying_key();
|
|
|
|
|
std::fs::create_dir_all(output_dir)
|
|
|
|
|
.with_context(|| format!("create {}", output_dir.display()))?;
|
|
|
|
|
std::fs::write(&key_path, hex::encode(signing_key.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", key_path.display()))?;
|
|
|
|
|
std::fs::write(&pub_path, hex::encode(verifying_key.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", pub_path.display()))?;
|
|
|
|
|
println!("private key: {}", key_path.display());
|
|
|
|
|
println!("public key: {}", pub_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sign_package(dir: &Path, key_file: &Path) -> anyhow::Result<()> {
|
|
|
|
|
use ed25519_dalek::{Signer, SigningKey};
|
|
|
|
|
let key_hex = std::fs::read_to_string(key_file)
|
|
|
|
|
.with_context(|| format!("read {}", key_file.display()))?;
|
|
|
|
|
let key_bytes: [u8; 32] = hex::decode(key_hex.trim())
|
|
|
|
|
.context("decode signing key: expected 64 hex chars")?
|
|
|
|
|
.try_into()
|
|
|
|
|
.map_err(|_| anyhow::anyhow!("signing key must be 32 bytes"))?;
|
|
|
|
|
let signing_key = SigningKey::from_bytes(&key_bytes);
|
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
|
|
|
let digest = weft_ipc_types::trust::content_digest(dir)?;
|
|
|
|
|
let signature = signing_key.sign(&digest);
|
|
|
|
|
let sig_path = dir.join(weft_ipc_types::trust::SIGNATURE_FILE);
|
2026-03-11 14:29:49 +00:00
|
|
|
std::fs::write(&sig_path, hex::encode(signature.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", sig_path.display()))?;
|
|
|
|
|
println!("signed: {}", sig_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
fn verify_package(dir: &Path, key: &PublisherKey) -> anyhow::Result<bool> {
|
|
|
|
|
let signature = weft_ipc_types::trust::read_signature(dir)?
|
|
|
|
|
.with_context(|| format!("{} is not signed", dir.display()))?;
|
|
|
|
|
let digest = weft_ipc_types::trust::content_digest(dir)?;
|
|
|
|
|
Ok(key.signed(&digest, &signature))
|
2026-03-11 14:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
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
|
|
|
/// Serialises the tests that change the process environment; the test
|
|
|
|
|
/// harness runs tests on parallel threads that share it.
|
|
|
|
|
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
|
|
|
|
|
|
|
|
|
fn env_lock() -> std::sync::MutexGuard<'static, ()> {
|
|
|
|
|
ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner())
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// A minimal valid package for `app_id` in `src` declaring `capabilities`.
|
|
|
|
|
fn write_package(src: &Path, app_id: &str, capabilities: &str) {
|
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
|
|
|
std::fs::create_dir_all(src.join("ui")).unwrap();
|
|
|
|
|
std::fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
std::fs::write(src.join("ui/index.html"), b"").unwrap();
|
|
|
|
|
std::fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
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
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"D\"\nversion = \"1.0.0\"\n\
|
|
|
|
|
capabilities = [{capabilities}]\n\n\
|
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
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Runs `f` with HOME set to `home` and XDG_DATA_HOME to `home/share`.
|
|
|
|
|
fn with_home<T>(home: &Path, f: impl FnOnce() -> T) -> T {
|
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
|
|
|
let _env = env_lock();
|
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
|
|
|
let prior: Vec<_> = ["HOME", "XDG_DATA_HOME"]
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|k| (*k, std::env::var_os(k)))
|
|
|
|
|
.collect();
|
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
|
|
|
// SAFETY: env_lock serialises every test that touches the environment.
|
|
|
|
|
unsafe {
|
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
|
|
|
std::env::set_var("HOME", home);
|
|
|
|
|
std::env::set_var("XDG_DATA_HOME", home.join("share"));
|
|
|
|
|
}
|
|
|
|
|
let result = f();
|
|
|
|
|
for (key, value) in prior {
|
|
|
|
|
unsafe {
|
|
|
|
|
match value {
|
|
|
|
|
Some(v) => std::env::set_var(key, v),
|
|
|
|
|
None => std::env::remove_var(key),
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
fn temp_root(name: &str) -> PathBuf {
|
|
|
|
|
let root = std::env::temp_dir().join(format!("weft_pack_{name}_{}", std::process::id()));
|
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
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
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
|
|
|
root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const APP_DATA: &str = "\"fs:rw:app-data\"";
|
|
|
|
|
|
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
|
|
|
/// Runs `f` like `with_home`, with only the keys in `home/keys` trusted.
|
|
|
|
|
fn with_trust<T>(home: &Path, f: impl FnOnce() -> T) -> T {
|
|
|
|
|
with_home(home, || {
|
|
|
|
|
let prior = std::env::var_os("WEFT_TRUSTED_KEYS");
|
|
|
|
|
// SAFETY: with_home holds env_lock.
|
|
|
|
|
unsafe { std::env::set_var("WEFT_TRUSTED_KEYS", home.join("keys")) };
|
|
|
|
|
let result = f();
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_TRUSTED_KEYS", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_TRUSTED_KEYS"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Writes a signing key derived from `seed` to `home/<name>.key` and
|
|
|
|
|
/// returns its path; with `trusted`, its public key joins `home/keys`.
|
|
|
|
|
fn key(home: &Path, name: &str, seed: u8, trusted: bool) -> PathBuf {
|
|
|
|
|
let signing = ed25519_dalek::SigningKey::from_bytes(&[seed; 32]);
|
|
|
|
|
std::fs::create_dir_all(home.join("keys")).unwrap();
|
|
|
|
|
let path = home.join(format!("{name}.key"));
|
|
|
|
|
std::fs::write(&path, hex::encode(signing.to_bytes())).unwrap();
|
|
|
|
|
if trusted {
|
|
|
|
|
std::fs::write(
|
|
|
|
|
home.join("keys").join(format!("{name}.pub")),
|
|
|
|
|
hex::encode(signing.verifying_key().to_bytes()),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn owner_of(home: &Path, app_id: &str) -> Option<Owner> {
|
|
|
|
|
weft_ipc_types::trust::read_owner(&weft_ipc_types::trust::owner_record_path(
|
|
|
|
|
&home.join("share"),
|
|
|
|
|
app_id,
|
|
|
|
|
))
|
|
|
|
|
.unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn staging_left(store: &Path) -> bool {
|
|
|
|
|
std::fs::read_dir(store).is_ok_and(|entries| {
|
|
|
|
|
entries
|
|
|
|
|
.flatten()
|
|
|
|
|
.any(|e| e.file_name().to_string_lossy().starts_with(".staging-"))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn only_packages_signed_by_a_trusted_key_install_as_verified() {
|
|
|
|
|
let home = temp_root("verified");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.verified";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let publisher = key(&home, "publisher", 1, true);
|
|
|
|
|
let stranger = key(&home, "stranger", 2, false);
|
|
|
|
|
|
|
|
|
|
// Unsigned, then signed by a key the host does not trust.
|
|
|
|
|
let unsigned = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
});
|
|
|
|
|
sign_package(&home.join("src"), &stranger).unwrap();
|
|
|
|
|
let untrusted = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
});
|
|
|
|
|
for refused in [&unsigned, &untrusted] {
|
|
|
|
|
let message = format!("{:#}", refused.as_ref().unwrap_err());
|
|
|
|
|
assert!(message.contains("not signed by a trusted key"), "{message}");
|
|
|
|
|
}
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert!(!staging_left(&store));
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), None);
|
|
|
|
|
|
|
|
|
|
// Signed by a trusted key.
|
|
|
|
|
sign_package(&home.join("src"), &publisher).unwrap();
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(store.join(app_id).join("signature.sig").exists());
|
|
|
|
|
let key = PublisherKey::from_file(&home.join("keys/publisher.pub")).unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), Some(Owner::Verified(key)));
|
|
|
|
|
assert!(!staging_left(&store));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn content_changed_after_signing_is_refused() {
|
|
|
|
|
let home = temp_root("tampered");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.tampered";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
sign_package(&home.join("src"), &key(&home, "publisher", 3, true)).unwrap();
|
|
|
|
|
std::fs::write(home.join("src/ui/index.html"), "<script>changed</script>").unwrap();
|
|
|
|
|
let refused = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
});
|
|
|
|
|
assert!(refused.is_err());
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert!(!staging_left(&store));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn an_app_id_stays_with_its_first_owner_while_its_data_remains() {
|
|
|
|
|
let home = temp_root("owner");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.owned";
|
|
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
sign_package(&home.join("src"), &key(&home, "first", 4, true)).unwrap();
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
let data = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
|
|
|
|
std::fs::create_dir_all(&data).unwrap();
|
|
|
|
|
with_trust(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
|
|
|
|
|
// Another trusted publisher, and a development build, cannot take the
|
|
|
|
|
// ID over while the first owner's data remains.
|
|
|
|
|
sign_package(&home.join("src"), &key(&home, "second", 5, true)).unwrap();
|
|
|
|
|
let other_publisher = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
});
|
|
|
|
|
let development = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
});
|
|
|
|
|
for refused in [&other_publisher, &development] {
|
|
|
|
|
let message = format!("{:#}", refused.as_ref().unwrap_err());
|
|
|
|
|
assert!(message.contains("belongs to publisher"), "{message}");
|
|
|
|
|
}
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert!(!staging_left(&store));
|
|
|
|
|
|
|
|
|
|
// With no data left, uninstall frees the ID.
|
|
|
|
|
std::fs::remove_dir_all(&data).unwrap();
|
|
|
|
|
sign_package(&home.join("src"), &home.join("first.key")).unwrap();
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
with_trust(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), None);
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), Some(Owner::Development));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn packages_with_links_are_refused() {
|
|
|
|
|
let home = temp_root("links");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.links";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
std::os::unix::fs::symlink("/etc/hostname", home.join("src/ui/host.txt")).unwrap();
|
|
|
|
|
assert!(check_package(&home.join("src")).is_err());
|
|
|
|
|
let refused = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
});
|
|
|
|
|
assert!(refused.is_err());
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert!(sign_package(&home.join("src"), &key(&home, "publisher", 6, true)).is_err());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 13:59:54 +00:00
|
|
|
#[test]
|
|
|
|
|
fn a_development_id_does_not_become_verified() {
|
|
|
|
|
let home = temp_root("dev_owned");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.devowned";
|
|
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
let data = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
|
|
|
|
std::fs::create_dir_all(&data).unwrap();
|
|
|
|
|
with_trust(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
|
|
|
|
|
sign_package(&home.join("src"), &key(&home, "publisher", 7, true)).unwrap();
|
|
|
|
|
let refused = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Verified)
|
|
|
|
|
});
|
|
|
|
|
let message = format!("{:#}", refused.unwrap_err());
|
|
|
|
|
assert!(message.contains("belongs to development"), "{message}");
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), Some(Owner::Development));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_failed_placement_leaves_no_claim_on_the_id() {
|
|
|
|
|
let home = temp_root("placement");
|
|
|
|
|
let staging = home.join(".staging-x");
|
|
|
|
|
let dest = home.join("org.weft.test.placed");
|
|
|
|
|
std::fs::create_dir_all(&staging).unwrap();
|
|
|
|
|
std::fs::create_dir_all(dest.join("ui")).unwrap();
|
|
|
|
|
let record = home.join("owners/org.weft.test.placed");
|
|
|
|
|
weft_ipc_types::trust::write_owner(&record, Owner::Development).unwrap();
|
|
|
|
|
|
|
|
|
|
let admission = Admission {
|
|
|
|
|
owner: Owner::Development,
|
|
|
|
|
created_record: Some(record.clone()),
|
|
|
|
|
};
|
|
|
|
|
assert!(place(&staging, &dest, admission).is_err());
|
|
|
|
|
assert!(!staging.exists());
|
|
|
|
|
assert!(!record.exists());
|
|
|
|
|
assert!(
|
|
|
|
|
dest.join("ui").is_dir(),
|
|
|
|
|
"the existing package is untouched"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// A record that existed before this installation is kept.
|
|
|
|
|
std::fs::create_dir_all(&staging).unwrap();
|
|
|
|
|
weft_ipc_types::trust::write_owner(&record, Owner::Development).unwrap();
|
|
|
|
|
let admission = Admission {
|
|
|
|
|
owner: Owner::Development,
|
|
|
|
|
created_record: None,
|
|
|
|
|
};
|
|
|
|
|
assert!(place(&staging, &dest, admission).is_err());
|
|
|
|
|
assert!(record.exists());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn installed_files_are_not_writable_by_others() {
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
let home = temp_root("modes");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.modes";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let set = |rel: &str, mode: u32| {
|
|
|
|
|
std::fs::set_permissions(
|
|
|
|
|
home.join("src").join(rel),
|
|
|
|
|
std::fs::Permissions::from_mode(mode),
|
|
|
|
|
)
|
|
|
|
|
.unwrap()
|
|
|
|
|
};
|
|
|
|
|
set("ui/index.html", 0o666);
|
|
|
|
|
set("app.wasm", 0o777);
|
|
|
|
|
set("ui", 0o777);
|
|
|
|
|
with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
let mode = |rel: &str| {
|
|
|
|
|
std::fs::metadata(store.join(app_id).join(rel))
|
|
|
|
|
.unwrap()
|
|
|
|
|
.permissions()
|
|
|
|
|
.mode()
|
|
|
|
|
& 0o777
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(mode("ui/index.html"), 0o644);
|
|
|
|
|
assert_eq!(mode("app.wasm"), 0o755);
|
|
|
|
|
assert_eq!(mode("ui"), 0o755);
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
#[test]
|
|
|
|
|
fn packages_with_non_utf8_names_are_refused() {
|
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
let home = temp_root("non_utf8");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.nonutf8";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let name = std::ffi::OsStr::from_bytes(b"ui/\xff.html");
|
|
|
|
|
std::fs::write(home.join("src").join(name), b"").unwrap();
|
|
|
|
|
let refused = with_trust(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
});
|
|
|
|
|
assert!(refused.is_err());
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
assert!(!staging_left(&store));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
#[test]
|
|
|
|
|
fn uninstall_releases_a_record_left_by_an_interrupted_install() {
|
|
|
|
|
let home = temp_root("interrupted");
|
|
|
|
|
let store = home.join("store");
|
|
|
|
|
let app_id = "org.weft.test.interrupted";
|
|
|
|
|
let record = weft_ipc_types::trust::owner_record_path(&home.join("share"), app_id);
|
|
|
|
|
weft_ipc_types::trust::write_owner(&record, Owner::Development).unwrap();
|
|
|
|
|
let data = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
|
|
|
|
std::fs::create_dir_all(&data).unwrap();
|
|
|
|
|
|
|
|
|
|
// While data remains the record stays, and uninstall reports nothing
|
|
|
|
|
// installed.
|
|
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &store)).is_err());
|
|
|
|
|
assert!(record.exists());
|
|
|
|
|
std::fs::remove_dir_all(&data).unwrap();
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
assert!(!record.exists());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 14:13:18 +00:00
|
|
|
#[test]
|
|
|
|
|
fn a_record_stays_while_another_store_holds_the_package() {
|
|
|
|
|
let home = temp_root("other_store");
|
|
|
|
|
let app_id = "org.weft.test.otherstore";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let user_store = home.join(".local/share/weft/apps");
|
|
|
|
|
let elsewhere = home.join("elsewhere");
|
|
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &user_store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &elsewhere)).is_err());
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), Some(Owner::Development));
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &user_store)).unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), None);
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
2026-10-09 14:25:09 +00:00
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_missing_store_is_created_readable_by_everyone() {
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
let home = temp_root("new_store");
|
|
|
|
|
std::fs::create_dir_all(&home).unwrap();
|
|
|
|
|
let mode = |p: &Path| std::fs::metadata(p).unwrap().permissions().mode() & 0o777;
|
|
|
|
|
// An absolute store with missing parents.
|
|
|
|
|
let absolute = home.join("a/b/store");
|
|
|
|
|
create_store(&absolute).unwrap();
|
|
|
|
|
for dir in [home.join("a"), home.join("a/b"), absolute.clone()] {
|
|
|
|
|
assert_eq!(mode(&dir), 0o755, "{}", dir.display());
|
|
|
|
|
}
|
|
|
|
|
// A relative store none of whose components exist yet.
|
|
|
|
|
let relative = PathBuf::from(format!("weft-pack-store-{}/sub", std::process::id()));
|
|
|
|
|
let _ = std::fs::remove_dir_all(relative.parent().unwrap());
|
|
|
|
|
create_store(&relative).unwrap();
|
|
|
|
|
assert_eq!(mode(&relative), 0o755);
|
|
|
|
|
std::fs::remove_dir_all(relative.parent().unwrap()).unwrap();
|
|
|
|
|
// An existing store is left as it is.
|
|
|
|
|
std::fs::set_permissions(&absolute, std::fs::Permissions::from_mode(0o750)).unwrap();
|
|
|
|
|
create_store(&absolute).unwrap();
|
|
|
|
|
assert_eq!(mode(&absolute), 0o750);
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
2026-10-09 14:13:18 +00:00
|
|
|
|
2026-10-09 14:17:09 +00:00
|
|
|
#[test]
|
|
|
|
|
fn uninstalling_one_of_two_copies_keeps_the_record() {
|
|
|
|
|
let home = temp_root("two_copies");
|
|
|
|
|
let app_id = "org.weft.test.twocopies";
|
|
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let user_store = home.join(".local/share/weft/apps");
|
|
|
|
|
let other = home.join("other");
|
|
|
|
|
for store in [&user_store, &other] {
|
|
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &other)).unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), Some(Owner::Development));
|
|
|
|
|
|
|
|
|
|
// A leftover directory that is not a package does not hold the ID.
|
|
|
|
|
std::fs::remove_dir_all(user_store.join(app_id)).unwrap();
|
|
|
|
|
std::fs::create_dir_all(user_store.join(app_id)).unwrap();
|
|
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &other, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &other)).unwrap();
|
|
|
|
|
assert_eq!(owner_of(&home, app_id), None);
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2026-10-09 14:04:53 +00:00
|
|
|
#[test]
|
|
|
|
|
fn copies_never_follow_links_swapped_in() {
|
2026-10-09 14:17:09 +00:00
|
|
|
use rustix::fs::{CWD, Mode, OFlags};
|
2026-10-09 14:04:53 +00:00
|
|
|
let home = temp_root("swapped");
|
2026-10-09 14:17:09 +00:00
|
|
|
for dir in ["outside", "pkg/dir", "held"] {
|
2026-10-09 14:13:18 +00:00
|
|
|
std::fs::create_dir_all(home.join(dir)).unwrap();
|
|
|
|
|
}
|
2026-10-09 14:20:35 +00:00
|
|
|
std::fs::write(home.join("outside/other"), b"outside").unwrap();
|
2026-10-09 14:13:18 +00:00
|
|
|
std::fs::write(home.join("pkg/dir/secret"), b"listed").unwrap();
|
2026-10-09 14:17:09 +00:00
|
|
|
let open_dir = |path: &Path| {
|
|
|
|
|
rustix::fs::openat(
|
|
|
|
|
CWD,
|
|
|
|
|
path,
|
|
|
|
|
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::NOFOLLOW,
|
|
|
|
|
Mode::empty(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A directory replaced by a link after it was opened, before its
|
|
|
|
|
// entries are read: the copy reads the directory that was opened.
|
|
|
|
|
let dir = open_dir(&home.join("pkg/dir"));
|
|
|
|
|
std::fs::rename(home.join("pkg/dir"), home.join("held/dir")).unwrap();
|
2026-10-09 14:13:18 +00:00
|
|
|
std::os::unix::fs::symlink(home.join("outside"), home.join("pkg/dir")).unwrap();
|
2026-10-09 14:17:09 +00:00
|
|
|
copy_tree(&dir, &home.join("pkg/dir"), &home.join("copied")).unwrap();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read(home.join("copied/secret")).unwrap(),
|
|
|
|
|
b"listed"
|
|
|
|
|
);
|
2026-10-09 14:20:35 +00:00
|
|
|
assert!(!home.join("copied/other").exists());
|
2026-10-09 14:13:18 +00:00
|
|
|
|
2026-10-09 14:17:09 +00:00
|
|
|
// A link where an entry is listed is refused, and so is a FIFO,
|
|
|
|
|
// without waiting for a writer.
|
|
|
|
|
let pkg = open_dir(&home.join("pkg"));
|
|
|
|
|
assert!(copy_tree(&pkg, &home.join("pkg"), &home.join("copied_link")).is_err());
|
|
|
|
|
std::fs::remove_file(home.join("pkg/dir")).unwrap();
|
2026-10-09 14:13:18 +00:00
|
|
|
rustix::fs::mknodat(
|
2026-10-09 14:17:09 +00:00
|
|
|
CWD,
|
2026-10-09 14:13:18 +00:00
|
|
|
home.join("pkg/fifo"),
|
|
|
|
|
rustix::fs::FileType::Fifo,
|
2026-10-09 14:17:09 +00:00
|
|
|
Mode::from_raw_mode(0o600),
|
2026-10-09 14:13:18 +00:00
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2026-10-09 14:17:09 +00:00
|
|
|
let pkg = open_dir(&home.join("pkg"));
|
|
|
|
|
assert!(copy_tree(&pkg, &home.join("pkg"), &home.join("copied_fifo")).is_err());
|
2026-10-09 14:04:53 +00:00
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
#[test]
|
|
|
|
|
fn uninstall_keeps_app_data_from_the_user_store() {
|
|
|
|
|
let home = temp_root("keep");
|
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
|
|
|
let app_id = "com.example.keep";
|
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
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
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
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
let legacy = store.join(app_id).join("data");
|
|
|
|
|
std::fs::create_dir_all(&legacy).unwrap();
|
|
|
|
|
std::fs::write(legacy.join("notes.txt"), "first\nsecond").unwrap();
|
|
|
|
|
|
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
|
|
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
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
|
|
|
assert!(!store.join(app_id).exists());
|
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
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
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
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(kept.join("notes.txt")).unwrap(),
|
|
|
|
|
"first\nsecond"
|
|
|
|
|
);
|
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
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
let mode = std::fs::metadata(&kept).unwrap().permissions().mode();
|
|
|
|
|
assert_eq!(mode & 0o777, 0o700);
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
// A second copy cannot be merged: uninstall refuses and removes nothing.
|
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
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
std::fs::create_dir_all(&legacy).unwrap();
|
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
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &store)).is_err());
|
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
|
|
|
assert!(legacy.is_dir() && kept.is_dir());
|
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
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-10-09 09:01:28 +00:00
|
|
|
fn data_that_is_not_moved_is_never_removed() {
|
|
|
|
|
let home = temp_root("refuse");
|
|
|
|
|
let app_id = "com.example.refuse";
|
|
|
|
|
// No app-data capability: the data directory is left and uninstall stops.
|
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
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
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
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
2026-10-09 09:01:28 +00:00
|
|
|
std::fs::write(store.join(app_id).join("data/x"), "x").unwrap();
|
|
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &store)).is_err());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(store.join(app_id).join("data/x")).unwrap(),
|
|
|
|
|
"x"
|
|
|
|
|
);
|
|
|
|
|
std::fs::remove_dir_all(store.join(app_id)).unwrap();
|
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
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
// Another store: earlier versions never kept data there, so it stops too.
|
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
|
|
|
write_package(&home.join("src2"), app_id, APP_DATA);
|
|
|
|
|
let other = home.join("other-store");
|
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
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src2"), &other, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
std::fs::create_dir_all(other.join(app_id).join("data")).unwrap();
|
2026-10-09 09:01:28 +00:00
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &other)).is_err());
|
|
|
|
|
assert!(other.join(app_id).join("data").is_dir());
|
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
|
|
|
assert!(!home.join("share/weft/app-data").exists());
|
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
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
#[test]
|
|
|
|
|
fn data_left_without_a_manifest_is_moved_not_deleted() {
|
|
|
|
|
let home = temp_root("orphan");
|
|
|
|
|
let app_id = "org.weft.demo.notes";
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
|
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
|
|
|
|
std::fs::write(store.join(app_id).join("data/notes.txt"), "kept").unwrap();
|
|
|
|
|
// The store reached through another spelling of the same path.
|
|
|
|
|
let spelled = home.join(".local/share/weft/../weft/apps");
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &spelled)).unwrap();
|
|
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(kept.join("notes.txt")).unwrap(),
|
|
|
|
|
"kept"
|
|
|
|
|
);
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_linked_home_still_finds_the_user_store() {
|
|
|
|
|
let root = temp_root("linked");
|
|
|
|
|
let real = root.join("var-home");
|
|
|
|
|
let app_id = "org.weft.demo.notes";
|
|
|
|
|
std::fs::create_dir_all(
|
|
|
|
|
real.join(".local/share/weft/apps")
|
|
|
|
|
.join(app_id)
|
|
|
|
|
.join("data"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::os::unix::fs::symlink(&real, root.join("home")).unwrap();
|
|
|
|
|
let store = real.join(".local/share/weft/apps");
|
|
|
|
|
with_home(&root.join("home"), || {
|
|
|
|
|
uninstall_package_from(app_id, &store)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(weft_ipc_types::package::app_data_dir(&root.join("home/share"), app_id).is_dir());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
#[test]
|
|
|
|
|
fn packages_cannot_ship_a_top_level_data_entry() {
|
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
|
|
|
let home = temp_root("packages_cannot_ship_a_top_level_data_entry");
|
|
|
|
|
with_home(&home.clone(), move || {
|
|
|
|
|
let root = temp_root("ships-data");
|
|
|
|
|
let src = root.join("src");
|
|
|
|
|
write_package(&src, "com.example.ships", "");
|
|
|
|
|
std::fs::create_dir_all(src.join("data")).unwrap();
|
|
|
|
|
std::fs::write(src.join("data/asset.json"), "{}").unwrap();
|
|
|
|
|
let err = check_package(&src).unwrap_err().to_string();
|
|
|
|
|
assert!(err.contains("'data'"), "{err}");
|
|
|
|
|
assert!(
|
|
|
|
|
install_package_to(&src, &root.join("store"), InstallMode::Development).is_err()
|
|
|
|
|
);
|
|
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
|
|
|
|
});
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn install_moves_leftover_app_data_out_of_the_way() {
|
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
|
|
|
let home = temp_root("leftover");
|
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
|
|
|
let app_id = "com.example.leftover";
|
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
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
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
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
|
|
|
|
std::fs::write(store.join(app_id).join("data/x"), "x").unwrap();
|
|
|
|
|
|
2026-10-09 14:04:53 +00:00
|
|
|
// The moved data has no recorded owner, so it is given to this
|
|
|
|
|
// package only when asked.
|
|
|
|
|
let unclaimed = with_home(&home, || {
|
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
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
2026-10-09 14:04:53 +00:00
|
|
|
});
|
|
|
|
|
let message = format!("{:#}", unclaimed.unwrap_err());
|
|
|
|
|
assert!(message.contains("--claim-data"), "{message}");
|
|
|
|
|
assert!(!store.join(app_id).join("wapp.toml").exists());
|
|
|
|
|
with_home(&home, || {
|
|
|
|
|
install_into(&home.join("src"), &store, InstallMode::Development, true)
|
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
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
assert!(store.join(app_id).join("wapp.toml").exists());
|
|
|
|
|
assert!(!store.join(app_id).join("data").exists());
|
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
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
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
|
|
|
assert_eq!(std::fs::read_to_string(kept.join("x")).unwrap(), "x");
|
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
|
|
|
|
|
|
|
|
// An empty directory left behind does not block installation either.
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
std::fs::create_dir_all(store.join(app_id)).unwrap();
|
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
|
|
|
with_home(&home, || {
|
|
|
|
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
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
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
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
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn app_id_valid() {
|
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
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"org.weft.calculator"
|
|
|
|
|
));
|
|
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"io.github.username.app"
|
|
|
|
|
));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn app_id_invalid() {
|
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
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id("com.example"));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"Com.example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.example.notes-app"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com..example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(""));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.Example.notes"
|
|
|
|
|
));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_manifest() {
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_empty");
|
|
|
|
|
let _ = std::fs::create_dir_all(&tmp);
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 12:07:45 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_wasm() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_no_wasm");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.nowasm"
|
|
|
|
|
name = "No Wasm"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_ui_entry() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_no_ui");
|
|
|
|
|
let _ = fs::create_dir_all(&tmp);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.noui"
|
|
|
|
|
name = "No UI"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_valid() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_valid");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.test"
|
|
|
|
|
name = "Test App"
|
|
|
|
|
version = "1.0.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert_eq!(result.unwrap(), "OK");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:54:39 +00:00
|
|
|
#[test]
|
|
|
|
|
fn install_package_copies_to_store() {
|
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
|
|
|
let home = temp_root("install_package_copies_to_store");
|
|
|
|
|
with_home(&home.clone(), move || {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("weft.pack.install{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(format!("weft_pack_install_src_{}", id));
|
|
|
|
|
let store = std::env::temp_dir().join(format!("weft_pack_install_store_{}", id));
|
|
|
|
|
let ui_dir = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.t{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"Test\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = install_package_to(&src, &store, InstallMode::Development);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert!(store.join(&app_id).join("app.wasm").exists());
|
|
|
|
|
assert!(store.join(&app_id).join("wapp.toml").exists());
|
|
|
|
|
assert!(store.join(&app_id).join("ui").join("index.html").exists());
|
|
|
|
|
assert!(install_package_to(&src, &store, InstallMode::Development).is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
});
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
2026-03-11 08:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn uninstall_package_removes_directory() {
|
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
|
|
|
let home = temp_root("uninstall_package_removes_directory");
|
|
|
|
|
with_home(&home.clone(), move || {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("weft.pack.uninstall{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(format!("weft_pack_uninstall_src_{}", id));
|
|
|
|
|
let store = std::env::temp_dir().join(format!("weft_pack_uninstall_store_{}", id));
|
|
|
|
|
let ui_dir = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
let app_id = format!("com.example.u{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"U\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
install_package_to(&src, &store, InstallMode::Development).unwrap();
|
|
|
|
|
assert!(store.join(&app_id).exists());
|
|
|
|
|
let result = uninstall_package_from(&app_id, &store);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert!(!store.join(&app_id).exists());
|
|
|
|
|
assert!(uninstall_package_from(&app_id, &store).is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
});
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
2026-03-11 08:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:21:43 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_bad_wasm_magic() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_bad_wasm");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"NOT_WASM").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.badwasm"
|
|
|
|
|
name = "Bad Wasm"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let msg = result.unwrap_err().to_string();
|
|
|
|
|
assert!(msg.contains("bad magic bytes"), "got: {msg}");
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_invalid_app_id() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_invalid_id");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "bad-id"
|
|
|
|
|
name = "Bad"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
2026-03-11 11:00:44 +00:00
|
|
|
|
2026-03-11 14:49:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn install_package_from_archive() {
|
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
|
|
|
let home = temp_root("install_package_from_archive");
|
|
|
|
|
with_home(&home.clone(), move || {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("instarch_{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(&id);
|
|
|
|
|
let ui = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.ia{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"IA\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let bundle_dir = std::env::temp_dir().join(format!("{id}_bnd"));
|
|
|
|
|
let _ = fs::create_dir_all(&bundle_dir);
|
|
|
|
|
bundle_package(&src, Some(&bundle_dir)).unwrap();
|
|
|
|
|
let archive = bundle_dir.join(format!("{app_id}.app.tar.zst"));
|
|
|
|
|
|
|
|
|
|
let store = std::env::temp_dir().join(format!("{id}_store"));
|
|
|
|
|
let _ = fs::create_dir_all(&store);
|
|
|
|
|
install_package_to(&archive, &store, InstallMode::Development).unwrap();
|
|
|
|
|
assert!(store.join(&app_id).join("app.wasm").exists());
|
2026-10-09 13:59:54 +00:00
|
|
|
let scratch_left = fs::read_dir(&store).unwrap().flatten().any(|e| {
|
|
|
|
|
let name = e.file_name().to_string_lossy().into_owned();
|
|
|
|
|
name.starts_with(".unpack") || name.starts_with(".staging-")
|
|
|
|
|
});
|
|
|
|
|
assert!(!scratch_left, "archive install left scratch directories");
|
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
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&bundle_dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
});
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
2026-03-11 14:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:37:53 +00:00
|
|
|
#[test]
|
|
|
|
|
fn bundle_and_unbundle_roundtrip() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("bundle_{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(&id);
|
|
|
|
|
let out = std::env::temp_dir().join(format!("{id}_out"));
|
|
|
|
|
let ui = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.b{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"B\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let _ = fs::create_dir_all(&out);
|
|
|
|
|
bundle_package(&src, Some(&out)).unwrap();
|
|
|
|
|
let archive = out.join(format!("{app_id}.app.tar.zst"));
|
|
|
|
|
assert!(archive.exists());
|
|
|
|
|
|
|
|
|
|
let unpack = std::env::temp_dir().join(format!("{id}_unpack"));
|
|
|
|
|
let _ = fs::create_dir_all(&unpack);
|
|
|
|
|
unbundle_package(&archive, &unpack).unwrap();
|
|
|
|
|
assert!(unpack.join(&app_id).join("app.wasm").exists());
|
|
|
|
|
assert!(unpack.join(&app_id).join("ui").join("index.html").exists());
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&out);
|
|
|
|
|
let _ = fs::remove_dir_all(&unpack);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 11:00:44 +00:00
|
|
|
#[test]
|
2026-03-11 14:29:49 +00:00
|
|
|
fn sign_and_verify_roundtrip() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("sign_verify_{}", std::process::id());
|
|
|
|
|
let dir = std::env::temp_dir().join(&id);
|
|
|
|
|
let key_dir = std::env::temp_dir().join(format!("{id}_keys"));
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
"[package]\nid = \"com.example.signed\"\nname = \"S\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
generate_key(&key_dir).unwrap();
|
|
|
|
|
let key_file = key_dir.join("weft-sign.key");
|
|
|
|
|
let pub_file = key_dir.join("weft-sign.pub");
|
|
|
|
|
|
|
|
|
|
sign_package(&dir, &key_file).unwrap();
|
|
|
|
|
assert!(dir.join("signature.sig").exists());
|
|
|
|
|
|
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
|
|
|
let ok = verify_package(&dir, &PublisherKey::from_file(&pub_file).unwrap()).unwrap();
|
2026-03-11 14:29:49 +00:00
|
|
|
assert!(ok, "signature should verify");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&key_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn verify_rejects_tampered_bundle() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("tamper_{}", std::process::id());
|
|
|
|
|
let dir = std::env::temp_dir().join(&id);
|
|
|
|
|
let key_dir = std::env::temp_dir().join(format!("{id}_keys"));
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
"[package]\nid = \"com.example.tamper\"\nname = \"T\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
generate_key(&key_dir).unwrap();
|
|
|
|
|
sign_package(&dir, &key_dir.join("weft-sign.key")).unwrap();
|
|
|
|
|
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\x01").unwrap();
|
|
|
|
|
|
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
|
|
|
let ok = verify_package(
|
|
|
|
|
&dir,
|
|
|
|
|
&PublisherKey::from_file(&key_dir.join("weft-sign.pub")).unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2026-03-11 14:29:49 +00:00
|
|
|
assert!(!ok, "tampered bundle should not verify");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&key_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-03-11 11:00:44 +00:00
|
|
|
fn list_installed_roots_uses_weft_app_store_when_set() {
|
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
|
|
|
let _env = env_lock();
|
2026-03-11 11:00:44 +00:00
|
|
|
let prior = std::env::var("WEFT_APP_STORE").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_APP_STORE", "/custom/store") };
|
|
|
|
|
let roots = list_installed_roots();
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APP_STORE", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APP_STORE"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(roots, vec![PathBuf::from("/custom/store")]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn list_installed_roots_includes_system_path() {
|
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
|
|
|
let _env = env_lock();
|
2026-03-11 11:00:44 +00:00
|
|
|
let prior = std::env::var("WEFT_APP_STORE").ok();
|
|
|
|
|
unsafe { std::env::remove_var("WEFT_APP_STORE") };
|
|
|
|
|
let roots = list_installed_roots();
|
|
|
|
|
unsafe {
|
|
|
|
|
if let Some(v) = prior {
|
|
|
|
|
std::env::set_var("WEFT_APP_STORE", v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(
|
|
|
|
|
roots
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|p| p == &PathBuf::from("/usr/share/weft/apps"))
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-11 17:35:07 +00:00
|
|
|
|
|
|
|
|
fn make_valid_package(dir: &std::path::Path, id: &str, caps: &str) {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{id}\"\nname = \"T\"\nversion = \"0.1.0\"\n{caps}\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_refuses_entries_outside_the_package() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_entries_{}", std::process::id()));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
make_valid_package(&tmp, "com.example.entries", "");
|
|
|
|
|
std::fs::write(tmp.with_extension("wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
std::os::unix::fs::symlink("index.html", tmp.join("ui/linked.html")).unwrap();
|
|
|
|
|
let manifest = std::fs::read_to_string(tmp.join("wapp.toml")).unwrap();
|
2026-10-09 10:18:36 +00:00
|
|
|
let escaping = format!(
|
|
|
|
|
"../{}",
|
|
|
|
|
tmp.with_extension("wasm").file_name().unwrap().display()
|
|
|
|
|
);
|
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
|
|
|
std::fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
manifest
|
|
|
|
|
.replace("module = \"app.wasm\"", &format!("module = \"{escaping}\""))
|
|
|
|
|
.replace("ui/index.html", "ui/linked.html"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let msg = check_package(&tmp).unwrap_err().to_string();
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
let _ = std::fs::remove_file(tmp.with_extension("wasm"));
|
2026-10-09 10:18:36 +00:00
|
|
|
assert!(
|
|
|
|
|
msg.contains("runtime.module") && msg.contains("not a relative path"),
|
|
|
|
|
"{msg}"
|
|
|
|
|
);
|
|
|
|
|
assert!(
|
|
|
|
|
msg.contains("ui.entry") && msg.contains("symbolic link"),
|
|
|
|
|
"{msg}"
|
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:35:07 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_unknown_capability_errors() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_caps_bad_{}", std::process::id()));
|
|
|
|
|
make_valid_package(&tmp, "com.example.caps", "capabilities = [\"network:tcp\"]");
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
assert!(result.unwrap_err().to_string().contains("network:tcp"));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_known_capabilities_accepted() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_caps_ok_{}", std::process::id()));
|
|
|
|
|
make_valid_package(
|
|
|
|
|
&tmp,
|
|
|
|
|
"com.example.caps",
|
|
|
|
|
"capabilities = [\"fs:rw:app-data\", \"fs:read:xdg-documents\"]",
|
|
|
|
|
);
|
|
|
|
|
assert!(check_package(&tmp).is_ok());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|