Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ done
unset _v

shared_git() {
env "${_shared_git_scrub[@]}" git "$@"
# `-c` overrides neutralize execution-capable settings a poisoned checkout
# could plant in its own .git/config: core.fsmonitor runs a command during
# `git status`, and the *Proxy/*Command hooks run during fetch.
env "${_shared_git_scrub[@]}" git \
-c core.fsmonitor= \
-c core.hooksPath=/dev/null \
-c core.sshCommand= \
-c core.askPass= \
-c credential.helper= \
-c protocol.ext.allow=never \
-c uploadpack.packObjectsHook= \
"$@"
}

scanner="$shared_dir/scripts/scan-commit-range.sh"
Expand Down
14 changes: 13 additions & 1 deletion scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ policy_git() {
for v in GIT_CONFIG_GLOBAL GIT_CONFIG_SYSTEM GIT_CONFIG_NOSYSTEM; do
scrub+=(-u "$v")
done
env "${scrub[@]}" git "$@"
# `-c` overrides neutralize execution-capable settings a poisoned cache could
# plant in its own .git/config: core.fsmonitor runs a command during `git
# status`, and the *Proxy/*Command hooks run during fetch. These must be off
# for every command that touches a cache we have not yet authenticated.
env "${scrub[@]}" git \
-c core.fsmonitor= \
-c core.hooksPath=/dev/null \
-c core.sshCommand= \
-c core.askPass= \
-c credential.helper= \
-c protocol.ext.allow=never \
-c uploadpack.packObjectsHook= \
"$@"
}

cleanup() {
Expand Down
13 changes: 12 additions & 1 deletion scripts/install-pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ done
unset _v

shared_git() {
env "${_shared_git_scrub[@]}" git "$@"
# `-c` overrides neutralize execution-capable settings a poisoned checkout
# could plant in its own .git/config: core.fsmonitor runs a command during
# `git status`, and the *Proxy/*Command hooks run during fetch.
env "${_shared_git_scrub[@]}" git \
-c core.fsmonitor= \
-c core.hooksPath=/dev/null \
-c core.sshCommand= \
-c core.askPass= \
-c credential.helper= \
-c protocol.ext.allow=never \
-c uploadpack.packObjectsHook= \
"$@"
}

shared_git -C "$shared_dir" rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
Expand Down
17 changes: 17 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ if VANA_POLICY_SHA="$policy_sha" "$bootstrap" bogus-action >/dev/null 2>&1; then
fi

printf '[remote "origin"]\n\turl = https://github.com/vana-com/.github\n' >"$test_root/spoof.gitconfig"
# A poisoned cache must not execute code through its own local config while it
# is being authenticated: core.fsmonitor runs a command during `git status`.
fsmonitor_home="$test_root/fsmonitor-home"
mkdir -p "$fsmonitor_home/vana-secret-scan/policy"
fsmonitor_cache="$fsmonitor_home/vana-secret-scan/policy/$policy_sha"
git clone -q "$root" "$fsmonitor_cache"
git -C "$fsmonitor_cache" remote set-url origin https://github.com/vana-com/.github.git
git -C "$fsmonitor_cache" checkout -q "$policy_sha"
printf '#!/bin/sh\ntouch %q\nexit 1\n' "$test_root/fsmonitor-fired" >"$test_root/evil-fsmonitor"
chmod 0755 "$test_root/evil-fsmonitor"
git -C "$fsmonitor_cache" config core.fsmonitor "$test_root/evil-fsmonitor"
XDG_DATA_HOME="$fsmonitor_home" VANA_POLICY_SHA="$policy_sha" "$bootstrap" status >/dev/null 2>&1 || true
if [[ -e "$test_root/fsmonitor-fired" ]]; then
printf 'expected bootstrap to neutralize core.fsmonitor on an unauthenticated cache\n' >&2
exit 1
fi

bootstrap_home="$test_root/bootstrap-home"
mkdir -p "$bootstrap_home/vana-secret-scan/policy"
bootstrap_cache="$bootstrap_home/vana-secret-scan/policy/$policy_sha"
Expand Down
Loading