pub struct FileSystemResolver { /* private fields */ }Expand description
Filesystem resolver with canonical root-containment checks, for TRUSTED hosts (a CLI, a static-site build). Not for untrusted input.
Every candidate is canonicalized (symlinks resolved) and only then checked
against the canonical root. This is deliberately NOT a lexical ban on ..,
which is wrong on both sides: TOO STRICT (a document in chapters/
including ../shared/glossary.crv is a normal book layout whose canonical
target is inside the root) and TOO WEAK (a symlink inside the root pointing
out of it, or an absolute path, escapes with no .. present at all).
Implementations§
Source§impl FileSystemResolver
impl FileSystemResolver
Sourcepub fn new(root: impl AsRef<Path>) -> Result<Self>
pub fn new(root: impl AsRef<Path>) -> Result<Self>
Canonicalizes root up front; fails if it does not exist, and refuses
a spec that is not ABSOLUTE.
A relative spec names no root: every canonicalizer resolves one against the process working directory, the value §19 forbids the root defaulting to. The test has to be on the CONFIGURED value - the canonicalized result is always absolute. A front end keeps the convenience by absolutizing its own flag before constructing this.
Sourcepub fn with_max_file_bytes(self, bytes: Option<u64>) -> Self
pub fn with_max_file_bytes(self, bytes: Option<u64>) -> Self
Largest target this resolver will read. None removes the cap.
Sourcepub fn allow_absolute(self, allow: bool) -> Self
pub fn allow_absolute(self, allow: bool) -> Self
Allow absolute include paths. They are STILL subject to the same canonical containment check, so this only widens spelling, not reach.
Trait Implementations§
Source§impl IncludeResolver for FileSystemResolver
Available on crate feature fs only.
impl IncludeResolver for FileSystemResolver
fs only.Source§fn unresolved_id(
&self,
include_path: &str,
ctx: &IncludeContext<'_>,
) -> Option<String>
fn unresolved_id( &self, include_path: &str, ctx: &IncludeContext<'_>, ) -> Option<String>
I11: a target that is simply not there is named by where it would be, the path a host watches. One that would land outside the root is refused like any other escape and keeps the directive’s spelling.