strict-path
Handle paths from external or unknown sources securely. strict-path defends against 19+ real-world CVEs including symlinks, Windows 8.3 short names, and encoding tricks and exploits.
Analogy:
strict-pathis to paths what prepared statements are to SQL.
β‘ Get Secure in 30 Seconds
[]
= "0.1"
use StrictPath;
// GET /download?file=report.pdf
let untrusted_user_input = request.query_param.to_string; // Untrusted: "report.pdf" or "../../etc/passwd"
let file = with_boundary?
.strict_join?; // Validates untrusted input - attack blocked!
let contents = file.read?; // Safe built-in I/O
send_response;
Note: Our doc comments and LLM_CONTEXT_FULL.md are designed for LLMs with function callingβenabling AI agents to use this crate safely and correctly for file and path operations.
π€ LLM agent prompt (copy/paste)
Fetch and follow this reference (single source of truth): https://github.com/DK26/strict-path-rs/blob/main/LLM_CONTEXT_FULL.mdContext7 Style
Fetch and follow this reference (single source of truth): https://github.com/DK26/strict-path-rs/blob/main/LLM_CONTEXT.md
π New to strict-path? Start with the Tutorial: Chapter 1 - The Basic Promise β
π‘οΈ Complete Path Security
strict-path handles edge cases you'd never think to check:
- π§
soft-canonicalizefoundation: Battle-tested against 19+ real-world path CVE scenarios - π Full canonicalization: Resolves symlinks, junctions,
./..components, handles race conditions - π« Advanced attacks: Catches Windows 8.3 short names (
PROGRA~1), UNC paths, NTFS ADS, encoding tricks - π Compile-time proof: Rust's type system enforces path boundaries
- ποΈ Explicit operations: Method names like
strict_join()make security visible in code review - π‘οΈ Built-in I/O: Complete filesystem API
- π€ LLM-aware: Built for untrusted AI-generated code and modern threat models
- β‘ Dual modes: PathBoundary (detection & rejection) or VirtualRoot (clamping & containing)
Real attacks we handle automatically:
- Path traversal (
../../../etc/passwd) - Symlink/junction escapes
- Windows 8.3 short names (
PROGRA~1βProgram Files) - NTFS Alternate Data Streams (
file.txt:hidden:$DATA) - Unicode normalization bypasses (
..β..βetcβpasswd) - Null byte injection (
file.txt\x00.pdf) - Mixed separators (
../\../etc/passwd) - UNC path tricks (
\\?\C:\..\..\etc\passwd) - Archive attacks (Zip slip - CVE-2018-1000178)
- Race conditions (TOCTOU - CVE-2022-21658)
Recently Addressed CVEs:
- CVE-2025-8088 (WinRAR): NTFS Alternate Data Stream traversal
- CVE-2022-21658: Race condition protection (TOCTOU)
- CVE-2019-9855, CVE-2020-12279, CVE-2017-17793: Windows 8.3 short names
What This Is NOT:
- β Not just string checking (handles symlinks, Windows quirks)
- β Not a kernel based sandbox (path-level security only)
π Read our complete security methodology β | π Built-in I/O Methods β
π― StrictPath vs VirtualPath: When to Use What
Which type should I use?
- Path/PathBuf (std): When the path comes from a safe source within your control, not external input.
- StrictPath: When you want to restrict paths to a specific boundary and error if they escape.
- VirtualPath: When you want to provide path freedom under isolation.
Choose StrictPath (90% of cases):
- Archive extraction, config loading
- File uploads to shared storage (admin panels, CMS assets, single-tenant apps)
- LLM/AI agent file operations
- Shared system resources (logs, cache, assets)
- Any case where escaping a path boundary, is considered malicious
Choose VirtualPath (10% of cases):
- Multi-tenant file uploads (SaaS per-user storage, isolated user directories)
- Multi-tenant isolation (per-user filesystem views)
- Malware analysis sandboxes
- Container-like plugins
- Any case where you would like to allow freedom of operations under complete isolation
π Complete Decision Matrix β | π More Examples β
API Philosophy: Minimal, restrictive, and explicitβdesigned to prevent and easily detect both human and LLM agent API misuse. Security is prioritized above performance; if your use case doesn't involve symlinks and you need to squeeze every bit of performance, a lexical-only solution may be a better fit.
strict-pathaccesses the disk to validate and secure paths, by resolving all its components. This predicts correctly where a path would end-up leading to on a disk filesystem by simulating disk access. This method ignores anything a hacker could put as input path string, since we validate only against where the file being accessed from or written to, would end up being.
π More Real-World Examples
Archive Extraction (Zip Slip Prevention)
PathBoundary is a special type that represents a boundary for paths. It is optional, and could be used to express parts in our code where we expect a path to represent a boundary path:
use PathBoundary;
// Prevents CVE-2018-1000178 (Zip Slip) automatically (https://snyk.io/research/zip-slip-vulnerability)
The equivalent
PathBoundaryforVirtualPathtype is theVirtualRoottype.
Multi-Tenant Isolation
use VirtualRoot;
// No path-traversal or symlinks, could escape a tenant.
// Everything is clamped to the virtual root, including symlink resolutions.
π§ Compile-Time Safety with Markers
StrictPath<Marker> enables domain separation and authorization at compile time:
;
;
let user_boundary = try_new_create?;
let sys_boundary = try_new_create?;
let user_input = get_filename_from_request;
let user_file = user_boundary.strict_join?;
process_user; // β
OK - correct marker type
let sys_file = sys_boundary.strict_join?;
// process_user(&sys_file); // β Compile error - wrong marker type!
π Complete Marker Tutorial β - Authorization patterns, permission matrices,
change_marker()usage
vs soft-canonicalize
Compared with manual soft-canonicalize path validations:
soft-canonicalize= low-level path resolution engine (returnsPathBuf)strict-path= high-level security API (returnsStrictPath<Marker>with compile-time guarantees: fit for LLM era)
π Security Methodology β | π Anti-Patterns Guide β
π Ecosystem Integration
Compose with standard Rust crates for complete solutions:
| Integration | Purpose | Guide |
|---|---|---|
| tempfile | Secure temp directories | Guide |
| dirs | OS standard directories | Guide |
| app-path | Application directories | Guide |
| serde | Safe deserialization | Guide |
| Axum | Web server extractors | Tutorial |
| Archives | ZIP/TAR extraction | Guide |
π Learn More
- π API Documentation - Complete API reference
- π User Guide - Tutorials and patterns
- Best Practices - Detailed decision matrix
- Anti-Patterns - Common mistakes
- Examples - Copy-paste scenarios
- π§ LLM_CONTEXT_FULL.md - Full API reference for AI agents
- π LLM_CONTEXT.md - Context7-style usage guide for AI agents
- π οΈ
soft-canonicalize- Path resolution engine
π Complete Guide & Examples | π API Docs | π§ Choosing Canonicalized vs Lexical Solution
π License
MIT OR Apache-2.0