Greptile found three ways a generated setup could still place an
executable hook in the sandbox repository, which a later accepted
`git commit` then runs on the host:
- git init --template=<dir> (any unvetted git option)
- option values attached to the flag: cp --target-directory=.git,
cp -t.git, tar --directory=.git
- archive members: tar -xf / unzip of an archive holding
.git/hooks/pre-commit
Fixes:
- allowlist options per git subcommand; --template, --separate-git-dir,
-c, --exec-path and the rest are refused
- treat every suffix of an option argument as a possible attached value
and apply the in-sandbox / no-.git path check to it
- before tar -x or unzip, open every existing file argument with
tarfile/zipfile and refuse unknown formats, links, special files and
members that are absolute, contain .., or have a .git component;
refuse unzip wildcards and run setup with stdin=/dev/null
- run setup git commands with -c core.hooksPath=/dev/null as defense
in depth
Each sequence has a real-execution test in tests/test_invariant_runner.py
that fails on the previous head and passes now.
Signed-off-by: Wen <jwcastillo@gmail.com>