Skip to content

Commit 5b852e4

Browse files
authored
fix: remove jwt key validation to allow new api keys (#212)
1 parent ec811da commit 5b852e4

File tree

6 files changed

+0
-86
lines changed

6 files changed

+0
-86
lines changed

supabase_functions/_async/functions_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from ..utils import (
88
FunctionRegion,
99
is_http_url,
10-
is_valid_jwt,
1110
is_valid_str_arg,
1211
)
1312
from ..version import __version__
@@ -103,9 +102,6 @@ def set_auth(self, token: str) -> None:
103102
the new jwt token sent in the authorization header
104103
"""
105104

106-
if not is_valid_jwt(token):
107-
raise ValueError("token must be a valid JWT authorization token string.")
108-
109105
self.headers["Authorization"] = f"Bearer {token}"
110106

111107
async def invoke(

supabase_functions/_sync/functions_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from ..utils import (
88
FunctionRegion,
99
is_http_url,
10-
is_valid_jwt,
1110
is_valid_str_arg,
1211
)
1312
from ..version import __version__
@@ -103,9 +102,6 @@ def set_auth(self, token: str) -> None:
103102
the new jwt token sent in the authorization header
104103
"""
105104

106-
if not is_valid_jwt(token):
107-
raise ValueError("token must be a valid JWT authorization token string.")
108-
109105
self.headers["Authorization"] = f"Bearer {token}"
110106

111107
def invoke(

supabase_functions/utils.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
import sys
32
from urllib.parse import urlparse
43
from warnings import warn
@@ -59,26 +58,3 @@ def is_valid_str_arg(target: str) -> bool:
5958

6059
def is_http_url(url: str) -> bool:
6160
return urlparse(url).scheme in {"https", "http"}
62-
63-
64-
def is_valid_jwt(value: str) -> bool:
65-
"""Checks if value looks like a JWT, does not do any extra parsing."""
66-
if not isinstance(value, str):
67-
return False
68-
69-
# Remove trailing whitespaces if any.
70-
value = value.strip()
71-
72-
# Remove "Bearer " prefix if any.
73-
if value.startswith("Bearer "):
74-
value = value[7:]
75-
76-
# Valid JWT must have 2 dots (Header.Paylod.Signature)
77-
if value.count(".") != 2:
78-
return False
79-
80-
for part in value.split("."):
81-
if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
82-
return False
83-
84-
return True

tests/_async/test_function_client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ async def test_set_auth_valid_token(client: AsyncFunctionsClient):
4949
assert client.headers["Authorization"] == f"Bearer {valid_token}"
5050

5151

52-
async def test_set_auth_invalid_token(client: AsyncFunctionsClient):
53-
invalid_token = "invalid-token"
54-
with pytest.raises(
55-
ValueError, match="token must be a valid JWT authorization token string."
56-
):
57-
client.set_auth(invalid_token)
58-
59-
6052
async def test_invoke_success_json(client: AsyncFunctionsClient):
6153
mock_response = Mock(spec=Response)
6254
mock_response.json.return_value = {"message": "success"}

tests/_sync/test_function_client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ def test_set_auth_valid_token(client: SyncFunctionsClient):
4949
assert client.headers["Authorization"] == f"Bearer {valid_token}"
5050

5151

52-
def test_set_auth_invalid_token(client: SyncFunctionsClient):
53-
invalid_token = "invalid-token"
54-
with pytest.raises(
55-
ValueError, match="token must be a valid JWT authorization token string."
56-
):
57-
client.set_auth(invalid_token)
58-
59-
6052
def test_invoke_success_json(client: SyncFunctionsClient):
6153
mock_response = Mock(spec=Response)
6254
mock_response.json.return_value = {"message": "success"}

tests/test_utils.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
FunctionRegion,
99
SyncClient,
1010
is_http_url,
11-
is_valid_jwt,
1211
is_valid_str_arg,
1312
)
1413

@@ -73,43 +72,6 @@ def test_is_http_url(test_input: str, expected: bool):
7372
assert is_http_url(test_input) == expected
7473

7574

76-
@pytest.mark.parametrize(
77-
"test_input,expected",
78-
[
79-
# Valid JWTs
80-
(
81-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U",
82-
True,
83-
),
84-
(
85-
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U",
86-
True,
87-
),
88-
# JWT with whitespace
89-
(
90-
" eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U ",
91-
True,
92-
),
93-
# Invalid inputs
94-
("", False),
95-
("not.a.jwt", False),
96-
("invalid.jwt.format.extra.dots", False),
97-
("Bearer ", False),
98-
("Bearer invalid", False),
99-
# Invalid types
100-
(None, False),
101-
(123, False),
102-
([], False),
103-
({}, False),
104-
# Invalid base64url format
105-
("invalid@.base64.format", False),
106-
("header.pay!load.signature", False),
107-
],
108-
)
109-
def test_is_valid_jwt(test_input: Any, expected: bool):
110-
assert is_valid_jwt(test_input) == expected
111-
112-
11375
def test_base64url_regex():
11476
import re
11577

0 commit comments

Comments
 (0)