t0411: add tests for cloning from partial repo

Cloning from a partial repository must not fetch missing objects into the partial repository, because that can lead to arbitrary code execution. Add a couple of test cases, pretending to the `upload-pack` command (and to that command only) that it is working on a repository owned by someone else. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Filip Hejsek committed Jan 28, 2024 at 04:29 UTC 5c5a4a1c05932378d259b1fdd9526cab971656a2
1 file changed +60
t/t0411-clone-from-partial.sh new
+60
@@ -0,0 +1,60 @@
1 +#!/bin/sh
2 +
3 +test_description='check that local clone does not fetch from promisor remotes'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success 'create evil repo' '
8 + git init tmp &&
9 + test_commit -C tmp a &&
10 + git -C tmp config uploadpack.allowfilter 1 &&
11 + git clone --filter=blob:none --no-local --no-checkout tmp evil &&
12 + rm -rf tmp &&
13 +
14 + git -C evil config remote.origin.uploadpack \"\$TRASH_DIRECTORY/fake-upload-pack\" &&
15 + write_script fake-upload-pack <<-\EOF &&
16 + echo >&2 "fake-upload-pack running"
17 + >"$TRASH_DIRECTORY/script-executed"
18 + exit 1
19 + EOF
20 + export TRASH_DIRECTORY &&
21 +
22 + # empty shallow file disables local clone optimization
23 + >evil/.git/shallow
24 +'
25 +
26 +test_expect_failure 'local clone must not fetch from promisor remote and execute script' '
27 + rm -f script-executed &&
28 + test_must_fail git clone \
29 + --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
30 + evil clone1 2>err &&
31 + ! grep "fake-upload-pack running" err &&
32 + test_path_is_missing script-executed
33 +'
34 +
35 +test_expect_failure 'clone from file://... must not fetch from promisor remote and execute script' '
36 + rm -f script-executed &&
37 + test_must_fail git clone \
38 + --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
39 + "file://$(pwd)/evil" clone2 2>err &&
40 + ! grep "fake-upload-pack running" err &&
41 + test_path_is_missing script-executed
42 +'
43 +
44 +test_expect_failure 'fetch from file://... must not fetch from promisor remote and execute script' '
45 + rm -f script-executed &&
46 + test_must_fail git fetch \
47 + --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
48 + "file://$(pwd)/evil" 2>err &&
49 + ! grep "fake-upload-pack running" err &&
50 + test_path_is_missing script-executed
51 +'
52 +
53 +test_expect_success 'pack-objects should fetch from promisor remote and execute script' '
54 + rm -f script-executed &&
55 + echo "HEAD" | test_must_fail git -C evil pack-objects --revs --stdout >/dev/null 2>err &&
56 + grep "fake-upload-pack running" err &&
57 + test_path_is_file script-executed
58 +'
59 +
60 +test_done