Files
craft-libs/crates/cloud-local/Cargo.toml
T
William Dunn aa4647a777 craft-cloud-local: confine every path through a Dir capability, not a path string
benandez's re-review reproduced three escapes the first confinement fix still
left open. A dangling symlink: canonicalize reported it as missing, so the
old confine_to_root walked up to root and accepted it, and write created the
symlink's target for real, outside root. A check-then-use race: confine_to_root
checked one path string and a later fs::read or fs::write resolved that same
string again, a second lookup a concurrently swapped link could land in
between. A hard link: write truncated the shared inode in place, with nothing
in a canonicalized path to show that another name pointed at the same file
outside root.

list, read, write and create now resolve every already segment-checked
relative path through a cap_std::fs::Dir capability opened on root, instead
of joining an absolute OS path and handing it to plain std::fs. cap_std
resolves one path component at a time against real, already-open directory
handles, so a symlink or a Windows junction cannot walk resolution above
root, dangling or not, and there is no separate check with a window for the
directory tree to change underneath it: the one resolution is the open. This
is the same family of guarantee craft-font-store already depends on through
cap-primitives, which cap_std is built on.

write no longer truncates its target in place either way: it writes a new
sibling file and renames it over the target, so a hard link's directory
entry is replaced rather than its shared content being overwritten.

Per that review's non-blocking notes: a name that already exists on disk
with an ordinary ':' or '\' byte (macOS stores a typed '/' as ':') stays
reachable by list and read, since neither character is a path separator on
any platform's filesystem; the stricter refusal now applies only to a name
being chosen by Create. Create also goes back to bringing a fresh root into
existence, matching its behaviour before the first confinement fix. A
Windows reserved device name (CON, COM1, CONIN$, with or without an
extension) is refused in a chosen name on every platform.

Regression tests reproduce all three escapes (dangling symlink, swapped-link
race, hard link), plus the previously missing coverage: a link in the folder
a Create targets, and a write test that actually reaches disk instead of
being refused for an unrelated reason before confinement ever ran. Verified
by hand that each of the three new write-path tests fails against the
pre-fix pattern (an absolute OS path joined by string concatenation) before
trusting them.
2026-11-17 00:51:58 -05:00

26 lines
907 B
TOML

[package]
name = "craft-cloud-local"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
description = "A reference CloudBackend over a local folder, proving the contract needs no specific provider"
[lints]
workspace = true
[dependencies]
# Resolution-time confinement: every path this crate resolves goes through a `Dir` capability
# opened on the configured root, never through an absolute OS path this crate builds itself.
# `craft-font-store` already depends on the lower-level `cap-primitives` for the same family of
# guarantee; this crate uses the ergonomic `cap-std` built on top of it instead of hand-rolling
# the equivalent `Dir`-style API again.
cap-std = "4"
craft-cloud = { workspace = true }
craft-ui = { workspace = true, features = ["cloud"] }
[dev-dependencies]
tempfile = "3"
egui = { workspace = true }