pathguard

package
v0.1.3-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Join(root string, elem ...string) (string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL