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): the waiver arm dropped the resolution, and mislabelled escapes as dotfiles
xerj-orgac4856dc1907
diff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rsindex b3be1f753..ec82e061e 100644--- a/engine/crates/xerj-autoindex/src/walk.rs+++ b/engine/crates/xerj-autoindex/src/walk.rs@@ -73,8 +73,17 @@ fn marker_generated_dir(path: &Path) -> Option<&'static str> {/// Why a followed symlink was refused. See the call site in `walk_reporting`.enum SymlinkVerdict {- /// The resolved target is not under the indexed root.- OutsideRoot,+ /// The resolved target is not under the indexed root. Carries the+ /// resolution so the waiver arm can store it: an admitted entry must read+ /// from the path that was judged rather than from the link it arrived by,+ /// and out-of-root entries are the only ones that arm ever admits.+ OutsideRoot(PathBuf),+ /// Outside the root AND through a dotted component. Separate from+ /// `OutsideRoot` because `--follow-symlinks-outside-root` must not reach+ /// it, and separate from `HiddenTarget` because the operator has no dotfile+ /// in their own folder to go looking for — the actionable fact is that a+ /// link left it.+ HiddenOutsideRoot,/// 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,@@ -145,9 +154,9 @@ fn escaped_or_hidden_target(.skip(shared).any(|c| is_hidden_name(c.as_os_str())){- return Err(SymlinkVerdict::HiddenTarget);+ return Err(SymlinkVerdict::HiddenOutsideRoot);}- return Err(SymlinkVerdict::OutsideRoot);+ return Err(SymlinkVerdict::OutsideRoot(real));};// In-root: judge only the part below the root. A brain over a dot-named// folder still works — that exemption is the same one the walker gives the@@ -304,8 +313,21 @@ pub fn walk_reporting_opts(if follow_symlinks && entry.depth() > 0 && through_link {match escaped_or_hidden_target(&root_canon, entry.path()) {Ok(real) => resolved = real,- Err(SymlinkVerdict::OutsideRoot) if allow_outside_root => {}- Err(SymlinkVerdict::OutsideRoot) => {+ // Admitted by the waiver — but with the RESOLVED path, so the+ // bytes read later are the bytes that were judged. This arm was+ // empty, which stored the walk path and re-followed the link at+ // read time for everything the flag ingests.+ Err(SymlinkVerdict::OutsideRoot(real)) if allow_outside_root => {+ resolved = Some(real);+ }+ Err(SymlinkVerdict::HiddenOutsideRoot) => {+ stack.record_symlink_escape(is_dir);+ if is_dir {+ it.skip_current_dir();+ }+ continue;+ }+ Err(SymlinkVerdict::OutsideRoot(_)) => {stack.record_symlink_escape(is_dir);if is_dir {it.skip_current_dir();diff --git a/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs b/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rsindex 43a52eba1..b576d0a91 100644--- a/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs+++ b/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs@@ -291,3 +291,76 @@ fn the_opt_in_does_not_admit_a_dotted_path_outside_the_root() {"an ordinary out-of-root target is what the opt-in exists for: {rels:?}");}++/// Two properties the escape hatch got wrong, both found by verification.+///+/// 1. An entry the waiver ADMITS must carry the resolved path. The arm was+/// empty, so `FileEntry::path` stayed the walk path and every later `open()`+/// re-followed the link — the decision made about one file, the bytes read+/// from another, for everything the flag ingests.+/// 2. An out-of-root target refused for a dotted component must be reported as+/// what it is. It was recorded under `hidden:dotfile`, so an operator was+/// told to look for a dotfile inside their own folder and+/// `symlink:outside-root` vanished from the report — on the DEFAULT path,+/// not just under the flag.+#[test]+fn out_of_root_entries_carry_the_resolved_path_and_are_reported_as_escapes() {+ let dir = tempfile::tempdir().unwrap();+ let base = dir.path().join("base");+ fs::create_dir_all(&base).unwrap();+ let root = base.join("root");+ let outside = base.join("outside");+ fs::create_dir_all(root.join("sub")).unwrap();+ fs::create_dir_all(outside.join("pkg")).unwrap();+ fs::create_dir_all(outside.join(".ssh")).unwrap();+ fs::write(root.join("README.md"), "readme\n").unwrap();+ fs::write(outside.join("pkg/lib.rs"), "pub fn f() {}\n").unwrap();+ fs::write(outside.join(".ssh/id_rsa"), "PRIVATE KEY\n").unwrap();++ symlink(outside.join("pkg"), root.join("shared-lib")).unwrap();+ symlink(outside.join(".ssh/id_rsa"), root.join("keys.txt")).unwrap();++ // (1) admitted out-of-root entries store the resolution.+ let (files, _) = xerj_autoindex::walk::walk_reporting_opts(+ &root,+ true,+ true,+ xerj_autoindex::ignore_rules::IgnoreOptions::default(),+ )+ .expect("walk succeeds");+ let lib = files+ .iter()+ .find(|f| f.rel == "shared-lib/lib.rs")+ .expect("the opt-in must follow an ordinary out-of-root link");+ assert_eq!(+ lib.path,+ outside.join("pkg/lib.rs").canonicalize().unwrap(),+ "the stored path must be the resolved one, or the read re-follows the link"+ );++ // (2) the dotted out-of-root refusal is an escape, not a dotfile — and it+ // is the DEFAULT path that has to say so.+ let (_, report) = xerj_autoindex::walk::walk_reporting_opts(+ &root,+ true,+ false,+ xerj_autoindex::ignore_rules::IgnoreOptions::default(),+ )+ .expect("walk succeeds");+ assert!(+ !report.by_rule.contains_key(HIDDEN_RULE),+ "there is no dotfile in the operator's folder to blame: {report:?}"+ );+ let escaped = report+ .by_rule+ .get(ESCAPED_ROOT_RULE)+ .copied()+ .unwrap_or_default();+ // `keys.txt` is a file link and `shared-lib` a directory link, so they land+ // in different counters — one each, not two files.+ assert_eq!(+ (escaped.files, escaped.dirs),+ (1, 1),+ "both links left the root: {report:?}"+ );+}