git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 8/8] refs: check refnames as fully qualified when resolving

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 30, 2024, 04:54 UTC
Message-ID
<ZjB5dPoEoq8D6qzJ@tanuki>
In-Reply-To
<20240429083533.GG233423@coredump.intra.peff.net>
On Mon, Apr 29, 2024 at 04:35:33AM -0400, Jeff King wrote:
Show 9 quoted lines
> Most code paths for resolving refs end up in refs_resolve_ref_unsafe(),
> which checks the names using check_refname_format(). The names we have
> at this stage are always full refnames, but we pass the ALLOW_ONELEVEL
> flag so that the function allows pseudorefs like MERGE_HEAD. We should
> instead pass the FULLY_QUALIFIED flag, which lets check_refname_format()
> do some extra syntactic checks on those pseudorefs.
> 
> With this patch we'll refuse to read anything outside of refs/ that does
> not match the usual pseudoref syntax (all caps plus dashes). This should
s/dashes/underscores
Show 7 quoted lines
> not be a loss of functionality (since such refs cannot be written as of
> the previous commit), but may protect us from mischief. For example, you
> can ask for silly things like "info/refs", "rr-cache/<sha1>/postimage",
> or "objects/info/commit-graphs/commit-graph-chain". It's doubtful you
> can really do anything _too_ terrible there, but it seems like peeking
> at random files in .git in response to possibly untrusted input is
> something we should avoid.
Agreed.
[snip]
Show 17 quoted lines
> diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh
> index 120e1557d7..5fb780cb08 100755
> --- a/t/t1430-bad-ref-name.sh
> +++ b/t/t1430-bad-ref-name.sh
> @@ -400,4 +400,14 @@ test_expect_success 'update-ref refuses non-underscore outside of refs/' '
>  	test_grep "refusing to update ref with bad name" err
>  '
>  
> +test_expect_success REFFILES 'rev-parse refuses non-pseudoref outside of refs/' '
> +	git rev-parse HEAD >.git/bad &&
> +	test_must_fail git rev-parse --verify bad
> +'
> +
> +test_expect_success REFFILES 'rev-parse recognizes non-pseudoref via worktree' '
> +	git rev-parse HEAD >.git/bad &&
> +	test_must_fail git rev-parse --verify main-worktree/bad
> +'

Are these really specific to the REFFILES backend? I would expect that the reftable backend sohuld fail to parse those, too. The fact that we write into the repository directly during the test setup doesn't change this, because all this patch is about is that we don't want to parse random files in the Git repo. And that is something we should want to enforce for all backends.

Patrick
Previous: Jeff KingNext: Jeff King
Message 2 of 6 in “refs: check refnames as fully qualified when resolving”
  1. 8/8 refs: check refnames as fully qualified when resolvingJeff King, Apr 29, 2024
  2. Patrick SteinhardtApr 30, 2024
  3. Jeff KingApr 30, 2024
  4. Patrick SteinhardtApr 30, 2024
  5. Jeff KingMay 3, 2024
  6. Patrick SteinhardtMay 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.