Skip to content

Commit 631f6f1

Browse files
committed
Merge branch 'jc/push-cert' into maint
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 ba63bfa + afcb6ee commit 631f6f1

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
@@ -281,6 +281,28 @@ static int generate_push_cert(struct strbuf *req_buf,
281281
return update_seen;
282282
}
283283

284+
#define NONCE_LEN_LIMIT 256
285+
286+
static void reject_invalid_nonce(const char *nonce, int len)
287+
{
288+
int i = 0;
289+
290+
if (NONCE_LEN_LIMIT <= len)
291+
die("the receiving end asked to sign an invalid nonce <%.*s>",
292+
len, nonce);
293+
294+
for (i = 0; i < len; i++) {
295+
int ch = nonce[i] & 0xFF;
296+
if (isalnum(ch) ||
297+
ch == '-' || ch == '.' ||
298+
ch == '/' || ch == '+' ||
299+
ch == '=' || ch == '_')
300+
continue;
301+
die("the receiving end asked to sign an invalid nonce <%.*s>",
302+
len, nonce);
303+
}
304+
}
305+
284306
int send_pack(struct send_pack_args *args,
285307
int fd[], struct child_process *conn,
286308
struct ref *remote_refs,
@@ -323,6 +345,7 @@ int send_pack(struct send_pack_args *args,
323345
push_cert_nonce = server_feature_value("push-cert", &len);
324346
if (!push_cert_nonce)
325347
die(_("the receiving end does not support --signed push"));
348+
reject_invalid_nonce(push_cert_nonce, len);
326349
push_cert_nonce = xmemdupz(push_cert_nonce, len);
327350
}
328351

0 commit comments

Comments
 (0)