Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 13008b3

Browse files
authored
fix: remove unused jwt key validation (#725)
1 parent 78a8eb7 commit 13008b3

File tree

2 files changed

+0
-53
lines changed

2 files changed

+0
-53
lines changed

supabase_auth/helpers.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -288,29 +288,6 @@ def is_http_url(url: str) -> bool:
288288
return urlparse(url).scheme in {"https", "http"}
289289

290290

291-
def is_valid_jwt(value: str) -> bool:
292-
"""Checks if value looks like a JWT, does not do any extra parsing."""
293-
if not isinstance(value, str):
294-
return False
295-
296-
# Remove trailing whitespaces if any.
297-
value = value.strip()
298-
299-
# Remove "Bearer " prefix if any.
300-
if value.startswith("Bearer "):
301-
value = value[7:]
302-
303-
# Valid JWT must have 2 dots (Header.Paylod.Signature)
304-
if value.count(".") != 2:
305-
return False
306-
307-
for part in value.split("."):
308-
if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
309-
return False
310-
311-
return True
312-
313-
314291
def validate_exp(exp: int) -> None:
315292
if not exp:
316293
raise AuthInvalidJwtError("JWT has no expiration time")

tests/test_helpers.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
generate_pkce_verifier,
2424
get_error_code,
2525
handle_exception,
26-
is_valid_jwt,
2726
model_dump,
2827
model_dump_json,
2928
model_validate,
@@ -166,35 +165,6 @@ def test_parse_response_api_version_invalid_date():
166165
assert result is None
167166

168167

169-
# Test for is_valid_jwt
170-
def test_is_valid_jwt():
171-
# Valid JWT format (3 parts with valid base64url encoding)
172-
valid_jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
173-
assert is_valid_jwt(valid_jwt) is True
174-
175-
# Valid JWT with Bearer prefix
176-
valid_jwt_with_bearer = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
177-
assert is_valid_jwt(valid_jwt_with_bearer) is True
178-
179-
# Invalid JWT - wrong number of parts
180-
invalid_jwt_parts = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ"
181-
assert is_valid_jwt(invalid_jwt_parts) is False
182-
183-
# Invalid JWT - not a string
184-
assert is_valid_jwt(123) is False
185-
186-
# Need to patch the BASE64URL_REGEX to make invalid_jwt_encoding fail validation
187-
with patch("supabase_auth.helpers.re.search") as mock_search:
188-
# Make the invalid JWT fail the regex check
189-
mock_search.side_effect = lambda pattern, string, flags=0: (
190-
False if string == "AAA" else True
191-
)
192-
193-
# Invalid JWT - invalid base64url encoding
194-
invalid_jwt_encoding = "AAA.BBB.CCC"
195-
assert is_valid_jwt(invalid_jwt_encoding) is False
196-
197-
198168
# Test for pydantic v1 compatibility in model_validate
199169
def test_model_validate_pydantic_v1():
200170
# We need to patch the actual calls inside the function

0 commit comments

Comments
 (0)