url_jail
SSRF-safe URL validation for Rust and Python.
Helps mitigate SSRF vulnerabilities like CVE-2024-0243 and CVE-2025-2828 (LangChain SSRF).
Note: This library has not undergone a formal security audit. See SECURITY.md for details.
The Problem
= # AWS credentials leaked via 169.254.169.254
Why url_jail?
String-based URL blocklists fail because attackers can encode IPs in unexpected ways:
| Attack | Naive Blocklist | url_jail |
|---|---|---|
http://0x7f000001/ (hex IP) |
PASS | BLOCKED |
http://0177.0.0.1/ (octal IP) |
PASS | BLOCKED |
http://2130706433/ (decimal IP) |
PASS | BLOCKED |
http://127.1/ (short-form) |
PASS | BLOCKED |
http://[::ffff:127.0.0.1]/ (IPv6-mapped) |
PASS | BLOCKED |
http://169.254.169.254/ |
BLOCKED | BLOCKED |
http://metadata.google.internal/ |
Maybe | BLOCKED |
| DNS rebinding (resolves to 127.0.0.1) | PASS | BLOCKED* |
* When using get_sync() or the returned Validated.ip directly.
url_jail validates after DNS resolution, so encoding tricks and DNS rebinding don't work.
The Solution
Python (recommended):
= # Validates URL and all redirects
Python (with existing HTTP client):
=
= # SSRF-safe requests.Session
Rust:
use ;
use Client;
let v = validate.await?;
let client = builder
.resolve
.build?;
let response = client.get.send.await?;
Installation
# With HTTP client adapters
[]
= "0.1"
# Enable fetch() for redirect chain validation
= { = "0.1", = ["fetch"] }
Policies
| Policy | Allows | Blocks |
|---|---|---|
PublicOnly |
Public IPs only | Private, loopback, link-local, metadata |
AllowPrivate |
Private + public | Loopback, metadata (for internal services) |
HTTP Client Adapters (Python)
# requests
=
=
# httpx (sync)
=
=
# httpx (async)
= await
# aiohttp
= await
Advanced: Custom Blocklist
use ;
let policy = new
.block_cidr
.block_host
.build;
What's Blocked
- Cloud metadata endpoints (AWS, GCP, Azure, Alibaba)
- Private IPs (10.x, 172.16.x, 192.168.x) with
PublicOnly - Loopback (127.x, ::1)
- Link-local (169.254.x, fe80::)
- IP encoding tricks: octal (
0177.0.0.1), decimal (2130706433), hex (0x7f000001), short-form (127.1) - IPv4-mapped IPv6 (
::ffff:127.0.0.1)
Features
| Feature | Description |
|---|---|
fetch |
fetch() / get_sync() with redirect validation |
tracing |
Logging for validation decisions |
License
MIT OR Apache-2.0