fixes #213, check if nameserver update secret is a valid base64 string

This commit is contained in:
Fabian Weisshaar 2015-12-29 13:12:22 +01:00
parent eccf53dcbb
commit b81c8919ef

View File

@ -3,6 +3,8 @@
form definitions (which fields are available, order, autofocus, ...) form definitions (which fields are available, order, autofocus, ...)
""" """
import binascii
from django import forms from django import forms
from .models import Host, RelatedHost, Domain, ServiceUpdaterHostConfig from .models import Host, RelatedHost, Domain, ServiceUpdaterHostConfig
@ -42,6 +44,14 @@ class EditRelatedHostForm(forms.ModelForm):
class CreateDomainForm(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): class Meta(object):
model = Domain model = Domain
fields = ['name', 'nameserver_ip', 'nameserver2_ip', 'nameserver_update_algorithm', fields = ['name', 'nameserver_ip', 'nameserver2_ip', 'nameserver_update_algorithm',