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 <noreply@anthropic.com>
This commit is contained in:
@@ -209,35 +209,26 @@ fn discover_files(patterns: &[String], root: &Path) -> Result<Vec<PathBuf>, Mani
|
|||||||
|
|
||||||
let mut result = Vec::new();
|
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 {
|
let entry = match entry {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Skip common large / non-project directories.
|
// Only interested in files.
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
if !entry.file_type().is_file() {
|
if !entry.file_type().is_file() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that no ancestor directory is in the skip list.
|
|
||||||
let abs_path = entry.path();
|
let abs_path = entry.path();
|
||||||
if has_skipped_ancestor(abs_path, root) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match relative path against the glob set.
|
// Match relative path against the glob set.
|
||||||
let rel = match abs_path.strip_prefix(root) {
|
let rel = match abs_path.strip_prefix(root) {
|
||||||
@@ -253,21 +244,6 @@ fn discover_files(patterns: &[String], root: &Path) -> Result<Vec<PathBuf>, Mani
|
|||||||
Ok(result)
|
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
|
// Single-file parsing
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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]
|
#[test]
|
||||||
fn opaque_file_formats_are_skipped_gracefully() {
|
fn opaque_file_formats_are_skipped_gracefully() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user