{"id":15295013,"url":"https://github.com/gatomod/path_trav","last_synced_at":"2025-04-13T15:01:09.763Z","repository":{"id":63584131,"uuid":"568949265","full_name":"gatomod/path_trav","owner":"gatomod","description":"🤨🔎 A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.","archived":false,"fork":false,"pushed_at":"2025-02-03T08:22:26.000Z","size":29,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T06:06:43.776Z","etag":null,"topics":["fs","path","path-traversal","rust","security"],"latest_commit_sha":null,"homepage":"https://docs.rs/path_trav/latest","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gatomod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-21T18:58:06.000Z","updated_at":"2025-02-03T08:22:29.000Z","dependencies_parsed_at":"2024-09-30T17:08:21.634Z","dependency_job_id":"feaea527-4c03-41f2-88bf-665b616ee554","html_url":"https://github.com/gatomod/path_trav","commit_stats":null,"previous_names":["gatomod/path_trav","gatomo-oficial/path_trav"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gatomod%2Fpath_trav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gatomod%2Fpath_trav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gatomod%2Fpath_trav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gatomod%2Fpath_trav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gatomod","download_url":"https://codeload.github.com/gatomod/path_trav/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732474,"owners_count":21152851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fs","path","path-traversal","rust","security"],"created_at":"2024-09-30T17:08:18.319Z","updated_at":"2025-04-13T15:01:09.686Z","avatar_url":"https://github.com/gatomod.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Path trav\n\n### A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.\n\n\u003cbr /\u003e\n\n[\u003cimg alt=\"license\" src=\"https://img.shields.io/github/license/gatomo-oficial/path_trav.svg?color=06b6d4\u0026style=for-the-badge\u0026logo=Apache\"\u003e](https://www.apache.org/licenses/LICENSE-2.0)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/path_trav.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\"\u003e](https://crates.io/crates/path_trav)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-path_trav-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\"\u003e](https://docs.rs/path_trav)\n\n\u003cbr /\u003e\n\n**Note:** this is a security tool. If you see something wrong, [please, read the security policy](https://github.com/gatomod/path_trav/security).\n\n## How it works?\n\nThe `is_path_trav` function is implemented in `std::path::Path`. It receives two paths, the base path and the path to check.\nTo verify if the second is inside the first, `path_trav` turn paths into absolute and check if the second route contains the first.\n\n#### Example 1.\n\n\u003e **Base\u0026nbsp;\u0026nbsp;:** _/home/user/data_ \u0026nbsp;\u0026nbsp;**--\u003e**\u0026nbsp; **_/home/user/data_**\n\n\u003e **Rel\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;:** _./data/folder_ \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**--\u003e**\u0026nbsp; **\\*/home/user/data**/folder\\*\n\nRelative path is inside base path.\n\n#### Example 2.\n\n\u003e **Base\u0026nbsp;\u0026nbsp;:** _/home/user/data_ \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**--\u003e**\u0026nbsp; _/home/user/data_\n\n\u003e **Rel\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;:** _./data/../../../etc/passwd_ \u0026nbsp;\u0026nbsp;**--\u003e**\u0026nbsp; _/etc/passwd_\n\nRelative path isn't inside base path, it's trying to access sensitive data\n\n## Examples\n\nFirst, add `path_trav` to your Cargo.toml\n\n```toml\n[dependencies]\npath_trav = \"2\"\n```\n\nThen, on your main.rs file\n\n```rust\nuse std::path::Path;\nuse path_trav::*;\n\nfn main() {\n    let server_folder       = Path::new(\"./\");\n    let server_file         = Path::new(\"./tests/test.rs\");\n    let important_file      = Path::new(\"~/../../etc/passwd\");\n    let non_existent_file   = Path::new(\"../weird_file\");\n\n    // Path is inside server_folder (Ok)\n    assert_eq!(Ok(false), server_folder.is_path_trav(\u0026server_file));\n\n    // Path tries to access sensitive data (Path Traversal detected)\n    assert_eq!(Ok(true), server_folder.is_path_trav(\u0026important_file));\n\n    // File does not exists (ENOENT)\n    assert_eq!(Err(ErrorKind::NotFound), server_folder.is_path_trav(\u0026non_existent_file));\n}\n\n```\n\n`is_path_trav` returns `Result\u003cbool, std::io::ErrorKind\u003e`. If returns true, there are path traversal.\n\n**Note:** _You can use it with `PathBuf`_\n\n```rust\nuse std::path:PathBuf\n\nlet server_folder   = PathBuf::from(\"./\");\nlet server_file     = PathBuf::from(\"./tests/test.rs\");\n\nassert_eq!(Ok(false), server_folder.is_path_trav(\u0026server_file));\n```\n\n## Tests\n\nThere are a few integration tests in `/tests` folder where you can check the Path Trav behavior.\n\n## License\n\n`path_trav` is licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).\n\n## Contribute\n\n🥳 Any PR is welcome! Path Trav is a small project, so please follow the code style and avoid making insane proposals.\n\n_Gátomo - Apache 2.0 License_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgatomod%2Fpath_trav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgatomod%2Fpath_trav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgatomod%2Fpath_trav/lists"}