Blame SOURCES/0001-submodule-allow-only-certain-protocols-for-submodule.patch

fdd391
From 6d69680505dbbc484178105815ed624fab40b2de Mon Sep 17 00:00:00 2001
fdd391
From: Petr Stodulka <pstodulk@redhat.com>
fdd391
Date: Wed, 28 Oct 2015 15:03:01 +0100
fdd391
Subject: [PATCH 1/5] submodule: allow only certain protocols for submodule
fdd391
 fetches
fdd391
fdd391
Some protocols (like git-remote-ext) can execute arbitrary
fdd391
code found in the URL. The URLs that submodules use may come
fdd391
from arbitrary sources (e.g., .gitmodules files in a remote
fdd391
repository). Let's restrict submodules to fetching from a
fdd391
known-good subset of protocols.
fdd391
fdd391
Note that we apply this restriction to all submodule
fdd391
commands, whether the URL comes from .gitmodules or not.
fdd391
This is more restrictive than we need to be; for example, in
fdd391
the tests we run:
fdd391
fdd391
  git submodule add ext::...
fdd391
fdd391
which should be trusted, as the URL comes directly from the
fdd391
command line provided by the user. But doing it this way is
fdd391
simpler, and makes it much less likely that we would miss a
fdd391
case. And since such protocols should be an exception
fdd391
(especially because nobody who clones from them will be able
fdd391
to update the submodules!), it's not likely to inconvenience
fdd391
anyone in practice.
fdd391
---
fdd391
 git-submodule.sh            |  9 +++++++++
fdd391
 t/t5815-submodule-protos-sh | 43 +++++++++++++++++++++++++++++++++++++++++++
fdd391
 2 files changed, 52 insertions(+)
fdd391
 create mode 100644 t/t5815-submodule-protos-sh
fdd391
fdd391
diff --git a/git-submodule.sh b/git-submodule.sh
fdd391
index 79bfaac..bec3362 100755
fdd391
--- a/git-submodule.sh
fdd391
+++ b/git-submodule.sh
fdd391
@@ -19,6 +19,15 @@ OPTIONS_SPEC=
fdd391
 . git-parse-remote
fdd391
 require_work_tree
fdd391
 
fdd391
+# Restrict ourselves to a vanilla subset of protocols; the URLs
fdd391
+# we get are under control of a remote repository, and we do not
fdd391
+# want them kicking off arbitrary git-remote-* programs.
fdd391
+#
fdd391
+# If the user has already specified a set of allowed protocols,
fdd391
+# we assume they know what they're doing and use that instead.
fdd391
+: ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh}
fdd391
+export GIT_ALLOW_PROTOCOL
fdd391
+
fdd391
 command=
fdd391
 branch=
fdd391
 force=
fdd391
diff --git a/t/t5815-submodule-protos-sh b/t/t5815-submodule-protos-sh
fdd391
new file mode 100644
fdd391
index 0000000..06f55a1
fdd391
--- /dev/null
fdd391
+++ b/t/t5815-submodule-protos-sh
fdd391
@@ -0,0 +1,43 @@
fdd391
+#!/bin/sh
fdd391
+
fdd391
+test_description='test protocol whitelisting with submodules'
fdd391
+. ./test-lib.sh
fdd391
+. "$TEST_DIRECTORY"/lib-proto-disable.sh
fdd391
+
fdd391
+setup_ext_wrapper
fdd391
+setup_ssh_wrapper
fdd391
+
fdd391
+test_expect_success 'setup repository with submodules' '
fdd391
+	mkdir remote &&
fdd391
+	git init remote/repo.git &&
fdd391
+	(cd remote/repo.git && test_commit one) &&
fdd391
+	# submodule-add should probably trust what we feed it on the cmdline,
fdd391
+	# but its implementation is overly conservative.
fdd391
+	GIT_ALLOW_PROTOCOL=ssh git submodule add remote:repo.git ssh-module &&
fdd391
+	GIT_ALLOW_PROTOCOL=ext git submodule add "ext::fake-remote %S repo.git" ext-module &&
fdd391
+	git commit -m "add submodules"
fdd391
+'
fdd391
+
fdd391
+test_expect_success 'clone with recurse-submodules fails' '
fdd391
+	test_must_fail git clone --recurse-submodules . dst
fdd391
+'
fdd391
+
fdd391
+test_expect_success 'setup individual updates' '
fdd391
+	rm -rf dst &&
fdd391
+	git clone . dst &&
fdd391
+	git -C dst submodule init
fdd391
+'
fdd391
+
fdd391
+test_expect_success 'update of ssh allowed' '
fdd391
+	git -C dst submodule update ssh-module
fdd391
+'
fdd391
+
fdd391
+test_expect_success 'update of ext not allowed' '
fdd391
+	test_must_fail git -C dst submodule update ext-module
fdd391
+'
fdd391
+
fdd391
+test_expect_success 'user can override whitelist' '
fdd391
+	GIT_ALLOW_PROTOCOL=ext git -C dst submodule update ext-module
fdd391
+'
fdd391
+
fdd391
+test_done
fdd391
-- 
fdd391
2.1.0
fdd391