Expand description
Hardening primitives that make rustinel safe to run against fully untrusted inputs (lockfiles, manifests, source trees, advisory databases, registry caches).
rustinel is a supply-chain tool, so it must never become a supply-chain attack vector itself. Every value that originates from analyzed data is treated as hostile:
- No code execution. The core never runs
build.rs, never compiles, and never spawns processes. (The CLI’sadvisory updateshells out togitwith a fixed argument vector and no shell interpolation.) - No attacker-controlled network. The optional metadata lookup (in the CLI) fetches the crates.io sparse index over HTTPS with a fixed host and a validated crate-name path; no request target is ever derived from analyzed data, which removes SSRF as a class of bug.
- Bounded I/O. Every file read is size-capped; directory walks are depth- and entry-bounded; symlinks are never followed during traversal.
- Validated identifiers. Crate names/versions are validated before they are ever used to build a filesystem path or an index lookup, blocking path traversal and separator injection.
Constants§
- MAX_
ADVISORY_ FILE_ BYTES - Maximum bytes read from a single advisory document.
- MAX_
DIR_ DEPTH - Maximum directory recursion depth for any walk.
- MAX_
DIR_ ENTRIES - Maximum number of filesystem entries visited in a single walk.
- MAX_
NAME_ LEN - Maximum length accepted for a crate name or version token.
- MAX_
SOURCE_ FILE_ BYTES - Maximum bytes read from a single source/manifest file.
- MAX_
VERSION_ LEN
Functions§
- has_
no_ parent_ components - A path is “lexically clean” if it contains no
..components (used as a cheap pre-check before any join). - is_
contained_ within - True if
child, once resolved, is contained withinbase. Both are canonicalized; if either cannot be canonicalized the check fails closed. - is_
safe_ crate_ name - Validate a Cargo crate name for safe use in filesystem paths and index
lookups. Conservative allowlist: ASCII alphanumerics plus
-and_. - is_
safe_ path_ segment - A single path segment that is safe to join onto a trusted base directory:
non-empty, no separators, not a
./..component. - is_
safe_ version - Validate a version token for safe use in a filesystem path. Allows the
semver character set (alnum,
.,+,-,_) and nothing else. - read_
file_ capped - Read a regular file, refusing anything larger than
max_bytes, anything that is not a regular file, and reading at mostmax_byteseven if the file grows underneath us. ReturnsNone(never an error) so callers degrade gracefully.