Skip to main content

SSRF-safe URL validation for Python

Project description

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

response = requests.get(user_url)  # 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):

from url_jail import get_sync

body = get_sync(user_url)  # Validates URL and all redirects

Python (with existing HTTP client):

from url_jail.adapters import safe_session

s = safe_session()
response = s.get(user_url)  # SSRF-safe requests.Session

Rust:

use url_jail::{validate, Policy};
use reqwest::Client;

let v = validate("https://example.com/api", Policy::PublicOnly).await?;

let client = Client::builder()
    .resolve(&v.host, v.to_socket_addr())
    .build()?;

let response = client.get(&v.url).send().await?;

Installation

pip install url_jail

# With HTTP client adapters
pip install url_jail[requests]  # or [httpx], [aiohttp], [all]
[dependencies]
url_jail = "0.1"

# Enable fetch() for redirect chain validation
url_jail = { version = "0.1", features = ["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
from url_jail.adapters import safe_session
s = safe_session()
response = s.get(user_url)

# httpx (sync)
from url_jail.adapters import safe_httpx_client
client = safe_httpx_client()
response = client.get(user_url)

# httpx (async)
from url_jail.adapters import safe_httpx_async_client
async with safe_httpx_async_client() as client:
    response = await client.get(user_url)

# aiohttp
from url_jail.adapters import safe_aiohttp_session
async with safe_aiohttp_session() as session:
    async with session.get(user_url) as response:
        body = await response.text()

Advanced: Custom Blocklist

use url_jail::{PolicyBuilder, Policy};

let policy = PolicyBuilder::new(Policy::AllowPrivate)
    .block_cidr("10.0.0.0/8")
    .block_host("*.internal.example.com")
    .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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

url_jail-0.1.10-cp314-cp314-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.14Windows x86-64

url_jail-0.1.10-cp314-cp314-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

url_jail-0.1.10-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

url_jail-0.1.10-cp313-cp313-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

url_jail-0.1.10-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

url_jail-0.1.10-cp312-cp312-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

url_jail-0.1.10-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11Windows x86-64

url_jail-0.1.10-cp311-cp311-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

url_jail-0.1.10-cp310-cp310-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.10Windows x86-64

url_jail-0.1.10-cp310-cp310-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp310-cp310-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

url_jail-0.1.10-cp39-cp39-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.9Windows x86-64

url_jail-0.1.10-cp39-cp39-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

url_jail-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

url_jail-0.1.10-cp39-cp39-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file url_jail-0.1.10-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4f8a317687e7c4675e7be2c8b489f12d3b44aff67ef8d4bd4c8bcc5dcceac59d
MD5 9695233f4c4e6376d772eececa7af7b0
BLAKE2b-256 af218a0fdaf8a2f8a1437b2d17e28966451515c9fede39da22872542f327fe21

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f2dc027fdc3f4de253ddb4b6fa6697ec3f8276fc3454ce767eb6512f83d53eb9
MD5 7404c15e14b1fd8afdc31af0dff83272
BLAKE2b-256 31716a4f1012dfc9223d786a982f66acae318278d4205be09692f5fc0c012d4e

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8d183d0a618ee36dd6a1d3a324ea97f23629d4b753f8a500c6bb5bfadfb61e1
MD5 8a9cde26fed408b35cabf3515e1deea8
BLAKE2b-256 0cfe8f88fe60ce2def0730909161d42a818cb53ab1597f4c9cbdc61391a57d5f

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20472a48cde3ea42ed00a797c8d99a4da5404f2484fa2c9e2d2de9fcda99963b
MD5 6d168a00794245d464d1c64829e557ee
BLAKE2b-256 0a2e7119e84e08251cb37dd3c94f2371c17c6b03e138b26b7a76110cd0f303dc

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 32d0a4ab3d652d6871acf9443433b8a0a1986610db8bcde3fde4df191002e856
MD5 4b3e0c73eade48332d816d1a0499aa42
BLAKE2b-256 bc17278eb273f6328cd09b1bf69f2a7a91eec63108fa10a759858beb0793c794

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9b444c265ff2fc587c28002787fca001bcf47c898bde7772f71cc796c7e98b83
MD5 e4483cd0e0442752ad5fcb0ce2b12d01
BLAKE2b-256 4907c96e16b6b6e8f0c3d4773837f4f32856554fe27a9c4f71cdbd8839f15b6e

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0feafdad58fb673d28005c50be883eaf065a361f7707615a16f16496ad54d2b1
MD5 4488d9dcf76600c9e213355e0bfe173e
BLAKE2b-256 435b9bdd2010e8a84d55f4fd74e8d288934020a07bde5332e9bb51c62ffac97d

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2c2e9900ebccfe98eb02ee9e71a1c47dfe93d5052bbdd52cc9d5829dde89bc4
MD5 6cdddcdfdb183b5ae89e7fc7af9cd244
BLAKE2b-256 6ed6d9a1fcc8c300e2cda1f2dbea6616990df03ee73e3d118d9a36550972281e

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 300556aa06eb809d36980e5dee94ca65c5947d43a9bc7215fdfb75905f8c4d62
MD5 6289c98722645228d3f8b6aa54408e6a
BLAKE2b-256 62a1cc8ebc8faf3d3704c09d7ed1817460422a69765002b96018f475d8bc44a5

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2bfc1f6ed95cfb71aa04c4b0338803cf2db93fde3b5712590971fb4cd8c5c779
MD5 8053fe39df1fb2b77cb2925223ca8b36
BLAKE2b-256 12eead50e8f27d53993ad3af95e63e219066c284ff57452cb8795d3838d0fdf6

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82771d7441f06fb841724daa72185eb9953076014417ad925fb40fd863d98ba0
MD5 5bd84431a850ceb6cb25cf06d9ea7e9c
BLAKE2b-256 6ae8caca416bb9280c6be31b3c30f01a50ae241eeae099624d4b922f8296fba5

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cfcc6957b900710a223c22895574dccfee2a6dc9df72d5a79357e92653fa641
MD5 8752bb310f97071be2a7dc48a9da5d68
BLAKE2b-256 afc7f7e18e0f319bc0ed2deb3fdf65cc55c363ea414266b6f3b74da7670cb206

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 18c6786cec34c1ff9a973b578bed621b2fccd46cabfc834152878bd9aef71ecf
MD5 013bb024a454eea32151787c56db91a9
BLAKE2b-256 c3d187c1a6504b49daaf22e928c013c2061877bd7d52685f3e54aa436cb4f056

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 27c507573b92bd01c65c8af0c25a35e286ee4ef50daee7a4a6337eb889155299
MD5 ae19c825e237b9c1d3581ae114f8c50d
BLAKE2b-256 4b08984e7f7dd08fe1f615824db2144006c3228d7e7f588ee8cf07a940538b54

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b1fe77d15ae7c92d37bd0c7dc591ad4c7218a999acb474683b272b77019fe1c
MD5 f72bac5fb417e2d432bfa8d5562ffab1
BLAKE2b-256 b4e2a2735a3c527bd1cc79ac0eaacc327b7286cfc813803dfd5b54b7624abfd1

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 149ad23bc2db17d0661e198c97413c05c9fbddcefaf5a7d34f8852db4d5dc651
MD5 e1501707ce72aea6793c46824fb4daf8
BLAKE2b-256 22ceb19004b1b5520a95923b0d210f3e088c7cc1bc2812a8d3a2c4c86c499028

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0d62f3a037c351af068885cd347b7537d82c5f9cafa21c9bc5849361c87c9c35
MD5 a43e9d75247b654ce6d1e56408f50f27
BLAKE2b-256 3611f4a9c23ef55387f093ba84d1d19a3f3a2a25a807594179238207ef63000f

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e21987c474708b0619b04adefa27a8bead7f293c416dddfd8b7a28f891c46ab9
MD5 2b64f17978fd8877cc70792b7d39a342
BLAKE2b-256 79169f6ecc74bc376410b3c64093ae138e2af4fb56ffdaba1a0e440bafe36411

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca3181bcb3d032c40cb3229debe98c61b77ddf368cbf6f856ee2b510c81c678b
MD5 5391904f49c1e1549905c607c1edaa9c
BLAKE2b-256 0628a1f481ae45acc674b7c22de80608558fd8d02e365841bc071390cc667eef

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 96d5b3abc046a8de60719babc44dd81828cc2fa122bde316c658c8eba68a547d
MD5 7fb17a853e9ae07d08304a52837f5bc3
BLAKE2b-256 9863da9a8d8d1ae6c5ef308165c747686f7b13fb5faf46790a258d30d7591138

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: url_jail-0.1.10-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for url_jail-0.1.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ad5e1dfb921512f1d60b5a81254c0e7f712da1410034f00df37b47859bc4a996
MD5 16d4c8690445d93d8747a8dea5b9faae
BLAKE2b-256 19aba6527bc31ad80f8a645e79f2f1dd901cfb4a431e675142fa55828e2cff7d

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2c2e5d3077a2d4535f859582eb0f9b520e18109497c8cacc08f31414ea5b37cf
MD5 e9bea5ad3ea19baa2751fea40df6f16d
BLAKE2b-256 e1003e72e5f2307b5395feb48b3faf4d4384a72ca54e8c01ff8a475830869b01

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bce202db688af3351c79b0d4eb529747bee6f04d0b813ca958361ac4b891fc4
MD5 c99f2c489f105660942a6d029fb1a114
BLAKE2b-256 9fe44e89d85fe95d5432589447e2b49a9cd970973694bc93917cae449af40257

See more details on using hashes here.

File details

Details for the file url_jail-0.1.10-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for url_jail-0.1.10-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c3b4737c1183003bd949084f95466aaaad22668ed745594ad4eada1ae82f3a0
MD5 7f37ff220bc03b4714de55f2e96246e0
BLAKE2b-256 4f736d1566ff9008456141a420de16237f2db3d4a1b3180df07c0cfecaa459ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page