Skip to content

Commit e693237

Browse files
chriscoolgitster
authored andcommitted
list-objects-filter: disable 'sparse:path' filters
If someone wants to use as a filter a sparse file that is in the repository, something like "--filter=sparse:oid=<ref>:<path>" already works. So 'sparse:path' is only interesting if the sparse file is not in the repository. In this case though the current implementation has a big security issue, as it makes it possible to ask the server to read any file, like for example /etc/password, and to explore the filesystem, as well as individual lines of files. If someone is interested in using a sparse file that is not in the repository as a filter, then at the minimum a config option, such as "uploadpack.sparsePathFilter", should be implemented first to restrict the directory from which the files specified by 'sparse:path' can be read. For now though, let's just disable 'sparse:path' filters. Helped-by: Matthew DeVore <[email protected]> Helped-by: Jeff Hostetler <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa25c82 commit e693237

7 files changed

+37
-116
lines changed

Documentation/rev-list-options.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,6 @@ specification contained in the blob (or blob-expression) '<blob-ish>'
725725
to omit blobs that would not be not required for a sparse checkout on
726726
the requested refs.
727727
+
728-
The form '--filter=sparse:path=<path>' similarly uses a sparse-checkout
729-
specification contained in <path>.
730-
+
731728
The form '--filter=tree:<depth>' omits all blobs and trees whose depth
732729
from the root tree is >= <depth> (minimum depth if an object is located
733730
at multiple depths in the commits traversed). <depth>=0 will not include
@@ -737,6 +734,10 @@ tree and blobs which are referenced directly by a commit reachable from
737734
<commit> or an explicitly-given object. <depth>=2 is like <depth>=1
738735
while also including trees and blobs one more level removed from an
739736
explicitly-given commit or tree.
737+
+
738+
Note that the form '--filter=sparse:path=<path>' that wants to read
739+
from an arbitrary path on the filesystem has been dropped for security
740+
reasons.
740741

741742
--no-filter::
742743
Turn off any previous `--filter=` argument.

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ _git_fetch ()
15361536
return
15371537
;;
15381538
--filter=*)
1539-
__gitcomp "blob:none blob:limit= sparse:oid= sparse:path=" "" "${cur##--filter=}"
1539+
__gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
15401540
return
15411541
;;
15421542
--*)

list-objects-filter-options.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ static int gently_parse_list_objects_filter(
7878
return 0;
7979

8080
} else if (skip_prefix(arg, "sparse:path=", &v0)) {
81-
filter_options->choice = LOFC_SPARSE_PATH;
82-
filter_options->sparse_path_value = strdup(v0);
83-
return 0;
81+
if (errbuf) {
82+
strbuf_addstr(
83+
errbuf,
84+
_("sparse:path filters support has been dropped"));
85+
}
86+
return 1;
8487
}
8588
/*
8689
* Please update _git_fetch() in git-completion.bash when you
@@ -136,7 +139,6 @@ void list_objects_filter_release(
136139
{
137140
free(filter_options->filter_spec);
138141
free(filter_options->sparse_oid_value);
139-
free(filter_options->sparse_path_value);
140142
memset(filter_options, 0, sizeof(*filter_options));
141143
}
142144

list-objects-filter-options.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ enum list_objects_filter_choice {
1313
LOFC_BLOB_LIMIT,
1414
LOFC_TREE_DEPTH,
1515
LOFC_SPARSE_OID,
16-
LOFC_SPARSE_PATH,
1716
LOFC__COUNT /* must be last */
1817
};
1918

@@ -44,7 +43,6 @@ struct list_objects_filter_options {
4443
* choice.
4544
*/
4645
struct object_id *sparse_oid_value;
47-
char *sparse_path_value;
4846
unsigned long blob_limit_value;
4947
unsigned long tree_exclude_depth;
5048
};

list-objects-filter.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -478,27 +478,6 @@ static void *filter_sparse_oid__init(
478478
return d;
479479
}
480480

