Secure urls before sending to Popen.

This commit is contained in:
Michael Lazar
2016-09-11 19:52:56 -07:00
parent 20b59d5c31
commit ed5292d9b4

View File

@@ -15,6 +15,7 @@ from contextlib import contextmanager
from tempfile import NamedTemporaryFile
import six
from six.moves.urllib.parse import quote
from kitchen.text.display import textual_width_chop
from mailcap_fix import mailcap
@@ -468,7 +469,12 @@ class Terminal(object):
"""
if self.display:
command = "import webbrowser; webbrowser.open_new_tab('%s')" % url
# Note that we need to sanitize the url before inserting it into
# the python code to prevent injection attacks.
command = (
"import webbrowser\n"
"from six.moves.urllib.parse import unquote\n"
"webbrowser.open_new_tab(unquote('%s'))" % quote(url))
args = [sys.executable, '-c', command]
with self.loader('Opening page in a new window'), \
open(os.devnull, 'ab+', 0) as null: