浏览代码

fix(api): explicitly whitelist characters allowed in pdns URLs

Peter Thomassen 6 年之前
父节点
当前提交
62819a3a90
共有 1 个文件被更改,包括 3 次插入4 次删除
  1. 3 4
      api/desecapi/pdns.py

+ 3 - 4
api/desecapi/pdns.py

@@ -1,4 +1,5 @@
 import json
+import re
 import requests
 
 from django.core.exceptions import SuspiciousOperation
@@ -63,13 +64,11 @@ def _pdns_delete(server, path):
 
 
 def pdns_id(name):
-    # / is allowed by pdns, but we don't want it
-    if '/' in name or '?' in name:
+    # See also pdns code, apiZoneNameToId() in ws-api.cc (with the exception of forward slash)
+    if not re.match(r'^[a-zA-Z0-9_.-]+$', name):
         raise SuspiciousOperation('Invalid hostname ' + name)
 
-    # See also pdns code, apiZoneNameToId() in ws-api.cc
     name = name.translate(str.maketrans({'/': '=2F', '_': '=5F'}))
-
     return name.rstrip('.') + '.'