Documentation
¶
Overview ¶
Package pathguard confines a path built from config, a manifest, an archive or a request under the directory it is meant to stay in.
It is the one place that rule is written. Every caller that joins a name it did not choose onto a directory -- a pack slug from the web UI, a set name from the audit form, an archive member, a fingerprint key -- goes through Join, so the checks cannot drift apart between them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEscape = errors.New("path escapes its root")
ErrEscape is wrapped by every refusal, so a caller can tell a path that would leave its root from an I/O error.
Functions ¶
func Join ¶
Join returns root joined with elem, cleaned, or an error wrapping ErrEscape when the result could leave root. A relative root gives a relative result, as filepath.Join would; the checks themselves run on the absolute path.
It refuses, before touching the filesystem:
- an empty root;
- an absolute element, or one with a volume name;
- any `..` at all, as a component or inside a name (`a..b.svg`): a name that needs one is not a name any caller here produces honestly, and refusing the substring is the check static analysis recognises. Measured 2026-11-05: none of the 260,763 shipped SVGs has `..` in its name.
Then, because a name with no `..` can still leave through a link, it resolves the deepest part of the result that exists and refuses it unless it is still under root with root's own links resolved too. A dangling link is refused, since creating the file would follow it. A root that does not exist yet holds no links, so a path under it is accepted.
The returned path is root joined with the relative path filepath.Rel computed, never with the caller's input as given.
Types ¶
This section is empty.