Skip to content

Security: tenuo-ai/path_jail

SECURITY.md

Security Policy

This document is the threat model and security contract for path_jail. It exists because every security library needs one: callers can only use the library correctly if they know what it defends against and what it doesn't.

If you find a vulnerability, see Reporting a vulnerability below.


Attacker model

path_jail is designed to defend against an attacker who supplies path strings to your application — for example:

  • A web client uploading a file with a chosen filename
  • A user-controlled config value naming a path inside a sandbox directory
  • A workflow step naming a file inside a CI working directory

The attacker can supply:

  • Arbitrary bytes in the path (including .., leading /, null bytes, magic link prefixes like /proc/self/fd/N)
  • A pre-existing symlink inside the jail that points outside the jail
  • A pre-existing hard link inside the jail that points to sensitive content
  • Concurrent filesystem activity attempting to swap paths between validation and open (TOCTOU)

The attacker is assumed to not have:

  • Privileges to mount filesystems, run as root inside the jail's filesystem, call ptrace, or otherwise escape the OS sandbox the application runs in
  • The ability to modify the running process's memory
  • A working kernel exploit

If your attacker can do any of the above, no userspace library can help — you need a process-level sandbox (seccomp, landlock, containers, VMs).


What each API defends against

path_jail ships three API layers with different security/ergonomics tradeoffs. Pick the strongest one your environment supports.

Threat Jail (default) secure-open guard (Linux 5.6+, x86_64/aarch64)⁰
Path traversal via .. ✅ ✅ ✅
Absolute path injection (/etc/passwd) ✅ ✅ ✅
Null-byte injection ✅ ✅ ✅
Symlink target outside the jail ✅ ✅ ✅
Broken symlinks (cannot verify target) ✅ ✅ ✅
Symlink swap on final component (TOCTOU) ❌ ✅ ✅
Symlink swap on intermediate directories ❌ ❌ ✅
Concurrent rename of jail root mid-operation ❌ ❌ ✅¹
Magic links (/proc/self/fd, /proc/self/root) ❌ ❌ ✅
Hard link to sensitive content (detect) ❌² ❌² ✅³
FIFO / device node opened as data (opt-in) ❌ ❌ ✅⁷
Bind-mount escape (opt-in) ❌ ❌ ✅⁴
Atomic open with kernel-enforced containment ❌ ❌ ✅
Atomic fd-relative create/remove/rename ❌ ❌ ✅⁶
Handle-relative directory iteration/open ❌ ❌ ✅⁸
Signed attestation of the open event ❌ ❌ ✅⁵

Footnotes:

  1. The guard column describes the openat2 path, used on Linux 5.6+ on x86_64 and aarch64. On macOS/BSD and other Linux architectures the same API falls back to an O_NOFOLLOW open with the protection of the secure-open column, and Attestation::toctou_safe is false. The handle policies (footnotes 3 and 7) work on every Unix target, because they check the opened handle rather than the path. The full matrix is in README.md § Platform support.

  2. guard::FdJail pins an O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC fd to the jail root at construction time. Subsequent renames or replacements of the root path do not affect the jail — all operations remain scoped to the original directory inode.

  3. Hard links are not detectable in user space before open. The path-based APIs do not stat the opened file and so cannot surface nlink.

  4. Opt in with OpenOptions::reject_hard_links(true): the open fails with JailError::HardLinkRejected when the opened handle's fstat reports nlink > 1 (directories are exempt), and a requested truncate is deferred until the check passes. Off by default because a content-addressed store may legitimately use hard links; GuardedFile::has_hard_links() remains for callers that apply their own policy after open. The check is point-in-time: a process that already holds the outside file can re-link it after the check, so do not rely on in-place truncation when that race matters (write a new file and rename it instead).

  5. Opt in with OpenOptions::no_xdev(true) (maps to RESOLVE_NO_XDEV). Off by default to preserve directory-tree containment semantics, which are what most callers want.

  6. Opt in by implementing the Signer trait. path_jail ships no crypto; bring your own (ed25519-dalek, ring, HSM client, KMS, etc.).

    Version 1 attestations (the format used by 0.4 and 0.5) prove that a holder of the configured signing key signed the recorded fields. They do not include a verifier challenge, audience, key identifier, or expiration policy, and are therefore replayable. Do not use them as authorization tokens. Bind freshness and request context in the surrounding protocol until the versioned attestation format is available.

  7. create_dir, create_dir_all, remove_file, remove_dir, rename, and replace_file are available only on Linux x86_64/aarch64. They pin parent directories beneath the jail before issuing fd-relative mutation syscalls. create_dir_all additionally validates existing components with O_PATH | O_DIRECTORY. replace_file creates its temporary entry and installs it relative to the same pinned destination parent. A pinned parent that another process moves out of the jail before the syscall is still the target. Where untrusted processes can modify the tree, use a dedicated filesystem or mount for the jail whose contents are not writable through any other path (a bind mount whose source stays writable elsewhere is not enough). replace_file additionally requires exclusive mutation authority over the destination directory while its writer callback runs. A process that can rename entries there can substitute the named temporary entry before installation. File mode 0o600 does not protect against another process running under the same identity or with elevated privileges. They are omitted on fallback targets rather than exposing a racy pathname implementation.

  8. Opt in with OpenOptions::require_regular_file(true): a directory, FIFO or device node that the OS lets us open fails with JailError::FileTypeRejected, and the open is non-blocking so a FIFO cannot hang the caller. Sockets and write-only FIFOs without a reader fail inside the kernel and return JailError::Io. Opening a device node can still trigger driver side effects before it is rejected.

  9. FdJail::open_dir pins a directory beneath the jail; GuardedDir::read_dir and GuardedDir::open operate through that descriptor. Entry names and type hints are point-in-time snapshots and may be replaced before open, but the later open remains confined beneath the pinned directory. This API is only available on Linux x86_64/aarch64.


