Path trav
A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.
Note: this is a security tool. If you see something wrong, please, read the security policy.
How it works?
The is_path_trav function is implemented in std::path::Path. It receives two paths, the base path and the path to check.
To verify if the second is inside the first, path_trav turn paths into absolute and check if the second route contains the first.
Example 1.
Base : /home/user/data --> /home/user/data
Rel : ./data/folder --> */home/user/data/folder*
Relative path is inside base path.
Example 2.
Base : /home/user/data --> /home/user/data
Rel : ./data/../../../etc/passwd --> /etc/passwd
Relative path isn't inside base path, it's trying to access sensitive data
Examples
First, add path_trav to your Cargo.toml
[]
= "2"
Then, on your main.rs file
use Path;
use *;
is_path_trav returns Result<bool, std::io::ErrorKind>. If returns true, there are path traversal.
Note: You can use it with PathBuf
use path:PathBuf
let server_folder = from;
let server_file = from;
assert_eq!;
Tests
There are a few integration tests in /tests folder where you can check the Path Trav behavior.
License
path_trav is licensed under the Apache 2.0 license.
Contribute
🥳 Any PR is welcome! Path Trav is a small project, so please follow the code style and avoid making insane proposals.
Gátomo - Apache 2.0 License