From 04a07648b4a42c5b29d1443b695aa2bbcb5156ba Mon Sep 17 00:00:00 2001 From: Tee Ngo Date: Mon, 24 Jun 2019 08:23:11 -0400 Subject: [PATCH] Beef up sysinv URL validator The current sysinv URL validator does not handle URLs containing IPv6 address correctly. This commit fixes that. Closes-Bug: 1833710 Change-Id: Ic5a450ede0390529e795ca0120200a0f7bbf52ce Signed-off-by: Tee Ngo --- sysinv/sysinv/centos/build_srpm.data | 2 +- sysinv/sysinv/centos/sysinv.spec | 1 + sysinv/sysinv/debian/control | 1 + sysinv/sysinv/sysinv/requirements.txt | 2 ++ sysinv/sysinv/sysinv/sysinv/common/utils.py | 17 ++++------------- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/sysinv/sysinv/centos/build_srpm.data b/sysinv/sysinv/centos/build_srpm.data index e66b3d682b..f3c2c4e149 100644 --- a/sysinv/sysinv/centos/build_srpm.data +++ b/sysinv/sysinv/centos/build_srpm.data @@ -1,2 +1,2 @@ SRC_DIR="sysinv" -TIS_PATCH_VER=324 +TIS_PATCH_VER=325 diff --git a/sysinv/sysinv/centos/sysinv.spec b/sysinv/sysinv/centos/sysinv.spec index c0de21af2d..8b98c13ad1 100644 --- a/sysinv/sysinv/centos/sysinv.spec +++ b/sysinv/sysinv/centos/sysinv.spec @@ -25,6 +25,7 @@ Requires: python-pbr Requires: python-webtest Requires: python-wsme Requires: python-six +Requires: python2-django Requires: python2-mox3 Requires: python2-oslo-config Requires: python2-oslo-concurrency diff --git a/sysinv/sysinv/debian/control b/sysinv/sysinv/debian/control index 646cc21c9a..eac73fe12d 100644 --- a/sysinv/sysinv/debian/control +++ b/sysinv/sysinv/debian/control @@ -15,6 +15,7 @@ Package: sysinv Architecture: all Depends: ${misc:Depends}, ${python:Depends}, + python-django, python-docker, python-parted, python-six, diff --git a/sysinv/sysinv/sysinv/requirements.txt b/sysinv/sysinv/sysinv/requirements.txt index eec3bfd240..e8d9376d5c 100644 --- a/sysinv/sysinv/sysinv/requirements.txt +++ b/sysinv/sysinv/sysinv/requirements.txt @@ -40,3 +40,5 @@ rpm ruamel.yaml>=0.13.14 # MIT docker # Apache-2.0 kubernetes # Apache-2.0 +Django<2,>=1.11.20 # BSD + diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index f94e85175a..cfa0bbcf89 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -51,6 +51,7 @@ import uuid import wsme import yaml +from django.core.validators import URLValidator from eventlet.green import subprocess from eventlet import greenthread import netaddr @@ -1769,20 +1770,10 @@ def is_openstack_applied(dbapi): def is_url(url_str): - # Django URL validation patterns - r = re.compile( - r'^(?:http|ftp)s?://' # http:// or https:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)' # domain... - r'+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' - r'localhost|' # localhost... - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip - r'(?::\d+)?' # optional port - r'(?:/?|[/?]\S+)$', re.IGNORECASE) - - url = r.match(url_str) - if url: + try: + URLValidator()(url_str) return True - else: + except Exception: return False