Skip to content

Commit 33cfccb

Browse files
peffgitster
authored andcommitted
submodule: allow only certain protocols for submodule fetches
Some protocols (like git-remote-ext) can execute arbitrary code found in the URL. The URLs that submodules use may come from arbitrary sources (e.g., .gitmodules files in a remote repository). Let's restrict submodules to fetching from a known-good subset of protocols. Note that we apply this restriction to all submodule commands, whether the URL comes from .gitmodules or not. This is more restrictive than we need to be; for example, in the tests we run: git submodule add ext::... which should be trusted, as the URL comes directly from the command line provided by the user. But doing it this way is simpler, and makes it much less likely that we would miss a case. And since such protocols should be an exception (especially because nobody who clones from them will be able to update the submodules!), it's not likely to inconvenience anyone in practice. Reported-by: Blake Burkhart <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a5adace commit 33cfccb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

git-submodule.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ require_work_tree
2222
wt_prefix=$(git rev-parse --show-prefix)
2323
cd_to_toplevel
2424

25+
# Restrict ourselves to a vanilla subset of protocols; the URLs
26+
# we get are under control of a remote repository, and we do not
27+
# want them kicking off arbitrary git-remote-* programs.
28+
#
29+
# If the user has already specified a set of allowed protocols,
30+
# we assume they know what they're doing and use that instead.
31+
: ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh}
32+
export GIT_ALLOW_PROTOCOL
33+
2534
command=
2635
branch=
2736
force=

t/t5815-submodule-protos.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
3+
test_description='test protocol whitelisting with submodules'
4+
. ./test-lib.sh
5+
. "$TEST_DIRECTORY"/lib-proto-disable.sh
6+
7+
setup_ext_wrapper
8+
setup_ssh_wrapper
9+
10+
test_expect_success 'setup repository with submodules' '
11+
mkdir remote &&
12+
git init remote/repo.git &&
13+
(cd remote/repo.git && test_commit one) &&
14+
# submodule-add should probably trust what we feed it on the cmdline,
15+
# but its implementation is overly conservative.
16+
GIT_ALLOW_PROTOCOL=ssh git submodule add remote:repo.git ssh-module &&
17+
GIT_ALLOW_PROTOCOL=ext git submodule add "ext::fake-remote %S repo.git" ext-module &&
18+
git commit -m "add submodules"
19+
'
20+
21+
test_expect_success 'clone with recurse-submodules fails' '
22+
test_must_fail git clone --recurse-submodules . dst
23+
'
24+
25+
test_expect_success 'setup individual updates' '
26+
rm -rf dst &&
27+
git clone . dst &&
28+
git -C dst submodule init
29+
'
30+
31+
test_expect_success 'update of ssh allowed' '
32+
git -C dst submodule update ssh-module
33+
'
34+
35+
test_expect_success 'update of ext not allowed' '
36+
test_must_fail git -C dst submodule update ext-module
37+
'
38+
39+
test_expect_success 'user can override whitelist' '
40+
GIT_ALLOW_PROTOCOL=ext git -C dst submodule update ext-module
41+
'
42+
43+
test_done

0 commit comments

Comments
 (0)