safehttpx
A small Python library created to help developers protect their applications from Server Side Request Forgery (SSRF) attacks.
What it is and what it does
safehttpx is an async HTTP client wrapper that adds SSRF attack protection on top of httpx. It validates URLs against public DNS before making requests and implements defenses against DNS rebinding attacks, which can trick applications into accessing internal services. The library rejects requests to private IP ranges (like 127.0.0.1) by default, but allows whitelisting of specific domains when needed—for instance, if your infrastructure uses DNS splitting to serve internal and external addresses differently.
The package is a thin, low-friction layer: it depends only on httpx and comes as a pure Python wheel. It was created following a security audit of Gradio and is now used in production there. The async-only API means you must structure code around asyncio, either by using it in an event-loop-aware environment (Jupyter, IPython) or by wrapping calls in asyncio.run() in standard scripts.
Use it for:
- Protect web services that fetch user-supplied URLs (e.g., link previews, webhook handlers) from SSRF attacks.
- Prevent attackers from using your server to scan internal networks or access cloud metadata services.
- Safely make HTTP requests in multi-tenant or untrusted-input scenarios where URL validation is critical.
- Block DNS rebinding attacks that attempt to redirect public domains to internal IP addresses mid-request.
- Whitelist trusted internal domains while still validating external URLs in hybrid network architectures.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Wraps httpx.AsyncClient.get() with DNS validation and DNS rebinding protections to prevent Server Side Request Forgery (SSRF) attacks.
Yes, if you need SSRF protection and are already using async HTTP in Python >3.9. The library is lightweight, permissively licensed, and battle-tested in Gradio. The aging maintenance status (no release in 294 days) is a minor concern but not a blocker if the current version meets your needs; no known vulnerabilities are recorded. Install it if SSRF is a real threat in your application; skip it if you are not accepting untrusted URLs or are not using async code.
Install
safehttpx on PyPI
pip
pip install safehttpxuv
uv add safehttpxpoetry
poetry add safehttpxInstalling safehttpx
Before you install
Low friction: pure Python wheel with a single runtime dependency (httpx). Maintenance status is aging—last commit was 2025-10-24 and the project has not released a new version in 294 days, though the repository remains active and unarchived.
License in practice
MIT license (permissive). You may use, modify, and distribute this package freely, including in commercial applications, provided you retain the license notice.
Quickstart
import asyncio
import safehttpx as sh
await sh.get("https://huggingface.co")
# or in a script:
asyncio.run(sh.get("https://huggingface.co"))
Requires Python >3.9 and an asyncio event loop; the get() method is async-only and will reject requests to private/reserved IP ranges by default.
Verify before relying
- Whether Google DNS is always reachable or if there is a fallback mechanism for DNS resolution.
- Performance overhead of DNS validation on each request compared to standard httpx.
- Whether the whitelist feature supports wildcards or only exact domain matches.
- Specific DNS rebinding attack scenarios the library defends against beyond basic validation.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — httpx |
| Maintenance | aging — 294 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,067,160/month — #1,974 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: safehttpx-0.1.7-py3-none-any.whl
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
advocateAdvocate wraps the requests library to prevent…
permissive · top 15,000 on PyPI
requests-hardenedWraps the requests library to enforce security…
permissive · top 15,000 on PyPI
asgi-csrfASGI middleware that protects web applications…
permissive · top 15,000 on PyPI
flask-talismanFlask extension that automatically sets HTTP…
permissive · top 5,000 on PyPI
fastapi-csrf-protectAdds stateless CSRF protection to FastAPI…
permissive · top 15,000 on PyPI
dnstwistGenerates domain name permutations to detect…
permissive · top 15,000 on PyPI
proxy.pyA lightweight, pluggable HTTP proxy server…
permissive · top 5,000 on PyPI
urllib3-futureHTTP client library supporting HTTP/1.1,…
permissive · top 5,000 on PyPI
httpx-socksAdds SOCKS4(a), SOCKS5(h), and HTTP CONNECT…
permissive · top 5,000 on PyPI
PySocksPySocks provides a SOCKS and HTTP proxy client…
permissive · top 1,000 on PyPI