Skip to content
/ git Public
forked from git/git

Commit

Permalink
refs: reject ref updates while GIT_QUARANTINE_PATH is set
Browse files Browse the repository at this point in the history
As documented in git-receive-pack(1), updating a ref from
within the pre-receive hook is dangerous and can corrupt
your repo. This patch forbids ref updates entirely during
the hook to make it harder for adventurous hook writers to
shoot themselves in the foot.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Apr 17, 2017
1 parent eaeed07 commit d8f4481
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Documentation/git-receive-pack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ This has a few user-visible effects and caveats:
3. The `pre-receive` hook MUST NOT update any refs to point to
quarantined objects. Other programs accessing the repository will
not be able to see the objects (and if the pre-receive hook fails,
those refs would become corrupted).
those refs would become corrupted). For safety, any ref updates
from within `pre-receive` are automatically rejected.


SEE ALSO
Expand Down
6 changes: 6 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,12 @@ int ref_transaction_commit(struct ref_transaction *transaction,
{
struct ref_store *refs = get_ref_store(NULL);

if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
}

return refs->be->transaction_commit(refs, transaction, err);
}

Expand Down
11 changes: 11 additions & 0 deletions t/t5547-push-quarantine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ test_expect_success 'rejected objects are removed' '
test_cmp expect actual
'

test_expect_success 'updating a ref from quarantine is forbidden' '
git init --bare update.git &&
write_script update.git/hooks/pre-receive <<-\EOF &&
read old new refname
git update-ref refs/heads/unrelated $new
exit 1
EOF
test_must_fail git push update.git HEAD &&
git -C update.git fsck
'

test_done

0 comments on commit d8f4481

Please sign in to comment.