A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.

Overview

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, open an issue in GitHub.

How it works?

The is_path_trav function receives two paths, one is the base path and the other is 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 paths isn't inside base path, tries to acces sensitive data

Example

Add path_trav to your Cargo.toml

[dependencies]
path_trav = "1.0.0"

Then, on your main.rs file

use std::path::Path;
use path_trav::is_path_trav;

fn main() {
    let important_file = Path::new("./data/../../../etc/passwd");

    // with absolute path
    let check_abs = is_path_trav(&Path::new("/home/user/data"), &important_file).unwrap();

    // with relative path
    let check_rel = is_path_trav(&Path::new("./data"), &important_file).unwrap();
}

is_path_trav returns Result<bool, &'static str>. Unwrap it or use match to get the result. If returns true, there are path traversal.

License

path_trav is licensed under the GPL-3 license.

Contribute

🥳 Any PR is welcome! Is a small project, so the guideline is to follow the code style and not make insane pruposes.

Links

Gátomo - GPL-3 License

You might also like...
A pure-rust(with zero dependencies) fenwick tree, for the efficient computation of dynamic prefix sums.

indexset A pure-rust(with zero dependencies, no-std) fenwick tree, for the efficient computation of dynamic prefix sums. Background Did you ever have

Keep a Hetzner Cloud firewall up to date with your dynamic public IP address.

hcloud-firewall-controller hcloud-firewall-controller determines the current public IP and creates or updates a Hetzner Cloud firewall with this IP. S

a function programming language for real world applications made in rust

a function programming language for real world applications made in rust

A conky-like system monitor made for the sole purpose of teaching myself rust-lang.

Pomky A conky-like system monitor made for the sole purpose of teaching myself rust-lang. It is not as configurable, modular, or feature packed as con

The Ribbon Programming Language, made in Rust.

The Ribbon Programming Language (WIP) This language is designed to be quick to write and is heavily inspired by Rust, which is also the language it wa

Extracting archives made easy for Rust 🦀

Decompress A library that supports decompression of archives in multiple formats, inspired by ergonomics from Node's decompress. Includes a default st

A refactoring kata, made to exercise learnings from Chapter 6 of Refactoring by Martin Fowler

Fighter Dude 2 - Refactoring Kata This is a tiny refactoring kata that I made to exercise some of the refactorings in Chapter 6 of Refactoring by Mart

Unify your game sources in one place and aquire more of them, using modules made by the community.

Project Black Pearl Unify your game sources in one place by using modules made by the community. What is Project Black Pearl? Project Black Pearl (or

Cross-platform GUI for youtube-dl made with Iced

youtube-dl-gui Cross-platform GUI for youtube-dl made with Iced. Installation Before you install this crate, make sure you have youtube-dl and FFmpeg

Owner
Gátomo
😁 Tu programador sin conocimientos de confianza
Gátomo
A skeleton WinRT component that can serve as a substitute for the Region Policy Evaluator in Windows.

Region Policy Evaluator Skeleton A skeleton WinRT component that can serve as a substitute for the Region Policy Evaluator in Windows. Please note tha

Rafael Rivera 3 Nov 20, 2023
Tools to feature more lenient Polonius-based borrow-checker patterns in stable Rust

Though this be madness, yet there is method in 't. More context Hamlet: For yourself, sir, shall grow old as I am – if, like a crab, you could go back

Daniel Henry-Mantilla 52 Dec 26, 2022
Build database expression type checker and vectorized runtime executor in type-safe Rust

Typed Type Exercise in Rust Build database expression type checker and vectorized runtime executor in type-safe Rust. This project is highly inspired

Andy Lok 89 Dec 27, 2022
"Crates for Cheese" is a Rust collection library of those crates I consider a useful "extended standard".

cfc The purpose of this library is to provide a minimal list of currated crates which enhance the std library. In addition, most or all crates in this

null 0 Dec 23, 2021
This blog provides detailed status updates and useful information about Theseus OS and its development

The Theseus OS Blog This blog provides detailed status updates and useful information about Theseus OS and its development. Attribution This blog was

Theseus OS 1 Apr 14, 2022
Rust Library for controlling divoom devices that support REST APIs, such as pixoo-64.

Divoom Rust Library for controlling divoom devices that support REST APIs, such as pixoo-64 (and from how divoom's api/doc organizes, maybe more in th

Riff 16 Dec 23, 2022
Safe, idiomatic bindings to cFE and OSAL APIs for Rust

n2o4 The n2o4 crate provides safe, idiomatic Rust bindings to the APIs of cFE and OSAL, the libraries of the Core Flight System (cFS). IMPORTANT NOTE

null 3 Aug 29, 2022
A backend framework for building fast and flexible APIs rapidly.

Andromeda Andromeda is a backend framework for Rust, to simplify the development of the kinds of basic API services that we developers have to build s

Framesurge 7 Dec 28, 2022
Safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework.

Introduction The dynamorio-rs crate provides safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework, essentially allowing you to

S.J.R. van Schaik 17 Nov 21, 2022
Oxido is a dynamic interpreted programming language basing most of its syntax on Rust.

Oxido Table of Contents: Oxido Installation Uninstallation Usage Syntax Data types Variables Reassignments Printing If statements Loop statements Func

Oxido 6 Oct 6, 2022