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.1.2

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.1.2
File Size Uploaded Provenance Actions
url_guard-0.1.2.tar.gz 11.4 kB With provenance Details for url_guard-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 20.9 kB

Release files / url_guard-0.1.2.tar.gz

Download URL url_guard-0.1.2.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6e30f68fbabc97cf1d044f9931114d3c58e28747d0a007832d64f89fb2776599
BLAKE2b-256 checksum
How to use checksums
76517249d8825bcd58c389b93372fc29ecb366c233ced0f8f9a6b95a420253c6
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.1.2-py3-none-any.whl

Download URL url_guard-0.1.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95dc926f477bd25477a20e67cdf4889bc338bd99378acc7bf2359fbbc6126b3e
BLAKE2b-256 checksum
How to use checksums
7d981e2730666a7a6061aafdc4621d448b0377d70697699721df4c173ff04806
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.1.2

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.1.2.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