Skip to content

Commit 07b10bd

Browse files
committed
webhook notification url size validation check
1 parent 0e1112f commit 07b10bd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

readthedocs/projects/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class WebHookForm(forms.Form):
476476

477477
"""Project webhook form."""
478478

479-
url = forms.URLField()
479+
url = forms.URLField(max_length=WebHook._meta.get_field('url').max_length)
480480

481481
def __init__(self, *args, **kwargs):
482482
self.project = kwargs.pop('project', None)

readthedocs/projects/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def __str__(self):
965965

966966
@python_2_unicode_compatible
967967
class WebHook(Notification):
968-
url = models.URLField(blank=True,
968+
url = models.URLField(max_length=600, blank=True,
969969
help_text=_('URL to send the webhook to'))
970970

971971
def __str__(self):

readthedocs/projects/views/private.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,20 @@ def project_notifications(request, project_slug):
510510
webhook_form = WebHookForm(data=request.POST or None, project=project)
511511

512512
if request.method == 'POST':
513-
if email_form.is_valid():
514-
email_form.save()
515-
if webhook_form.is_valid():
516-
webhook_form.save()
513+
if 'email' not in request.POST:
514+
email_form = EmailHookForm(data=None, project=project)
515+
if 'url' not in request.POST:
516+
webhook_form = WebHookForm(data=None, project=project)
517517
project_dashboard = reverse(
518518
'projects_notifications',
519519
args=[project.slug],
520520
)
521-
return HttpResponseRedirect(project_dashboard)
521+
if email_form.is_valid():
522+
email_form.save()
523+
return HttpResponseRedirect(project_dashboard)
524+
if webhook_form.is_valid():
525+
webhook_form.save()
526+
return HttpResponseRedirect(project_dashboard)
522527

523528
emails = project.emailhook_notifications.all()
524529
urls = project.webhook_notifications.all()

0 commit comments

Comments
 (0)