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 out-of-root opt-in was skipping the hidden-file rule entirely
xerj-org30fff1468c31
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 78fdcf352..ab796e69e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,7 +27,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0link. If following links outward is why you turned the flag on — a vendoredsibling checkout, a monorepo package link, a mounted volume — pass`--follow-symlinks-outside-root` to restore it. That waives the root boundary- and nothing else: the hidden-file rule still applies to the resolved path.+ and nothing else: the hidden-file rule still applies to the resolved path,+ judged from the point where the target diverges from the folder you pointed+ at — so `notes -> ../sibling/pkg` is followed and `keys -> ../sibling/.ssh/id_rsa`+ is not, while a dotted directory the two paths SHARE (a `/tmp/.tmpXXXX`, a+ checkout under `~/.local`) does not refuse anything, because your own folder+ is already inside it.Known limit, stated rather than implied: this is a rule about names and aboutwhere a link resolves. A **hard** link has neither, so a visible name hard-diff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rsindex d8dbf4bb9..b3be1f753 100644--- a/engine/crates/xerj-autoindex/src/walk.rs+++ b/engine/crates/xerj-autoindex/src/walk.rs@@ -121,8 +121,37 @@ fn escaped_or_hidden_target(Err(_) => return Err(SymlinkVerdict::Unresolvable),};let Some(rel) = real.strip_prefix(root_canon).ok() else {+ // Outside the root — but the hidden-name question is asked FIRST and+ // against the whole resolved path, because `OutsideRoot` is the only+ // verdict `--follow-symlinks-outside-root` waives. Returning it before+ // looking for a dotted component let that flag admit+ // `keys.txt -> ../outside/.ssh/id_rsa` unexamined, which is #438+ // reopened through the escape hatch built to be safe.+ //+ // Judged from where the target DIVERGES from the root, not from `/`.+ // Checking every component would refuse any target whose absolute path+ // passes through a dotted ancestor — `/home/u/.cache/...`, and every+ // path under a `tempfile` directory, which is named `.tmpXXXXXX`. Those+ // ancestors are shared with the root the operator pointed at, so they+ // are as consented-to as the root itself; the components BELOW the+ // divergence are the ones nobody asked for.+ let shared = root_canon+ .components()+ .zip(real.components())+ .take_while(|(a, b)| a == b)+ .count();+ if real+ .components()+ .skip(shared)+ .any(|c| is_hidden_name(c.as_os_str()))+ {+ return Err(SymlinkVerdict::HiddenTarget);+ }return Err(SymlinkVerdict::OutsideRoot);};+ // 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+ // root itself at depth 0.if rel.components().any(|c| is_hidden_name(c.as_os_str())) {return Err(SymlinkVerdict::HiddenTarget);}diff --git a/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs b/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rsindex 782bad704..43a52eba1 100644--- a/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs+++ b/engine/crates/xerj-autoindex/tests/follow_symlinks_boundary.rs@@ -32,10 +32,15 @@ use xerj_autoindex::walk::walk_reporting;/// shared -> ../outside (escapes the root)/// sub/deep.md visible, ordinary, below a directory/// outside/etc/shadow must never appear-fn fixture() -> tempfile::TempDir {+fn fixture() -> (tempfile::TempDir, std::path::PathBuf) {let dir = tempfile::tempdir().expect("tempdir");- let root = dir.path().join("root");- let outside = dir.path().join("outside");+ // `tempfile` names its directories `.tmpXXXXXX`, a hidden component. Every+ // fixture is anchored one level below it so the harness's own name does not+ // trip the dotfile rule the tests are about.+ let base = dir.path().join("base");+ std::fs::create_dir_all(&base).expect("base");+ let root = base.join("root");+ let outside = base.join("outside");fs::create_dir_all(root.join(".secretdir")).unwrap();fs::create_dir_all(root.join("sub")).unwrap();@@ -52,7 +57,7 @@ fn fixture() -> tempfile::TempDir {symlink("README.md", root.join("plain-link.txt")).unwrap();symlink(&outside, root.join("shared")).unwrap();- dir+ (dir, root)}fn walk_rels(@@ -69,8 +74,7 @@ fn walk_rels(/// The whole point: with links followed, no secret and nothing from outside.#[test]fn following_links_indexes_neither_the_secret_nor_anything_outside_the_root() {- let dir = fixture();- let root = dir.path().join("root");+ let (_dir, root) = fixture();let (rels, report) = walk_rels(&root, true);@@ -123,8 +127,7 @@ fn following_links_indexes_neither_the_secret_nor_anything_outside_the_root() {/// the link files themselves are the entries and nothing resolves.#[test]fn not_following_links_is_unchanged() {- let dir = fixture();- let root = dir.path().join("root");+ let (_dir, root) = fixture();let (rels, report) = walk_rels(&root, false);@@ -144,7 +147,7 @@ fn not_following_links_is_unchanged() {#[test]fn a_link_to_a_visible_file_inside_the_root_is_still_indexed() {let dir = tempfile::tempdir().unwrap();- let root = dir.path().join("root");+ let root = dir.path().join("base").join("root");fs::create_dir_all(root.join("docs")).unwrap();fs::write(root.join("docs/real.md"), "real\n").unwrap();symlink("docs/real.md", root.join("alias.md")).unwrap();@@ -162,7 +165,7 @@ fn a_link_to_a_visible_file_inside_the_root_is_still_indexed() {#[test]fn a_link_to_a_directory_inside_the_root_is_walked_and_still_hides_dotfiles() {let dir = tempfile::tempdir().unwrap();- let root = dir.path().join("root");+ let root = dir.path().join("base").join("root");fs::create_dir_all(root.join("real/.hidden")).unwrap();fs::write(root.join("real/open.md"), "open\n").unwrap();fs::write(root.join("real/.hidden/secret.md"), "secret\n").unwrap();@@ -184,7 +187,7 @@ fn a_link_to_a_directory_inside_the_root_is_walked_and_still_hides_dotfiles() {#[test]fn a_broken_link_is_not_an_escape() {let dir = tempfile::tempdir().unwrap();- let root = dir.path().join("root");+ let root = dir.path().join("base").join("root");fs::create_dir_all(&root).unwrap();fs::write(root.join("real.md"), "real\n").unwrap();symlink("nowhere-at-all", root.join("dangling.md")).unwrap();@@ -205,8 +208,7 @@ fn a_broken_link_is_not_an_escape() {/// which is the half that keeps `.ssh` out.#[test]fn the_outside_root_opt_in_waives_the_boundary_and_nothing_else() {- let dir = fixture();- let root = dir.path().join("root");+ let (_dir, root) = fixture();let (refused, _) = xerj_autoindex::walk::walk_reporting_opts(&root,@@ -233,7 +235,7 @@ fn the_outside_root_opt_in_waives_the_boundary_and_nothing_else() {"the opt-in must actually follow the link outward: {rels:?}");- // The half that must NOT be waived.+ // The half that must NOT be waived, in-root.for leaked in ["notes.txt", "hop.txt", "chain.txt"] {assert!(!rels.contains(&leaked),@@ -242,3 +244,50 @@ fn the_outside_root_opt_in_waives_the_boundary_and_nothing_else() {);}}++/// The same half, OUTSIDE the root — which is the only place the opt-in+/// actually changes anything, and where the first version of it failed.+///+/// `escaped_or_hidden_target` answered `OutsideRoot` before it looked for a+/// hidden component, so the opt-in admitted the entry unexamined and+/// `keys.txt -> ../outside/.ssh/id_rsa` was indexed with the key as its body.+/// That is #438 reopened through the escape hatch built to be safe, and the+/// test above did not catch it because every one of its links points inward.+#[test]+fn the_opt_in_does_not_admit_a_dotted_path_outside_the_root() {+ 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(".ssh")).unwrap();+ fs::create_dir_all(outside.join("pkg")).unwrap();+ fs::write(root.join("README.md"), "readme\n").unwrap();+ fs::write(outside.join(".ssh/id_rsa"), "PRIVATE KEY\n").unwrap();+ fs::write(outside.join("pkg/lib.rs"), "pub fn f() {}\n").unwrap();++ symlink(outside.join(".ssh/id_rsa"), root.join("keys.txt")).unwrap();+ symlink(outside.join(".ssh"), root.join("conf")).unwrap();+ symlink(outside.join("pkg"), root.join("shared-lib")).unwrap();++ let (files, report) = xerj_autoindex::walk::walk_reporting_opts(+ &root,+ true,+ true,+ xerj_autoindex::ignore_rules::IgnoreOptions::default(),+ )+ .expect("walk succeeds");+ let rels: Vec<&str> = files.iter().map(|f| f.rel.as_str()).collect();++ assert!(+ !rels+ .iter()+ .any(|r| r.starts_with("keys.txt") || r.starts_with("conf")),+ "the opt-in must not admit a target under a dotted directory: {rels:?} {report:?}"+ );+ assert!(+ rels.iter().any(|r| r.starts_with("shared-lib")),+ "an ordinary out-of-root target is what the opt-in exists for: {rels:?}"+ );+}