481-
static void *filter_sparse_path__init(
482-
struct oidset *omitted,
483-
struct list_objects_filter_options *filter_options,
484-
filter_object_fn *filter_fn,
485-
filter_free_fn *filter_free_fn)
486-
{
487-
struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
488-
d->omits = omitted;
489-
if (add_excludes_from_file_to_list(filter_options->sparse_path_value,
490-
NULL, 0, &d->el, NULL) < 0)
491-
die("could not load filter specification");
492-
493-
ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc);
494-
d->array_frame[d->nr].defval = 0; /* default to include */
495-
d->array_frame[d->nr].child_prov_omit = 0;
496-
497-
*filter_fn = filter_sparse;
498-
*filter_free_fn = filter_sparse_free;
499-
return d;
500-
}
501-
502481
typedef void *(*filter_init_fn)(
503482
struct oidset *omitted,
504483
struct list_objects_filter_options *filter_options,
@@ -514,7 +493,6 @@ static filter_init_fn s_filters[] = {
514493
filter_blobs_limit__init,
515494
filter_trees_depth__init,
516495
filter_sparse_oid__init,
517-
filter_sparse_path__init,
518496
};
519497

520498
void *list_objects_filter__init(

t/t5317-pack-objects-filter-objects.sh

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ test_expect_success 'verify normal and blob:limit packfiles have same commits/tr
277277
'
278278

279279
# Test sparse:path=<path> filter.
280+
# !!!!
281+
# NOTE: sparse:path filter support has been dropped for security reasons,
282+
# so the tests have been changed to make sure that using it fails.
283+
# !!!!
280284
# Use a local file containing a sparse-checkout specification to filter
281285
# out blobs not required for the corresponding sparse-checkout. We do not
282286
# require sparse-checkout to actually be enabled.
@@ -315,73 +319,24 @@ test_expect_success 'verify blob count in normal packfile' '
315319
test_cmp expected observed
316320
'
317321

318-
test_expect_success 'verify sparse:path=pattern1' '
319-
git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
320-
awk -f print_2.awk ls_files_result |
321-
sort >expected &&
322-
323-
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
322+
test_expect_success 'verify sparse:path=pattern1 fails' '
323+
test_must_fail git -C r3 pack-objects --revs --stdout \
324+
--filter=sparse:path=../pattern1 <<-EOF
324325
HEAD
325326
EOF
326-
git -C r3 index-pack ../filter.pack &&
327-
328-
git -C r3 verify-pack -v ../filter.pack >verify_result &&
329-
grep blob verify_result |
330-
awk -f print_1.awk |
331-
sort >observed &&
332-
333-
test_cmp expected observed
334-
'
335-
336-
test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
337-
git -C r3 verify-pack -v ../all.pack >verify_result &&
338-
grep -E "commit|tree" verify_result |
339-
awk -f print_1.awk |
340-
sort >expected &&
341-
342-
git -C r3 verify-pack -v ../filter.pack >verify_result &&
343-
grep -E "commit|tree" verify_result |
344-
awk -f print_1.awk |
345-
sort >observed &&
346-
347-
test_cmp expected observed
348327
'
349328

350-
test_expect_success 'verify sparse:path=pattern2' '
351-
git -C r3 ls-files -s sparse1 dir1/sparse1 >ls_files_result &&
352-
awk -f print_2.awk ls_files_result |
353-
sort >expected &&
354-
355-
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
329+
test_expect_success 'verify sparse:path=pattern2 fails' '
330+
test_must_fail git -C r3 pack-objects --revs --stdout \
331+
--filter=sparse:path=../pattern2 <<-EOF
356332
HEAD
357333
EOF
358-
git -C r3 index-pack ../filter.pack &&
359-
360-
git -C r3 verify-pack -v ../filter.pack >verify_result &&
361-
grep blob verify_result |
362-
awk -f print_1.awk |
363-
sort >observed &&
364-
365-
test_cmp expected observed
366-
'
367-
368-
test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
369-
git -C r3 verify-pack -v ../all.pack >verify_result &&
370-
grep -E "commit|tree" verify_result |
371-
awk -f print_1.awk |
372-
sort >expected &&
373-
374-
git -C r3 verify-pack -v ../filter.pack >verify_result &&
375-
grep -E "commit|tree" verify_result |
376-
awk -f print_1.awk |
377-
sort >observed &&
378-
379-
test_cmp expected observed
380334
'
381335

382336
# Test sparse:oid=<oid-ish> filter.
383-
# Like sparse:path, but we get the sparse-checkout specification from
384-
# a blob rather than a file on disk.
337+
# Use a blob containing a sparse-checkout specification to filter
338+
# out blobs not required for the corresponding sparse-checkout. We do not
339+
# require sparse-checkout to actually be enabled.
385340

386341
test_expect_success 'setup r4' '
387342
git init r4 &&

t/t6112-rev-list-filters-objects.sh

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ test_expect_success 'verify blob:limit=1m' '
157157
'
158158

159159
# Test sparse:path=<path> filter.
160+
# !!!!
161+
# NOTE: sparse:path filter support has been dropped for security reasons,
162+
# so the tests have been changed to make sure that using it fails.
163+
# !!!!
160164
# Use a local file containing a sparse-checkout specification to filter
161165
# out blobs not required for the corresponding sparse-checkout. We do not
162166
# require sparse-checkout to actually be enabled.
@@ -176,37 +180,20 @@ test_expect_success 'setup r3' '
176180
echo sparse1 >pattern2
177181
'
178182

179-
test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
180-
git -C r3 ls-files -s sparse1 sparse2 >ls_files_result &&
181-
awk -f print_2.awk ls_files_result |
182-
sort >expected &&
183-
184-
git -C r3 rev-list --quiet --objects --filter-print-omitted \
185-
--filter=sparse:path=../pattern1 HEAD >revs &&
186-
awk -f print_1.awk revs |
187-
sed "s/~//" |
188-
sort >observed &&
189-
190-
test_cmp expected observed
183+
test_expect_success 'verify sparse:path=pattern1 fails' '
184+
test_must_fail git -C r3 rev-list --quiet --objects \
185+
--filter-print-omitted --filter=sparse:path=../pattern1 HEAD
191186
'
192187

193-
test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
194-
git -C r3 ls-files -s sparse2 dir1/sparse2 >ls_files_result &&
195-
awk -f print_2.awk ls_files_result |
196-
sort >expected &&
197-
198-
git -C r3 rev-list --quiet --objects --filter-print-omitted \
199-
--filter=sparse:path=../pattern2 HEAD >revs &&
200-
awk -f print_1.awk revs |
201-
sed "s/~//" |
202-
sort >observed &&
203-
204-
test_cmp expected observed
188+
test_expect_success 'verify sparse:path=pattern2 fails' '
189+
test_must_fail git -C r3 rev-list --quiet --objects \
190+
--filter-print-omitted --filter=sparse:path=../pattern2 HEAD
205191
'
206192

207193
# Test sparse:oid=<oid-ish> filter.
208-
# Like sparse:path, but we get the sparse-checkout specification from
209-
# a blob rather than a file on disk.
194+
# Use a blob containing a sparse-checkout specification to filter
195+
# out blobs not required for the corresponding sparse-checkout. We do not
196+
# require sparse-checkout to actually be enabled.
210197

211198
test_expect_success 'setup r3 part 2' '
212199
echo dir1/ >r3/pattern &&

0 commit comments

Comments
 (0)