bookwyrm/bookwyrm/utils/validate.py
2023-01-01 19:57:10 +01:00

16 lines
399 B
Python

"""Validations"""
from bookwyrm.settings import DOMAIN, USE_HTTPS
def validate_url_domain(url, default="/"):
"""Basic check that the URL starts with the instance domain name"""
if url in ("/", default, None):
return url
protocol = "https://" if USE_HTTPS else "http://"
origin = f"{protocol}{DOMAIN}"
if url.startswith(origin):
return url
return default