Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow urls in full_name during registration #16663

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/unit/accounts/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,33 @@ def test_name_contains_null_bytes(self, pyramid_config):
assert not form.validate()
assert form.full_name.errors.pop() == "Null bytes are not allowed."

@pytest.mark.parametrize(
"input_name",
[
"https://example.com",
"hello http://example.com",
"http://example.com goodbye",
],
)
def test_name_contains_url(self, pyramid_config, input_name):
form = forms.RegistrationForm(
request=pretend.stub(),
formdata=MultiDict({"full_name": input_name}),
user_service=pretend.stub(
find_userid=pretend.call_recorder(lambda _: None)
),
captcha_service=pretend.stub(
enabled=False,
verify_response=pretend.call_recorder(lambda _: None),
),
breach_service=pretend.stub(check_password=lambda pw, tags=None: True),
)
assert not form.validate()
assert (
str(form.full_name.errors.pop())
== "URLs are not allowed in the name field."
)


class TestRequestPasswordResetForm:
@pytest.mark.parametrize(
Expand Down
4 changes: 4 additions & 0 deletions warehouse/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class RegistrationForm( # type: ignore[misc]
"Choose a name with 100 characters or less."
),
),
wtforms.validators.Regexp(
r"(?i)(?:(?!:\/\/).)*$",
message=_("URLs are not allowed in the name field."),
),
PreventNullBytesValidator(),
]
)
Expand Down
14 changes: 9 additions & 5 deletions warehouse/locale/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ msgstr ""
msgid "The name is too long. Choose a name with 100 characters or less."
msgstr ""

#: warehouse/accounts/forms.py:446
#: warehouse/accounts/forms.py:361
msgid "URLs are not allowed in the name field."
msgstr ""

#: warehouse/accounts/forms.py:450
msgid "Invalid TOTP code."
msgstr ""

#: warehouse/accounts/forms.py:463
#: warehouse/accounts/forms.py:467
msgid "Invalid WebAuthn assertion: Bad payload"
msgstr ""

#: warehouse/accounts/forms.py:532
#: warehouse/accounts/forms.py:536
msgid "Invalid recovery code."
msgstr ""

#: warehouse/accounts/forms.py:541
#: warehouse/accounts/forms.py:545
msgid "Recovery code has been previously used."
msgstr ""

#: warehouse/accounts/forms.py:571
#: warehouse/accounts/forms.py:575
msgid "The username isn't valid. Try again."
msgstr ""

Expand Down