Skip to content

Commit

Permalink
upload-pack: disallow object-info capability by default
Browse files Browse the repository at this point in the history
We added an "object-info" capability to the v2 upload-pack protocol in
a2ba162 (object-info: support for retrieving object info,
2021-04-20). In the almost 3 years since, we have not added any
client-side support, and it does not appear to exist in other
implementations either (JGit understands the verb on the server side,
but not on the client side).

Since this largely unused code is accessible over the network by
default, it increases the attack surface of upload-pack. I don't know of
any particularly severe problem, but one issue is that because of the
request/response nature of the v2 protocol, it will happily read an
unbounded number of packets, adding each one to a string list (without
regard to whether they are objects we know about, duplicates, etc).

This may be something we want to improve in the long run, but in the
short term it makes sense to disable the feature entirely. We'll add a
config option as an escape hatch for anybody who wants to develop the
feature further.

A more gentle option would be to add the config option to let people
disable it manually, but leave it enabled by default. But given that
there's no client side support, that seems like the wrong balance with
security.

Disabling by default will slow adoption a bit once client-side support
does become available (there were some patches[1] in 2022, but nothing
got merged and there's been nothing since). But clients have to deal
with older servers that do not understand the option anyway (and the
capability system handles that), so it will just be a matter of servers
flipping their config at that point (and hopefully once any unbounded
allocations have been addressed).

[jk: this is a patch that GitHub has been running for several years, but
     rebased forward and with a new commit message for upstream]

[1] https://lore.kernel.org/git/20220208231911.725273-1-calvinwan@google.com/

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
ttaylorr authored and gitster committed Feb 28, 2024
1 parent 179776f commit 8c735b1
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Documentation/config/transfer.txt
Original file line number Diff line number Diff line change
@@ -121,3 +121,7 @@ transfer.bundleURI::
information from the remote server (if advertised) and download
bundles before continuing the clone through the Git protocol.
Defaults to `false`.

transfer.advertiseObjectInfo::
When `true`, the `object-info` capability is advertised by
servers. Defaults to false.
14 changes: 13 additions & 1 deletion serve.c
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#include "trace2.h"

static int advertise_sid = -1;
static int advertise_object_info = -1;
static int client_hash_algo = GIT_HASH_SHA1;

static int always_advertise(struct repository *r UNUSED,
@@ -67,6 +68,17 @@ static void session_id_receive(struct repository *r UNUSED,
trace2_data_string("transfer", NULL, "client-sid", client_sid);
}

static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED)
{
if (advertise_object_info == -1 &&
repo_config_get_bool(r, "transfer.advertiseobjectinfo",
&advertise_object_info)) {
/* disabled by default */
advertise_object_info = 0;
}
return advertise_object_info;
}

struct protocol_capability {
/*
* The name of the capability. The server uses this name when
@@ -135,7 +147,7 @@ static struct protocol_capability capabilities[] = {
},
{
.name = "object-info",
.advertise = always_advertise,
.advertise = object_info_advertise,
.command = cap_object_info,
},
{
1 change: 0 additions & 1 deletion t/t5555-http-smart-common.sh
Original file line number Diff line number Diff line change
@@ -131,7 +131,6 @@ test_expect_success 'git upload-pack --advertise-refs: v2' '
fetch=shallow wait-for-done
server-option
object-format=$(test_oid algo)
object-info
0000
EOF
24 changes: 23 additions & 1 deletion t/t5701-git-serve.sh
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ test_expect_success 'test capability advertisement' '
fetch=shallow wait-for-done
server-option
object-format=$(test_oid algo)
object-info
EOF
cat >expect.trailer <<-EOF &&
0000
@@ -323,6 +322,8 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
# Test the basics of object-info
#
test_expect_success 'basics of object-info' '
test_config transfer.advertiseObjectInfo true &&
test-tool pkt-line pack >in <<-EOF &&
command=object-info
object-format=$(test_oid algo)
@@ -380,4 +381,25 @@ test_expect_success 'basics of bundle-uri: dies if not enabled' '
test_must_be_empty out
'

test_expect_success 'object-info missing from capabilities when disabled' '
test_config transfer.advertiseObjectInfo false &&
GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
--advertise-capabilities >out &&
test-tool pkt-line unpack <out >actual &&
! grep object.info actual
'

test_expect_success 'object-info commands rejected when disabled' '
test_config transfer.advertiseObjectInfo false &&
test-tool pkt-line pack >in <<-EOF &&
command=object-info
EOF
test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
grep invalid.command err
'

test_done

0 comments on commit 8c735b1

Please sign in to comment.