Functions
is_safe_url
1
bool
▼
Check whether *url* is safe to redirect to.
A URL is considered safe if it is …
is_safe_url
1
bool
▼
def is_safe_url(url: str) -> bool
Check whether url is safe to redirect to.
A URL is considered safe if it is a relative path on the same origin:
- Must be a non-empty string
- Must start with
/ - Must not start with
//(protocol-relative URL) - Must not contain
://(absolute URL with scheme)
Examples::
>>> is_safe_url("/dashboard")
True
>>> is_safe_url("/login?next=/home")
True
>>> is_safe_url("//evil.com")
False
>>> is_safe_url("https://evil.com")
False
>>> is_safe_url("")
False
Parameters
| Name | Type | Description |
|---|---|---|
url |
str |
Returns
bool