is_safe_url()
Redirecting a visitor to another URL is common. It's also common that the
redirect target is controllable by a visitor. One can often find a ?next or
?on_complete GET parameter with the redirect target.
While this form of redirection is convenient, blindly redirecting a visitor to the given target can easily lead to Unvalidated Redirect and Forwards. Thus, one needs to check if the redirect target is "safe" before redirecting a visitor.
The Django web framework has a utility function
is_safe_url() that attempts to validate a given target against a set of valid
hosts. This package unbundles the function and easily allows other projects to
use it.
>>> from is_safe_url import is_safe_url
>>> is_safe_url("/redirect/target", {"example.com", "www.example.com"})
True
>>> is_safe_url("//example.com/redirect/target", {"example.com", "www.example.com"})
True
>>> is_safe_url("//evil.net/redirect/target", {"example.com"})
False
>>> is_safe_url("http://example.com/redirect/target", {"example.com"})
True
>>> is_safe_url("http://example.com/redirect/target", {"example.com"}, require_https=True)
False
>>> is_safe_url("https://example.com/redirect/target", {"example.com"}, require_https=True)
True
Security
Please report security issues privately to the Django security team or Markus Holtermann.
Metadata
Release files for is-safe-url 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| is_safe_url-1.0.tar.gz | 5.1 kB | Without provenance | Details for is_safe_url-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| is_safe_url-1.0-py3-none-any.whl | Python 3 | none | any | Details for is_safe_url-1.0-py3-none-any.whl |
Total release size: 10.6 kB
Release files / is_safe_url-1.0.tar.gz
| Download URL | is_safe_url-1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d776186f6877211daefde6a18da1df520de985a582b293e7aa24ea1df1cd5abb
|
|
BLAKE2b-256 checksum How to use checksums |
a494be63323c7096a133a1b3ca89f4c096f0828ad0e169dba24cef6c28e1dd0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
|
Release files / is_safe_url-1.0-py3-none-any.whl
| Download URL | is_safe_url-1.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d55e554974039deec7f9a395aab1e488abac811006d17f930607c43e6d3948e
|
|
BLAKE2b-256 checksum How to use checksums |
7ac340c363bc4c3d0ddcda3489239ba64752b8c18cb6493e058f8f1b73154925
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
|
Security for is-safe-url 1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.