threads / discuss / 48898

clean filter run in top of repo with wrong GIT_WORK_TREE

Subject: clean filter run in top of repo with wrong GIT_WORK_TREE

## tl;dr

2 messages between Jul 17, 2018 and Jul 17, 2018.

replies: 1people: 1as markdown or json

Joey Hess· Jul 17, 2018, 16:58 UTC · lore

When git is running inside a subdirectory of the repository, and needs to run the clean filter, it runs it chdired back to the top of the repository. However, if git was run with a relative --work-tree, it passes that relative path in GIT_WORK_TREE on to the clean filter.

If git was run with eg, "--work-tree=..", the clean filter sees a work tree that is outside the repository. It might then read files located outside the repository. That seems like it could have security consequences, but it's certianly a surprising problem to need to deal with when writing a clean filter.

Brian posted a fix for a very similar bug in sequencer.c on the 14th, so it seems likely there are other occurances of the same problem elsewhere.

Demonstration of this bug:
joey@darkstar:~/tmp/repo>cat .gitattributes
* filter=foo
joey@darkstar:~/tmp/repo>git config filter.foo.clean
clean-filter %f
joey@darkstar:~/tmp/repo>cat ~/bin/clean-filter 
#!/bin/sh
pwd >&2
echo $GIT_WORK_TREE >&2
ls "$GIT_WORK_TREE/$1"
joey@darkstar:~/tmp/repo>cd foo/bar/
joey@darkstar:~/tmp/repo/foo/bar>ls
x
joey@darkstar:~/tmp/repo/foo/bar>touch x
joey@darkstar:~/tmp/repo/foo/bar>git --work-tree=../.. ls-files --modified
/home/joey/tmp/repo
../..
ls: cannot access '../../foo/bar/x': No such file or directory
git version 2.18.0
-- 
see shy jo
Joey Hess· Jul 17, 2018, 17:32 UTC · re: Joey Hess · lore

Re: clean filter run in top of repo with wrong GIT_WORK_TREE

The clean filter can work around this problem by chdir GIT_PREFIX, but needing to do this in unusual cases seems to be asking for bugs.

-- 
see shy jo

← back to recent threads