url-sanitizer is a Rust command-line tool designed to process and sanitize URLs, removing unwanted parameters or formatting them for safe use. This tool is lightweight, fast, and built for reliability.
- Redirect URL Detection: Automatically detects and follows redirect URLs from platforms like YouTube, Google, Facebook, and Twitter
- Smart URL Extraction: Extracts the actual destination URL from redirect parameters (e.g.,
q,url,dest) - Tracking Parameter Removal: Removes common tracking parameters including:
- UTM parameters (
utm_source,utm_medium,utm_campaign, etc.) - Social media trackers (
fbclid,gclid,msclkid) - Platform-specific trackers (
sifor YouTube,ref,source, etc.)
- UTM parameters (
- Recursive Processing: Handles nested redirects and sanitizes extracted URLs
- Fast execution with Rust's performance
- Portable, statically linked binary for easy distribution
To build and install url-sanitizer on a Debian system, ensure the following are installed:
- Rust and Cargo: The Rust toolchain.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env
- musl-tools: For static linking with the
musltarget.sudo apt update sudo apt install musl-tools
- Git: To clone the repository (optional if you have the local codebase).
sudo apt install git
Verify installations:
rustc --version && cargo --version && git --versionFollow these steps to build a statically linked binary, which can run on any x86_64 Linux system without external library dependencies.
- Clone the repository:
# http git clone
git clone https://github.com/LinuxUser255/url-sanitizer.git
cd url-sanitizer- Add the
muslTarget:rustup target add x86_64-unknown-linux-musl
- Build the Static Binary:
Compile in release mode for an optimized, standalone binary:
The binary will be at
cargo build --release --target x86_64-unknown-linux-musl
target/x86_64-unknown-linux-musl/release/url-sanitizer.
- Verify Static Linking:
Ensure the binary has no dynamic dependencies:
Expected output:
ldd target/x86_64-unknown-linux-musl/release/url-sanitizer
statically linkedornot a dynamic executable.
- Optional: Strip the Binary:
Reduce binary size by removing debug symbols:
strip target/x86_64-unknown-linux-musl/release/url-sanitizer
- Install Globally:
Move the binary to
/usr/local/binfor system-wide access:Verify it’s accessible:sudo mv target/x86_64-unknown-linux-musl/release/url-sanitizer /usr/local/bin/
which url-sanitizer
- Test the Binary:
Run the tool to ensure it works:
(Replace
url-sanitizer --help
--helpwith appropriate arguments if your CLI requires them.)
➜ ~ url-sanitizer -h
Usage: url-sanitizer --url <URL>
Options:
-u, --url <URL>
-h, --help Print help
-V, --version Print version
url-sanitizer --url https://youtu.be/gW464nWLdAs\?si\=TAZ3qCA1503uB__t
Sanitized URL: https://youtu.be/gW464nWLdAsurl-sanitizer --url 'https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhq...&q=https%3A%2F%2Fopenart.ai%2Fhome%3Fref%3Daitanalopez&v=fxiDS2C9XYA'
# Output: https://openart.ai/home
# (Extracts the actual URL from the redirect and removes the 'ref' tracking parameter)url-sanitizer --url 'https://example.com/page?utm_source=newsletter&utm_medium=email&id=123'
# Output: https://example.com/page?id=123
# (Preserves the 'id' parameter while removing UTM tracking)