-
Notifications
You must be signed in to change notification settings - Fork 3
fix(security): prevent path traversal in NestedGlob search root #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yacosta738
merged 5 commits into
main
from
fix/security-nested-glob-traversal-10326664153959606349
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cea2ac4
fix(security): prevent path traversal in NestedGlob search root
yacosta738 597f869
fix: address security PR review feedback
yacosta738 2fe4580
Merge branch 'main' into fix/security-nested-glob-traversal-103266641…
yacosta738 bcb9ac7
Merge branch 'main' into fix/security-nested-glob-traversal-103266641…
yacosta738 b20a90f
fix(test): escape backslashes in absolute path TOML string for Window…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use agentsync::config::Config; | ||
| use agentsync::linker::{Linker, SyncOptions}; | ||
| use std::fs; | ||
| use tempfile::TempDir; | ||
|
|
||
| #[test] | ||
| fn test_nested_glob_search_root_traversal() { | ||
| let temp_dir = TempDir::new().unwrap(); | ||
| let project_root = temp_dir.path().join("project"); | ||
| let agents_dir = project_root.join(".agents"); | ||
| fs::create_dir_all(&agents_dir).unwrap(); | ||
|
|
||
| // Create a file OUTSIDE the project root | ||
| let outside_dir = temp_dir.path().join("outside_dir"); | ||
| fs::create_dir_all(&outside_dir).unwrap(); | ||
| fs::write(outside_dir.join("AGENTS.md"), "outside").unwrap(); | ||
|
|
||
| let config_path = agents_dir.join("agentsync.toml"); | ||
|
|
||
| // We want to walk a directory OUTSIDE the project root | ||
| let relative_outside = "../outside_dir"; | ||
|
|
||
| let toml = format!( | ||
| r#" | ||
| source_dir = "." | ||
| [agents.malicious] | ||
| enabled = true | ||
| [agents.malicious.targets.nested] | ||
| source = "{}" | ||
| destination = "leaked/{{file_name}}" | ||
| type = "nested-glob" | ||
| "#, | ||
| relative_outside | ||
| ); | ||
|
|
||
| fs::write(&config_path, toml).unwrap(); | ||
|
|
||
| let config = Config::load(&config_path).unwrap(); | ||
| let linker = Linker::new(config, config_path.clone()); | ||
|
|
||
| let options = SyncOptions { | ||
| verbose: true, | ||
| ..Default::default() | ||
| }; | ||
| let result = linker.sync(&options).unwrap(); | ||
|
|
||
| // The target should have failed due to unsafe search root | ||
| assert!( | ||
| result.errors > 0, | ||
| "Sync should have errors for malicious search root" | ||
| ); | ||
|
|
||
| let leaked_link = project_root.join("leaked").join("AGENTS.md"); | ||
| assert!( | ||
| !leaked_link.exists(), | ||
| "Should NOT have created a symlink to a file discovered outside project root" | ||
| ); | ||
| assert!( | ||
| !project_root.join("leaked").exists(), | ||
| "Should NOT have created the leaked directory" | ||
| ); | ||
|
|
||
| // Absolute paths should also be rejected. | ||
| // Use replace to escape backslashes so the path is valid in a TOML basic string on Windows. | ||
| let path_str = outside_dir.display().to_string().replace('\\', "\\\\"); | ||
| let absolute_toml = format!( | ||
| r#" | ||
| source_dir = "." | ||
| [agents.malicious] | ||
| enabled = true | ||
| [agents.malicious.targets.nested] | ||
| source = "{}" | ||
| destination = "leaked/{{file_name}}" | ||
| type = "nested-glob" | ||
| "#, | ||
| path_str | ||
| ); | ||
| fs::write(&config_path, absolute_toml).unwrap(); | ||
|
|
||
| let absolute_config = Config::load(&config_path).unwrap(); | ||
| let absolute_linker = Linker::new(absolute_config, config_path); | ||
| let absolute_result = absolute_linker.sync(&options).unwrap(); | ||
| assert!( | ||
| absolute_result.errors > 0, | ||
| "Sync should have errors for absolute-path search root" | ||
| ); | ||
|
|
||
| // clean() must not traverse or remove anything outside the project. | ||
| let clean_result = absolute_linker.clean(&SyncOptions::default()).unwrap(); | ||
| assert_eq!( | ||
| clean_result.removed, 0, | ||
| "Clean should not remove anything for an invalid search root" | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.