AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(autoindex): a path that cannot be resolved is refused, not admitted
xerj-org95c171e1ebb8
diff --git a/engine/crates/xerj-autoindex/src/ignore_rules.rs b/engine/crates/xerj-autoindex/src/ignore_rules.rsindex bd3438b62..1aaef6e7b 100644--- a/engine/crates/xerj-autoindex/src/ignore_rules.rs+++ b/engine/crates/xerj-autoindex/src/ignore_rules.rs@@ -114,6 +114,16 @@ pub const HIDDEN_RULE: &str = "hidden:dotfile";/// going to do.pub const ESCAPED_ROOT_RULE: &str = "symlink:outside-root";+/// A followed entry whose path could not be resolved for a reason other than+/// "it does not exist" — `realpath(3)` is bounded by `PATH_MAX` where the+/// kernel is not, so a canonical path over that limit fails here while `open`+/// on the walk path still succeeds; `ELOOP` and `EACCES` behave the same.+///+/// Refused, because the hidden-name and root-boundary questions could not be+/// answered and "could not compute" is not "yes". Reported so that a file the+/// operator expected is named rather than silently missing.+pub const UNRESOLVED_LINK_RULE: &str = "symlink:unresolved";+const MAX_WARNINGS: usize = 20;/// Directory entries the `--dry-run` deep count may examine in total. A/// pathological `node_modules` is not allowed to turn "tell me the plan" into@@ -704,6 +714,20 @@ impl IgnoreStack {}}+ /// A followed entry that could not be resolved. See [`UNRESOLVED_LINK_RULE`].+ pub fn record_symlink_unresolved(&mut self, is_dir: bool) {+ if is_dir {+ self.report.dirs_pruned += 1;+ self.report+ .by_rule+ .entry(UNRESOLVED_LINK_RULE.to_string())+ .or_default()+ .dirs += 1;+ } else {+ self.record_file(UNRESOLVED_LINK_RULE);+ }+ }+/// The marker-gated generated-dir prune (`walk::MARKER_GENERATED_DIRS`)/// is also decided by the walker — the verdict needs the SIBLING marker/// file, which the per-directory matcher stack cannot see — and reporteddiff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rsindex 31a57181b..32cc5ddbe 100644--- a/engine/crates/xerj-autoindex/src/walk.rs+++ b/engine/crates/xerj-autoindex/src/walk.rs@@ -78,6 +78,9 @@ enum SymlinkVerdict {/// The resolved target is under the root but its real path runs through a/// hidden component — the link's visible name was hiding a dotfile.HiddenTarget,+ /// The path could not be resolved at all, so neither question could be+ /// answered. Refused rather than admitted; see `escaped_or_hidden_target`.+ Unresolvable,}/// Judge a followed entry by where it actually resolves.@@ -88,10 +91,30 @@ enum SymlinkVerdict {/// and a link partway up a directory path behave the same as a direct one.////// `None` means the entry is where it appears to be and the ordinary rules-/// govern it. An unresolvable path is `None` too: a broken link has no target-/// to leak, and walkdir already reports it through the error arm.+/// govern it.+///+/// A resolution FAILURE is not `None`. An earlier version of this function+/// wrote `path.canonicalize().ok()?`, which collapsed every error into "the+/// entry is where it appears" and justified it with "a broken link has no+/// target to leak". That is true of `NotFound` and of nothing else, and the+/// difference is a bypass rather than a nicety: `canonicalize` is `realpath(3)`+/// and is bounded by `PATH_MAX`, while the kernel's own resolution is not, so an+/// entry can be unresolvable HERE and perfectly readable by every later stage —+/// `stat`, `open`, hashing, extraction. The guard was then skipped for exactly+/// the entries it could not vet, which is the wrong direction for a rule whose+/// job is to keep `.ssh` out of a queryable index. `ELOOP` and `EACCES` land in+/// the same arm.+///+/// So only `NotFound` is treated as "nothing here to leak" — walkdir already+/// reports a dangling link through its error arm. Everything else is refused+/// and named in the report, because an answer that could not be computed is not+/// an answer of "yes".fn escaped_or_hidden_target(root_canon: &Path, path: &Path) -> Option<SymlinkVerdict> {- let real = path.canonicalize().ok()?;+ let real = match path.canonicalize() {+ Ok(real) => real,+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => return None,+ Err(_) => return Some(SymlinkVerdict::Unresolvable),+ };let rel = real.strip_prefix(root_canon).ok();let Some(rel) = rel else {return Some(SymlinkVerdict::OutsideRoot);@@ -206,6 +229,13 @@ pub fn walk_reporting(}continue;}+ Some(SymlinkVerdict::Unresolvable) => {+ stack.record_symlink_unresolved(is_dir);+ if is_dir {+ it.skip_current_dir();+ }+ continue;+ }None => {}}}@@ -294,6 +324,50 @@ fn stable_path_id(path: &Path) -> String {#[cfg(test)]mod hidden_skip_tests {+ use super::{escaped_or_hidden_target, SymlinkVerdict};++ /// The dispatch this file was refuted for. `canonicalize` failing is not+ /// evidence that the entry is where it appears; only `NotFound` is.+ ///+ /// A path with an interior NUL cannot be canonicalised and reports+ /// `InvalidInput`, which stands in here for the errno that actually+ /// motivates the arm: `realpath(3)` is `PATH_MAX`-bounded while the kernel+ /// is not, so a canonical path over that limit gives `ENAMETOOLONG` here+ /// while `open` on the walk path still succeeds. That asymmetry is what+ /// made `.ok()?` a bypass — the guard was skipped for precisely the entries+ /// it could not vet.+ #[test]+ fn an_unresolvable_entry_is_refused_not_admitted() {+ use std::ffi::OsStr;+ use std::os::unix::ffi::OsStrExt;++ let dir = tempfile::tempdir().expect("tempdir");+ let root = dir.path().canonicalize().expect("canonical root");++ // Exists and resolves inside the root: admitted.+ std::fs::write(root.join("plain.txt"), "x").unwrap();+ assert!(+ escaped_or_hidden_target(&root, &root.join("plain.txt")).is_none(),+ "an ordinary in-root file must be governed by the ordinary rules"+ );++ // Does not exist: nothing to leak, so also admitted — walkdir reports it.+ assert!(+ escaped_or_hidden_target(&root, &root.join("gone.txt")).is_none(),+ "a dangling link has no target and must not be reported as a refusal"+ );++ // Cannot be resolved for any OTHER reason: refused.+ let bad = root.join(OsStr::from_bytes(b"nul\0inside"));+ assert!(+ matches!(+ escaped_or_hidden_target(&root, &bad),+ Some(SymlinkVerdict::Unresolvable)+ ),+ "an unresolvable path must be refused — `could not compute` is not `yes`"+ );+ }+use super::walk;use std::fs;