Skip to content

Commit 268d5bc

Browse files
committed
Merge branch 'jc/push-cert'
The "git push --signed" protocol extension did not limit what the "nonce" that is a server-chosen string can contain or how long it can be, which was unnecessarily lax. Limit both the length and the alphabet to a reasonably small space that can still have enough entropy. * jc/push-cert: push --signed: tighten what the receiving end can ask to sign
2 parents 6b1258b + afcb6ee commit 268d5bc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

send-pack.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,28 @@ static int atomic_push_failure(struct send_pack_args *args,
308308
failing_ref->name, failing_ref->status);
309309
}
310310

311+
#define NONCE_LEN_LIMIT 256
312+
313+
static void reject_invalid_nonce(const char *nonce, int len)
314+
{
315+
int i = 0;
316+
317+
if (NONCE_LEN_LIMIT <= len)
318+
die("the receiving end asked to sign an invalid nonce <%.*s>",
319+
len, nonce);
320+
321+
for (i = 0; i < len; i++) {
322+
int ch = nonce[i] & 0xFF;
323+
if (isalnum(ch) ||
324+
ch == '-' || ch == '.' ||
325+
ch == '/' || ch == '+' ||
326+
ch == '=' || ch == '_')
327+
continue;
328+
die("the receiving end asked to sign an invalid nonce <%.*s>",
329+
len, nonce);
330+
}
331+
}
332+
311333
int send_pack(struct send_pack_args *args,
312334
int fd[], struct child_process *conn,
313335
struct ref *remote_refs,
@@ -354,6 +376,7 @@ int send_pack(struct send_pack_args *args,
354376
push_cert_nonce = server_feature_value("push-cert", &len);
355377
if (!push_cert_nonce)
356378
die(_("the receiving end does not support --signed push"));
379+
reject_invalid_nonce(push_cert_nonce, len);
357380
push_cert_nonce = xmemdupz(push_cert_nonce, len);
358381
}
359382

0 commit comments

Comments
 (0)