Merge pull request #114 from zeronet-conservancy/xmlupnp

return upnp punch using secure xml library
This commit is contained in:
caryoscelus 2022-06-29 11:50:31 +00:00 committed by GitHub
commit c5f5479ba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 6 deletions

View file

@ -12,3 +12,4 @@ gevent-ws
coincurve coincurve
maxminddb maxminddb
rich rich
defusedxml>=0.7

View file

@ -28,8 +28,8 @@ class PeerPortchecker(object):
return urllib.request.urlopen(req, timeout=20.0) return urllib.request.urlopen(req, timeout=20.0)
def portOpen(self, port): def portOpen(self, port):
self.log.info("Not trying to open port using UpnpPunch until it's proven robust...") # self.log.info("Not trying to open port using UpnpPunch until it's proven robust...")
return False # return False
try: try:
UpnpPunch.ask_to_open_port(port, 'ZeroNet', retries=3, protos=["TCP"]) UpnpPunch.ask_to_open_port(port, 'ZeroNet', retries=3, protos=["TCP"])
@ -37,7 +37,6 @@ class PeerPortchecker(object):
except Exception as err: except Exception as err:
self.log.warning("UpnpPunch run error: %s" % Debug.formatException(err)) self.log.warning("UpnpPunch run error: %s" % Debug.formatException(err))
return False return False
return True return True
def portClose(self, port): def portClose(self, port):

View file

@ -3,8 +3,7 @@ import urllib.request
import http.client import http.client
import logging import logging
from urllib.parse import urlparse from urllib.parse import urlparse
from xml.dom.minidom import parseString from defusedxml.minidom import parseString
from xml.parsers.expat import ExpatError
from gevent import socket from gevent import socket
import gevent import gevent
@ -105,7 +104,7 @@ def _parse_igd_profile(profile_xml):
""" """
try: try:
dom = parseString(profile_xml) dom = parseString(profile_xml)
except ExpatError as e: except Exception as e:
raise IGDError( raise IGDError(
'Unable to parse IGD reply: {0} \n\n\n {1}'.format(profile_xml, e)) 'Unable to parse IGD reply: {0} \n\n\n {1}'.format(profile_xml, e))