From b81c8919efd36fddb683a1ab8540bb4723199d5b Mon Sep 17 00:00:00 2001 From: Fabian Weisshaar Date: Tue, 29 Dec 2015 13:12:22 +0100 Subject: [PATCH] fixes #213, check if nameserver update secret is a valid base64 string --- nsupdate/main/forms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nsupdate/main/forms.py b/nsupdate/main/forms.py index 420c1a2..8e62e1e 100644 --- a/nsupdate/main/forms.py +++ b/nsupdate/main/forms.py @@ -3,6 +3,8 @@ form definitions (which fields are available, order, autofocus, ...) """ +import binascii + from django import forms from .models import Host, RelatedHost, Domain, ServiceUpdaterHostConfig @@ -42,6 +44,14 @@ class EditRelatedHostForm(forms.ModelForm): class CreateDomainForm(forms.ModelForm): + def clean_nameserver_update_secret(self): + secret = self.cleaned_data['nameserver_update_secret'] + try: + binascii.a2b_base64(secret.encode(encoding="ascii", errors="strict")) + except (binascii.Error, UnicodeEncodeError): + raise forms.ValidationError(_("Enter a valid secret in base64 format."), code='invalid') + return secret + class Meta(object): model = Domain fields = ['name', 'nameserver_ip', 'nameserver2_ip', 'nameserver_update_algorithm',