Skip to content

Commit 830c10b

Browse files
Merge pull request #212 from supertokens/fix/emailpassword-handle-invalid-req
fix(emailpassword): Send 400 on passing non-string email in request body
2 parents a7b2198 + 1329c24 commit 830c10b

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [unreleased]
88

9+
### Bug fix
10+
- Send 400 instead of 500 on invalid request body or when user passes non-string values as email ID for `/auth/signin`
11+
12+
### Changes
913
- Add to test to ensure that overrides are applying correctly in methods called on SessionContainer instances
1014

1115
## [0.10.2] - 2022-07-14

supertokens_python/recipe/emailpassword/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def validate_form_fields_or_throw_error(
7373
"All elements of formFields must contain an 'id' and 'value' field"
7474
)
7575
value = current_form_field["value"]
76-
if current_form_field["id"] == FORM_FIELD_EMAIL_ID:
76+
if current_form_field["id"] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
7777
value = value.strip()
7878
form_fields.append(FormField(current_form_field["id"], value))
7979

supertokens_python/recipe/emailpassword/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ async def default_password_validator(value: str) -> Union[str, None]:
7070
return None
7171

7272

73-
async def default_email_validator(value: str) -> Union[str, None]:
73+
async def default_email_validator(value: Any) -> Union[str, None]:
7474
# We check if the email syntax is correct
7575
# As per https://github.com/supertokens/supertokens-auth-react/issues/5#issuecomment-709512438
7676
# Regex from https://stackoverflow.com/a/46181/3867175
77-
if (
77+
if (not isinstance(value, str)) or (
7878
fullmatch(
7979
r'^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,'
8080
r"3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$",

tests/emailpassword/test_passwordreset.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,15 @@ async def test_email_validation_checks_in_generate_token_API(
107107
)
108108
start_st()
109109

110-
response_1 = driver_config_client.post(
111-
url="/auth/user/password/reset/token",
112-
json={"formFields": [{"id": "email", "value": "random"}]},
113-
)
110+
for invalid_email in ["random", 5]:
111+
res = driver_config_client.post(
112+
url="/auth/user/password/reset/token",
113+
json={"formFields": [{"id": "email", "value": invalid_email}]},
114+
)
114115

115-
assert response_1.status_code == 200
116-
dict_response = json.loads(response_1.text)
117-
assert dict_response["status"] == "FIELD_ERROR"
116+
assert res.status_code == 200
117+
dict_res = json.loads(res.text)
118+
assert dict_res["status"] == "FIELD_ERROR"
118119

119120

120121
@mark.asyncio

0 commit comments

Comments
 (0)