Skip to content

Commit

Permalink
Prevent setting SSH arguments in SSH URLs when using subprocess SSH c…
Browse files Browse the repository at this point in the history
…lient.
  • Loading branch information
jelmer committed Oct 29, 2017
1 parent fe7b856 commit 7116a0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -7,6 +7,10 @@
* Fix setting of origin in config when non-standard origin is passed into
``Repo.clone``. (Kenneth Lareau, #565)

* Prevent setting SSH arguments from SSH URLs when using SSH through a
subprocess. Note that Dulwich doesn't support cloning submodules.
(CVE 2017-1000117) (Jelmer Vernooij)

IMPROVEMENTS

* Silently ignored directories in ``Repo.stage``.
Expand Down
9 changes: 9 additions & 0 deletions dulwich/client.py
Expand Up @@ -1080,6 +1080,13 @@ def run_command(self, host, command, username=None, port=None):
raise NotImplementedError(self.run_command)


class StrangeHostname(Exception):
"""Refusing to connect to strange SSH hostname."""

def __init__(self, hostname):
super(StrangeHostname, self).__init__(hostname)


class SubprocessSSHVendor(SSHVendor):
"""SSH vendor that shells out to the local 'ssh' command."""

Expand All @@ -1090,6 +1097,8 @@ def run_command(self, host, command, username=None, port=None):
args.extend(['-p', str(port)])
if username is not None:
host = '%s@%s' % (username, host)
if host.startswith('-'):
raise StrangeHostname(hostname=host)
args.append(host)
proc = subprocess.Popen(args + [command], bufsize=0,
stdin=subprocess.PIPE,
Expand Down
10 changes: 10 additions & 0 deletions dulwich/tests/test_client.py
Expand Up @@ -50,6 +50,8 @@
HttpGitClient,
ReportStatusParser,
SendPackError,
StrangeHostname,
SubprocessSSHVendor,
UpdateRefsError,
default_urllib2_opener,
get_transport_and_path,
Expand Down Expand Up @@ -942,3 +944,11 @@ def test_config_proxy(self):
opener = default_urllib2_opener(config=config)
self.assertIn(urllib2.ProxyHandler,
list(map(lambda x: x.__class__, opener.handlers)))


class SubprocessSSHVendorTests(TestCase):

def test_run_command_dashes(self):
vendor = SubprocessSSHVendor()
self.assertRaises(StrangeHostname, vendor.run_command, '--weird-host',
'git-clone-url')

0 comments on commit 7116a0c

Please sign in to comment.