Expand description
Path-safety helpers for confining ceremony-derived names and paths.
Ceremony files are authored by third parties and may be downloaded and run
by an operator who never inspected them. Any string from a ceremony that
ends up on the filesystem — an artifact id used as an output filename, a
material’s path: value — is therefore untrusted and must not be allowed to
escape the directory it is meant to live in.
Two primitives cover the cases that occur in practice:
validate_component/safe_joinfor a value that must be a single path component (a bare file or directory name). This is the right tool for identifiers that become filenames. Because these names are created by the runtime and a ceremony is portable across operating systems, the rules are the intersection of what every platform accepts (seevalidate_componentfor the full list).confinefor a value that may legitimately be a multi-segment relative path but must stay within a known root (e.g.keys/root.pemunder the ceremony directory). This is used for reading files that already exist on the host, so it only enforces containment, not name portability.
Both are purely lexical: they never touch the filesystem, so they are safe to
call on paths that do not exist yet and cannot be confused by the current
working directory. Lexical checks do not defend against symlinks placed
at the destination — call sites that create files should additionally open
with create_new (no-follow, no-clobber) so a pre-planted symlink cannot
redirect the write.
Enums§
- Path
Safety Error - Why a ceremony-supplied name or path was rejected as unsafe.
Functions§
- confine
- Resolve an untrusted relative
candidateagainstroot, guaranteeing the result stays withinroot. - is_
safe_ component - Returns
trueifnameis a safe single path component. - safe_
join - Join a single untrusted
nameontobase, guaranteeing the result is a direct child ofbase. - validate_
component - Validate that
nameis a safe, portable single path component: a non-empty plain file or directory name that every supported platform accepts and that cannot leave its directory.