Skip to content

Commit

Permalink
feat: Check if url is an HTTP URL (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Nov 2, 2024
1 parent 27bd96f commit f0ccae5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion supabase_auth/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ..constants import COOKIE_OPTIONS, DEFAULT_HEADERS, GOTRUE_URL, STORAGE_KEY
from ..exceptions import APIError
from ..helpers import model_dump, model_validate
from ..helpers import is_http_url, model_dump, model_validate
from ..types import (
AuthChangeEvent,
CookieOptions,
Expand Down Expand Up @@ -61,6 +61,8 @@ def __init__(
proxy: str
HTTP Proxy string or None, None by default, None disables proxy.
"""
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
if url.startswith("http://"):
print(
"Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOTRUE EVER!\n"
Expand Down Expand Up @@ -428,6 +430,8 @@ def get_session_from_url(
APIError
If an error occurs.
"""
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
data = urlparse(url)
query = parse_qs(data.query)
error_description = query.get("error_description")
Expand Down
5 changes: 5 additions & 0 deletions supabase_auth/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime
from json import loads
from typing import Any, Dict, Optional, Type, TypeVar, cast
from urllib.parse import urlparse

from httpx import HTTPStatusError, Response
from pydantic import BaseModel
Expand Down Expand Up @@ -238,3 +239,7 @@ def parse_response_api_version(response: Response):
return dt
except Exception as e:
return None


def is_http_url(url: str) -> bool:
return urlparse(url).scheme in {"https", "http"}

0 comments on commit f0ccae5

Please sign in to comment.