diff --git a/fideslog/api/models/analytics_event.py b/fideslog/api/models/analytics_event.py index e6c3954..66b16f5 100644 --- a/fideslog/api/models/analytics_event.py +++ b/fideslog/api/models/analytics_event.py @@ -96,6 +96,10 @@ def check_not_an_email_address(cls, value: str) -> str: def validate_endpoint_format(cls, value: Optional[str]) -> Optional[str]: """ Ensure that `endpoint` contains the request's HTTP method and URL. + + If the URL contains the host `0.0.0.0` this validation would fail, + so it's replaced with `localhost` to ensure the URL can be legitimately + validated. The host is never stored in the databse, so it doesn't matter. """ if value is None: @@ -112,7 +116,9 @@ def validate_endpoint_format(cls, value: Optional[str]) -> Optional[str]: ), f"HTTP method must be one of {', '.join(ALLOWED_HTTP_METHODS)}" url = endpoint_components[1].strip() - assert is_valid_url(url), "endpoint URL must be a valid URL" + assert is_valid_url( + url.replace("://0.0.0.0", "://localhost", 1) + ), "endpoint URL must be a valid URL" return f"{http_method}: {url}" diff --git a/fideslog/sdk/python/event.py b/fideslog/sdk/python/event.py index 339e9aa..97694c1 100644 --- a/fideslog/sdk/python/event.py +++ b/fideslog/sdk/python/event.py @@ -94,7 +94,9 @@ def __init__( ), f"HTTP method must be one of {', '.join(ALLOWED_HTTP_METHODS)}" url = endpoint_components[1].strip() - assert is_valid_url(url), "endpoint URL must be a valid URL" + assert is_valid_url( + url.replace("://0.0.0.0", "://localhost", 1) + ), "endpoint URL must be a valid URL" self.endpoint = f"{http_method}: {url}"