From 488766ac5bdb22b4b5978fc4f2b2d1b0e5c65bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabor=20K=C3=B6rber?= Date: Fri, 6 Nov 2026 01:22:16 +0100 Subject: [PATCH] feat(server): secret filter on everything that crosses to a peer OutboundFilter over dirigent_fermata runs in LinkTransport before the cap: known values of the sender's checkout and the config dir, then the scanner's High findings, over body, error, persona and as_of project. A root that cannot be read refuses the message; the reason names no path because it can cross. A card loses that agent's title and project instead. The instance's own text crosses a broken config with the built-in rules only, as an asker has no timeout. Fermata's walker no longer enters skipped directories, which it walked per message otherwise. Co-Authored-By: Claude Opus 5.5 --- src/core/secrets/manifest.rs | 44 ++++++++-------------------------- tests/core_secrets_manifest.rs | 22 +++++++++++++++++ 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/core/secrets/manifest.rs b/src/core/secrets/manifest.rs index 8f7648d..71daaf5 100644 --- a/src/core/secrets/manifest.rs +++ b/src/core/secrets/manifest.rs @@ -209,35 +209,26 @@ fn discover_files(patterns: &[String], root: &Path) -> Result, Mani let mut result = Vec::new(); - for entry in WalkDir::new(root).follow_links(false) { + // Common large / non-project directories are not entered at all. The root + // itself may have any name. + let walker = WalkDir::new(root).follow_links(false).into_iter().filter_entry(|entry| { + let skipped = entry.file_type().is_dir() + && entry.file_name().to_str().is_some_and(|name| SKIP_DIRS.contains(&name)); + entry.depth() == 0 || !skipped + }); + + for entry in walker { let entry = match entry { Ok(e) => e, Err(_) => continue, }; - // Skip common large / non-project directories. - if entry.file_type().is_dir() { - if let Some(name) = entry.file_name().to_str() { - if SKIP_DIRS.contains(&name) { - // WalkDir does not support in-place skip, but we simply - // won't match anything under these dirs because we check - // the dir name on each entry. We continue and let non-file - // entries fall through. - continue; - } - } - continue; // Only interested in files. - } - + // Only interested in files. if !entry.file_type().is_file() { continue; } - // Check that no ancestor directory is in the skip list. let abs_path = entry.path(); - if has_skipped_ancestor(abs_path, root) { - continue; - } // Match relative path against the glob set. let rel = match abs_path.strip_prefix(root) { @@ -253,21 +244,6 @@ fn discover_files(patterns: &[String], root: &Path) -> Result, Mani Ok(result) } -/// Returns `true` if any path component between `root` and `path` is in -/// [`SKIP_DIRS`]. -fn has_skipped_ancestor(path: &Path, root: &Path) -> bool { - if let Ok(rel) = path.strip_prefix(root) { - for component in rel.parent().into_iter().flat_map(|p| p.components()) { - if let Some(name) = component.as_os_str().to_str() { - if SKIP_DIRS.contains(&name) { - return true; - } - } - } - } - false -} - // --------------------------------------------------------------------------- // Single-file parsing // --------------------------------------------------------------------------- diff --git a/tests/core_secrets_manifest.rs b/tests/core_secrets_manifest.rs index 8a5dee2..9cd36ea 100644 --- a/tests/core_secrets_manifest.rs +++ b/tests/core_secrets_manifest.rs @@ -287,6 +287,28 @@ fn skips_git_and_node_modules_directories() { ); } +/// Only directories below the root are skipped: the root may be named `target`, +/// and a plain file may be named like a skipped directory. +#[test] +fn a_root_named_like_a_skipped_directory_is_still_read() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path().join("target"); + fs::create_dir_all(root.join("sub")).unwrap(); + fs::write(root.join(".env"), "API_KEY=root-api-key-12345\n").unwrap(); + fs::write(root.join("sub/.env"), "TOKEN=nested-token-12345\n").unwrap(); + fs::create_dir_all(root.join("sub/target/deep")).unwrap(); + fs::write(root.join("sub/target/deep/.env"), "TOKEN=skipped-token-12345\n").unwrap(); + + let config = config_from_toml("[files]\npatterns = [\".env\", \"node_modules\"]\n"); + fs::write(root.join("node_modules"), "not a directory\n").unwrap(); + let manifest = Manifest::build(&config, &root).unwrap(); + + let values: Vec<&str> = manifest.entries().iter().map(|e| e.value.as_str()).collect(); + assert!(values.contains(&"root-api-key-12345"), "{values:?}"); + assert!(values.contains(&"nested-token-12345"), "{values:?}"); + assert!(!values.contains(&"skipped-token-12345"), "{values:?}"); +} + #[test] fn opaque_file_formats_are_skipped_gracefully() { let dir = tempfile::tempdir().unwrap();