is_within
Whether path, taken relative to base, stays inside base: a guard against path traversal.
A relative path is joined to base and both are cleaned lexically (see
normalize), so "a/../../b" escapes and "a/../b" does not; an
absolute path must itself lie under base. base counts as inside itself. Nothing touches
the file system, so this does not see symbolic links: if the directory can contain links
an attacker controls, resolve the path with std::fs::canonicalize and compare that instead.
Import
Section titled “Import”Cargo feature fs (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
base | &Path | The directory that must contain the result. |
path | &Path | The path to check, relative to base or absolute. |
Returns
Section titled “Returns”bool — true when the cleaned path is base or lies under it.
