Skip to content

Commit 8c735b1

Browse files
ttaylorrgitster
authored andcommitted
upload-pack: disallow object-info capability by default
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/[email protected]/ Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 179776f commit 8c735b1

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

Documentation/config/transfer.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@ transfer.bundleURI::
121121
information from the remote server (if advertised) and download
122122
bundles before continuing the clone through the Git protocol.
123123
Defaults to `false`.
124+
125+
transfer.advertiseObjectInfo::
126+
When `true`, the `object-info` capability is advertised by
127+
servers. Defaults to false.

serve.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "trace2.h"
1313

1414
static int advertise_sid = -1;
15+
static int advertise_object_info = -1;
1516
static int client_hash_algo = GIT_HASH_SHA1;
1617

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

71+
static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED)
72+
{
73+
if (advertise_object_info == -1 &&
74+
repo_config_get_bool(r, "transfer.advertiseobjectinfo",
75+
&advertise_object_info)) {
76+
/* disabled by default */
77+
advertise_object_info = 0;
78+
}
79+
return advertise_object_info;
80+
}
81+
7082
struct protocol_capability {
7183
/*
7284
* The name of the capability. The server uses this name when
@@ -135,7 +147,7 @@ static struct protocol_capability capabilities[] = {
135147
},
136148
{
137149
.name = "object-info",
138-
.advertise = always_advertise,
150+
.advertise = object_info_advertise,
139151
.command = cap_object_info,
140152
},
141153
{

t/t5555-http-smart-common.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ test_expect_success 'git upload-pack --advertise-refs: v2' '
131131
fetch=shallow wait-for-done
132132
server-option
133133
object-format=$(test_oid algo)
134-
object-info
135134
0000
136135
EOF
137136

t/t5701-git-serve.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ test_expect_success 'test capability advertisement' '
2020
fetch=shallow wait-for-done
2121
server-option
2222
object-format=$(test_oid algo)
23-
object-info
2423
EOF
2524
cat >expect.trailer <<-EOF &&
2625
0000
@@ -323,6 +322,8 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
323322
# Test the basics of object-info
324323
#
325324
test_expect_success 'basics of object-info' '
325+
test_config transfer.advertiseObjectInfo true &&
326+
326327
test-tool pkt-line pack >in <<-EOF &&
327328
command=object-info
328329
object-format=$(test_oid algo)
@@ -380,4 +381,25 @@ test_expect_success 'basics of bundle-uri: dies if not enabled' '
380381
test_must_be_empty out
381382
'
382383

384+
test_expect_success 'object-info missing from capabilities when disabled' '
385+
test_config transfer.advertiseObjectInfo false &&
386+
387+
GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
388+
--advertise-capabilities >out &&
389+
test-tool pkt-line unpack <out >actual &&
390+
391+
! grep object.info actual
392+
'
393+
394+
test_expect_success 'object-info commands rejected when disabled' '
395+
test_config transfer.advertiseObjectInfo false &&
396+
397+
test-tool pkt-line pack >in <<-EOF &&
398+
command=object-info
399+
EOF
400+
401+
test_must_fail test-tool serve-v2 --stateless-rpc <in 2>err &&
402+
grep invalid.command err
403+
'
404+
383405
test_done

0 commit comments

Comments
 (0)