Skip to main content

url-guard (Python)

SSRF guard for outbound URLs. This is the Python twin of the @mpointer/url-guard npm package: identical IP-literal grammar, identical classification tables, identical URL rules, shared vectors decoded by both suites in CI. Zero dependencies.

pip install url-guard
from url_guard import assert_public_url, assert_public_url_resolved, UnsafeUrlError

url = assert_public_url("https://api.example.com/v1")            # structural check, no DNS
url = assert_public_url_resolved("https://partner.example/feed")  # every resolved address must be public

assert_public_url(
    "http://docling.railway.internal:5001",
    allow_private=True,                              # self-hosted targets on the private network
    allowed_host_suffixes=(".railway.internal",),    # and nothing else
)
assert_public_url(base_url, require_https=True)      # plaintext only to loopback

UnsafeUrlError subclasses ValueError and carries .reason (parse, protocol, blocked-host, private-address, allow-list, dns, timeout), so a call site that already catches ValueError around its own URL check keeps working when it switches.

A URL whose host another client would read differently is rejected as parse: a \ in the netloc (requests ends the host there), a % in the host (urllib3 decodes it), or a non-ASCII netloc. Pass internationalized hosts IDNA-encoded (xn--...).

See the repository README for the full design: why hostname string matching is not a guard, the encodings that are canonicalized, what allow_private never relaxes, the DNS rules, and the rebinding window this does not close.

Metadata

Release files for url-guard 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for url-guard 0.2.0
File Size Uploaded Provenance Actions
url_guard-0.2.0.tar.gz 11.5 kB With provenance Details for url_guard-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for url-guard 0.2.0
File Interpreter ABI Platform Actions
url_guard-0.2.0-py3-none-any.whl Python 3 none any Details for url_guard-0.2.0-py3-none-any.whl

Total release size: 21.2 kB

Release files / url_guard-0.2.0.tar.gz

Download URL url_guard-0.2.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
08924d6ae216b13de6759d3388a3d5007bb528b81d387b51d5a795140195a201
BLAKE2b-256 checksum
How to use checksums
f25f0e01a763183039a16cb034ce8acaabd3db08eb0b69da370a4c7f1671fe8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / url_guard-0.2.0-py3-none-any.whl

Download URL url_guard-0.2.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f636c801fc44c65eb2860e3f030581a4c6ea3a778d3036e0a8e9ae3e4b9a118f
BLAKE2b-256 checksum
How to use checksums
85c4f2b0e7a4fcaba942fedc6160e15a86b74641639c452bf7501f47495d0edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for url-guard 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for url_guard-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page