Out of scope

These threats are documented as not defended by any API:

  • Privileged local attackers. A process with root or CAP_SYS_ADMIN on the host can mount, bind-mount, or ptrace around any user-space check.
  • Kernel and filesystem exploits. A kernel-level bug, a FUSE filesystem misbehaving, or an openat2 semantic regression in a specific kernel version are outside our control. We pin to documented kernel ABI.
  • Side-channel attacks. Timing, cache, filesystem-metadata leaks.
  • Recursive directory walks. GuardedDir safely confines one pinned directory and relative opens beneath it, but the crate does not provide a recursive walker. Entry metadata is still a snapshot; treat every name as untrusted and open it through the directory handle before use.
  • Windows. No Windows-specific protections are implemented. Jail and secure-open compile on Windows but provide no defenses beyond the cross-platform path-string checks; the guard module is Unix-only and is not compiled on Windows.
  • Unicode normalization. Paths are accepted byte-for-byte. We do not normalize NFC/NFD on macOS or fold case on Windows/macOS. If your storage layer is case-insensitive, treat Report.PDF and report.pdf as potentially the same file.
  • Resource exhaustion. Very long paths, deep symlink chains, etc. are rejected by the kernel (ENAMETOOLONG, ELOOP) but path_jail does not impose its own limits.

Choosing the right API

                              ┌──────────────────────────────────┐
You only need a validated     │ Use `Jail::join` / `join_typed`. │
path (e.g., for logging) →    │ Cheap, portable.                 │
                              └──────────────────────────────────┘

                              ┌──────────────────────────────────┐
You open the file in          │ Use `secure-open`.               │
process, on Unix, and need    │ Protects final-component swaps.  │
final-component TOCTOU →      └──────────────────────────────────┘

                              ┌──────────────────────────────────┐
Security-critical opens on    │ Use `guard` (Linux 5.6+ on       │
Linux, attestation needed,    │ x86_64/aarch64).                 │
or hostile multi-tenant →     │ Kernel-enforced; signable.       │
                              └──────────────────────────────────┘

guard is the strongest. Use it on Linux where you can.


Versioning & supported releases

  • We follow Semantic Versioning. In the 0.y.z pre-release series, minor-version bumps (0.4 → 0.5) may include breaking API changes; patch bumps (0.4.0 → 0.4.1) will not. Starting with 1.0.0, the standard semver contract applies: only major bumps (1.x → 2.0) may break the public API.
  • Security fixes are issued on the latest minor line. We do not currently backport to older 0.x lines; after 1.0.0 we will evaluate backports case-by-case for high-severity findings.
  • The MSRV (currently 1.85) may be bumped in any minor release in the 0.x series. After 1.0.0, MSRV bumps will be treated as minor-version changes and documented in the changelog.

Reporting a vulnerability

Do not open a public GitHub issue for security bugs.

Use GitHub Private Vulnerability Reporting on the tenuo-ai/path_jail repository (Security tab → "Report a vulnerability"), or email security@tenuo.ai with:

  • A minimal reproducer (Rust code that demonstrates the issue)
  • The affected path_jail version and feature flags
  • The platform (OS, kernel version, architecture)
  • Your assessment of the impact (information disclosure / write outside jail / etc.)

We aim to acknowledge within 5 business days and to ship a fix within 30 days for high-severity findings (escape from a documented containment guarantee). Lower-severity findings (e.g., a missing defense for a documented out-of-scope threat) will be triaged on the open repository.


A note on the Jail default API

The README quick-start uses Jail::new and Jail::join — the path-based API. That API is not TOCTOU-safe. It validates a path string and returns a PathBuf; whatever the caller does with that PathBuf is a separate operation with its own race window.

This is documented but easy to miss. If you operate in any of these environments, strongly prefer guard over the path-based API:

  • Multi-tenant systems where another local process can manipulate the filesystem
  • File-upload paths where the same directory is also writable by other workers
  • Anywhere "the file you validated" and "the file you opened" need to be the same file with certainty

We may make guard the default in 1.0.0 or a future major release. For now, choose explicitly.

There aren't any published security advisories